Browse Source

crm stats

zz 6 years ago
parent
commit
5666e2ac91

+ 51 - 0
app/Console/Commands/WapVisitStat.php

@@ -694,4 +694,55 @@ class WapVisitStat extends Command
         }
         Redis::del(sprintf('push:stylepush:date:%s',$date));
     }
+
+    private function crm(){
+        $date = date('Y-m-d',time()-86400);
+        $record = Redis::SMEMBERS('crm_'.$date);
+        $data = [];
+        $sql = "select
+ order_params.data_hour_key,
+sum(price) as charge_amount,
+ count(*) as charge_num
+from orders 
+join order_params on orders.id = order_params.order_id 
+where orders.created_at BETWEEN '%s' and '%s' and order_params.gxhp='crm'  and orders.status = 'PAID'
+GROUP by order_params.data_hour_key";
+        if($record){
+            foreach ($record as $value){
+                $pv = Redis::hget(sprintf('crm:pv:%s',$value));
+                $uv = Redis::hget(sprintf('crm:Uv:%s',$value));
+                $data[] =
+                    ['crm_id'=>$value,'day'=>$date,'pv'=>$pv,
+                        'uv'=>$uv,'charge_num'=>0,'charge_amount'=>0,
+                        'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
+
+                //Redis::hdel(sprintf('crm:pv:%s',$value));
+                //Redis::hdel(sprintf('crm:Uv:%s',$value));
+
+            }
+            if($data){
+                DB::table('crm_stats')->insert($data);
+            }
+        }
+        $data = [];
+        $order_info = DB::select(sprintf($sql,$date,date('Y-m-d 00:00:00')));
+        if($order_info){
+            foreach ($order_info as $o){
+                $update_status = DB::table('crm_stats')->where('day',$date)->where('crm_id',$o->data_hour_key)->update([
+                    'charge_num'=>$o->charge_num,
+                    'charge_amount'=>$o->charge_amount
+                ]);
+                if(!$update_status){
+                    $data[] =
+                        ['crm_id'=>$o->data_hour_key,'day'=>$date,'pv'=>0,
+                            'uv'=>0,'charge_num'=>$o->charge_num,'charge_amount'=>$o->charge_amount,
+                            'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];
+                }
+            }
+
+            if($data){
+                DB::table('crm_stats')->insert($data);
+            }
+        }
+    }
 }

+ 0 - 285
app/Console/Kernel.php

@@ -13,117 +13,14 @@ class Kernel extends ConsoleKernel
      * @var array
      */
     protected $commands = [
-        Commands\ChapterImageTask::class,
-        Commands\BillTask::class,
-        Commands\PaymentQueryTask::class,
-        Commands\PaymentStatisticTask::class,
-        Commands\BusinessChannelStatTask::class,
         Commands\BookAdjust::class,
         Commands\BookAdjustOne::class,
         Commands\BookSpider::class,
         Commands\BookUpdate::class,
         Commands\BookUpdateOne::class,
-        Commands\UpdateBookClickCount::class,
         Commands\BookTest::class,
-        Commands\SignReward::class,
-        Commands\NoPayRemind::class,
-        Commands\Trade\GenerateOrderDayStat::class,
-        Commands\Trade\GenerateOrderStat::class,
-        Commands\SendServiceMsg::class,
-        Commands\FailOrderAlert::class,
         Commands\BookAfterSpider::class,
-        Commands\PayChannelCheck::class,
-        Commands\ChangePay::class,
-        Commands\WechatCustumerPushStatistical::class,
-        Commands\Sub\GenerateCpSubDayStat::class,
-        Commands\Channel\CheckStatus::class,
-        Commands\ChapterOrderTotal::class,
-        Commands\SendOrder\GenerateForceDayStat::class,
-        Commands\SendOrder\GenerateStat::class,
-        Commands\SendOrder\SetExtraStats::class,
-        Commands\SendOrder\GenerateBookUvRegisterStat::class,
-        Commands\SendOrder\UserActivityStats::class,
-        Commands\CheckAndSend::class,
-        Commands\RecoverPush::class,
-        Commands\ForceUserActive::class,
-        Commands\ForceUserActiveDetail::class,
-        Commands\PaidUserRemind::class,
-        Commands\SendOrderBreakevenForceUser::class,
-        Commands\UnPaidUserActivity::class,
-        Commands\CustomSubscribePush::class,
-        Commands\CustomSignPush::class,
-
-        Commands\SmartPush\AllPushHotBook::class,
-        Commands\SmartPush\PaidPushPointBook::class,
-        Commands\SmartPush\UnPaidPushHotBook::class,
-        Commands\SmartPush\UnPaidPushPointBook::class,
-        Commands\SmartPush\UnPaidUserBigActivity::class,
-        Commands\SmartPush\UnPaidUserSmallActivity::class,
-        Commands\SmartPush\LongChapterTemplate::class,
-        Commands\SmartPush\LongChapterCustom::class,
-        Commands\SmartPush\PaidUserCustom::class,
-        
-        Commands\Tool\OfficialAccountUserTranser::class,
-        Commands\Tool\TestSmartPush::class,
-        Commands\Tool\MaintainTempForceSubscribeUser::class,
-        Commands\Tool\MaintainSubscribeReplyRedisData::class,
-        Commands\Tool\TitleImageStatistics::class,
-        Commands\Tool\ThirdPlatomUserTranser::class,
-        
-        
-        Commands\DistributionStats\WeeklyDailyStats::class,
-        
-        Commands\SubscribeDataStats::class,
-        Commands\ForBiddenOfficialAccountRemind::class,
-        Commands\RepeatBookOrderRecover::class,
-        Commands\SubscribeAlert::class,
-        Commands\CheckOfficialAccountTemplate::class,
-        Commands\OfficialAccountStat\SubUserRecharge::class,
-        Commands\Temp\UserSign::class,
-        Commands\Temp\FansArpu::class,
-        Commands\Temp\Siorder::class,
-        Commands\Temp\FixRealReg::class,
-        Commands\Temp\OfficialAccountSubStat::class,
-        Commands\WapVisitStat::class,
-        Commands\CP\GenerateCpBookStat::class,
-        Commands\CP\GenerateCpBookBetweenStat::class,
-        Commands\AutoSendTrusteeShipCustomerMsg::class,
-        Commands\WelfareNextDay::class,
-        Commands\WelfarePrize::class,
         Commands\BookAttr::class,
-        Commands\OfficialAccountBillsTask::class,
-        Commands\Temp\PayUserAutoSub::class,
-        Commands\Temp\SelectPayUser::class,
-        Commands\Temp\SensitiveChapter::class,
-
-        Commands\SendOrder\SendStatsEmail::class,
-        Commands\ProductStats\SendMonthStatsEmail::class,
-        Commands\ProductStats\DailyProductionStats::class,
-        Commands\ProductStats\MonthlyProductionStats::class,
-        Commands\ProductStats\SendDailyProductionStats::class,
-        Commands\ProductStats\SendMonthlyProductStats::class,
-        Commands\SuperiorBooks\DailyScanForSupriorNewBook::class,
-        Commands\SuperiorBooks\HistorySupriorBook::class,
-
-        Commands\UserSubscribleStatistic::class,
-        Commands\SuperiorBooks\TempCommand::class,
-        Commands\CheckBookCover::class,
-        Commands\fansMaximumNotice::class,
-        Commands\BookGiftStats\BookGiftStatsByBook::class,
-        Commands\BookGiftStats\BookGiftStatsByGift::class,
-        Commands\MovedChannelsReback::class,
-        Commands\WholeBookOrderData::class,
-        Commands\ChargeTemplateStat::class,
-
-        Commands\TemporaryTask::class,
-        Commands\CheckSiteStatus::class,
-        Commands\AutoWithdrawCash::class,
-
-        Commands\ChannelReaderVisitStats::class,
-
-        Commands\ChannelReaderVisitStats::class,
-        Commands\UserPayUpdateTask::class,
-        Commands\CheckZhangDuSiteStatus::class,
         Commands\YqBook::class
     ];
 
@@ -135,188 +32,6 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
-        //每日派单数据生成
-        $schedule->command('send_order:generate_force_day_stat')->dailyAt("04:30");
-
-        $schedule->command('bill_task')->dailyAt("00:30");
-
-        //每日打款报表
-        $schedule->command('payment_statistic_task')->dailyAt("00:30");
-        //打款状态查询 10分钟执行一次
-        $schedule->command('payment_query_task')->everyTenMinutes();
-
-        //每日商务渠道数据报表
-        $schedule->command('BusinessChannelStat_task')->dailyAt("00:30");
-
-        //点击率
-        $schedule->command('book:clicknumupdate')->dailyAt('01:00');
-
-        //更新图书
-        $schedule->command('book:update')->dailyAt('22:00');
-
-        //未支付提醒
-        $schedule->command('Pay:remind')->hourly();
-
-        //检查公众号模板
-        $schedule->command('CheckOfficialAccountTemplate')->hourly();
-
-        //订单相关
-        //生成渠道日统计
-        $schedule->command('generate_order_day_stat')->dailyAt("00:05");
-        //生成渠道汇总统计
-        $schedule->command('generate_order_stat')->dailyAt("00:25");
-
-        //订单预警
-        $schedule->command('foa')->everyMinute();
-        //$schedule->command('foa --qrcode')->everyMinute();
-        //签到推送
-        //$schedule->command('sign:reward')->everyMinute();
-        //测试账号支付通道切换
-        //$schedule->command('pay:change')->dailyAt('00:00');
-        //推送统计
-        $schedule->command('pay:wcps')->dailyAt('02:30');
-        //托管推送
-        $schedule->command('pay:wcps --auto')->dailyAt('05:20');
-
-        //更新章节订购统计
-        $schedule->command('book:cot')->dailyAt('01:15');
-
-        //检查渠道账号状态
-        //$schedule->command('channel_user_check_status')->dailyAt('03:30');
-
-        $schedule->command('CheckAndSend')->everyMinute();
-
-        // 检查公众号被封
-        $schedule->command('ForBiddenOfficialAccountRemind')->everyFiveMinutes();
-
-        //付费用户每日提醒
-//         $schedule->command('PaidUserRemind')->dailyAt('08:00');
-        
-        //更新粉丝数
-        $schedule->command('sendorderbreadforceuser')->dailyAt('02:50');
-        //签到统计
-        $schedule->command('sign:reward --record')->dailyAt('02:00');
-        //cp订阅书币和充值币和赠送币
-        $schedule->command('book:cot --type=cp')->dailyAt('02:20');
-        //order_day_stats 阅书币和充值币和赠送币
-        $schedule->command('book:cot --type=order')->dailyAt('02:40');
-        //send_orders_stats 阅书币和充值币和赠送币
-        $schedule->command('book:subds')->dailyAt('03:10');
-
-        //粉丝预警
-        $schedule->command('subscribealert --type=getTopAlert')->hourly();
-        //强关预警
-        $schedule->command('subscribealert --type=subscribeRateAlert')->hourly();
-
-        //uv pv redis持久
-        $schedule->command('wvs 9')->dailyAt('04:00');
-
-        // 每天周报数据
-
-        $schedule->command('WeeklyDailyStats all')->dailyAt('02:02');
-
-        // CP 
-        // cp书籍订阅数据,需在order_day_stats后执行,每周一执行一次
-//         $schedule->command('cp_generate_cp_book_stat')->weekly()->mondays()->at('05:10');
-        //  cp书籍订阅数据,需在order_day_stats后执行,改为每天执行一次
-        $schedule->command('cp_generate_cp_book_stat')->dailyAt('05:10');
-
-        // 自动提现申请
-        $schedule->command('AutoWithdrawCash')->dailyAt('01:20');
-        
-        //自动推送托管客服消息
-        $schedule->command('AutoSendTrusteeShipCustomerMsg')->dailyAt('19:00');
-
-        //跑派单ID的24小时的uv、pv
-        $schedule->command('send_order:set_extra_stats')->everyMinute();
-
-        //分销红包
-        $schedule->command('welfare:prize')->everyMinute();
-        $schedule->command('welfare:nextday')->dailyAt('23:55');
-
-        //服务号每日充值统计
-        $schedule->command('official_account_bills_task')->dailyAt('05:00');
-        //每日派单数量统计
-        $schedule->command('book:attr')->dailyAt('04:40');
-
-        //书币消耗 筛选必须在刷之后
-        $schedule->command('temp:select_user_pay')->dailyAt('16:00');
-        $schedule->command('temp:pay_user_auto_do')->dailyAt('06:00');
-
-        //统计每周派单发送邮件
-        $schedule->command('sendOrderEmail')->dailyAt('08:00');
-        $schedule->command('sendMonthOrderEmail')->monthlyOn(3, '08:00');
-        //每日作品统计
-        //$schedule->command('saveDailyProductsStats')->dailyAt('00:10');
-        //$schedule->command('saveMonthlyProductsStats')->monthlyOn(1, '00:20');
-        //$schedule->command('SendDailyProductsStats')->dailyAt('08:00');
-        $schedule->command('SendMonthlyProductsStats')->monthlyOn(1, '08:20');
-
-        //优质书库
-        $schedule->command('addSuperiorBook')->dailyAt('00:50');
-        $schedule->command('addHistorySuperiorBook')->dailyAt('01:20');
-
-        /********** 智能推送统一这里管理 ***********/
-
-        //全量推送热门书籍
-        $schedule->command('SmartPush:AllPushHotBook')->hourly()->between('6:00', '24:00');
-        //已付费推送定制书籍
-        $schedule->command('SmartPush:PaidPushPointBook')->hourly()->between('6:00', '24:00');
-        //未付费推送热门书籍
-        $schedule->command('SmartPush:UnpaidPushHotBook')->hourly()->between('6:00', '24:00');
-        //未付费推送定制书籍
-        $schedule->command('SmartPush:UnpaidPushPointBook')->hourly()->between('6:00', '24:00');
-        //未支付新用户优惠充值活动(更多充值选项)
-        $schedule->command('SmartPush:UnPaidUserBigActivity')->hourly()->between('6:00', '24:00');
-        //未支付新用户9.9充值活动
-        $schedule->command('SmartPush:UnPaidUserSmallActivity')->hourly()->between('6:00', '24:00');
-        //支付用户6小时后推送客服消息
-        $schedule->command('SmartPush:PaidUserCustom')->hourly()->between('6:00', '24:00');
-        
-        //测试用户推送长篇客服
-        $schedule->command('SmartPush:LongChapterCustom')->hourly()->between('6:00', '24:00');
-        //测试用户推送长篇模板
-        $schedule->command('SmartPush:LongChapterTemplate')->hourly()->between('6:00', '24:00');
-        
-        //关注智能推送
-        $schedule->command('CustomSubscribePush')->everyTenMinutes();
-
-        //签到智能推送
-        $schedule->command('CustomSignPush')->everyTenMinutes();
-
-        /********** 智能推送 end ***********/
-
-        //敏感章节生成查询
-        $schedule->command('temp:sensitive_chapter')->dailyAt('03:20');
-
-        //粉丝统计:用户强关行为统计
-        $schedule->command('user_subscribe_statistic')->dailyAt('01:10');
-
-        //强关中间表每日维护
-        $schedule->command('MaintainTempForceSubscribeUser')->dailyAt('03:02');
-
-        $schedule->command('check_book_cover_status')->weekly()->mondays()->at('04:10');
-        //阈值提醒
-        $schedule->command('addFansMaximumNotice')->hourly();
-
-        //用户打赏统计
-        $schedule->command('BookGiftDailyStatsByBook')->dailyAt('01:05');
-        $schedule->command('BookGiftDailyStatsByGift')->dailyAt('01:10');
-
-        $schedule->command('compensateForChannels')->everyMinute();
-
-        //内外部派单按数据统计数据
-        $schedule->command('sendOrder_book_uv_register_stat')->dailyAt('7:00');
-
-        //掌中云新增站点信息采集
-        $schedule->command('check_site_status')->dailyAt('6:00');
-        //掌读新增站点信息采集
-        $schedule->command('check_zhang_du_site_status')->dailyAt('6:00');
-
-        //阅读页面PV 和  UV 的记录
-        $schedule->command('channel_reader_visit_stats')->dailyAt('8:00');
 
-        //更新user_pay表
-        $schedule->command('userPayUpdateTask')->dailyAt('03:00');
     }
 }

