123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2020/10/29
- * Time: 9:49
- */
- namespace App\Console\Commands\Book;
- use DB;
- use Illuminate\Console\Command;
- use App\Modules\Message\MessageNotify;
- class BookAutoOffShelf extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'Book:BookAutoOffShelf';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '自动下架';
- private $emails = ['zhaojp@yqsd.net',
- 'songdb@yqsd.net','zhoulj@iqiyoo.com'
- ];
- //private $emails = ['zhaoy@zw88.net','baixq@zw88.net'];
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle(){
- $this->start();
- }
- private function start(){
- $day = date('Y-m-d',time()+86400*10);
- $book = DB::table('book_configs')->where('is_on_shelf',2)
- ->where('copyright_limit_data','<=',$day)
- ->where('copyright_limit_data','>=',date('Y-m-d'))
- ->select('bid','book_name','copyright_limit_data')
- ->get();
- $off_shelf_book = [];
- $alert_book = [];
- if($book){
- foreach ($book as $item){
- if($item->copyright_limit_data <= date('Y-m-d')){
- $off_shelf_book[] = ['bid'=>$item->bid,'book_name'=>$item->book_name];
- }
- if($item->copyright_limit_data == $day){
- $alert_book[] = ['bid'=>$item->bid,'book_name'=>$item->book_name];
- }
- }
- }
- //《陆先生的情之所至》将于2020.10.29日下架,请尽快确认!
- if($alert_book){
- $content = '';
- foreach ($alert_book as $item_book){
- $content .= sprintf('<p>《%s》将于%s日下架,请尽快确认!</p>',$item_book['book_name'],$day);
- }
- $this->warning('[网读]书籍下架提醒',$content);
- }
- if($off_shelf_book){
- $to_insert = [];
- $bid = [];
- foreach ($off_shelf_book as $item){
- $bid[] = $item['bid'];
- $to_insert[] = [
- 'bid' => $item['bid'],'book_name'=>$item['book_name'],'channel_name'=>'',
- 'update_date' => date('Y-m-d'),'update_chapter_count'=>2,'update_words'=>1,
- 'update_type' => 'onshelfstatus','operator'=>'command-Book:BookAutoOffShelf',
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s')
- ];
- }
- DB::table('book_updates')->insert($to_insert);
- DB::table('book_configs')->whereIn('bid',$bid)->update([
- 'is_on_shelf'=>4,'updated_at'=>date('Y-m-d H:i:s')
- ]);
- }
- }
- private function warning($subject,$msg){
- $notify = MessageNotify::mail([
- 'to_emails' => implode(",", $this->emails),
- 'subject' => $subject,
- 'body' =>$msg,
- 'delay_times' => 0,
- ]);
- $notify->notify();
- return ;
- }
- }
|