OfficialAccountForbiddenStatus.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands\OfficialAccountStat;
  9. use App\Modules\Statistic\Services\SendStatsEmailService;
  10. use DB;
  11. use Illuminate\Console\Command;
  12. use Log;
  13. class OfficialAccountForbiddenStatus extends Command
  14. {
  15. /**
  16. *
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'check_official_account_forbidden_status';
  22. /**
  23. * The console command description.
  24. *
  25. * @var string
  26. */
  27. protected $description = '公众号每日被封号的情况';
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. Log::info('check_official_account_forbidden_status start command');
  36. $date = date('Y-m-d', strtotime('-1 day'));
  37. $table_name = 'forbidden_official_account_records';
  38. $result = DB::table($table_name)->where('date', $date)->orderBy('created_at')->get();
  39. if ($result && count($result) > 0) {
  40. Log::info('check_official_account_forbidden_status need sendEmail');
  41. $this->sendEmail($result);
  42. } else {
  43. Log::info('check_official_account_forbidden_status not need sendEmail');
  44. }
  45. }
  46. function sendEmail($result)
  47. {
  48. Log::info('check_official_account_forbidden_status start sendEmail');
  49. $to_user = array(
  50. ['address' => 'songdb@iqiyoo.com', 'name' => '宋栋波'],
  51. ['address' => 'zhaojp@yqsd.net', 'name' => '赵君平'],
  52. ['address' => 'zhoulj@iqiyoo.com', 'name' => '周灵杰'],
  53. );
  54. $content = "<table border='1' cellpadding='10' cellspacing='0'>
  55. <tr>
  56. <td align='center'>日期</td>
  57. <td align='center'>站点id</td>
  58. <td align='center'>appid</td>
  59. <td align='center'>服务号名称</td>
  60. <td align='center'>公司名称</td>
  61. <td align='center'>封号时间</td>
  62. </tr>";
  63. $index = 0;
  64. foreach ($result as $item) {
  65. $index++;
  66. $content .= "<tr>
  67. <td align='center' nowrap='nowrap'>{$item->date}</td>
  68. <td align='center' nowrap='nowrap'>{$item->distribution_channel_id}</td>
  69. <td align='center' nowrap='nowrap'>{$item->appid}</td>
  70. <td align='center' nowrap='nowrap'>{$item->nickname}</td>
  71. <td align='center' nowrap='nowrap'>{$item->company_name}</td>
  72. <td align='center' nowrap='nowrap'>{$item->forbbidden_time}</td>
  73. </tr>";
  74. }
  75. $content .= "</table>";
  76. SendStatsEmailService::SendHtmlEmailWithAcce($to_user, ['subject' => date("Y-m-d", time()) . "网读昨天封号" . $index . "个", 'body' => $content]);
  77. }
  78. }