argument('cdate'); if (!$cdate) { $cdate = date('Ymd', strtotime('-1 day')); } Seller::chunkById(500, function ($sellers) use ($cdate) { foreach ($sellers as $seller) { $this->report($seller, $cdate); } }); } public function report(Seller $seller, $cdate) { $chupiaoMoney = Order::usable() ->where('draft_date', $cdate) ->where('draft_user_id', $seller->id) ->sum('money'); $sendMoney = Order::usable() ->where('send_date', $cdate) ->where('send_user_id', $seller->id) ->sum('lottery_send_prize'); $winMoney = Order::usable() ->where('draft_date', $cdate) ->where('draft_user_id', $seller->id) ->sum('lottery_should_send_prize'); $incrMoney = ShopBill::where('created_date', $cdate) ->where('type', ShopBill::TYPE_SELLER_INCR) ->where('seller_id', $seller->id) ->sum('money'); $reduceMoney = ShopBill::where('created_date', $cdate) ->where('type', ShopBill::TYPE_SELLER_REDUCE) ->where('seller_id', $seller->id) ->sum('money'); $report = ReportDaySeller::where('seller_id', $seller->id) ->where('cdate', $cdate) ->first(); if (!$report) { $report = new ReportDaySeller(); } $report->seller_id = $seller->id; $report->shop_id = $seller->shop_id; $report->cdate = $cdate; $report->chupiao_money = $chupiaoMoney; $report->send_prize = $sendMoney; $report->win_prize = $winMoney; $report->incr_money = $incrMoney; $report->reduce_money = $reduceMoney; $report->save(); return $report; } }