SendStatsEmail.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace App\Console\Commands\SendOrder;
  3. use App\Modules\Book\Services\BookTagsService;
  4. use App\Modules\Statistic\Services\SendStatsEmailService;
  5. use Illuminate\Console\Command;
  6. use App\Modules\Message\MessageNotify;
  7. class SendStatsEmail extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'sendOrderEmail';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '发送外部派单作品分析报表';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. //
  38. $this->getSuperiorBooks();
  39. return ;
  40. $beginLastweek = date('Y-m-d',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
  41. $endLastweek = date('Y-m-d',mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')));
  42. $data = SendStatsEmailService::getOrderStats($beginLastweek,$endLastweek);
  43. $page = view('email.weekOrderStats',['datas'=>$data]);
  44. $html = response($page)->getContent();
  45. //\Log::info($html);
  46. $data_temp = array();
  47. $header = ['书籍ID','书籍名称','UV','注册用户数','注册/UV','强关粉','强关率(强关/注册)','充值金额','付费人数','充值/UV','强关付费率(付费/强关)','UV付费率(付费/UV)','派单数','男女频'];
  48. foreach ($data as $k=>$item) {
  49. $title='';
  50. switch ($k){
  51. case 0:$title='注册UV比高于85%';break;
  52. case 1:$title='注册UV比介于30%到85%';break;
  53. case 2:$title='注册UV比低于30%';break;
  54. }
  55. $temp = array('header'=>$header,'title'=>$title,'data'=>array());
  56. foreach ($item as $key=>$value) {
  57. $temp['data'][] = array(
  58. $value['bid'],
  59. $value['book_name'],
  60. $value['UV'],
  61. $value['register_user_sum'],
  62. $value['UV']>0?(round($value['register_user_sum']/$value['UV'],4)*100).'%':0,
  63. $value['force_user_sum'],
  64. $value['register_user_sum']>0?(round($value['force_user_sum']/$value['register_user_sum'],4)*100).'%':0,
  65. $value['recharge_sum'],
  66. $value['pay_user_num'],
  67. $value['UV']>0?round($value['recharge_sum']/ $value['UV'],2):0,
  68. $value['force_user_sum']>0?(round($value['pay_user_num']/$value['force_user_sum'],4)*100).'%':0,
  69. $value['UV']>0?(round($value['pay_user_num']/$value['UV'],4)*100).'%':0,
  70. $value['send_orders_num'],
  71. $value['pid']
  72. );
  73. }
  74. $data_temp[] = $temp;
  75. }
  76. $storage_file = 'app/last_week_send_order.xlsx';
  77. saveExcelDataToMultiSheet($data_temp,storage_path($storage_file));
  78. $to_user = array(
  79. ['address'=>'songdb@iqiyoo.com','name'=>'songdb'],
  80. ['address'=>'zhaojp@yqsd.net','name'=>'赵君平'],
  81. ['address' => 'zhoulj@iqiyoo.com', 'name' => '周灵杰'],
  82. );
  83. $to_users = '';
  84. foreach ($to_user as $item){
  85. $to_users .= $item['address'].";";
  86. }
  87. $notify = MessageNotify::mail([
  88. 'to_emails' => $to_users,
  89. 'subject' => "上周( $beginLastweek 至 $endLastweek )外部派单作品分析报表",
  90. 'body' => $html,
  91. 'delay_times' => 0,
  92. ]);
  93. $notify->addAttach($storage_file);
  94. $notify->notify();
  95. //SendStatsEmailService::SendHtmlEmailWithAcce($to_user,['subject'=>"上周( $beginLastweek 至 $endLastweek )外部派单作品分析报表",'body'=>$html],storage_path('app/last_week_send_order.xlsx'));
  96. }
  97. private function getSuperiorBooks() {
  98. $data = SendStatsEmailService::getOrderStatsNew();
  99. $page = view('email.daySendOrderStats',['datas'=>$data]);
  100. $html = response($page)->getContent();
  101. //\Log::info($html);
  102. $data_temp = array();
  103. $header = ['书籍ID','书籍名称','是否下架','篇幅','24小时uv','24小时充值总额','72小时uv','72小时充值总额','uv','24~72小时充值增长','24小时充值比24小时UV','72小时充值比24小时UV','强关率'];
  104. foreach ($data as $k=>$item) {
  105. $title='';
  106. switch ($k){
  107. case 0:$title='注册UV比高于85%';break;
  108. //case 1:$title='注册UV比介于30%到85%';break;
  109. case 1:$title='注册UV比低于30%';break;
  110. }
  111. $temp = array('header'=>$header,'title'=>$title,'data'=>array());
  112. foreach ($item as $key=>$value) {
  113. $temp['data'][] = array(
  114. $value['bid'],
  115. $value['book_name'],
  116. $value['is_on_shelf']==1?'内部上架':'外部上架',
  117. $value['charge_type']=='BOOK'?'短篇':'长篇',
  118. $value['uv_one_day_sum'],
  119. $value['recharge_amount_in_one_day'],
  120. $value['uv_three_day_sum'],
  121. $value['recharge_amount_in_three_days'],
  122. $value['UV'],
  123. $value['recharge_amount_in_one_day']>0?round(($value['recharge_amount_in_three_days']-$value['recharge_amount_in_one_day'])/$value['recharge_amount_in_one_day'],2):0,
  124. $value['uv_one_day_sum']>0?round(($value['recharge_amount_in_one_day']/$value['uv_one_day_sum']),2):0,
  125. //$value['uv_three_day_sum']>0?round(($value['recharge_amount_in_three_days']/$value['uv_three_day_sum']),2):0,
  126. $value['uv_one_day_sum']>0?round(($value['recharge_amount_in_three_days']/$value['uv_one_day_sum']),2):0,
  127. $value['register_user_sum']>0?(round(($value['force_user_sum']/$value['register_user_sum']),4)*100).'%':0,
  128. );
  129. }
  130. $data_temp[] = $temp;
  131. }
  132. $storage_file = 'app/last_week_send_order.xlsx';
  133. saveExcelDataToMultiSheet($data_temp,storage_path($storage_file));
  134. $to_user = array(
  135. ['address'=>'zhangzg@iqiyoo.com','name'=>'张总'],
  136. ['address'=>'chensj@zw88.net','name'=>'陈帅君'],
  137. ['address'=>'zhaojp@yqsd.net','name'=>'赵君平'],
  138. ['address'=>'liur@iqiyoo.com','name'=>'刘嵘'],
  139. ['address'=>'panxp@zw88.net','name'=>'潘霞萍'],
  140. ['address'=>'2711046732@qq.com','name'=>'樊柯'],
  141. // ['address'=>'lisy@zw88.net','name'=>'test'],
  142. );
  143. $to_users = '';
  144. foreach ($to_user as $item){
  145. $to_users .= $item['address'].";";
  146. }
  147. $notify = MessageNotify::mail([
  148. 'to_emails' => $to_users,
  149. 'subject' => '追书云'.date('Y-m-d',strtotime('-1 day'))."优质书外部派单分析报表",
  150. 'body' => $html,
  151. 'delay_times' => 0,
  152. ]);
  153. $notify->addAttach($storage_file);
  154. $notify->notify();
  155. //SendStatsEmailService::SendHtmlEmailWithAcce($to_user,['subject'=>'追书云'.date('Y-m-d',strtotime('-1 day'))."优质书外部派单分析报表",'body'=>$html],storage_path('app/last_week_send_order.xlsx'));
  156. }
  157. }