zz 4 سال پیش
والد
کامیت
414b48db52

+ 73 - 6
app/Console/Commands/Channel/ReportUserAndOrderToChannel.php

@@ -8,6 +8,8 @@
 
 namespace App\Console\Commands\Channel;
 
+use App\Modules\Channel\Services\ReportToChannelUserAndOrderService;
+use GuzzleHttp\Client;
 use Illuminate\Console\Command;
 use DB;
 
@@ -34,20 +36,85 @@ class ReportUserAndOrderToChannel extends Command
      *
      * @return mixed
      */
-    public function handle(){
+    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(){
 
+
+    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 = DB::table('report_to_channel_users')->where('created_at','>=',$date)
-            ->where('report_status',0)
-            ->select('id','uid','distribution_channel_id','register_ip','user_agent','user_created_at')->get();
-        if(!$result)return ;
+        $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]);
+
 
         }
     }

+ 1 - 0
app/Jobs/AsyncOrderStats.php

@@ -111,6 +111,7 @@ class AsyncOrderStats implements ShouldQueue
                '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)){
                return ;

+ 2 - 1
app/Jobs/AsyncUserRegister.php

@@ -63,7 +63,8 @@ class AsyncUserRegister implements ShouldQueue
                 'distribution_channel_id'=>$this->distribution_channel_id,
                 'register_ip'=>$this->register_ip,
                 'user_agent'=>$this->user_agent,
-                'user_created_at'=>$this->user_created_at
+                'user_created_at'=>$this->user_created_at,
+                'event'=>'user'
             ]])->getBody()->getContents();
             if($result && str_contains(strtolower($result),self::SUCCESS)){
                 return ;

+ 21 - 1
app/Modules/Channel/Services/ReportToChannelUserAndOrderService.php

@@ -10,6 +10,9 @@ namespace App\Modules\Channel\Services;
 
 
 
+use App\Modules\Channel\Models\ReportToChannelOrders;
+use App\Modules\Channel\Models\ReportToChannelUsers;
+
 class ReportToChannelUserAndOrderService
 {
     public static $user_type = 'user';
@@ -22,8 +25,25 @@ class ReportToChannelUserAndOrderService
     }
 
 
+    public static function updateUserErrorRecord($id,$data){
+        ReportToChannelUsers::where('id',$id)->update($data);
+    }
 
-    public static function createUserErrorRecord($uid,$distribution_channel_id,$register_ip,$user_agent,$user_created_at){
+    public static function updateOrderErrorRecord($id,$data){
+        ReportToChannelOrders::where('id',$id)->update($data);
+    }
+
+    public static function getUserErrorRecord($date){
+        return ReportToChannelUsers::where('report_status',0)
+            ->where('created_at','>=',$date)
+            ->select('id','uid','distribution_channel_id','register_ip','user_agent','user_created_at')
+            ->get();
+    }
 
+    public static function getOrderErrorRecord($date){
+        return ReportToChannelOrders::where('report_status',0)
+            ->where('created_at','>=',$date)
+            ->select('id','uid','distribution_channel_id','price','order_created_at')
+            ->get();
     }
 }