user_id = $user_id; $this->from_user_id = $from_user_id; } /** * Execute the job. * * @return void */ public function handle() { try { $start_time = env('APP_ENV') == 'producation'?'2020-12-24':'2020-12-22'; if (date('Y-m-d') < $start_time) return true; $user = User::find($this->from_user_id); if (empty($user)) throw new \Exception("用户不存在", 1); $log = $user->inviteLogs()->where('user_id',$this->user_id)->first(); if (empty($log)) throw new \Exception("分享记录不存在", 1); $coin = $log->type=='FIRST'?10:1; $this->sendCoin($user, $this->user_id, $coin); return true; } catch (\Exception $e) { $this->getError($e); return false; } } public function sendCoin($user, $login_user_id, $coin) { try { $remark='分享用户'; //判断记录是否存在 $count = $user->coinLogs()->where(['type'=>CoinLog::RECSYSTEM, 'coin'=>$coin, 'remark'=>$remark,'type_id'=>$login_user_id])->count(); if ($count) return false; \DB::beginTransaction(); //增加福币记录 $user->addCoinLog(CoinLog::RECSYSTEM, $login_user_id, $coin, $remark); //修改福币钱包 $user->updateCoinInfo('add', $coin, 'other'); \DB::commit(); return true; } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return false; } } }