Переглянути джерело

Merge branch 'stabble' into rand_sign

songdb 6 роки тому
батько
коміт
0288b8915b

+ 52 - 0
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -7,6 +7,7 @@ use App\Modules\Book\Services\BookGiftsService;
 use App\Modules\Book\Services\ChapterService;
 use App\Modules\OfficialAccount\Services\OfficialAccountService;
 use App\Modules\Subscribe\Services\OrderParamService;
+use App\Modules\Subscribe\Services\OrderParamWsoService;
 use App\Modules\Subscribe\Services\SubstituteOrderService;
 use App\Modules\User\Services\ReadRecordService;
 use App\Modules\User\Services\UserDivisionCpcPropertyService;
@@ -335,6 +336,7 @@ class OrdersController extends Controller
                     'order_id'=>$result->id,'gxhp'=>'crm','appid'=>'','bid'=>$bid,'data_hour_key'=>$crm,'times'=>'','distribution_channel_id'=>$distribution_channel_id
                 ]);
             }
+            $this->orderParamWso($uid,$result->id);
         }
 
         if ($request->get('suid')) {
@@ -539,6 +541,7 @@ class OrdersController extends Controller
                     'order_id'=>$result->id,'gxhp'=>'crm','appid'=>'','bid'=>$bid,'data_hour_key'=>$crm,'times'=>'','distribution_channel_id'=>$distribution_channel_id
                 ]);
             }
+            $this->orderParamWso($uid,$result->id);
         }
         if ($suid) {
             $this->createSubstituteOrder($result->id, $uid, $suid);
@@ -1805,4 +1808,53 @@ class OrdersController extends Controller
         }
         return ;
     }
+
+    private function orderParamWso($uid,$order_id){
+        list($new_outer,$new_inner,$new_total) = ReadRecordService::getByMultiField($uid,'new_outer','new_inner','new_total');
+        if(!$new_outer && !$new_inner && !$new_total){
+            return ;
+        }
+        if(!$new_total) return ;
+        $new_outer = $new_outer?$new_outer:0;
+        $new_inner = $new_inner?$new_inner:0;
+        $total_type = '';
+        $total_param_id = 0;
+        if(is_numeric($new_total)){
+            $send_order_info = SendOrderService::getById($new_total);
+            $total_param_id = $new_total;
+            $total_type = 'none';
+            if($send_order_info && isset($send_order_info->promotion_type)){
+                if($send_order_info->promotion_type == 'EXTERNAL'){
+                    $total_type = 'OUTER';
+                }
+                if($send_order_info->promotion_type == 'INTERNAL'){
+                    $total_type = 'INNER';
+                }
+            }
+        }
+        if(str_contains($new_total,'custom')){
+            $total_type = 'CUSTOM';
+            $temp = explode('_',$new_total);
+            if(isset($temp[1]) && is_numeric($temp[1])){
+                $total_param_id = $temp[1];
+            }
+        }
+        if(str_contains($new_total,'template')){
+            $total_type = 'TEMPLATE';
+            $temp = explode('_',$new_total);
+            if(isset($temp[1]) && is_numeric($temp[1])){
+                $total_param_id = $temp[1];
+            }
+        }
+
+        if($total_type){
+            OrderParamWsoService::createOrder($order_id,
+                $new_inner,
+                $new_outer,
+                $total_param_id,
+                $new_total,
+                $total_type);
+        }
+
+    }
 }

+ 24 - 185
app/Http/Controllers/Wap/Web/RedirectController.php

@@ -127,7 +127,8 @@ class RedirectController extends BaseController
                 $uv = Redis::hget('send_order_uv_' . $param, $key);
                 $this->updateSendOrderTime($param, $uv);
             }
