CheckZsySiteStatus.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qincp
  5. * Date: 2019/1/7
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands;
  9. use App\Modules\Channel\Models\Channel;
  10. use App\Modules\Channel\Models\ChannelUser;
  11. use App\Modules\OfficialAccount\Models\OfficialAccount;
  12. use App\Modules\Statistic\Services\SendStatsEmailService;
  13. use Illuminate\Console\Command;
  14. use Log;
  15. class CheckZsySiteStatus extends Command
  16. {
  17. /**
  18. * 执行命令 检查站点信息
  19. *
  20. * The name and signature of the console command.
  21. *
  22. * @var string
  23. */
  24. protected $signature = 'check_zsy_site_status';
  25. /**
  26. * The console command description.
  27. *
  28. * @var string
  29. */
  30. protected $description = '检查网读云站点信息';
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. Log::info('CheckZsySiteStatus start command');
  39. $start_date = date("Y-m-d", strtotime("-1 day"));
  40. $end_date = date("Y-m-d");
  41. $params = compact('start_date', 'end_date');
  42. //站点信息
  43. $result = Channel::getChannelInfoList($params, true);
  44. //服务号信息
  45. $officialAccounts = OfficialAccount::getInfoList($params);
  46. //账号数
  47. $accountCount = ChannelUser::getCount($params);
  48. if ($result) {
  49. $this->sendEmail($result, $officialAccounts, $accountCount);
  50. } else {
  51. Log::info('CheckZsySiteStatus not need sendEmail');
  52. }
  53. }
  54. function sendEmail($result, $officialAccounts, $accountCount)
  55. {
  56. Log::info('CheckZsySiteStatus start sendEmail');
  57. $to_user = array(
  58. ['address'=>'songdb@iqiyoo.com','name'=>'songdb'],
  59. ['address'=>'zhaojp@yqsd.net','name'=>'赵君平'],
  60. ['address' => 'zhoulj@iqiyoo.com', 'name' => '周灵杰'],
  61. );
  62. $content = "<table border='1' cellpadding='10' cellspacing='0' style='float: left'><tr><td align='center'>序号</td><td align='center'>站点id</td><td align='center'>公司名称</td></tr>";
  63. $siteIndex = 0;
  64. foreach ($result as $item) {
  65. $siteIndex++;
  66. $content .= "<tr><td align='center'>{$siteIndex}</td><td align='center'>{$item->id}</td><td align='center'>{$item->company_name}</td></tr>";
  67. }
  68. $content .= "</table>";
  69. $content .= "<table border='1' style='float: left;margin-left: 35px' cellpadding='10' cellspacing='0'><tr><td align='center'>序号</td><td align='center'>站点id</td><td align='center'>服务号名称</td><td align='center'>主体</td></tr>";
  70. $officialAccountIndex = 0;
  71. foreach ($officialAccounts as $item) {
  72. $officialAccountIndex++;
  73. $content .= "<tr><td align='center'>{$officialAccountIndex}</td><td align='center'>{$item->distribution_channel_id}</td><td align='center'>{$item->nickname}</td><td align='center'>{$item->principal_name}</td></tr>";
  74. }
  75. $content .= "</table>";
  76. SendStatsEmailService::SendHtmlEmailWithAcce($to_user, ['subject' => date("Y-m-d", time()) . "网读云昨天新增站点" . $siteIndex . "个,账号" . $accountCount . "个,服务号" . $officialAccountIndex . "个", 'body' => $content]);
  77. }
  78. }