params = $params; } public function handle() { $itemId = data_get($this->params, 'item_id', null); try { $userInfo = UserModel::query()->where('code', $this->params['user_uid'])->first(['coins', 'balance', 'code']); // 1:金币;2:现金 if ($this->params['currency_type'] == 1) { $amount = $userInfo->coins; } else { $amount = $userInfo->balance; } $beforeAmount = 0; if ($amount != 0) { switch ($this->params['way']) { case 1: if ($amount < $this->params['amount']) { $beforeAmount = $amount; $amount = $amount + $this->params['amount']; } else { $beforeAmount = $amount - $this->params['amount']; } break; case 2: $beforeAmount = $amount + $this->params['amount']; break; } } else { if ($this->params['way'] == 2) { $beforeAmount = $amount + $this->params['amount']; } } $saveData = [ 'user_uid' => $userInfo->code, 'way' => $this->params['way'], 'currency_type' => $this->params['currency_type'], 'amount' => $this->params['amount'], 'before_amount' => $beforeAmount, 'after_amount' => $amount, 'type' => $this->params['type'], 'remark' => ChangeLogConstant::TYPE_TEXT[$this->params['type']], ]; if (!is_null($itemId)) { // 关联ID $saveData['item_id'] = $itemId; } $res = ChangeLogModel::query()->create($saveData); if (!$res) { logger('SaveChangeLogJob-储存帐变失败', $saveData); } } catch (\Exception $exception) { logger('SaveChangeLogJob', [$exception->getMessage()]); } } }