"desc"]) { $failData = [ 'total' => 0, 'current' => $page, 'size' => $size, 'list' => new Collection(), ]; $rep = CouponBill::alias("a") ->join("business b","a.business_code = b.code") ->join("account c","a.user_code = c.user_code") ->join("coupon_main d","a.coupon_main_id = d.id") ->when(!empty($keyword),function ($q) use($keyword){ $q->where("b.business_name|c.nick_name|d.name", "like", "%$keyword%"); }) ->when(MemberModel::is_agency(session("auth")['roles']),function ($q) { $q->where("b.agency_code", "=", session("auth")['business_code']); }) ->when(!empty($startTime), function ($q) use ($startTime) { $q->whereTime("a.create_time", ">=", $startTime); }) ->when(!empty($endTime), function ($q) use ($endTime) { $q->whereTime("a.create_time", "<=", $endTime); }) ->field("a.*,b.business_name,c.nick_name,c.avatar_url,d.name as coupon_main_name") ; $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); }) ->when(MemberModel::is_agency(session("auth")['roles']),function ($q) { $q->where("agency_code", "=", session("auth")['business_code']); }) ->sum($field); } }