user_id = $array['user_id']; $this->other_user_id = $array['other_user_id']; $this->score = $array['score']; $this->type = $array['type']; $this->message = $array['message']; $this->status = isset($array['status']) ? $array['status'] : 0; $container = new Container(); $this->sms = new Sms($container); } /** * Execute the job. * * @return void */ public function handle() { try { $uid = $this->getAccountUserID($this->user_id); $other_uid = $this->getAccountUserID($this->other_user_id); if (empty($uid)) { return; } $data = [ 'mp'=>'LOVE', 'score'=>$this->score, 'type'=>$this->type, 'message'=>$this->message, 'other_uid'=>$other_uid, 'status'=>$this->status, ]; $url = config('app.account_url').'/api/change/user/'.$uid.'/score'; $result = json_decode(Http::http($url, $data, 'POST'),true); //\Log::info('syncScore success'); } catch (\Exception $e) { //\Log::info('syncScore failure'); $message = '用户id: '.$this->user_id.'同步积分失败'; $this->sms->sentMessage($this->mobile, $message); } } public function getAccountUserID($user_id) { $user = User::with('wechat')->where('id', $user_id)->first(); if (empty($user)) { return $uid = 0; } if ($user->uid) { $uid = $user->uid; }else{ if (empty($user->wechat)) { return; } $url = config('app.account_url').'/api/user'; $data = [ 'mobile' => $user->mobile, 'name' => $user->name, 'nickname' => $user->wechat->nickname, 'gender' => $user->wechat->gender, 'city' => $user->wechat->city, 'province' => $user->wechat->province, 'country' => $user->wechat->country, 'unionid' => $user->wechat->unionid, 'avatar' => $user->wechat->avatar2?$user->wechat->avatar2:$user->wechat->avatar, ]; try { $account_user = json_decode(Http::http($url, $data, 'POST'), true); } catch (Exception $e) { $message = $e->getMessage(); Messenger::sendSMS('15872844805', $message); } if (isset($account_user['id'])) { $uid = $account_user['id']; $user->uid = $uid; $user->save(); }else{ $uid = 0; } } return $uid; } }