SendDailyProductionStats.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Console\Commands\ProductStats;
  3. use App\Modules\Statistic\Services\ProductionStatsEmailService;
  4. use App\Modules\Statistic\Services\SendStatsEmailService;
  5. use Illuminate\Console\Command;
  6. use DB;
  7. class SendDailyProductionStats extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'SendDailyProductsStats';
  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. $date = date('Y-m-d',strtotime('-1 day'));
  39. $data = DB::table('product_stats')
  40. ->where([['date','=',$date],['type','=','day']])
  41. ->first();
  42. if($data) {
  43. $data = json_decode(json_encode($data),true);
  44. $data['date'] = $date;
  45. }else{
  46. $data = ProductionStatsEmailService::getAll(date('Y-m-d 00:00:00',strtotime('-1 day')),date('Y-m-d 23:59:59',strtotime('-1 day')));
  47. $data['date'] = $date;
  48. }
  49. $suspends = ProductionStatsEmailService::getSuspendProducts(false);
  50. $suspends_format = array();
  51. foreach ($suspends as $suspend){
  52. $time_diff = time()-strtotime($suspend->updated_at);
  53. $product_type = $suspend->is_on_shelf;
  54. switch ($product_type){
  55. case 1:$product_type = '内部作品';break;
  56. case 2:$product_type = '外部作品';break;
  57. default:;
  58. }
  59. $suspends_format[] = array($suspend->id,$suspend->name,$suspend->pid,$suspend->updated_at,round(($time_diff)/3600,1),round($time_diff/(3600*24),1),$product_type);
  60. }
  61. $suspends_header = ['bid','书名','一级分类','最近更新','累计断更时长(小时)','断更天数','作品类型'];
  62. saveExcelData($suspends_header ,$suspends_format,storage_path('app/suspend_books'.date('Y-m-d').'.xlsx'));
  63. $to_user = array(
  64. ['address'=>'zhangzg@iqiyoo.com','name'=>'张总'],
  65. //['address'=>'1373617746@qq.com','name'=>'tusx'],
  66. ['address'=>'songdb@iqiyoo.com','name'=>'songdb'],
  67. ['address'=>'zhaojp@yqsd.net','name'=>'赵君平'],
  68. ['address'=>'huangrr@yqsd.net','name'=>'黄蓉蓉'],
  69. ['address'=>'wankw@zw88.net','name'=>'万开伟'],
  70. ['address'=>'liur@iqiyoo.com','name'=>'刘嵘'],
  71. ['address'=>'chensj@zw88.net','name'=>'chensj'],
  72. ['address'=>'sijj@yqsd.net','name'=>'sijj'],
  73. ['address'=>'yuyy@yqsd.net','name'=>'俞焰艳']
  74. );
  75. $page = view('email.productStats',['data'=>$data,'datas2'=>$suspends_format,'title'=>$date.' 作品数据报表','title2'=>$date.' 断更作品']);
  76. $html = response($page)->getContent();
  77. SendStatsEmailService::SendHtmlEmailWithAcce($to_user,['subject'=>"每日作品数据报表",'body'=>$html],storage_path('app/suspend_books'.date('Y-m-d').'.xlsx'));
  78. }
  79. }