Browse Source

Merge branch 'master' of iqiyoo:zhuishuyun_wap

onlinetest 6 years ago
parent
commit
69306e60c1

+ 37 - 0
app/Console/Commands/BookTest.php

@@ -8,6 +8,7 @@ use App\Modules\Product\Services\ProductService;
 use App\Modules\Subscribe\Services\ChapterOrderService;
 use App\Modules\Subscribe\Services\SubstituteOrderService;
 use App\Modules\User\Services\ReadRecordService;
+use App\Modules\User\Services\UserDivisionCpcPropertyService;
 use App\Modules\User\Services\UserService;
 use App\Modules\YunQi\Models\BookUser;
 use App\Modules\YunQi\Models\YqUserBidRelation;
@@ -660,4 +661,40 @@ class BookTest extends Command
         }
     }
 
+    private function userPropertyV2(){
+        $tmp = 0;
+        //19493455
+        while (true){
+            $info = DB::table('orders')
+                ->select('id','uid','price','status')
+                ->where('id','>',$tmp)
+                ->orderBy('id')
+                ->limit(1000)
+                ->get();
+            if($info->isEmpty()) break;
+            foreach ($info as $item){
+                if($item->status != 'PAID') continue;
+                //$old = UserDivisionCpcPropertyService::getUserPropertyV2($item->uid);
+                //if($old) continue;
+                $property = UserDivisionCpcPropertyService::calculateUserPropertyV2($item->uid);
+                if($property){
+                    $info = UserDivisionCpcPropertyService::getUserPropertyV2($item->uid);
+                    if($info == 'none'){
+                        DB::table('user_division_cpc_property_v2')->insert([
+                            'openid'=>$property['openid'],
+                            'property'=>$property['property'],
+                            'is_enable'=>1,
+                            'created_at'=>date('Y-m-d H:i:s'),
+                            'updated_at'=>date('Y-m-d H:i:s')
+                        ]);
+                    }
+                    if($info == 'high') continue;
+                    UserDivisionCpcPropertyService::updateV2($property);
+                }
+            }
+            $tmp = $item->id;
+            if($tmp >=19493455) break;
+        }
+    }
+
 }

+ 19 - 1
app/Http/Controllers/Wap/Pay/MonthOrderController.php

@@ -15,6 +15,7 @@ use App\Modules\Subscribe\Models\Order;
 use App\Modules\Subscribe\Services\OrderService;
 use App\Modules\Subscribe\Services\YearOrderService;
 use App\Modules\User\Services\ReadRecordService;
+use App\Modules\User\Services\UserDivisionCpcPropertyService;
 use App\Modules\User\Services\UserMonthService;
 use App\Modules\User\Services\UserService;
 use GuzzleHttp\Client;
@@ -150,7 +151,9 @@ class MonthOrderController extends Controller
         $total_fee = $request->post('total_fee');
         $trade_no = $request->post('trade_no');
         $out_trade_no = $request->post('out_trade_no');
+        $result_code = $request->post('result_code',0);
         $this->recordOrderCallBack($request);
+        if(!$result_code) return response('success');
         if ($check = checkParam($request->except('_url'), ['app_id', 'user_id', 'total_fee', 'trade_no', 'out_trade_no'])) {
             return response()->error('PARAM_EMPTY', ['msg' => $check]);
         }
@@ -161,6 +164,7 @@ class MonthOrderController extends Controller
             UserMonthService::createLOrder($user_id, $plan_id, $total_fee, $trade_no, $out_trade_no);
             $this->addOrderAndVip($user_id, $out_trade_no, $trade_no, $total_fee);
             $this->successPayPushMsg($user_id);
+            $this->userProperty($user_id);
         }
         //}
 
@@ -289,7 +293,7 @@ class MonthOrderController extends Controller
                 )
             ]);
         }catch (\Exception $e){
-            Log::error();
+            Log::error('recordOrderCallBack error');
         }
 
 
@@ -331,4 +335,18 @@ class MonthOrderController extends Controller
         }
         return;
     }
+
+    private function userProperty($uid){
+        try{
+            $userproperty = UserDivisionCpcPropertyService::calculateUserPropertyV2($uid);
+            if(!$userproperty) {
+                return ;
+            }
+            UserDivisionCpcPropertyService::createorUpdateV2($userproperty);
+        }catch (\Exception $e){
+            Log::error('month userProperty error');
+            Log::error($e);
+        }
+
+    }
 }

