123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?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();
- }
- 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'
- ]])->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'),
- ]);
- }
- }
|