+ 3 - 0
app/Http/Controllers/Wap/BaseController.php

@@ -53,6 +53,8 @@ class BaseController extends Controller
      */
     protected $from_type;
 
+    protected $crm = '';
+
     function __construct(Request $request)
     {
         $domain = _domain();
@@ -85,6 +87,7 @@ class BaseController extends Controller
         if($this->uid == 114933690) {
             $this->uid = 108535910;
         }
+        $this->crm = Cookie::get('crm');
         $this->innerSendOrderIdFromFromtype($this->uid);
         $this->send_order_id = $send_order_id;
         $this->from_type  = Cookie::get('from') ? Cookie::get('from') : 'main';

+ 3 - 2
app/Http/Controllers/Wap/Book/ChapterController.php

@@ -1307,13 +1307,14 @@ class ChapterController extends BaseController
     private function getCorrespondBookUrl()
     {
         $url = sprintf(
-            'https://site%s.%s/reader?bid=%s&cid=%s&send_order_id=%s&fromtype=%s&stats=2',
+            'https://site%s.%s/reader?bid=%s&cid=%s&send_order_id=%s&fromtype=%s&stats=2&crm=%s',
             $this->en_distribution_channel_id,
             $this->book_info->promotion_domain,
             $this->en_bid,
             $this->cid,
             $this->send_order_id,
-            $this->from_type
+            $this->from_type,
+            $this->crm
         );
         return $url;
     }

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

@@ -73,6 +73,7 @@ class OrdersController extends Controller
         $activity_id = $request->has('activity_id') ? $request->get('activity_id') : 0;
         $ip = $request->has('ip') ? $request->get('ip') : '';
         $n = $request->has('n') ? $request->get('n') : 0;
+        $crp = $request->has('crp') ? $request->get('crp') : 0;
 
         if ($send_order_id && strlen($send_order_id) > 50) {
             try {
@@ -322,6 +323,11 @@ class OrdersController extends Controller
                     'order_id'=>$result->id,'gxhp'=>'mw_transfer','appid'=>'','bid'=>$bid,'data_hour_key'=>'','times'=>'','distribution_channel_id'=>$p_channel_id
                 ]);
             }
