user_id = $user_id; } /** * Execute the job. * * @return void */ public function handle() { try { $user = User::find($this->user_id); //连续签到天数 $sign_days = UserSign::where('user_id', $user->id)->value('sign_days') ?: 0; if($sign_days == 0) return; //是否新用户 $logs = $user->signLogs()->signType(SignLog::NEWYEARTYPE)->order('sign_date')->pluck('sign_date')->toArray(); $is_new = 0; if (count($logs) < 4 && $user->created_at > '2020-12-31 23:59:59' && $sign_days == count($logs)) { $is_new = 1; } //\Log::info('签到天数---'.$sign_days); //新用户 if ($is_new) { $new_coin = config('sign.new'); $this->sendCoin($user, $new_coin[$sign_days], $sign_days, 1); } else { $old_coin = config('sign.old'); $this->sendCoin($user, $old_coin[$sign_days], $sign_days); //赠送会员 $rank = config('sign.rank'); if (!empty($rank[$sign_days])) { $user->addSuperRank($rank[$sign_days], $month = 0, $type = RankHistory::SIGNNEWYEAR); } } }catch (\Exception $e) { $this->getError($e); } } public function sendCoin($user, $coin, $count,$is_new=0) { try { $remark=$is_new ? '新用户连续'.$count.'天签到' : '连续'.$count.'天签到'; \DB::beginTransaction(); //增加福币记录 $user->addCoinLog(CoinLog::RECSYSTEM, 0, $coin, $remark); //修改福币钱包 $user->updateCoinInfo('add', $coin, 'other'); \DB::commit(); return true; } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return false; } } }