1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Console\Commands\ContentManage;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- use Modules\ContentManage\Services\Notice\NoticesService;
- class NewCpBookComeIn extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'ContentManage:NewCpBookComeIn';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '如果发现当天有cp方新的书籍接入进来后,自动生成公告通知';
- /**
- * Execute the console command.
- */
- public function handle(): void
- {
- $datetime = date_sub(date_create(), date_interval_create_from_date_string('28 hour'))->format('Y-m-d H:i:s');
- $books = DB::table('books')
- ->where('created_at', '>=', $datetime)
- ->select('id', 'cp_name', 'name')
- ->get();
- $redisKey = 'contentManage.cp.newBook.alreadyAlert';
- $str = '';
- foreach ($books as $book) {
- if(Redis::sismember($redisKey, $book->id)) {
- continue;
- }
- $str .= sprintf('%s cp方的新书:%s <br>', $book->cp_name, $book->name);
- Redis::sadd($redisKey, $book->id);
- }
- if(!$str) {
- return ;
- }
- $str .= '已经进入植宇内容中台,请尽快查看';
- NoticesService::addNotice([
- 'title' => '有cp方新的书籍接入',
- 'notice_type_id' => 2,
- 'type' => 1,
- 'is_popup' => 1,
- 'content' => $str
- ]);
- }
- }
|