pending()->chunkById(200, function ($jobs) use ($jobService) { foreach ($jobs as $job) { try { DB::beginTransaction(); $jobService->run($job); DB::commit(); } catch (Throwable $e) { DB::rollBack(); report($e); if ($e instanceof BizException) { $job->update([ 'status' => DistributionPreIncomeJob::STATUS_FAILED, 'failed_reason' => $e->getMessage(), ]); } } //发送商家端预收益进帐消息 try { DB::beginTransaction(); switch (get_class($job->jobable)) { case Order::class://如果是订单类型,则发送预收益消息 $order = $job->jobable; $incomesLogs = DistributionPreIncome::where('order_id', $order->id)->get(); foreach ($incomesLogs as $log) { MerchantMessage::createDistributionMessage($log->user_id, [ 'title'=>'恭喜收入'.$log->total_revenue.'元', 'content'=>'您有新的预收益产生,共'.$log->total_revenue.'元。', ]); } break; default: break; } DB::commit(); } catch (Throwable $e) { DB::rollBack(); report($e); } } }); } }