where('is_pushed', 0)->chunkById(100, function ($tasks) { $mallPushService = new MallUnipushService(); $merchantPushService = new MerchantUnipushService(); foreach ($tasks as $task) { try { DB::beginTransaction(); $status = 2; //默认失败 //如果是系统消息 if ($task->message instanceof Message) { if ((bool) app_settings('unipush.is_use')) {//如果开启了推送 $status = $mallPushService->push($task->sn, $task->message) ? 1 : 2; } } elseif ($task->message instanceof MerchantMessage) { if ((bool) app_settings('unipush.merchant_is_use')) {//如果开启了推送 $status = $merchantPushService->push($task->sn, $task->message) ? 1 : 2; } } $task->update([ 'is_pushed'=> 1, 'status'=> $status, ]); DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); } } }); return Command::SUCCESS; } }