SendOrderStatisticsService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <?php
  2. /**
  3. * 派单数据统计
  4. */
  5. namespace App\Modules\SendOrder\Services;
  6. use App\Modules\SendOrder\Models\SendOrderStat;
  7. use DB;
  8. use Redis;
  9. class SendOrderStatisticsService
  10. {
  11. public static function get_query_date(){
  12. $today = date('Y-m-d H:i:s');
  13. // $today = '2018-11-21 12:00:00';
  14. $today_time = strtotime($today);
  15. $week_date = self::getWeek($today_time);
  16. \Log::info('$week_date');
  17. \Log::info($week_date);
  18. $today = date('Y-m-d');
  19. $start_date = $end_date = '';
  20. // 算最后end_date计算时间
  21. // 周六~周五 小周期
  22. // 周六~下二个周一 大周期
  23. // 周一算上周的
  24. if($week_date['week_num'] ==1){
  25. $reduce_big_end_day = -7;
  26. }
  27. // 周日
  28. elseif($week_date['week_num'] ==0){
  29. $reduce_big_end_day = -6;
  30. }else{
  31. $reduce_big_end_day = 1-$week_date['week_num'];
  32. }
  33. $reduce_big_start_day = $reduce_big_end_day - 9;
  34. $reduce_small_start_day = $reduce_big_start_day;
  35. $reduce_small_end_day = $reduce_big_end_day - 3;
  36. \Log::info('$reduce_big_start_day:'.$reduce_big_start_day.' $reduce_big_end_day:'.$reduce_big_end_day.' $reduce_small_start_day:'.$reduce_small_start_day.' $reduce_small_end_day:'.$reduce_small_end_day);
  37. $small_start_day = date('Y-m-d',$today_time + 3600*24*$reduce_small_start_day);
  38. $small_end_day = date('Y-m-d',$today_time + 3600*24*$reduce_small_end_day);
  39. $big_start_day = date('Y-m-d',$today_time + 3600*24*$reduce_big_start_day);
  40. $big_end_day = date('Y-m-d',$today_time +3600*24*$reduce_big_end_day);
  41. $data = [
  42. 'start_day'=>$small_start_day,
  43. 'end_day'=>$small_end_day,
  44. 'small_start_day'=>$small_start_day.' 00:00:00',
  45. 'small_end_day'=>$small_end_day.' 23:59:59',
  46. 'big_start_day'=>$big_start_day.' 00:00:00',
  47. 'big_end_day'=>$big_end_day.' 23:59:59',
  48. ];
  49. \Log::info('get_query_date_end');
  50. \Log::info($data);
  51. return $data;
  52. }
  53. //php获取今天是星期几
  54. public static function getWeek($unixTime=''){
  55. $unixTime=is_numeric($unixTime)?$unixTime:time();
  56. $weekarray=array('日','一','二','三','四','五','六');
  57. $week_num = date('w',$unixTime);
  58. $data = [
  59. 'week_num'=>$week_num,
  60. 'week_name'=>'星期'.$weekarray[$week_num]
  61. ];
  62. return $data;
  63. }
  64. //充值总额:周六~周五该账号的充值总额
  65. public static function get_total_charge_amount($distribution_channel_id,$start_date,$end_date){
  66. $data = DB::table('orders')
  67. ->select(DB::raw('sum(price) as total_charge_amount '))
  68. ->where('created_at','>=',$start_date)
  69. ->where('created_at','<',$end_date)
  70. ->where('status','PAID')
  71. ->where('distribution_channel_id',$distribution_channel_id)
  72. ->first();
  73. return isset($data->total_charge_amount) && $data->total_charge_amount ? $data->total_charge_amount:'0';
  74. }
  75. //充值人数:周六~周五该账号的充值人数
  76. public static function get_charge_user_num($distribution_channel_id,$start_date,$end_date){
  77. $data = DB::table('orders')
  78. ->select(DB::raw('count(distinct uid) as user_num'))
  79. ->where('created_at','>=',$start_date)
  80. ->where('created_at','<',$end_date)
  81. ->where('status','PAID')
  82. ->where('distribution_channel_id',$distribution_channel_id)
  83. ->first();
  84. return isset($data->user_num) && $data->user_num ? $data->user_num:'0';
  85. }
  86. //成功订单数:周六~周五该账号的成功订单数
  87. public static function get_suc_order_num($distribution_channel_id,$start_date,$end_date){
  88. $data = DB::table('orders')
  89. ->select(DB::raw('count(1) as order_num'))
  90. ->where('created_at','>=',$start_date)
  91. ->where('created_at','<',$end_date)
  92. ->where('status','PAID')
  93. ->where('distribution_channel_id',$distribution_channel_id)
  94. ->first();
  95. return isset($data->order_num) && $data->order_num ? $data->order_num:'0';
  96. }
  97. //实际消耗成本:周六~周五该账号实际派单对应的成本
  98. public static function get_real_cost_amount($distribution_channel_id,$start_date,$end_date){
  99. $data = DB::table('send_orders')
  100. ->select(DB::raw('sum(cost) as real_cost_amount'))
  101. ->where('send_time','>=',$start_date)
  102. ->where('send_time','<',$end_date)
  103. ->where('is_enable','1')
  104. ->where('distribution_channel_id',$distribution_channel_id)
  105. ->first();
  106. return isset($data->real_cost_amount) && $data->real_cost_amount ? $data->real_cost_amount:'0';
  107. }
  108. //实际派单数:周六~周五该账号在派单表中派单ID计数
  109. public static function get_real_send_order_num($distribution_channel_id,$start_date,$end_date){
  110. $data = DB::table('send_orders')
  111. ->select(DB::raw('count(1) as send_order_num'))
  112. ->where('send_time','>=',$start_date)
  113. ->where('send_time','<',$end_date)
  114. ->where('is_enable','1')
  115. ->where('distribution_channel_id',$distribution_channel_id)
  116. ->first();
  117. return isset($data->send_order_num) && $data->send_order_num ? $data->send_order_num:'0';
  118. }
  119. //强关率:周六~周五该账号派单的 总强关数/总注册数
  120. public static function get_force_subscribe_rate($new_subscribe_user_num,$register_user_num){
  121. if($register_user_num){
  122. return round($new_subscribe_user_num*100/$register_user_num,2);
  123. }else{
  124. return 0;
  125. }
  126. }
  127. //内推数量(强关人数不满20人算内推):周六~周五该账号的内推数量
  128. public static function get_inner_send_order_num($distribution_channel_id,$start_date,$end_date){
  129. $inner_send_orders = DB::table('send_orders')
  130. ->select('send_orders.id',
  131. DB::raw('(select count(1) from force_subscribe_users where send_order_id=send_orders.id and is_subscribed=1 and distribution_channel_id=send_orders.distribution_channel_id) as subscribe_num'))
  132. ->where('send_time','>=',$start_date)
  133. ->where('send_time','<',$end_date)
  134. ->where('is_enable','1')
  135. ->where('distribution_channel_id',$distribution_channel_id)
  136. ->groupBy('send_orders.id')
  137. ->having('subscribe_num','<','20')
  138. ->get();
  139. \Log::info('$inner_send_orders');\Log::info($inner_send_orders);
  140. return count($inner_send_orders);
  141. }
  142. //内推数量(通过派单类型):周六~周五该账号的内推数量
  143. public static function get_inner_send_order_num_by_order_type($distribution_channel_id,$start_date,$end_date){
  144. $data = DB::table('send_orders')
  145. ->select(DB::raw('count(1) as send_order_num'))
  146. ->where('send_time','>=',$start_date)
  147. ->where('send_time','<',$end_date)
  148. ->where('promotion_type','INTERNAL')
  149. ->where('is_enable','1')
  150. ->where('distribution_channel_id',$distribution_channel_id)
  151. ->first();
  152. return isset($data->send_order_num) && $data->send_order_num ? $data->send_order_num:'0';
  153. }
  154. //新关用户数:周六~周五该账号的新关人数
  155. public static function get_new_subscribe_user_num($distribution_channel_id,$start_date,$end_date){
  156. $data = DB::table('send_orders')
  157. ->join('force_subscribe_users','force_subscribe_users.send_order_id','send_orders.id')
  158. ->select(DB::raw('count(1) as new_subscribe_user_num'))
  159. ->where('send_orders.send_time','>=',$start_date)
  160. ->where('send_orders.send_time','<',$end_date)
  161. ->where('send_orders.is_enable','1')
  162. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  163. ->first();
  164. return isset($data->new_subscribe_user_num) && $data->new_subscribe_user_num ? $data->new_subscribe_user_num:'0';
  165. }
  166. //新关用户充值人数:周六~周五该账号的新关粉中,在周六~周一的充值人数
  167. // 以uid作为基准,一个用户的send_order_id会被覆盖
  168. public static function get_new_subscribe_charge_user_num($distribution_channel_id,$start_date,$end_date,$big_start_date,$big_end_date){
  169. $data = DB::table('send_orders')
  170. ->join('force_subscribe_users','force_subscribe_users.send_order_id','send_orders.id')
  171. ->join('orders','orders.uid','force_subscribe_users.uid')
  172. ->select(DB::raw('count(distinct orders.uid) as new_subscribe_charge_user_num'))
  173. ->where('orders.created_at','>=',$big_start_date)
  174. ->where('orders.created_at','<',$big_end_date)
  175. ->where('orders.status','PAID')
  176. ->where('send_orders.send_time','>=',$start_date)
  177. ->where('send_orders.send_time','<',$end_date)
  178. ->where('send_orders.is_enable','1')
  179. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  180. ->first();
  181. return isset($data->new_subscribe_charge_user_num) && $data->new_subscribe_charge_user_num ? $data->new_subscribe_charge_user_num:'0';
  182. }
  183. //新关用户充值金额:周六~周五该账号的新关粉中,在周六~周一的充值金额
  184. public static function get_new_subscribe_charge_amount($distribution_channel_id,$start_date,$end_date,$big_start_date,$big_end_date){
  185. $data = DB::table('send_orders')
  186. ->join('force_subscribe_users','force_subscribe_users.send_order_id','send_orders.id')
  187. ->join('orders','orders.uid','force_subscribe_users.uid')
  188. ->select(DB::raw('ifnull(sum(price),0) as new_subscribe_charge_amount'))
  189. ->where('orders.created_at','>=',$big_start_date)
  190. ->where('orders.created_at','<',$big_end_date)
  191. ->where('orders.status','PAID')
  192. ->where('send_orders.send_time','>=',$start_date)
  193. ->where('send_orders.send_time','<',$end_date)
  194. ->where('send_orders.is_enable','1')
  195. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  196. ->first();
  197. return isset($data->new_subscribe_charge_amount) && $data->new_subscribe_charge_amount ? $data->new_subscribe_charge_amount:'0';
  198. }
  199. //新关成本:实际消耗成本/新关用户数
  200. public static function get_new_subscribe_cost($real_cost_amount,$new_subscribe_user_num){
  201. if($new_subscribe_user_num){
  202. return round($real_cost_amount/$new_subscribe_user_num,2);
  203. }else{
  204. return 0;
  205. }
  206. }
  207. //新关单粉3天产出:分母:周六~周五的新关数;分子:这批粉周六~周一的充值总额;
  208. public static function get_new_subscribe_3day_out($new_subscribe_charge_amount,$new_subscribe_user_num){
  209. if($new_subscribe_user_num){
  210. return round($new_subscribe_charge_amount/$new_subscribe_user_num,2);
  211. }else{
  212. return 0;
  213. }
  214. }
  215. //新用户复充率:分母:周六~周五新关粉,在周六~周五的付费用户数;分子:这批付费用户在订单表属于复充的人数;
  216. public static function get_new_subscribe_re_filling_rate($small_re_charge_user_num,$new_subscribe_charge_user_num){
  217. if($new_subscribe_charge_user_num){
  218. return round($small_re_charge_user_num*100/$new_subscribe_charge_user_num,2);
  219. }else{
  220. return 0;
  221. }
  222. }
  223. //新用户充值充值率(新关用户充值人数/新关用户数量)
  224. public static function get_new_subscribe_charge_rate($new_subscribe_charge_user_num,$new_subscribe_user_num){
  225. if($new_subscribe_user_num){
  226. return round($new_subscribe_charge_user_num*100/$new_subscribe_user_num,2);
  227. }else{
  228. return 0;
  229. }
  230. }
  231. //新注册用户数:周六~周五该账号的新注册人数,暂时注册时间不考虑
  232. public static function get_new_register_user_num($distribution_channel_id,$start_date,$end_date){
  233. $data = DB::table('send_orders')
  234. ->join('users','users.send_order_id','send_orders.id')
  235. ->select(DB::raw('count(1) as new_register_user_num'))
  236. ->where('send_orders.send_time','>=',$start_date)
  237. ->where('send_orders.send_time','<',$end_date)
  238. ->where('send_orders.is_enable','1')
  239. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  240. ->first();
  241. return isset($data->new_register_user_num) && $data->new_register_user_num ? $data->new_register_user_num:'0';
  242. }
  243. //周六~周五新关粉,在周六~周五的付费用户数(算复充率专用,限制强关时间,其他不限制)
  244. public static function get_new_subscribe_small_charge_user_num($distribution_channel_id,$start_date,$end_date){
  245. $data = DB::table('send_orders')
  246. ->join('force_subscribe_users','force_subscribe_users.send_order_id','send_orders.id')
  247. ->join('orders','force_subscribe_users.uid','orders.uid')
  248. ->select(DB::raw('count(distinct orders.uid) as new_subscribe_small_charge_user_num'))
  249. ->where('send_orders.send_time','>=',$start_date)
  250. ->where('send_orders.send_time','<',$end_date)
  251. ->where('send_orders.is_enable','1')
  252. ->where('orders.created_at','>=',$start_date)
  253. ->where('orders.created_at','<',$end_date)
  254. ->where('force_subscribe_users.created_at','>=',$start_date)
  255. ->where('force_subscribe_users.created_at','<',$end_date)
  256. ->where('orders.status','PAID')
  257. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  258. ->first();
  259. return isset($data->new_subscribe_small_charge_user_num) && $data->new_subscribe_small_charge_user_num ? $data->new_subscribe_small_charge_user_num:'0';
  260. }
  261. //周六~周五新关粉,在周六~周五的付费用户数(算复充率专用,限制强关时间,其他不限制)
  262. public static function get_new_subscribe_small_re_charge_user_num($distribution_channel_id,$start_date,$end_date,$big_start_date,$big_end_date){
  263. $data = DB::table('send_orders')
  264. ->join('force_subscribe_users','force_subscribe_users.send_order_id','send_orders.id')
  265. ->join('orders','force_subscribe_users.uid','orders.uid')
  266. ->select(DB::raw('count(distinct orders.id) as new_subscribe_small_re_charge_user_order_num'),'orders.uid')
  267. ->where('send_orders.send_time','>=',$start_date)
  268. ->where('send_orders.send_time','<',$end_date)
  269. ->where('send_orders.is_enable','1')
  270. ->where('orders.created_at','>=',$big_start_date)
  271. ->where('orders.created_at','<',$big_end_date)
  272. // ->where('force_subscribe_users.created_at','>=',$start_date)
  273. // ->where('force_subscribe_users.created_at','<',$end_date)
  274. ->where('orders.status','PAID')
  275. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  276. ->groupBy('orders.uid')
  277. ->having('new_subscribe_small_re_charge_user_order_num','>',1)
  278. ->get();
  279. return count($data);
  280. }
  281. //top3的书籍名称,派单量:对应书籍周六~周五的实际派单数
  282. public static function get_top_send_order_num_books($distribution_channel_id,$start_date,$end_date){
  283. $data = DB::table('send_orders')
  284. ->select(DB::raw('count(1) as send_order_num'),'book_id','book_name')
  285. ->where('send_time','>=',$start_date)
  286. ->where('send_time','<',$end_date)
  287. ->where('is_enable','1')
  288. ->where('distribution_channel_id',$distribution_channel_id)
  289. ->groupBy('book_id')
  290. ->orderBy('send_order_num','desc')
  291. ->limit(3)
  292. ->get();
  293. if(!empty($data)){
  294. return $data->toArray();
  295. }
  296. return $data;
  297. }
  298. //top3的书籍名称,要求派单带来的注册用户,充值注册比:周六~周一该书的 充值总额/注册数
  299. public static function get_top_charge_register_books($distribution_channel_id,$start_date,$end_date){
  300. $charge_register_books = DB::table('send_orders')
  301. ->select(
  302. DB::raw('ifnull((select sum(orders.price) from orders inner join users ON users.send_order_id=orders.send_order_id and users.id=orders.uid where orders.send_order_id=send_orders.id and status="PAID"),0) as recharge_amount'),
  303. DB::raw('ifnull((select count(1) from users where users.send_order_id=send_orders.id),1) as register_num'),
  304. 'book_id','book_name')
  305. ->where('send_orders.send_time','>=',$start_date)
  306. ->where('send_orders.send_time','<',$end_date)
  307. ->where('send_orders.is_enable','1')
  308. ->where('send_orders.distribution_channel_id',$distribution_channel_id)
  309. ->groupBy('book_id')
  310. ->having('register_num','>','100')
  311. ->orderBy(DB::raw('(recharge_amount/register_num)'),'desc')
  312. ->limit(3)
  313. ->get();
  314. if(!empty($charge_register_books)){
  315. foreach($charge_register_books as $key=>$charge_register_book){
  316. $charge_register_books[$key]->charge_register_number = (int)$charge_register_book->recharge_amount.'/'.$charge_register_book->register_num;
  317. if($charge_register_book->register_num > 0){
  318. $charge_register_books[$key]->charge_register = round($charge_register_book->recharge_amount/$charge_register_book->register_num,2);
  319. }else{
  320. $charge_register_books[$key]->charge_register = 0;
  321. }
  322. }
  323. }
  324. if(!empty($charge_register_books)){
  325. return $charge_register_books->toArray();
  326. }
  327. return $charge_register_books;
  328. }
  329. /**
  330. * 渠道周报表数据
  331. * @param Request $request
  332. */
  333. public static function getWeeklySendOrderStatistics($distribution_channel_id)
  334. {
  335. if(empty($distribution_channel_id)){
  336. return response()->error('PARAM_EMPTY');
  337. }
  338. \Log::info('getWeeklySendOrderStatistics_start:'.$distribution_channel_id);
  339. $data = [];
  340. try{
  341. $date = SendOrderStatisticsService::get_query_date();
  342. $data['date'] = [
  343. 'start_day'=>$date['start_day'],
  344. 'end_day'=>$date['end_day'],
  345. 'small_start_day'=>$date['small_start_day'],
  346. 'small_end_day'=>$date['small_end_day'],
  347. 'big_start_day'=>$date['big_start_day'],
  348. 'big_end_day'=>$date['big_end_day'],
  349. ];
  350. // 从redis取
  351. $weekly_report_key = 'weeklyReport:distribution_channel_id:'.$distribution_channel_id.':start_day:'.$date['start_day'].':end_day:'.$date['end_day'];
  352. $redis_data = Redis::get($weekly_report_key);
  353. if(!empty($redis_data)){
  354. \Log::info('redis_has_weekly_report:'.$weekly_report_key);
  355. $data = object_to_array(json_decode($redis_data));
  356. \Log::info($data);
  357. return $data;
  358. }
  359. // 充值统计
  360. \Log::info('get_total_charge_amount_start:'.$distribution_channel_id);
  361. $total_charge_amount = SendOrderStatisticsService::get_total_charge_amount($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  362. \Log::info('get_charge_user_num_start:'.$distribution_channel_id);
  363. $charge_user_num = SendOrderStatisticsService::get_charge_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  364. \Log::info('get_suc_order_num_start:'.$distribution_channel_id);
  365. $suc_order_num = SendOrderStatisticsService::get_suc_order_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  366. \Log::info('get_real_cost_amount_start:'.$distribution_channel_id);
  367. $real_cost_amount = SendOrderStatisticsService::get_real_cost_amount($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  368. $data['charge_statistics'] = [
  369. 'total_charge_amount' => $total_charge_amount,
  370. 'charge_user_num' => $charge_user_num,
  371. 'suc_order_num' => $suc_order_num,
  372. 'real_cost_amount' => $real_cost_amount,
  373. ];
  374. // 派单统计
  375. \Log::info('get_new_register_user_num_start:'.$distribution_channel_id);
  376. $new_register_user_num = SendOrderStatisticsService::get_new_register_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  377. \Log::info('get_new_subscribe_user_num_start:'.$distribution_channel_id);
  378. $new_subscribe_user_num = SendOrderStatisticsService::get_new_subscribe_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  379. \Log::info('get_force_subscribe_rate_start:'.$distribution_channel_id);
  380. $force_subscribe_rate = SendOrderStatisticsService::get_force_subscribe_rate($new_subscribe_user_num,$new_register_user_num);
  381. \Log::info('get_real_send_order_num_start:'.$distribution_channel_id);
  382. $real_send_order_num = SendOrderStatisticsService::get_real_send_order_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  383. \Log::info('get_inner_send_order_num_start:'.$distribution_channel_id);
  384. $inner_send_order_num = SendOrderStatisticsService::get_inner_send_order_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  385. \Log::info('get_new_subscribe_charge_user_num_start:'.$distribution_channel_id);
  386. $new_subscribe_charge_user_num = SendOrderStatisticsService::get_new_subscribe_charge_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day'],$date['big_start_day'],$date['big_end_day']);
  387. \Log::info('get_new_subscribe_charge_amount_start:'.$distribution_channel_id);
  388. $new_subscribe_charge_amount = SendOrderStatisticsService::get_new_subscribe_charge_amount($distribution_channel_id,$date['small_start_day'],$date['small_end_day'],$date['big_start_day'],$date['big_end_day']);
  389. \Log::info('get_new_subscribe_cost_start:'.$distribution_channel_id);
  390. $new_subscribe_cost = SendOrderStatisticsService::get_new_subscribe_cost($real_cost_amount,$new_subscribe_user_num);
  391. \Log::info('get_new_subscribe_3day_out_start:'.$distribution_channel_id);
  392. $new_subscribe_3day_out = SendOrderStatisticsService::get_new_subscribe_3day_out($new_subscribe_charge_amount,$new_subscribe_user_num);
  393. //\Log::info('get_new_subscribe_small_charge_user_num_start:'.$distribution_channel_id);
  394. //$new_subscribe_small_charge_user_num = SendOrderStatisticsService::get_new_subscribe_small_charge_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  395. \Log::info('get_new_subscribe_small_re_charge_user_num_start:'.$distribution_channel_id);
  396. $small_re_charge_user_num = SendOrderStatisticsService::get_new_subscribe_small_re_charge_user_num($distribution_channel_id,$date['small_start_day'],$date['small_end_day'],$date['big_start_day'],$date['big_end_day']);
  397. \Log::info('get_new_subscribe_re_filling_rate_start:'.$distribution_channel_id);
  398. $new_subscribe_re_filling_rate = SendOrderStatisticsService::get_new_subscribe_re_filling_rate($small_re_charge_user_num,$new_subscribe_charge_user_num);
  399. \Log::info('get_new_subscribe_charge_rate_start:'.$distribution_channel_id);
  400. $new_subscribe_charge_rate = SendOrderStatisticsService::get_new_subscribe_charge_rate($new_subscribe_charge_user_num,$new_subscribe_user_num);
  401. $data['send_order_statistics'] = [
  402. 'real_send_order_num' =>$real_send_order_num,
  403. 'force_subscribe_rate' => $force_subscribe_rate.'%',
  404. 'inner_send_order_num' => $inner_send_order_num,
  405. 'new_subscribe_user_num' => $new_subscribe_user_num,
  406. 'new_subscribe_charge_user_num' => $new_subscribe_charge_user_num,
  407. 'new_subscribe_charge_amount' => $new_subscribe_charge_amount,
  408. 'new_subscribe_cost' => $new_subscribe_cost,
  409. 'new_subscribe_3day_out' => $new_subscribe_3day_out,
  410. 'new_subscribe_re_charge_user_num' => $small_re_charge_user_num,// 新关用户复充人数
  411. 'new_subscribe_re_filling_rate' => $new_subscribe_re_filling_rate.'%',
  412. 'new_subscribe_charge_rate' => $new_subscribe_charge_rate.'%',//新用户充值充值率
  413. 'charge_register_rate' => $charge_user_num.'/'.$new_register_user_num,//充值注册比
  414. ];
  415. // 书籍统计
  416. \Log::info('get_top_send_order_num_books_start:'.$distribution_channel_id);
  417. $top_send_order_num_books = SendOrderStatisticsService::get_top_send_order_num_books($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  418. \Log::info('get_top_charge_register_books_start:'.$distribution_channel_id);
  419. $top_charge_register_books = SendOrderStatisticsService::get_top_charge_register_books($distribution_channel_id,$date['small_start_day'],$date['small_end_day']);
  420. $data['book_statistics'] = [
  421. 'top_send_order_num_books' => object_to_array($top_send_order_num_books),
  422. 'top_charge_register_books' => object_to_array($top_charge_register_books)
  423. ];
  424. }catch(Exception $e){
  425. \Log::info('getWeeklySendOrderStatistics_ept:'.$e->getMessage());
  426. }
  427. Redis::set($weekly_report_key,json_encode($data));
  428. \Log::info('getWeeklySendOrderStatistics_end:'.$distribution_channel_id);
  429. \Log::info($data);
  430. return $data;
  431. }
  432. }