BookAutoOffShelf.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2020/10/29
  6. * Time: 9:49
  7. */
  8. namespace App\Console\Commands\Book;
  9. use DB;
  10. use Illuminate\Console\Command;
  11. use App\Modules\Message\MessageNotify;
  12. class BookAutoOffShelf extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'Book:BookAutoOffShelf';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '自动下架';
  26. private $emails = ['zhaojp@yqsd.net',
  27. 'songdb@yqsd.net','zhoulj@iqiyoo.com'
  28. ];
  29. //private $emails = ['zhaoy@zw88.net','baixq@zw88.net'];
  30. /**
  31. * Create a new command instance.
  32. *
  33. * @return void
  34. */
  35. public function __construct()
  36. {
  37. parent::__construct();
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return mixed
  43. */
  44. public function handle(){
  45. $this->start();
  46. }
  47. private function start(){
  48. $day = date('Y-m-d',time()+86400*10);
  49. $book = DB::table('book_configs')->where('is_on_shelf',2)
  50. ->where('copyright_limit_data','<=',$day)
  51. ->where('copyright_limit_data','>=',date('Y-m-d'))
  52. ->select('bid','book_name','copyright_limit_data')
  53. ->get();
  54. $off_shelf_book = [];
  55. $alert_book = [];
  56. if($book){
  57. foreach ($book as $item){
  58. if($item->copyright_limit_data <= date('Y-m-d')){
  59. $off_shelf_book[] = ['bid'=>$item->bid,'book_name'=>$item->book_name];
  60. }
  61. if($item->copyright_limit_data == $day){
  62. $alert_book[] = ['bid'=>$item->bid,'book_name'=>$item->book_name];
  63. }
  64. }
  65. }
  66. //《陆先生的情之所至》将于2020.10.29日下架,请尽快确认!
  67. if($alert_book){
  68. $content = '';
  69. foreach ($alert_book as $item_book){
  70. $content .= sprintf('<p>《%s》将于%s日下架,请尽快确认!</p>',$item_book['book_name'],$day);
  71. }
  72. $this->warning('[网读]书籍下架提醒',$content);
  73. }
  74. if($off_shelf_book){
  75. $to_insert = [];
  76. $bid = [];
  77. foreach ($off_shelf_book as $item){
  78. $bid[] = $item['bid'];
  79. $to_insert[] = [
  80. 'bid' => $item['bid'],'book_name'=>$item['book_name'],'channel_name'=>'',
  81. 'update_date' => date('Y-m-d'),'update_chapter_count'=>2,'update_words'=>1,
  82. 'update_type' => 'onshelfstatus','operator'=>'command-Book:BookAutoOffShelf',
  83. 'created_at' => date('Y-m-d H:i:s'),
  84. 'updated_at' => date('Y-m-d H:i:s')
  85. ];
  86. }
  87. DB::table('book_updates')->insert($to_insert);
  88. DB::table('book_configs')->whereIn('bid',$bid)->update([
  89. 'is_on_shelf'=>4,'updated_at'=>date('Y-m-d H:i:s')
  90. ]);
  91. }
  92. }
  93. private function warning($subject,$msg){
  94. $notify = MessageNotify::mail([
  95. 'to_emails' => implode(",", $this->emails),
  96. 'subject' => $subject,
  97. 'body' =>$msg,
  98. 'delay_times' => 0,
  99. ]);
  100. $notify->notify();
  101. return ;
  102. }
  103. }