+ 18 - 2
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -1896,7 +1896,7 @@ class OrdersController extends Controller
     }
 
     private function userProperty($uid,$price,$charge_type,$activity_id){
-        try{
+        /*try{
             $old_property = UserDivisionCpcPropertyService::getUserProperty($uid);
             if(!$activity_id){
                 $this->chargeGiveGift($uid,$old_property,$price,$charge_type);
@@ -1906,7 +1906,23 @@ class OrdersController extends Controller
                 return ;
             }
             UserDivisionCpcPropertyService::createorUpdate($userproperty);
-        }catch (\Exception $e){}
+        }catch (\Exception $e){}*/
+
+
+        try{
+            $old_property = UserDivisionCpcPropertyService::getUserPropertyV2($uid);
+            if(!$activity_id){
+                $this->chargeGiveGift($uid,$old_property,$price,$charge_type);
+            }
+            $userproperty = UserDivisionCpcPropertyService::calculateUserPropertyV2($uid);
+            if(!$userproperty) {
+                return ;
+            }
+            UserDivisionCpcPropertyService::createorUpdateV2($userproperty);
+        }catch (\Exception $e){
+            Log::error('pay userProperty error');
+            Log::error($e);
+        }
 
     }
 

+ 25 - 7
app/Http/Controllers/Wap/Web/WelcomeController.php

@@ -42,6 +42,8 @@ class WelcomeController extends BaseController
     private $force_subscribe_info = null;
 
     private $property = '';
+
+    private $user = null;
     /**
      * 首页
      */
@@ -64,6 +66,7 @@ class WelcomeController extends BaseController
         $bottom_show_type = $activity_options['bottom_show_type'];
         $activity_img = $activity_options['activity_img'];
         $user = $activity_options['user'];
+        $this->user = $user;
         $hidden_reader_menus = false;
         $send_order_id = $this->send_order_id;
         //隐藏阅读页面菜单
@@ -103,6 +106,7 @@ class WelcomeController extends BaseController
         }
         //设置用户是否充值
         $this->setIsPaid();
+        $this->setProperty($user->openid);
         $channel_activities_flag = $this->judgeChannelActivity($user);
         //最近阅读页面 推荐
         if(isset($user->sex)){
@@ -330,9 +334,9 @@ class WelcomeController extends BaseController
         //if( in_array($this->distribution_channel_id,explode(',',env('OUTSTANDING_YEAR_ORDER_SITE'))) ){
             //if($this->uid%2 == 0){
                 //$userDivisionProperty = UserDivisionPropertyService::getUserProperty($this->uid);
-                $userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($this->uid);
+                //$userDivisionProperty = UserDivisionCpcPropertyService::getUserProperty($this->uid);
 
-                $userDivisionProperty && $userDivisionProperty == 'high' && $outstanding_year_order = true;
+                $this->property == 'high' && $outstanding_year_order = true;
             //}
         //}
         return $outstanding_year_order;
@@ -523,6 +527,7 @@ class WelcomeController extends BaseController
      */
     private function getSiteTitle(Request $request)
     {
+        if($this->distribution_channel_id == 6398) return '花溪亭苑';
         $title = "追书云";
         $get_force_subscribe_name = false;
         $subscribe = $request->cookie('force_subscribe_name');
@@ -598,12 +603,12 @@ class WelcomeController extends BaseController
         if(is_null($cpc_status) || $cpc_status == 1){
             $cookie_ad_status = Cookie::get('cpc_ad_status');
             if($cookie_ad_status) return $cookie_ad_status == 'show';
-            $property = UserDivisionCpcPropertyService::userLevel($openid);
+            //$property = UserDivisionCpcPropertyService::userLevel($openid);
             /*if(UserService::isCpcUser($this->uid)){
                 Cookie::queue('cpc_ad_status', 'show');
                 return true;
             }*/
-            if($property  &&  $property->property == 'none'){
+            if($this->property == 'none'){
                 Cookie::queue('cpc_ad_status', 'show');
                 return true;
             }
@@ -2107,8 +2112,16 @@ class WelcomeController extends BaseController
     }
 
 
-    private function userPproperty($openid){
-        $old = UserDivisionCpcPropertyService::userLevel($openid);
+    private function userPproperty(){
+        if($this->property == 'undefined'){
+            if($this->user && time()-strtotime($this->user->created_at) >= 3*66400){
+                $info = UserDivisionCpcPropertyService::calculateUserPropertyV2($this->uid);
+                if($info && $info['property'] != 'undefined'){
+                    UserDivisionCpcPropertyService::updateV2($info['openid'],$info['property']);
+                }
+            }
+        }
+        /*$old = UserDivisionCpcPropertyService::userLevel($openid);
         if(!$old) return ;
         $this->property = $old->property;
         if($old->type != 'NEW') return ;
@@ -2123,7 +2136,7 @@ class WelcomeController extends BaseController
             dispatch($job);
         } catch (\Exception $e) {
             \Log::info($e);
-        }
+        }*/
     }
 
     private function guidePersonalAccount($openid){
@@ -2213,6 +2226,11 @@ class WelcomeController extends BaseController
         }
     }
 
+    private function setProperty($openid){
+        $property = UserDivisionCpcPropertyService::userLevelV2($openid);
+        $this->property = $property;
+    }
+
     //统计ua
     private function recordUA($ua)
     {

+ 2 - 2
app/Http/Middleware/ReadOauth.php

@@ -337,7 +337,7 @@ class ReadOauth
             'last_interactive_time' => date('Y-m-d H:i:s')
         ]);
 
-        try {
+        /*try {
             $send_data = array(
                 'type' => 'subscribe',
                 'data' => ['openid'=>'','uid'=>$uid]
@@ -347,7 +347,7 @@ class ReadOauth
             dispatch($job);
         } catch (\Exception $e) {
             Log::info($e);
-        }
+        }*/
         return true;
     }
 

+ 17 - 0
app/Modules/User/Models/UserDivisionCpcPropertyV2.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/8/21
+ * Time: 16:13
+ */
+
+namespace App\Modules\User\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class UserDivisionCpcPropertyV2 extends Model
+{
+    protected $table = 'user_division_cpc_property_v2';
+    protected $fillable = ['openid','property','is_enable'];
+}

+ 5 - 2
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','new_outer','new_inner','new_total'];
+    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','next_push_hour'];
 
     /**
      * 获取
@@ -129,7 +129,7 @@ class ReadRecordService
         /*Redis::hset('book_read:' . $uid, 'last_read', "{$bid}_{$cid}_" . time());
         //Redis::hset('book_read:'.$uid, $bid, $cid."_".time());
         Redis::hset('book_read:' . $uid, $bid, "{$cid}_" . time());*/
-        Redis::hmset('book_read:' . $uid,'last_read', "{$bid}_{$cid}_" . time(),$bid, "{$cid}_" . time());
+        Redis::hmset('book_read:' . $uid,'last_read', "{$bid}_{$cid}_" . time(),$bid, "{$cid}_" . time(),'next_push_hour',8);
         $num = random_int(1,100);
         if($num <=3){
             self::delTheLastRecord($uid);
@@ -189,7 +189,9 @@ class ReadRecordService
         if($record){
             $record_arr = explode('_',$record);
             $bid = $record_arr[0];
+            $bid = Hashids::encode($bid);
             $cid = $record_arr[1];
+            $time = $record_arr[2];
             $book_info = BookConfigService::getBookById($bid);
             $book_name = isset($book_info->book_name)?$book_info->book_name:'';
             $cover = isset($book_info->cover)?$book_info->cover:'';
@@ -199,6 +201,7 @@ class ReadRecordService
                 'book_name'=>$book_name,
                 'cover' =>$cover,
                 'channel_name'=>$channel_name,
+                'time'=>$time
             ];
             return $res;
         }

+ 88 - 0
app/Modules/User/Services/UserDivisionCpcPropertyService.php

@@ -9,6 +9,7 @@
 namespace App\Modules\User\Services;
 
 use App\Modules\User\Models\UserDivisionCpcProperty;
+use App\Modules\User\Models\UserDivisionCpcPropertyV2;
 use DB;
 
 class UserDivisionCpcPropertyService
@@ -213,4 +214,91 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
             );
         }
     }
+
+    /**
+     *   Openid一对一注册uid,充值超过30元直接成为高净值用户,否则注册3天后做净值分档;
+     *   Openid一对多注册uid,注册3天以上成为有效uid,有效uid充值总额比uid个数;
+     *   净值区间无论一对一注册uid还是一对多注册uid:
+     *   低净值:0<充值<10,openid数占比35.51%,充值占比6.03%;
+     *   中净值:10=<充值<=30,openid数占比32.89%,充值占比23.81%;
+     *   高净值:充值>30,openid数占比31.60%,充值占比70.16%;
+     * @param $uid
+     */
+    public static function calculateUserPropertyV2($uid)
+    {
+        $sql = "SELECT users.id as uid,users.openid,users.created_at as register,(select SUM(price) from orders where orders.uid = users.id and `status` = 'PAID') as price FROM users 
+WHERE openid in (SELECT openid FROM users WHERE id = $uid)";
+        $result = DB::select($sql);
+        if (!$result) return [];
+        if(count($result) == 1 ){
+            if($result[0]->price && $result[0]->price>30){
+                return ['openid'=>$result[0]->openid,'property'=>'high'];
+            }
+            if(time()-strtotime($result[0]->register) < 3*86400){
+                return ['openid'=>$result[0]->openid,'property'=>'undefined'];
+            }
+        }
+        $valid_user_num = 0;
+        $amount = 0;
+        $openid = '';
+        $all_amount = 0;
+        foreach ($result as $item){
+            $openid = $item->openid;
+            if($item->price) $all_amount += $item->price;
+            if(time()-strtotime($item->register) < 3*86400) continue;
+            if($item->price) $amount += $item->price;
+            $valid_user_num += 1;
+        }
+        if(!$valid_user_num){
+            if($all_amount)return ['openid'=>$openid,'property'=>'undefined'];
+            return [];
+        }
+
+        $average_amount = $amount/$valid_user_num;
+        if($average_amount >30){
+            return ['openid'=>$openid,'property'=>'high'];
+        }elseif ($average_amount >=10){
+            return ['openid'=>$openid,'property'=>'medium'];
+        }else{
+            return ['openid'=>$openid,'property'=>'low'];
+        }
+    }
+
+    public static function userLevelV2($openid){
+        $result =  UserDivisionCpcPropertyV2::where('openid',$openid)->where('is_enable',1)->select('property')->first();
+        if($result)
+            return $result->property;
+        return 'none';
+    }
+
+    public static function getUserPropertyV2($uid){
+        $result = UserDivisionCpcPropertyV2::join('users','users.openid','=','user_division_cpc_property_v2.openid')
+            ->where('users.id',$uid)
+            ->select('user_division_cpc_property_v2.property')->first();
+        if($result)
+            return $result->property;
+        return 'none';
+    }
+
+    public static function updateV2($openid,$property=''){
+        if(empty($property)) return ;
+        $update_info = [];
+        $property && $update_info['property'] = $property;
+
+        UserDivisionCpcPropertyV2::where('openid',$openid)->where('is_enable',1)->update($update_info);
+    }
+
+    public static function createorUpdateV2($data){
+        $old = UserDivisionCpcPropertyV2::where('openid',$data['openid'])->where('is_enable',1)->first();
+        if(!$old){
+            UserDivisionCpcPropertyV2::create([
+                'openid'=>$data['openid'] ,
+                'property'=>$data['property'] ,
+                'is_enable'=>1
+            ]);
+        }else{
+            $old->property = $data['property'];
+            $old->save();
+        }
+    }
 }

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

@@ -465,7 +465,7 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'bid'=>$g->bid,
                     'icon'=>$g->icon,
                     'name_desc'=>$g->name_desc,
-                    'cost'=>$g->cost,
+                    'cost'=>0,
                     'cost_reward'=>$g->cost_reward,
                     'cost_recharge'=>$g->cost_recharge,
                     'created_at'=>$g->created_at,

+ 6 - 2
resources/views/wap-browser/subscribe.blade.php

@@ -54,7 +54,7 @@
             width:85%;
             padding:15px;
             margin:30px auto;
-
+            user-select: none;
         }
 
         .q_bottom h3{
@@ -102,8 +102,9 @@
                 <img src="{{$img}}">
         </div>
     @else
-        <div class="img_qr" id="qrcode_url">
+        <div class="img_qr" id="qrcode_url" style="display: none;">
         </div>
+        <img id="buildImage" src="" alt="" />
     @endif
 
     <div class="q_bottom" >
@@ -155,5 +156,8 @@
             colorLight : "#ffffff",
             correctLevel : QRCode.CorrectLevel.H
         });
+        var codeSrc = qrcode._oDrawing._elCanvas.toDataURL("image/jpg");
+
+        document.querySelector("#buildImage").setAttribute("src", codeSrc);
 </script>
 </html>

File diff suppressed because it is too large
+ 2 - 2
resources/views/wap/index.blade.php