uniacid = $u->uniacid; $this->orderCouponSend(); } } public function orderCouponSend(){ // \Log::debug(' 发放优惠券 - 每月订单支付时间后发放 - 开始处理'); $records = OrderGoodsCoupon::uniacid() ->where(function ($query){ $query->where('next_time','<=', time())->orWhere('next_time','=',null); }) ->where(['send_type'=>OrderGoodsCoupon::MONTH_PAY_TIME,'status'=>OrderGoodsCoupon::WAIT_STATUS]) ->whereHas('hasOneOrderGoods',function ($query){ $query->whereHas('hasOneOrder',function ($q){ $q->where('status',Order::COMPLETE); }) ; }) ->get(); if($records->isEmpty()) return; foreach ($records as $record){ $numReason = $record->num_reason?$record->num_reason.'||':''; (new CronSendService($record,$numReason,2))->sendCoupon(); } } }