zz 5 роки тому
батько
коміт
ef51a5f804
1 змінених файлів з 312 додано та 0 видалено
  1. 312 0
      app/Http/Controllers/Wap/Crm/CrmGuideFansController.php

+ 312 - 0
app/Http/Controllers/Wap/Crm/CrmGuideFansController.php

@@ -0,0 +1,312 @@
+<?php
+
+namespace App\Http\Controllers\Wap\Crm;
+
+use Illuminate\Http\Request;
+use App\Modules\Subscribe\Services\OrderService;
+use App\Modules\User\Services\UserDivisionCpcPropertyService;
+use App\Modules\User\Services\ForceGuidePersonAccountService;
+use App\Http\Controllers\Wap\BaseController;
+use App\Modules\User\Services\UserService;
+use App\Modules\User\Services\UserBindHkWelfareService;
+use Log;
+use Redis;
+use Cookie;
+use DB;
+use Hashids;
+
+class CrmGuideFansController extends BaseController
+{
+
+    /**
+     * 主动导粉
+     * @param Request $request
+     * @param $channel_id
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View}
+     */
+    public function activeGuidePersonalAccount(Request $request,$channel_id){
+        $uid = $request->get('uid',0);
+        //$user_cookie = Cookie::get(env('COOKIE_AUTH_WEB_WECHAT'));
+        //$uid = $user_cookie ? decrypt($user_cookie) : null;
+        $cookie_crm_img = Cookie::get('crm_person_img');
+        $cookie_crm_name = Cookie::get('crm_person_name','');
+        $request_img = $request->get('img');
+        $fee = $request->get('fee',200);
+        if($request_img){
+            $name = $request_img = $request->get('name');
+            return view('jump.guidePersonalAccountOurs',['img'=>$cookie_crm_img,'name'=>$name,'fee'=>$fee]);
+        }
+        $get_info = UserBindHkWelfareService::isHasGet($uid);
+
+        if($get_info)   return back();
+        if($cookie_crm_img){
+            return view('jump.guidePersonalAccountOurs',['img'=>$cookie_crm_img,'name'=>$cookie_crm_name,'fee'=>$fee]);
+        }
+
+        $distribution_channel_id = decodeDistributionChannelId($channel_id);
+        //$distribution_channel_id = $channel_id;
+        //if(in_array($distribution_channel_id,Redis::SISMEMBER('')));
+        //$out = false;
+        $group = 'ACTIVE';
+        if(Redis::SISMEMBER('crm:out_channel_sites',$distribution_channel_id)){
+            //$out = true;
+            $group = 'OUT_ACTIVE';
+            $env_config = redisEnvMulti('OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
+                'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV','OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
+                'OUT_ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
+        }else{
+            $env_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
+                'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV','ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
+                'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
+        }
+        if(empty($env_config[0])){
+            return back();
+        }
+        //$img = empty($env_config[0])?'https://cdn-novel.iycdm.com/h5/personal_account/chenchen.jpg':$env_config[0];
+        $img =$env_config[0];
+        $max = empty($env_config[1])?100:$env_config[1];
+        $max = (int)$max;
+        $one_loop_max = empty($env_config[3])?10:$env_config[3];
+        $now_id = (int)$env_config[2];
+
+        if($group == 'OUT_ACTIVE'){
+            $uv_key = 'out_active_guide_personal_uv';
+        }else{
+            $uv_key = 'active_guide_personal_uv';
+        }
+        $uv = Redis::scard($uv_key);
+        $personal_info = DB::table('personal_account_list')->where('id',$now_id)->select('count')->first();
+        if(!$personal_info){
+            return back();
+        }
+        $total_max = (int)($personal_info->count+$uv);
+        //Log::info('$total_max is: '.);
+        if($uv >= $one_loop_max || $total_max>=$max){
+            if($total_max>=$max){
+                DB::table('personal_account_list')->where('id',$now_id)->update([
+                    'status'=>2,
+                    'count'=>$total_max,
+                    'updated_at'=>date('Y-m-d H:i:s')
+                ]);
+            }else{
+                DB::table('personal_account_list')->where('id',$now_id)->increment('count',$uv,[
+                    'updated_at'=>date('Y-m-d H:i:s')
+                ]);
+            }
+
+            $account = DB::table('personal_account_list')
+                ->where('is_enable',1)
+                ->whereIn('status',[1,0])
+                ->select('id','url')
+                ->where('group',$group)
+                ->where('count','<',$max)
+                ->orderBy('count','asc')
+                ->orderBy('id')
+                ->first();
+            Redis::del($uv_key);
+            if($account){
+                DB::table('personal_account_list')->where('id',$account->id)->update([
+                    'status'=>1,
+                    'updated_at'=>date('Y-m-d H:i:s')
+                ]);
+                $img = $account->url;
+                $now_id = $account->id;
+                Redis::Hmset('env',$group.'_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',$account->url,$group.'_GUIDE_PERSONAL_ACCOUNT_ID',$account->id);
+            }else{
+                Redis::Hmset('env',$group.'_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE','',$group.'_GUIDE_PERSONAL_ACCOUNT_ID','');
+                return back();
+            }
+        }
+        Redis::sadd($uv_key,$uid);
+
+        if($uid){
+            if($group == 'OUT_ACTIVE'){
+                DB::table('ad_pdd')->insert([
+                    'uid'=>$uid,
+                    'img'=>'OUT_GUIDE_PERSONAL_ACCOUNT_'.$now_id,
+                    'date'=>date('Y-m-d'),
+                    'created_at'=>date('Y-m-d H:i:s'),
+                    'updated_at'=>date('Y-m-d H:i:s')
+                ]);
+                $user = UserService::getById($uid);
+                Redis::hset('crm:out_guide_exposure_user',$user->openid,$uid);
+            }else{
+                DB::table('ad_pdd')->insert([
+                    'uid'=>$uid,
+                    'img'=>'GUIDE_PERSONAL_ACCOUNT_'.$now_id,
+                    'date'=>date('Y-m-d'),
+                    'created_at'=>date('Y-m-d H:i:s'),
+                    'updated_at'=>date('Y-m-d H:i:s')
+                ]);
+            }
+
+        }
+        $name = '';
+        $name_info = DB::table('personal_account_list')->where('id',$now_id)->select('name')->first();
+        if($name_info){
+            $name = $name_info->name;
+        }
+
+        $page = 'jump.guidePersonalAccountOurs';
+        $time = strtotime(date('Y-m-d',time()+86400))-time();
+        Cookie::queue('crm_person_img', $img,$time);
+        Cookie::queue('crm_person_name', $name,$time);
+        return view($page,['img'=>$img,'name'=>$name,'fee'=>$fee]);
+    }
+
+    /**
+     * 强制导粉
+     * @param Request $request
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
+     */
+    public function forceGuidePersonalAccount(Request $request)
+    {
+        $bid = $request->get('bid');
+        $cid = $request->get('cid');
+        $prev_cid = $request->get('prev_cid');
+        $book_name = $request->get('book_name');
+        $bid_no = Hashids::decode($bid)[0];
+        if (Redis::SISMEMBER('crm:out_channel_sites', $this->distribution_channel_id)) {
+            $group = 'OUT_FORCE';
+        } else {
+            $group = 'FORCE';
+        }
+        $env_config = redisEnvMulti($group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_UV',
+            $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $group . '_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
+        if (empty($env_config[0])) return back();
+        $img = $env_config[0];
+        $max = empty($env_config[1]) ? 100 : $env_config[1];
+        $one_loop_max = empty($env_config[3]) ? 10 : $env_config[3];
+        $now_id = (int)$env_config[2];
+        $uv = Redis::scard(strtolower($group) . '_guide_personal_uv');
+        $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('count')->first();
+        $total_max = $personal_info->count + $uv;
+        //Log::info('$total_max is: '.);
+        if ($uv >= $one_loop_max || $total_max >= $max) {
+            if ($total_max >= $max) {
+                DB::table('personal_account_list')->where('id', $now_id)->update([
+                    'status' => 2,
+                    'count' => $total_max,
+                    'updated_at' => date('Y-m-d H:i:s')
+                ]);
+            } else {
+                DB::table('personal_account_list')->where('id', $now_id)->increment('count', $uv, [
+                    'updated_at' => date('Y-m-d H:i:s')
+                ]);
+            }
+
+            $account = DB::table('personal_account_list')
+                ->where('is_enable', 1)
+                ->whereIn('status', [1, 0])
+                ->select('id', 'url')
+                ->where('count', '<', $max)
+                ->where('group', $group)
+                ->orderBy('count', 'asc')
+                ->orderBy('id')
+                ->first();
+            Redis::del(strtolower($group) . '_guide_personal_uv');
+            if ($account) {
+                DB::table('personal_account_list')->where('id', $account->id)->update([
+                    'status' => 1,
+                    'updated_at' => date('Y-m-d H:i:s')
+                ]);
+                $img = $account->url;
+                $now_id = $account->id;
+                Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', $account->url, $group . '_GUIDE_PERSONAL_ACCOUNT_ID', $account->id);
+            } else {
+                Redis::Hmset('env', $group . '_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE', '', $group . '_GUIDE_PERSONAL_ACCOUNT_ID', '');
+            }
+        }
+        Redis::sadd(strtolower($group) . '_guide_personal_uv', $this->uid);
+        if ($group == 'OUT_FORCE') {
+            $data = UserService::getById($this->uid);
+            Redis::hset('crm:out_guide_exposure_user', $data->openid, $this->uid);
+        }
+        $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('name')->first();
+        DB::table('ad_pdd')->insert([
+            'uid' => $this->uid,
+            'img' => $group . '_GUIDE_PERSONAL_ACCOUNT_' . $now_id,
+            'date' => date('Y-m-d'),
+            'created_at' => date('Y-m-d H:i:s'),
+            'updated_at' => date('Y-m-d H:i:s')
+        ]);
+
+        ForceGuidePersonAccountService::create($this->uid, $bid_no, $cid);
+
+        $link['next'] = sprintf('/reader?bid=%s&cid=%s', $bid, $cid);
+        $link['prev'] = sprintf('/reader?bid=%s&cid=%s', $bid, $prev_cid);
+        $link['catalog'] = sprintf('/catalog?id=%s', $bid);
+
+        return view('jump.forceGuidePersonalAccountV2', ['img' => $img, 'link' => $link, 'title' => $book_name, 'name' => $personal_info->name]);
+    }
+
+
+    public function crmPushView(Request $request)
+    {
+        $crm_config = redisEnvMulti('ACTIVE_GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',
+            'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_UV', 'ACTIVE_GUIDE_PERSONAL_ACCOUNT_ID',
+            'ACTIVE_GUIDE_PERSONAL_ACCOUNT_MAX_EVERY_UV');
+        $img = $crm_config[0];
+        $max = empty($crm_config[1]) ? 100 : $crm_config[1];
+        $max = (int)$max;
+        $one_loop_max = empty($crm_config[3]) ? 10 : $crm_config[3];
+        $now_id = (int)$crm_config[2];
+        $uv_key = 'active_guide_personal_uv';
+        $uv = Redis::scard($uv_key);
+        $personal_info = DB::table('personal_account_list')->where('id', $now_id)->select('id','count','name')->first();
+        $total_max = (int)($personal_info->count + $uv);
+        if (empty($img) || empty($now_id) || $total_max >= $max) {
+            //没有名额
+            $data = ['code' => -1, 'read_url' => '/sign'];
+            return view('crm.crmPush', $data);
+        }
+        $sql = 'SELECT friend_link_uid_bind.uid FROM friend_link_uid_bind where openid = (SELECT openid FROM users WHERE id = %s) ORDER by id desc limit 1';
+        $friend_link_uid_bind = DB::select(sprintf($sql, $this->uid));
+        //$get_info = UserBindHkWelfareService::isHasGet($this->uid);
+        if ($friend_link_uid_bind) {
+            $info = DB::table('ad_pdd')->where('uid', $friend_link_uid_bind[0]->uid)->orderBy('id', 'desc')->first();
+            if ($info) {
+                $personal_account_id = preg_replace('/\D+/', '', $info->img);
+                if ($info) {
+                    $personal_info = DB::table('personal_account_list')
+                        ->where('id', $personal_account_id)
+                        ->where('is_enable', 1)
+                        ->select('name', 'url', 'status', 'is_enable')->first();
+                    if ($personal_info) {
+                        $data = ['code' => -2, 'name' => $personal_info->name];
+                        return view('crm.crmPush', $data);
+                    }
+                }
+            }
+            $user_info = UserService::getById($friend_link_uid_bind[0]->uid);
+            $link = 'https://site'.encodeDistributionChannelId($user_info->distribution_channel_id).'.leyuee.com/sign';
+            $data = ['code' => -3, 'read_url' => $link];
+            return view('crm.crmPush', $data);
+        }
+        $property = UserDivisionCpcPropertyService::getUserPropertyV2($this->uid);
+        $charge = false;
+        if (in_array($property, ['medium', 'high'])) {
+            $charge = true;
+        } else {
+            if ($this->property == 'undefined' && OrderService::getChargeNum($this->uid) >= 10) {
+                $charge = true;
+            }
+        }
+        if (!$charge) {
+            //不符合条件
+            $data = ['code' => -1, 'read_url' => '/sign'];
+            return view('crm.crmPush', $data);
+        }
+
+        Redis::sadd($uv_key, $this->uid);
+
+        DB::table('ad_pdd')->insert([
+            'uid' => $this->uid,
+            'img' => 'GUIDE_PERSONAL_ACCOUNT_' . $now_id,
+            'date' => date('Y-m-d'),
+            'created_at' => date('Y-m-d H:i:s'),
+            'updated_at' => date('Y-m-d H:i:s')
+        ]);
+        return view('crm.crmPush2', ['name' => $personal_info->name, 'img' => $img]);
+    }
+}