|  | @@ -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);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |