123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2020/12/24
- * Time: 16:47
- */
- namespace App\Console\Commands\Channel;
- use App\Modules\Channel\Services\ReportToChannelUserAndOrderService;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- use DB;
- class ReportUserAndOrderToChannel extends Command
- {
- /**
- * 执行命令 php artisan generate_order_day_stat
- *
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'channel:ReportUserAndOrderToChannel {--type=}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '渠道订单推送异常重试';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- const SUCCESS = 'success';
- public function handle(){
- $date = date('Y-m-d H:i:s',time()-3600);
- $type = $this->option('type');
- if($type == 'users'){
- $this->reportUsers($date);
- }
- if($type == 'orders'){
- $this->reportOrders($date);
- }
- }
- private function reportOrders($date){
- $result = ReportToChannelUserAndOrderService::getOrderErrorRecord($date);
- if(!$result) return ;
- $client = new Client(['timeout'=>5.0]);
- foreach ($result as $item){
- $distribution_channel_id = $item->distribution_channel_id;
- $uid = $item->uid;
- $price = $item->price;
- $order_created_at = $item->order_created_at;
- $link = ReportToChannelUserAndOrderService::getReportUrl($distribution_channel_id,ReportToChannelUserAndOrderService::$user_type);
- try{
- $result = $client->request('post',$link,['form_params'=>[
- 'uid'=>$uid,
- 'distribution_channel_id'=>$distribution_channel_id,
- 'price'=>$price,
- 'order_created_at'=>$order_created_at,
- 'event'=>'order'
- ]])->getBody()->getContents();
- if($result && str_contains(strtolower($result),self::SUCCESS)){
- ReportToChannelUserAndOrderService::updateOrderErrorRecord($item->id,['report_status'=>2]);
- return ;
- }
- $error = 'result error ,'.$result;
- }catch (\Exception $e){
- $error = 'exception,'.$e->getMessage();
- }
- ReportToChannelUserAndOrderService::updateOrderErrorRecord($item->id,['report_status'=>1,'error_msg'=>$error]);
- }
- }
- private function reportUsers($date){
- $result = ReportToChannelUserAndOrderService::getUserErrorRecord($date);
- if(!$result) return ;
- $client = new Client(['timeout'=>5.0]);
- foreach ($result as $item){
- $distribution_channel_id = $item->distribution_channel_id;
- $uid = $item->uid;
- $register_ip = $item->register_ip;
- $user_agent = $item->user_agent;
- $user_created_at = $item->user_created_at;
- $link = ReportToChannelUserAndOrderService::getReportUrl($distribution_channel_id,ReportToChannelUserAndOrderService::$user_type);
- try{
- $result = $client->request('post',$link,['form_params'=>[
- 'uid'=>$uid,
- 'distribution_channel_id'=>$distribution_channel_id,
- 'register_ip'=>$register_ip,
- 'user_agent'=>$user_agent,
- 'user_created_at'=>$user_created_at,
- 'event'=>'user'
- ]])->getBody()->getContents();
- if($result && str_contains(strtolower($result),self::SUCCESS)){
- ReportToChannelUserAndOrderService::updateUserErrorRecord($item->id,['report_status'=>2]);
- return ;
- }
- $error = 'result error ,'.$result;
- }catch (\Exception $e){
- $error = 'exception,'.$e->getMessage();
- }
- ReportToChannelUserAndOrderService::updateUserErrorRecord($item->id,['report_status'=>1,'error_msg'=>$error]);
- }
- }
- }
|