Prechádzať zdrojové kódy

Merge branch 'master' into stabble

zz 6 rokov pred
rodič
commit
89bee1e24e

+ 39 - 6
app/Http/Controllers/Wap/User/CoflController.php

@@ -344,18 +344,50 @@ class CoflController extends Controller
     }
 
     public function guidePersonalAccount(Request $request,$channel_id){
-        $uid = $request->get('uid');
+        $uid = $request->get('uid',0);
+
+        $env_config = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE','GUIDE_PERSONAL_ACCOUNT_MAX_USER','GUIDE_PERSONAL_ACCOUNT_ID');
+        $img = empty($env_config[0])?'https://cdn-novel.iycdm.com/h5/personal_account/chenchen.jpg':$env_config[0];
+        $max = empty($env_config[1])?100:$env_config[1];
+        $now_id = (int)$env_config[2];
+        $uv = Redis::scard('guide_personal_uv');
+        if($uv>=$max){
+            DB::table('personal_account_list')->where('id',$now_id)->update([
+                'status'=>2,
+                'count'=>$uv,
+                'updated_at'=>date('Y-m-d H:i:s')
+            ]);
+            $account = DB::table('personal_account_list')
+                ->where('is_enable',1)
+                ->where('status',0)
+                ->select('id','url')
+                ->orderBy('id')
+                ->first();
+            Redis::del('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','GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',$account->url,'GUIDE_PERSONAL_ACCOUNT_ID',$account->id);
+            }else{
+                return back();
+            }
+        }
+        Redis::sadd('guide_personal_uv',$uid);
+
         if($uid){
             DB::table('ad_pdd')->insert([
                 'uid'=>$uid,
-                'img'=>'GUIDE_PERSONAL_ACCOUNT',
+                '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')
             ]);
         }
-
-        if(in_array($channel_id,explode(',',redisEnv('GUIDE_PERSONAL_ACCOUNT_WEID_SITES')))){
+        /*if(in_array($channel_id,explode(',',redisEnv('GUIDE_PERSONAL_ACCOUNT_WEID_SITES')))){
             $imgs = redisEnv('GUIDE_PERSONAL_ACCOUNT_WEID_QRCODE',[]);
             if($imgs) $imgs = json_decode($imgs,1);
             $page = 'jump.guidePersonalAccount';
@@ -363,8 +395,9 @@ class CoflController extends Controller
             $imgs = redisEnv('GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',[]);
             if($imgs) $imgs = json_decode($imgs,1);
             $page = 'jump.guidePersonalAccountOurs';
-        }
-        $img = collect($imgs)->random();
+        }*/
+        $page = 'jump.guidePersonalAccountOurs';
+        //$img = collect($imgs)->random();
         return view($page,['img'=>$img]);
     }
 }

+ 30 - 2
app/Http/Controllers/Wap/Web/WelcomeController.php

