26 次代碼提交 72d96e19cc ... 81c4dd728d

作者 SHA1 備註 提交日期
  zz 81c4dd728d Merge branch 'master' of 47.110.49.99:wangdu/wangdu_public_api 4 年之前
  zz 2ef7f2a559 report resister 4 年之前
  zz fd5cde90bf pay alert limit 4 年之前
  zz 628e380ffc order aldert 4 年之前
  zz e104d86f25 Merge branch 'master' of 47.110.49.99:wangdu/wangdu_public_api 4 年之前
  zz f76bee4f3d finance sandpay 4 年之前
  zz 87a91caf89 Merge branch 'master' of 47.110.49.99:wangdu/wangdu_public_api 4 年之前
  zz 051c859e99 order alert 4 年之前
  zz 8562925b76 Merge branch 'master' of 47.110.49.99:wangdu/wangdu_public_api 4 年之前
  zz 190d233d7e icon 4 年之前
  zz 8618f5795b Merge branch 'master' of 47.110.49.99:wangdu/wangdu_public_api 4 年之前
  zz f35494a821 job 4 年之前
  zz e69d799482 pay 4 年之前
  zhoulj 8d05b9e4ee add get_new_book_test_type 4 年之前
  zhoulj 87acc1a004 1 4 年之前
  zhoulj d94ab6bc99 内部站点配置 4 年之前
  zhoulj 84fdc58acd 1 4 年之前
  zz 568992a12b encodeDistributionChannelId 4 年之前
  zhoulj 872148d9a9 1 4 年之前
  zhoulj a2c50b8b94 1 4 年之前
  zhoulj 848ce36c4b 1 4 年之前
  zhoulj bf31186cf8 1 4 年之前
  zhoulj a5a1df06cd 路由bug 4 年之前
  zz 1cd1034b0b clean 4 年之前
  root 4d5c54a283 init 4 年之前
  zhoulj 68983aa875 Initial commit 4 年之前
共有 2 個文件被更改,包括 135 次插入26 次删除
  1. 43 26
      app/Jobs/AsyncOrderStats.php
  2. 92 0
      app/Jobs/AsyncUserRegister.php

+ 43 - 26
app/Jobs/AsyncOrderStats.php

@@ -10,6 +10,7 @@
 namespace App\Jobs;
 
 use App\Modules\Subscribe\Services\OrderService;
+use GuzzleHttp\Client;
 use Illuminate\Bus\Queueable;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Queue\InteractsWithQueue;
@@ -22,6 +23,8 @@ class AsyncOrderStats implements ShouldQueue
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
+    const SUCCESS = 'success';
+
     private $orderId;
     private $order_info = null;
 
@@ -40,13 +43,13 @@ class AsyncOrderStats implements ShouldQueue
     public function handle()
     {
         $this->init();
-        //qkm推送统计
-        //$this->qkmPushOrderStats();
         //activity 活动统计
         $this->activityStats();
         //$this->saveActivityOrder();
         //图书充值统计
         $this->bookChargeStats();
+        //订单上报给渠道
+        $this->reportToChannel();
     }
 
     private function init()
@@ -55,18 +58,6 @@ class AsyncOrderStats implements ShouldQueue
         $this->uid = $this->order_info->uid;
     }
 
-    private function qkmPushOrderStats()
-    {
-        $push_id = Redis::hget('book_read:' . $this->uid, 'qkm_push');
-        if (!$push_id) return;
-        $push_time = Redis::hget('qkm_push:time', $push_id);
-        if (empty($push_time) || !is_numeric($push_time)) return;
-        $time = ceil((time() - $push_time) / 86400);
-        if ($time > 0 && $time <= 31) {
-            $price = $this->order_info->price * 100;
-            Redis::hincrby('qkm_push:amount', $push_id, $price);
-        }
-    }
 
     private function activityStats()
     {
@@ -96,18 +87,6 @@ class AsyncOrderStats implements ShouldQueue
         ]);
     }
 
-    private function saveActivityOrder()
-    {
-        if ($this->order_info->status != 'PAID') return;
-        if (!$this->order_info->activity_id) return;
-        DB::table('activity_order')->insert([
-            'order_id' => $this->orderId,
-            'activity_id' => $this->order_info->activity_id,
-            'distribution_channel_id' => $this->order_info->distribution_channel_id,
-            'created_at' => $this->order_info->created_at,
-            'updated_at' => date('Y-m-d H:i:s')
-        ]);
-    }
 
     private function bookChargeStats(){
         $bid = $this->order_info->from_bid;
@@ -116,4 +95,42 @@ class AsyncOrderStats implements ShouldQueue
         $price = $this->order_info->price * 100;
         Redis::hincrby('book:charge:stats:'.$day, $bid, $price);
     }
+
+   private function reportToChannel(){
+       $link = $this->getReportUrl($this->distribution_channel_id);
+       if(!$link) return ;
+       $uid = $this->uid;
+       $distribution_channel_id = $this->order_info->distribution_channel_id;
+       $price = $this->order_info->price;
+       $order_created_at = $this->order_info->created_at->format('Y-m-d H:i:s');
+       $client = new Client(['timeout'=>3.0]);
+       try{
+           $result = $client->request('post',$link,['form_params'=>[
+               'uid'=>$uid,
+               'distribution_channel_id'=>$distribution_channel_id,
+               'price'=>$price,
+               'order_created_at'=>$order_created_at,
+           ]])->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_orders')->insert([
+           'uid'=>$uid,
+           'distribution_channel_id'=>$distribution_channel_id,
+           'price'=>$price,
+           'order_created_at'=>$order_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 getReportUrl($distribution_channel_id){
+        return '';
+    }
 }

+ 92 - 0
app/Jobs/AsyncUserRegister.php

@@ -0,0 +1,92 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2020/12/24
+ * Time: 11:36
+ */
+
+namespace App\Jobs;
+
+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 = $this->getReportUrl($this->distribution_channel_id);
+        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
+            ]])->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 getReportUrl($distribution_channel_id){
+        return '';
+    }
+
+}