NewCpBookComeIn.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands\ContentManage;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Redis;
  6. use Modules\ContentManage\Services\Notice\NoticesService;
  7. class NewCpBookComeIn extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'ContentManage:NewCpBookComeIn';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '如果发现当天有cp方新的书籍接入进来后,自动生成公告通知';
  21. /**
  22. * Execute the console command.
  23. */
  24. public function handle(): void
  25. {
  26. $datetime = date_sub(date_create(), date_interval_create_from_date_string('28 hour'))->format('Y-m-d H:i:s');
  27. $books = DB::table('books')
  28. ->where('created_at', '>=', $datetime)
  29. ->select('id', 'cp_name', 'name')
  30. ->get();
  31. $redisKey = 'contentManage.cp.newBook.alreadyAlert';
  32. $str = '';
  33. foreach ($books as $book) {
  34. if(Redis::sismember($redisKey, $book->id)) {
  35. continue;
  36. }
  37. $str .= sprintf('%s cp方的新书:%s <br>', $book->cp_name, $book->name);
  38. Redis::sadd($redisKey, $book->id);
  39. }
  40. if(!$str) {
  41. return ;
  42. }
  43. $str .= '已经进入植宇内容中台,请尽快查看';
  44. NoticesService::addNotice([
  45. 'title' => '有cp方新的书籍接入',
  46. 'notice_type_id' => 2,
  47. 'type' => 1,
  48. 'is_popup' => 1,
  49. 'content' => $str
  50. ]);
  51. }
  52. }