+            if($crp){
+                OrderParamService::createByParam([
+                    'order_id'=>$result->id,'gxhp'=>'crm','appid'=>'','bid'=>$bid,'data_hour_key'=>$crp,'times'=>'','distribution_channel_id'=>$distribution_channel_id
+                ]);
+            }
         }
 
         if ($request->get('suid')) {

+ 31 - 3
app/Http/Controllers/Wap/User/CoflController.php

@@ -14,6 +14,8 @@ use Hashids;
 use EasyWeChat\Foundation\Application;
 use Log;
 use Exception;
+use Redis;
+use Cookie;
 
 /**
  * 朋友圈链接
@@ -43,7 +45,7 @@ class CoflController extends Controller
         }catch (Exception $e){
             return redirect()->to($this->getLink());
         }
-
+        $crm = $request->get('crm');
         //获取用户
         $user = $this->getUsers($openid);
         if(!$user[0]){
@@ -62,6 +64,7 @@ class CoflController extends Controller
         if(isset($params['openid']))  unset($params['openid']);
         if(isset($params['unionid']))  unset($params['unionid']);
         $url = $this->getLink($user[1]).'reader?'.http_build_query($params);
+        $this->stats('book',$crm);
         return redirect()->to($url);
     }
 
@@ -79,11 +82,15 @@ class CoflController extends Controller
         $uri = $request->path();
         $token = $request->get('token');
         $rfee = $request->get('amount');
+        $crm = $request->get('crm');
         if($uri == 'freethrhcurrency'){
             $fee = 300;
+            $this->stats('reward_300',$crm);
         }else{
+            $this->stats('reward_200',$crm);
             $fee = $this->freeCurrencyFee($token,$rfee);
         }
+
         $user = $this->getUsers($openid);
         if(!$user || !$user[0] || !$user[1]) return redirect()->to($this->getLink());
         $get_free_currency = UserBindHkWelfareService::isHasGet($user[0]);
@@ -128,7 +135,8 @@ class CoflController extends Controller
             $app = new Application($this->auth($params));
             return $app->oauth->redirect();
         }
-
+        $crm = $request->get('crm');
+        $this->stats('activity',$crm);
         $activity = ActivityService::getByToken($token);
         if($activity){
             $user = $this->getUsers($openid);
@@ -161,6 +169,8 @@ class CoflController extends Controller
         }else{
             $distribution_channel_id = $user[1];
         }
+        $crm = $request->get('crm');
+        $this->stats('recent',$crm);
         $link = $this->getLink($distribution_channel_id).'recent';
         return redirect()->to($link);
     }
@@ -181,6 +191,8 @@ class CoflController extends Controller
         }else{
             $distribution_channel_id = $user[1];
         }
+        $crm = $request->get('crm');
+        $this->stats('person',$crm);
         $link = $this->getLink($distribution_channel_id).'person';
         return redirect()->to($link);
     }
@@ -236,5 +248,21 @@ class CoflController extends Controller
         return $options;
     }
 
-    private function stats(){}
+    private function stats($page,$flag){
+        if(!$page || !$flag) return ;
+        //pv
+        $day = date('Y-m-d');
+        $pv_key = sprintf('crm:pv:%s',$flag);
+        Redis::hincrby($pv_key, $day, 1);
+        //Redis::hincrby($pv_key, 'total', 1);
+        Redis::sadd('crm_'.$day,$flag);
+        //uv
+        $cookie_flag = Cookie::get('crm_flag');
+        if(!$cookie_flag || $cookie_flag != $flag){
+            $uv_key = sprintf('crm:uv:%s',$flag);
+            Redis::hincrby($uv_key, $day, 1);
+            //Redis::hincrby($uv_key, 'total', 1);
+        }
+        Cookie::queue('crm_flag', $flag, env('U_COOKIE_EXPIRE'), null, null, false, false);
+    }
 }

+ 8 - 1
app/Http/Controllers/Wap/Web/WelcomeController.php

@@ -87,6 +87,12 @@ class WelcomeController extends BaseController
         if (!$from) {
             $from = Cookie::get('from') ? Cookie::get('from') : 'main';
         }
+        //crm
+        $crm = $request->get('crm');
+        if (!$crm) {
+            $crm = Cookie::get('crm') ? Cookie::get('crm') : '';
+        }
+
         $channel_activities_flag = $this->judgeChannelActivity($user);
         //最近阅读页面 推荐
         $latest_read_rec_books = $this->latest_read_rec_books($channel, $user->sex);
@@ -177,7 +183,8 @@ class WelcomeController extends BaseController
             'share_domain'=>env('share_domain_url'),
             'share_switch'=>$share_switch,
             'pdd_ad'=>$pdd_ad,
-            'special_pay_template'=>$this->isMiWan()  //米玩站点特殊充值页面
+            'special_pay_template'=>$this->isMiWan(),  //米玩站点特殊充值页面
+            'crm'=>$crm
         ]);
         if ($this->uid == env('SPECIAL_USER_LOG', 2)) {
             myLog('special')->info('welcome --------------------------');

+ 3 - 1
app/Http/Middleware/EncryptCookies.php

@@ -22,6 +22,8 @@ class EncryptCookies extends BaseEncrypter
         'reader_share_bid',
         'reader_share_cid',
         'force_show_qrcode',
-        'cpc_ad_status'
+        'cpc_ad_status',
+        'crm',
+        'crm_flag'
     ];
 }

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

@@ -190,7 +190,8 @@ class ReadOauth
         if ($inner_order_id) {
             $this->innerSendOrderIdStats($uid_cookie, $inner_order_id, $stats);
         }
-
+        //crm
+        $this->crmParam($request);
         //from_title_image
         $this->fromTitleImage($request, $uid_cookie);
 
@@ -1175,4 +1176,11 @@ class ReadOauth
         ];
         return $options;
     }
+
+    private function crmParam(Request $request){
+        $crm_param = $request->get('crm');
+        if(!$crm_param){
+            Cookie::queue('crm', $crm_param);
+        }
+    }
 }