123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2020/12/24
- * Time: 11:36
- */
- namespace App\Jobs;
- use App\Modules\Channel\Services\ReportToChannelUserAndOrderService;
- use DB;
- use GuzzleHttp\Client;
- use Illuminate\Bus\Queueable;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- /**
- * 回传订单给渠道
- * Class AsyncUserRegister
- * @package App\Jobs\
- */
- class AsyncUserRegister implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- private $uid;
- private $distribution_channel_id;
- private $register_ip;
- private $user_agent;
- private $user_created_at;
- const SUCCESS = 'success';
- public function __construct($uid,$distribution_channel_id,$register_ip,$user_agent,$user_created_at){
- $this->uid = $uid;
- $this->distribution_channel_id = $distribution_channel_id;
- $this->register_ip = $register_ip;
- $this->user_agent = $user_agent;
- $this->user_created_at = $user_created_at;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- $this->reportToChannel();
- $this->fireRegisterReport();
- }
- private function reportToChannel(){
- $link = ReportToChannelUserAndOrderService::getReportUrl($this->distribution_channel_id,ReportToChannelUserAndOrderService::$user_type);
- if(!$link) return ;
- $client = new Client(['timeout'=>3.0]);
- try{
- $result = $client->request('post',$link,['form_params'=>[
- 'uid'=>$this->uid,
- 'distribution_channel_id'=>$this->distribution_channel_id,
- 'register_ip'=>$this->register_ip,
- 'user_agent'=>$this->user_agent,
- 'user_created_at'=>$this->user_created_at,
- 'event'=>'user',
- 'source'=>'wangduyun'
- ]])->getBody()->getContents();
- if($result && str_contains(strtolower($result),self::SUCCESS)){
- return ;
- }
- $error = 'result error ,'.$result;
- }catch (\Exception $e){
- $error = 'exception,'.$e->getMessage();
- }
- DB::table('report_to_channel_users')->insert([
- 'uid'=>$this->uid,
- 'distribution_channel_id'=>$this->distribution_channel_id,
- 'register_ip'=>$this->register_ip,
- 'user_agent'=>$this->user_agent,
- 'user_created_at'=>$this->user_created_at,
- 'report_status'=>0,
- 'error_msg'=>$error,
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s'),
- ]);
- }
- private function fireRegisterReport(){
- $client = new Client();
- $ip = $this->register_ip;
- $register_time = $this->user_created_at;
- $reportData = [
- 'platform' => 'wangduyun',
- 'register' => [
- 'uid' => $this->uid,
- 'channel_id' => $this->distribution_channel_id,
- 'register_time' => $register_time,
- 'register_ip' => $ip,
- ]
- ];
- $record = [
- 'uid'=>$this->uid,
- 'ip'=>$ip,
- 'register_time'=>$register_time,
- 'created_at'=>date('Y-m-d H:i:s'),
- 'updated_at'=>date('Y-m-d H:i:s'),
- ];
- $host = 'https://firetrack.wd.amanbook.com';
- try{
- // 执行上报
- $client->post($host . '/api/reportRegister', [
- 'headers' => [
- 'x-code' => 'Mvnx1Yr3O8i!TS5u'
- ],
- 'json' => $reportData
- ]);
- }catch (\Exception $e){
- \Log::error($e);
- $record['status'] = 2;
- DB::table('fire_user_report_record')->insert($record);
- }
- }
- }
|