SendMonthlyProductStats.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 SendMonthlyProductStats extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'SendMonthlyProductsStats';
  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-01',strtotime('-1 month'));
  39. $data = DB::table('product_stats')
  40. ->where([['date','=',$date],['type','=','month']])
  41. ->first();
  42. if($data) {
  43. $data = json_decode(json_encode($data),true);
  44. $data['date'] = date('Y-m',strtotime('-1 month'));
  45. }else{
  46. $data = ProductionStatsEmailService::getAll(date('Y-m-01 00:00:00',strtotime('-1 month')),date('Y-m-d 23:59:59',strtotime(date('Y-m-01').'-1 day')));
  47. $data['date'] = date('Y-m',strtotime('-1 month'));
  48. }
  49. $to_user = array(
  50. ['address'=>'zhangzg@iqiyoo.com','name'=>'张总'],
  51. //['address'=>'tushengxiang@yahoo.com','name'=>'tusx'],
  52. ['address'=>'songdb@iqiyoo.com','name'=>'songdb'],
  53. ['address'=>'zhaojp@yqsd.net','name'=>'赵君平'],
  54. ['address'=>'huangrr@yqsd.net','name'=>'黄蓉蓉'],
  55. ['address'=>'wankw@zw88.net','name'=>'万开伟'],
  56. ['address'=>'liur@iqiyoo.com','name'=>'刘嵘'],
  57. ['address'=>'chensj@zw88.net','name'=>'chensj'],
  58. ['address'=>'sijj@yqsd.net','name'=>'sijj'],
  59. ['address'=>'yuyy@yqsd.net','name'=>'俞焰艳']
  60. );
  61. $page = view('email.productStats',['data'=>$data,'title'=>date('m月',strtotime('-1 month')).' 作品数据报表']);
  62. $html = response($page)->getContent();
  63. SendStatsEmailService::SendHtmlEmailWithAcce($to_user,['subject'=>date('m月',strtotime('-1 month'))."作品数据报表",'body'=>$html]);
  64. }
  65. }