@@ -2068,12 +2068,40 @@ class WelcomeController extends BaseController
     }
 
     private function guidePersonalAccount(){
-        if(!in_array($this->distribution_channel_id,explode(',',redisEnv('GUIDE_PERSONAL_ACCOUNT_SITES')))){
+        //GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE
+        $env_config = redisEnvMulti('GUIDE_PERSONAL_ACCOUNT_SITES','GUIDE_PERSONAL_ACCOUNT_START_TIME','GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE');
+        //\Log::info('guidePersonalAccount------------------------guidePersonalAccount');
+        //\Log::info($env_config);
+
+        if(empty($env_config[0]) || empty($env_config[1]) ){
+            \Log::info( 'empty' );
+            return '';
+        }
+        //Log::info( '$this->distribution_channel_id is: '.$this->distribution_channel_id );
+        if(!in_array($this->distribution_channel_id,explode(',',$env_config[0]))){
             return '';
         }
-        $guide_personal_account_start_time = redisEnv('GUIDE_PERSONAL_ACCOUNT_START_TIME');
+        //\Log::info('distribution_channel_id in');
+        $guide_personal_account_start_time = $env_config[1];
         if(!$guide_personal_account_start_time)
             return false;
+        if(empty($env_config[2])){
+            $account = DB::table('personal_account_list')
+                ->where('is_enable',1)
+                ->where('status',0)
+                ->select('id','url')
+                ->orderBy('id')
+                ->first();
+            if(!$account){
+                return false;
+            }
+            DB::table('personal_account_list')->where('id',$account->id)->update([
+                'status'=>1,
+                'updated_at'=>date('Y-m-d H:i:s')
+            ]);
+            Redis::Hmset('env','GUIDE_PERSONAL_ACCOUNT_OURS_QRCODE',$account->url,'GUIDE_PERSONAL_ACCOUNT_ID',$account->id);
+        }
+
         $get_info = UserBindHkWelfareService::isHasGet($this->uid);
         if($get_info){
             return '';

+ 49 - 6
app/Modules/Subscribe/Models/CustomChapterOrder.php

@@ -12,13 +12,18 @@ class CustomChapterOrder extends Model
     'fee','custom_id','flag','charge_balance','reward_balance','send_time'];
 
 
-    public static function getStats($custom_id=0,$distribution_channel_id=0,$bid=0)
+    public static function getStats($custom_id=0,$distribution_channel_id=0,$bid=0,$book_name='',$is_all=false)
     {
         $where = [];
         $custom_id && $where[] = ['custom_chapter_orders.custom_id','=',$custom_id];
         $distribution_channel_id && $where[] = ['custom_chapter_orders.distribution_channel_id','=',$distribution_channel_id];
         $bid && $where[] = ['custom_chapter_orders.bid','=',$bid];
-        return self::join('custom_send_msgs',function ($join){
+        $bids = [];
+        if($book_name){
+            $bids = DB::table('book_configs')->where('book_name','like','%'.$book_name.'%')->select('bid')->pluck('bid')->all();
+		    \Log::info($bids);
+        }
+        $result =  self::join('custom_send_msgs',function ($join){
             $join->on('custom_send_msgs.id','=','custom_chapter_orders.custom_id')
                 ->where('custom_chapter_orders.flag',1);
         })->select(
@@ -38,14 +43,52 @@ class CustomChapterOrder extends Model
             <= ADDDATE(custom_chapter_orders.send_time,"INTERVAL 3 day") 
             then custom_chapter_orders.fee else null end) as three_day_amount'),//72小时订阅总额
             DB::raw('count(distinct case when custom_chapter_orders.send_time 
-            <= ADDDATE(custom_chapter_orders.uid,"INTERVAL 3 day") 
+            <= ADDDATE(custom_chapter_orders.send_time,"INTERVAL 3 day") 
             then custom_chapter_orders.uid else null end) as three_day_num'),//72小时订阅人数
             DB::raw('count(distinct uid) as total_num'),//订阅用户
             //DB::raw('one_day_amount/one_day_num as one_day_rate'),//24小时人均订阅
             //DB::raw('three_day_amount/three_day_num as three_day_rate'),//72h人均订阅
             DB::raw('sum(fee) as total_amount')//订阅总额
-        )->where($where)
-        ->groupBy('custom_chapter_orders.custom_id')
-        ->paginate();
+        )->where($where);
+        if($bids){
+            $result->whereIn('custom_chapter_orders.bid',$bids);
+        }
+        if($is_all){
+            return $result->groupBy('custom_chapter_orders.custom_id')
+                ->get();
+        }else{
+            return $result->groupBy('custom_chapter_orders.custom_id')
+                ->paginate();
+        }
     }
+
+    public static function export(\Illuminate\Http\Request $request)
+    {
+        $custom_id = $request->get('custom_id');
+        $distribution_channel_id = $request->get('distribution_channel_id');
+        $bid = $request->get('bid');
+        $book_name = $request->get('book_name');
+        $result = self::getStats($custom_id,$distribution_channel_id,$bid,$book_name,true);
+        $filename = 'custom_chapter_order'.date('YmdHis').'.csv';
+        \Storage::append($filename,mb_convert_encoding("id,站点,推送时间,书籍,送达人数,24小时订阅总额,24小时订阅人数,24小时人均订阅,72小时订阅总额,72小时订阅人数,72h人均订阅,订阅用户,订阅总额",'gbk'));
+        $str = '';
+        foreach ($result as $val){
+            if(!$val->one_day_num){
+                $one_day_rate = 0;
+            }else{
+                $one_day_rate = round($val->one_day_amount/$val->one_day_num,2);
+            }
+            if(!$val->three_day_num){
+                $three_day_rate =0;
+            }else{
+                $three_day_rate = round($val->three_day_amount/$val->three_day_num,2);
+            }
+
+
+            $str .= "{$val->custom_id},{$val->distribution_channel_id},{$val->send_time},{$val->book_name},{$val->user_num},{$val->one_day_amount},{$val->one_day_num},{$one_day_rate},{$val->three_day_amount},{$val->three_day_num},{$three_day_rate},{$val->total_num},{$val->total_amount}\r\n";
+        }
+        \Storage::append($filename,mb_convert_encoding($str,'gbk'));
+        return response()->download(storage_path('app/'.$filename))->deleteFileAfterSend(true);
+    }
+
 }