-
+            //统计
+            $this->InnerOuterWeixinStats($link->promotion_type,$param);
             //
             $redirect_path = $request->get('redirect_path');
            if($redirect_path){
@@ -183,6 +184,7 @@ class RedirectController extends BaseController
         $param['cid'] = $record_info_arr[0];
         $param['bid'] = $bid_str;
         $param['soid'] = $send_order_id;
+        $param['jump_from'] = 'yun';
         if ($cid && $cid != $record_info_arr[0]) {
             $url = env('H5_SCHEME', 'https') . '://' . _domain() . '/reader?' . http_build_query($param);
             return $url;
@@ -250,190 +252,6 @@ class RedirectController extends BaseController
         return false;
     }
 
-    /**
-     * 添补订单
-     * @param int $send_order_id
-     * @param int $uv
-     * @param string $send_time
-     * @param int $distribution_channel_id
-     * @param string $send_order_name
-     */
-    private function insertOrder(int $send_order_id, string $send_time, int $distribution_channel_id,string $send_order_name):void
-    {
-        if ($this->isCanInsert($send_order_id, $send_time)) {
-            $num = $this->InsertNum($send_order_id,$distribution_channel_id);
-            //失败订单
-            $this->orderSuccessRate($send_order_id,$distribution_channel_id,$send_order_name);
-            //\Log::info('$num-----------$num is :');
-            //   //\Log::info($num);
-            if ($num) {
-                $uids = ForceSubscribeService::getUidByParam($send_order_id, $distribution_channel_id);
-                //\Log::info('$uids-----------$uids is :');
-                //\Log::info($uids);
-                if ($uids->count() > 0) {
-                    foreach ($num as $price){
-                        $uid_colection = $uids->random(1)->first();
-                        //\Log::info($uid_colection);
-                        $uid = $uid_colection->uid;
-                        if($price == 50){
-                            $product_id = 2;
-                        }else{
-                            $product_id = 1;
-                        }
-                        OrderService::save_order([
-                            'uid'=>$uid,
-                            'price'=>$price,
-                            'pay_type'=>1,
-                            'product_id'=>$product_id,
-                            'status'=>'PAID',
-                            'distribution_channel_id'=>$distribution_channel_id,
-                            'trade_no'=>date("YmdHis").hexdec(uniqid()),
-                            'pay_merchant_source'=>'PALMPAY',
-                            'pay_merchant_id'=>12,
-                            'order_type'=>'RECHARGE',
-                            'transaction_id'=>'4200000150'.date('YmdHis').random_int(100000,999999),
-                            'from_bid'=>0,
-                            'pay_end_at'=>date('Y-m-d H:i:s',time()+10),
-                            'create_ip'=>'100.116.252.84',
-                            'send_order_id'=>$send_order_id,
-                            'send_order_name'=>$send_order_name,
-                            'from_type'=>'order_add',
-                            'activity_id'=>0
-                        ]);
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 是否可以填补订单
-     * @param int $send_order_id int
-     * @param string $send_time
-     * @return bool
-     */
-    private function isCanInsert(int $send_order_id, string $send_time):bool
-    {
-        //$send_order_id不存在 或者为0
-        if (!$send_order_id)
-            return false;
-        //配置文件设置的派单id
-        $setting_fill_send_order_id = env('FILL_SEND_ORDER_ID', '');
-        if (!$setting_fill_send_order_id)
-            return false;
-        $setting_fill_send_order_id_arr = explode(',', $setting_fill_send_order_id);
-        //不在派单设置的派单中
-        if (!in_array($send_order_id, $setting_fill_send_order_id_arr))
-            return false;
-
-        $time = (int)date('H');
-        //两点到5点之间不添加
-        if ($time >= 2 && $time <= 4) {
-            return false;
-        }
-        //派单两个小时之内不加
-        if (time() - strtotime($send_time) <= 3600 * 2) {
-            return false;
-        }
-
-        $this->alluv = (int)WapVisitStatService::getSendOrderTotalUv($send_order_id);
-        if($this->alluv && $this->alluv%25 == 0 && $this->alluv <= 1000){
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * 是否达到条件,且需要添补的订单
-     * @param int $send_order_id
-     * @param int $distribution_channel_id
-     * @param int $uv
-     * @return array
-     */
-    private function InsertNum(int $send_order_id,int $distribution_channel_id):array
-    {
-        $uv = $this->alluv;
-        //uv的平均价值
-        $up_value = env('PER_USER_UP_VALUE', 1) * 100;
-        //当前充值总量
-        $sum = ceil(OrderService::getSumBySendOrderId($send_order_id,$distribution_channel_id));
-        //\Log::info('$sum   -    is :'.$sum);
-        $now_up_value = round($sum / $uv, 2) * 100;
-
-        if ($now_up_value >= $up_value) {
-            //如果当前值大于设定的值,则不填补
-            return [];
-        }
-        //计算应当添加的总金额
-        $add_sum = (int)(($up_value - $now_up_value) * $uv) / 100;
-        if ($add_sum > 60) {
-            return [50,50];
-        }
-        elseif ($add_sum > 50){
-            return [30,30];
-        }
-        elseif ($add_sum > 30){
-            return [50];
-        }
-        else {
-            return [30];
-        }
-    }
-
-    /**
-     * 失败订单
-     * @param int $send_order_id
-     * @param int $distribution_channel_id
-     * @param string $send_order_name
-     */
-    private function orderSuccessRate(int $send_order_id,int $distribution_channel_id,string $send_order_name):void{
-        $rate_array = OrderService::getSuccessRate($send_order_id);
-
-        //\Log::info($rate_array);
-        if(empty($rate_array['total']) || empty($rate_array['success'])){
-            return ;
-        }
-        $rate = round($rate_array['success']/$rate_array['total']);
-        $rate_level = random_int(28,35);
-        if($rate*100>=$rate_level){
-            $num = ceil(($rate_array['success']-ceil(($rate_level*$rate_array['total'])/100))/($rate_level/100));
-            //\Log::info($num);
-            $data = [];
-            $price_map = [[30,1],[50,2]];
-            for ($i = 0;$i<$num;$i++){
-                $uid = rand(10000,20000000);
-                $k = $uid%2;
-                $time = random_int(1,500);
-                $data[] =  [
-                    'uid'=>$uid,
-                    'price'=>$price_map[$k][0],
-                    'pay_type'=>1,
-                    'product_id'=>$price_map[$k][1],
-                    'status'=>'UNPAID',
-                    'distribution_channel_id'=>$distribution_channel_id,
-                    'trade_no'=>date("YmdHis").hexdec(uniqid()),
-                    'pay_merchant_source'=>'PALMPAY',
-                    'pay_merchant_id'=>12,
-                    'order_type'=>'RECHARGE',
-                    'transaction_id'=>'',
-                    'from_bid'=>0,
-                    'pay_end_at'=>'0000-00-00 00:00:00',
-                    'create_ip'=>'100.116.252.84',
-                    'send_order_id'=>$send_order_id,
-                    'send_order_name'=>$send_order_name,
-                    'from_type'=>'order_add',
-                    'activity_id'=>0,
-                    'created_at'=>date('Y-m-d H:i:s',time()-$time),
-                    'updated_at'=>date('Y-m-d H:i:s',time()-$time)
-                ];
-            }
-
-            if($data){
-                DB::table('orders')->insert($data);
-            }
-        }
-        return ;
-    }
 
     /**
      * 用户从A连接推送的书,进入后,被标记bookid+派单id,之后所有的统计计算到该派单下
@@ -458,4 +276,25 @@ class RedirectController extends BaseController
         WapVisitStatService::specialChannelIdStatsMarkUser($uid,$bid,$send_order_id);
         return ;
     }
+
+    //内外部模板客服统计埋点
+    private function InnerOuterWeixinStats($promotion_type,$send_order_id){
+        if(!$promotion_type || !$send_order_id) return ;
+        $openChannel = redisEnv('OPEN_INNER_OUTER_WEIXIN_STATS');
+        if(!$openChannel || !in_array($this->distribution_channel_id,explode(',',$openChannel))) return ;
+        if($promotion_type == 'EXTERNAL'){
+            ReadRecordService::setByMultiField($this->uid,['new_outer'=>$send_order_id,'new_total'=>$send_order_id]);
+        }
+
+        if($promotion_type == 'INTERNAL'){
+            ReadRecordService::setByMultiField($this->uid,['new_inner'=>$send_order_id,'new_total'=>$send_order_id]);
+        }
+        $day = date('Y-m-d');
+        $pv_key = sprintf('InnerOuterWeixinStats:pv:%s:%s',$send_order_id,$this->distribution_channel_id);
+        $uv_key = sprintf('InnerOuterWeixinStats:uv:%s:%s:%s',$send_order_id,$this->distribution_channel_id,$day);
+        Redis::hincrby($pv_key,$day,1);
+        Redis::sadd($uv_key,$this->uid);
+        Redis::sadd('InnerOuterWeixinStats:'.$day,$send_order_id.':'.$this->distribution_channel_id);
+    }
+
 }

+ 3 - 0
app/Http/Controllers/Wap/Web/WelcomeController.php

@@ -2135,6 +2135,9 @@ class WelcomeController extends BaseController
             where('created_at','>=',date('Y-m-d H:i:s',$guide_personal_account_start_time))
             ->select('id')
             ->first();
+        if($this->distribution_channel_id == 6887){
+            $charge = true;
+        }
         if($charge){
             if(!empty($other_crm[1])){
                 return ['title'=>'点击领取200书币>>','link'=>$other_crm[1]];

+ 21 - 1
app/Http/Middleware/ReadOauth.php

@@ -164,7 +164,7 @@ class ReadOauth
         $this->crmParam($request);
         //from_title_image
         $this->fromTitleImage($request, $uid_cookie);
-
+        $this->InnerOuterWeixinStats($request,$uid_cookie,$distribution_channel_id);
         if ($test) {
             Cookie::queue(env('COOKIE_AUTH_WEB_WECHAT'), 9, env('U_COOKIE_EXPIRE'), null, null, false, false);
         }
@@ -727,4 +727,24 @@ class ReadOauth
             Cookie::queue('crm', $crm_param);
         }
     }
+
+
+    //内外部模板客服统计埋点  custom_379989  template_75113
+    private function InnerOuterWeixinStats(Request $request,$uid,$distribution_channel_id){
+        if($request->has('jump_from') || !$request->has('fromtype')) return ;
+        $from = $request->get('fromtype');
+        if(!str_contains($from,['custom','template'])){
+            return ;
+        }
+        $openChannel = redisEnv('OPEN_INNER_OUTER_WEIXIN_STATS');
+        if(!$openChannel || !in_array($distribution_channel_id,explode(',',$openChannel))) return ;
+        ReadRecordService::setByField($uid,'new_total',$from);
+
+        $day = date('Y-m-d');
+        $pv_key = sprintf('InnerOuterWeixinStats:pv:%s:%s',$from,$distribution_channel_id);
+        $uv_key = sprintf('InnerOuterWeixinStats:uv:%s:%s:%s',$from,$distribution_channel_id,$day);
+        Redis::hincrby($pv_key,$day,1);
+        Redis::sadd($uv_key,$uid);
+        Redis::sadd('InnerOuterWeixinStats:'.$day,$from.':'.$distribution_channel_id);
+    }
 }

+ 1 - 1
app/Modules/SendOrder/Services/SendOrderService.php

@@ -274,7 +274,7 @@ class SendOrderService
      */
     static function getRedirectUrlById($id)
     {
-        return SendOrder::where('id', $id)->select('redirect_url', 'book_id', 'send_time', 'distribution_channel_id', 'name','promotion_point','force_show_qrcode')->first();
+        return SendOrder::where('id', $id)->select('redirect_url', 'book_id', 'send_time', 'distribution_channel_id', 'name','promotion_point','force_show_qrcode','promotion_type')->first();
     }
 
     /**

+ 11 - 0
app/Modules/Subscribe/Models/OrderParamWso.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Modules\Subscribe\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class OrderParamWso extends Model
+{
+    protected $table = 'order_param_wso';
+    protected $fillable = ['order_id','inner_send_order_id','outer_send_order_id','total_param_id','total_param','total_type'];
+}

+ 23 - 0
app/Modules/Subscribe/Services/OrderParamWsoService.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/6/28
+ * Time: 15:48
+ */
+
+namespace App\Modules\Subscribe\Services;
+
+
+use App\Modules\Subscribe\Models\OrderParamWso;
+
+class OrderParamWsoService
+{
+    public static function createOrder($order_id,$inner_send_order_id,$outer_send_order_id,$total_param_id,$total_param,$total_type)
+    {
+        try{
+            OrderParamWso::create(compact('order_id','inner_send_order_id','outer_send_order_id','total_param_id','total_param','total_type'));
+        }catch (\Exception $e){}
+
+    }
+}

+ 1 - 1
app/Modules/User/Services/ReadRecordService.php

@@ -20,7 +20,7 @@ class ReadRecordService
     //阅读记录数
     const RECORD_COUNT = 50;
 
-    private static $not_uid_key = ['last_read','send_order_id','sign_count','sign_counts','sign_info','sign_day','smart_push','inner_send_order_id','gxhp','property','bind_phone_status','ua','sign_version'];
+    private static $not_uid_key = ['last_read','send_order_id','sign_count','sign_counts','sign_info','sign_day','smart_push','inner_send_order_id','gxhp','property','bind_phone_status','ua','sign_version','new_outer','new_inner','new_total'];
 
     /**
      * 获取

Різницю між файлами не показано, бо вона завелика
+ 27 - 4
resources/views/wap/index.blade.php