SendStatsEmail.php 6.8 KB

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