CheckCidError.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use Illuminate\Console\Command;
  4. use App\Modules\Message\MessageNotify;
  5. use DB;
  6. class CheckCidError extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'check_cid_error';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '检查cid';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. private $emails = ['lisy@zw88.net','songdb@iqiyoo.com','zhoulj@iqiyoo.com','zhaoy@zw88.net'];
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle(){
  36. \Log::info('check_cid_error_start'.date('Y-m-d'));
  37. $this->Check();
  38. \Log::info('check_cid_error_end'.date('Y-m-d'));
  39. }
  40. public function Check()
  41. {
  42. $msg = '['.env('PROJECT_NAME').']';
  43. $wrong_next_cid = DB::select('select bid,next_cid,count(1) as num
  44. from chapters c
  45. where next_cid =0 and bid > 0
  46. group by c.bid
  47. having num > 1');
  48. $msg .= !empty($wrong_next_cid) ? 'wrong_next_cid: '.\GuzzleHttp\json_encode($wrong_next_cid) : '';
  49. $wrong_prev_cid = DB::select('select bid,prev_cid,count(1) as num
  50. from chapters c
  51. where prev_cid =0 and bid > 0
  52. group by c.bid
  53. having num > 1;');
  54. $msg .= !empty($wrong_prev_cid) ? 'wrong_prev_cid: '.\GuzzleHttp\json_encode($wrong_prev_cid) : '';
  55. \Log::info('check_cid_error'.date('Y-m-d').$msg);
  56. if($msg){
  57. $notify = MessageNotify::mail([
  58. 'to_emails' => implode(",", $this->emails),
  59. 'subject' => $msg,
  60. 'body' =>$msg,
  61. 'delay_times' => 0,
  62. ]);
  63. $notify->notify();
  64. exit();
  65. }
  66. }
  67. }