BusinessChannelStatTask.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/26
  6. * Time: 下午3:29
  7. */
  8. namespace App\Console\Commands;
  9. use App\Modules\Channel\Services\BusinessChannelDayStatService;
  10. use App\Modules\Channel\Services\BusinessChannelStatService;
  11. use App\Modules\Channel\Services\ChannelOrdersService;
  12. use App\Modules\Channel\Services\ChannelService;
  13. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  14. use App\Modules\SendOrder\Services\SendOrderService;
  15. use App\Modules\Statistic\Services\WapVisitStatService;
  16. use App\Modules\User\Services\UserService;
  17. use Log;
  18. use Illuminate\Console\Command;
  19. class BusinessChannelStatTask extends Command
  20. {
  21. /**
  22. * 执行命令 php artisan BusinessChannelStat_task
  23. *
  24. * The name and signature of the console command.
  25. *
  26. * @var string
  27. */
  28. protected $signature = 'BusinessChannelStat_task';
  29. /**
  30. * The console command description.
  31. *
  32. * @var string
  33. */
  34. protected $description = '每日商务渠道数据生成';
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. print_r("======每日生商务渠道数据生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  43. Log::info("======每日商务渠道数据生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  44. $dateNow = date("Y-m-d");
  45. // $dateNow = "2018-01-30";
  46. $yesterStartDay = date('Y-m-d', strtotime($dateNow." -1 day"))." 00:00:00";
  47. $yesterEndDay = date('Y-m-d', strtotime($dateNow))." 00:00:00";
  48. $last_monthStartDay = date('Y-m', strtotime($dateNow." -1 month"))."-01 00:00:00";
  49. $current_monthStartDay = date('Y-m', strtotime($dateNow))."-01 00:00:00";
  50. $beginLastweek=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
  51. $endLastweek=date('Y-m-d H:i:s',mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')));
  52. $current_week_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));
  53. $current_week_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
  54. $channels = ChannelService::getAllChannels();
  55. foreach ($channels as $channel) {
  56. $userRegisterNum = UserService::getChannelDayTotal($channel['id'], $yesterStartDay);
  57. $sendOrderDataNum = SendOrderService::getDuraingPromotionCountByChannelId($channel['id'], $yesterStartDay, $yesterEndDay);
  58. $data = WapVisitStatService::getReaderUvAndPv($channel, date('Y-m-d',strtotime('-1 day')));
  59. $whole_pv=$whole_uv=0;
  60. if ($data) {
  61. $whole_uv = $data['uv'];
  62. $whole_pv = $data['pv'];
  63. }
  64. try{
  65. $paramsA = [
  66. 'distribution_channel_id' => $channel['id'],
  67. 'date' => $yesterStartDay,
  68. 'register_user_num' => $userRegisterNum,
  69. 'send_order_num' => $sendOrderDataNum,
  70. 'is_login_yesterday'=>UserService::judgeUserYesterdayLogin($channel['id'],$yesterStartDay,$yesterEndDay),
  71. 'whole_site_uv'=>$whole_uv,
  72. 'whole_site_pv'=>$whole_pv,
  73. 'auto_force_sub_num'=>BusinessChannelDayStatService::getAutoForceSubUserNum($channel['id'],$yesterStartDay,$yesterEndDay),
  74. 'self_force_sub_num'=>BusinessChannelDayStatService::getSelfForceSubUserNum($channel['id'],$yesterStartDay,$yesterEndDay),
  75. 'subscribe_user_num'=>BusinessChannelDayStatService::getChannelSubscribeNum($channel['id'],$yesterStartDay,$yesterEndDay),
  76. 'subscribe_amount' =>BusinessChannelDayStatService::getChannelSubscribeRecharge($channel['id'],$yesterStartDay,$yesterEndDay)
  77. ];
  78. BusinessChannelDayStatService::createBusinessChannelDayStat($paramsA);
  79. }catch (\Exception $exception){
  80. \Log::error($exception->getMessage());
  81. }
  82. $yesterday_register_user_num = $userRegisterNum;
  83. $current_month_register_user_num = UserService::getChannelDayToDayTotal([$channel['id']], $current_monthStartDay, $yesterEndDay);
  84. $last_month_register_user_num = UserService::getChannelDayToDayTotal([$channel['id']], $last_monthStartDay, $current_monthStartDay);
  85. $total_register_user_num = UserService::getChannelDayToDayTotal([$channel['id']], '', $yesterEndDay);
  86. $total_send_order_num = SendOrderService::getPromotionCountByChannelId($channel['id']);
  87. $current_month_new_channel_recharge = ChannelOrdersService::getCurrentMonthNewChannelsOrdersSum($channel['id']);
  88. $current_month_channel_recharge = ChannelOrdersService::getChannelsOrdersSum($channel['id'],$current_monthStartDay);
  89. $paramsB = [
  90. 'yesterday_register_user_num' => $yesterday_register_user_num,
  91. 'current_month_register_user_num' => $current_month_register_user_num,
  92. 'last_month_register_user_num' => $last_month_register_user_num,
  93. 'total_register_user_num' => $total_register_user_num,
  94. 'total_send_order_num' => $total_send_order_num,
  95. 'current_month_new_channels_recharge'=>$current_month_new_channel_recharge,
  96. 'current_month_channels_recharge'=>$current_month_channel_recharge,
  97. 'service_account_num' =>BusinessChannelStatService::getServiceAccountNum($channel['id']),
  98. 'last_week_login_days' =>BusinessChannelStatService::getLoginDays($channel['id'],$beginLastweek,$endLastweek),
  99. 'current_week_login_days'=>BusinessChannelStatService::getLoginDays($channel['id'],$current_week_start,$current_week_end),
  100. 'last_week_actual_send_orders'=>SendOrderService::getPeriodActualSendOrdersNum($channel['id'], $beginLastweek,$endLastweek),
  101. 'current_week_actual_send_orders'=>SendOrderService::getPeriodActualSendOrdersNum($channel['id'], $current_week_start,$current_week_end),
  102. 'yesterday_create_orders'=>SendOrderService::getDuraingPromotionCountByChannelId($channel['id'],$yesterStartDay,$yesterEndDay),
  103. 'is_login_yesterday'=>$paramsA['is_login_yesterday'],
  104. 'last_month_channels_recharge'=>BusinessChannelStatService::getLastMonthChannelRecharge($channel['id']),
  105. 'last_month_new_channel_recharge'=>BusinessChannelStatService::getLastMonthNewChannelRecharge($channel['id']),
  106. ];
  107. //\Log::info('paramB'.json_encode($paramsB));
  108. BusinessChannelStatService::crateUpdate($channel['id'], $paramsB);
  109. }
  110. Log::info("======每日商务渠道数据生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
  111. print_r("======每日商务渠道数据生成 【任务执行结束】=====".date("y-m-d H:i:s"."\n"));
  112. }
  113. }