"desc"]) { $failData = [ 'total' => 0, 'current' => $page, 'size' => $size, 'list' => new Collection(), ]; $rep = CouponBill::with([ "business" => function ($query) use ($keyword) { $query->field(["code", "business_name"])->when(empty($keyword), function ($q) use ($keyword) { $q->where("business_name", "like", "%$keyword%"); }); }, "account" => function ($q) { $q->field(["user_code", "nick_name"]); }, "couponMain" => function ($q) { $q->field(["id", "name"]); }, ]) ->when(!empty($startTime), function ($q) use ($startTime) { $q->whereTime("create_time", ">=", $startTime); }) ->when(!empty($endTime), function ($q) use ($endTime) { $q->whereTime("create_time", "<=", $endTime); }); $failData ['total'] = $rep->count(); $failData ['list'] = $rep ->page($page, $size) ->order($orders) ->select(); return $failData; } /** * 总收益 * @param $field * @param null $start_time * @param null $end_time * @return float */ public function getAgencyMoneySum($field, $start_time = null, $end_time = null) { return CouponBill::when(!empty($start_time), function ($q) use ($start_time) { $q->whereTime("create_time", ">=", $start_time); })->when(!empty($end_time), function ($q) use ($end_time) { $q->whereTime("create_time", "<=", $end_time); }) ->sum($field); } }