middleware(function ($request, $next) { $this->checkMasterNext(); return $next($request); }); } /** * @api {POST} /api/seller/cooperate/apply 合作-申请合作 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {String} shop_sn 店铺编号 * @apiParam {String} shop_name 店铺编号 * @apiParam {String} [apply_message] 申请信息 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function apply(Request $request) { $shopSn = $request->input('shop_sn'); $shopName = $request->input('shop_name'); $applyMessage = $request->input('apply_message'); $cooperate = Shop::where('shop_sn', $shopSn)->first(); ThrowException::isTrue(!$cooperate, '编号不存在'); ThrowException::isTrue($cooperate->name != $shopName, '编号与名称无法匹配'); ThrowException::isTrue($cooperate->status != BoolEnum::YES, '该店铺未启用'); ThrowException::isTrue($cooperate->id == $this->shopId(), '不支持申请自己'); $shopCooperate = ShopCooperate::where('shop_id', $this->shopId()) ->where('cooperate_id', $cooperate->id) ->first(); if ($shopCooperate) { if ($shopCooperate->audit_state == CooperateState::SUCCESS || $shopCooperate->audit_state == CooperateState::PENDING) { ThrowException::isTrue($shopCooperate, '不可重复申请'); } } if (!$shopCooperate) { $shopCooperate = new ShopCooperate(); } $shopCooperate->shop_seller_id = $this->sellerId(); $shopCooperate->shop_id = $this->shopId(); $shopCooperate->cooperate_seller_id = 0; $shopCooperate->cooperate_id = $cooperate->id; $shopCooperate->audit_state = CooperateState::PENDING; $shopCooperate->apply_message = strval($applyMessage); $shopCooperate->save(); return $this->jsonSuccess($shopCooperate); } /** * @api {POST} /api/seller/cooperate/audit 合作-审核申请合作 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作数据id * @apiParam {Int} audit_state 审核状态:1通过;2失败 * @apiParam {String} [audit_message] 审核信息 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function audit(Request $request) { $shopCooperateId = $request->input('shop_cooperate_id'); $auditState = $request->input('audit_state'); $auditMessage = $request->input('audit_message'); ThrowException::isTrue(!CooperateState::hasValue($auditState), '状态不对'); $shopCooperate = ShopCooperate::find($shopCooperateId); ThrowException::isTrue(!$shopCooperate, '数据不存在'); ThrowException::isTrue($shopCooperate->cooperate_id != $this->shopId(), '数据错误'); $shopCooperate->audit_state = $auditState; $shopCooperate->audit_message = strval($auditMessage); $shopCooperate->save(); return $this->jsonSuccess($shopCooperate); } /** * @api {GET} /api/seller/cooperate/entrust_list 合作-申请列表 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {String} [keyword] 店铺名称/手机号 * @apiParam {String} [audit_state] 审核状态:1成功,2失败,3申请中 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "total_balance": "0.0000", // 余额 * "list": { * "current_page": 1, * "data": [ * { * "id": 1000, // 合作店铺id(shop_cooperate_id) * "balance": "0.0000", * "shop_seller_id": 1000, * "shop_id": 2000, * "cooperate_id": 2001, * "cooperate_seller_id": 0, * "apply_message": "", * "audit_state": 1, // 审核状态:1成功,2失败,3申请中 * "audit_message": "", * "created_at": "2023-07-05 21:04:01", * "updated_at": "2023-07-05 21:04:56", * "deleted_at": null, * "cooperate": { // 合作店铺信息 * "id": 2000, * "shop_sn": "S100001", * "name": "第一家", // 店铺名称 * }, * "shop_cooperate_lottery": [] // * } * ], * "per_page": 20, * "total": 1 * } * } * } */ public function entrustList(Request $request) { $keyword = $request->input('keyword'); $auditState = $request->input('audit_state'); $query = ShopCooperate::with([ 'cooperate:id,name,shop_sn', 'shopCooperateLottery', 'shopCooperateLottery.lotteryType' ]) ->where('shop_id', $this->shopId()) ->whereHas('cooperate', function($query) use ($keyword) { if ($keyword) { $query->where('seller_phone', 'like', $keyword) ->orWhere('name', 'like', $keyword); } }); if ($auditState) { $query->where('audit_state', $auditState); } $balance = $query->sum('balance'); $shops = $query->paging(); return $this->jsonSuccess([ 'total_balance' => $balance, 'list' => $shops, ]); } /** * @api {GET} /api/seller/cooperate/entrusted_list 合作-审核列表 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {String} [keyword] 店铺名称/手机号 * @apiParam {String} [audit_state] 审核状态:1成功,2失败,3申请中 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "total_balance": "0.0000", // 余额 * "list": { * "current_page": 1, * "data": [ * { * "id": 1000, // 合作店铺id(shop_cooperate_id) * "balance": "0.0000", * "shop_seller_id": 1000, * "shop_id": 2000, * "cooperate_id": 2001, * "cooperate_seller_id": 0, * "apply_message": "", * "audit_state": 1, // 审核状态:1成功,2失败,3申请中 * "audit_message": "", * "created_at": "2023-07-05 21:04:01", * "updated_at": "2023-07-05 21:04:56", * "deleted_at": null, * "shop": { // 合作店铺信息 * "id": 2000, * "shop_sn": "S100001", * "name": "第一家", // 店铺名称 * }, * "shop_cooperate_lottery": [] // * } * ], * "per_page": 20, * "total": 1 * } * } * } */ public function entrustedList(Request $request) { $keyword = $request->input('keyword'); $auditState = $request->input('audit_state'); $query = ShopCooperate::with([ 'shop:id,name,shop_sn', 'shopCooperateLottery', 'shopCooperateLottery.lotteryType' ]) ->where('cooperate_id', $this->shopId()) ->whereHas('shop', function($query) use ($keyword) { if ($keyword) { $query->where('seller_phone', 'like', $keyword) ->orWhere('name', 'like', $keyword); } }); if ($auditState) { $query->where('audit_state', $auditState); } $balance = $query->sum('balance'); /** @var LengthAwarePaginator $shops */ $shops = $query->paging(); foreach ($shops->getIterator() as $shop) { $shop->lottery_auditing_num = ShopCooperateLottery::where('shop_cooperate_id', $shop->id) ->where('audit_state', CooperateState::PENDING)->count(); } return $this->jsonSuccess([ 'total_balance' => $balance, 'list' => $shops, ]); } /** * @api {GET} /api/seller/cooperate/entrust_lottery_list 合作-申请的店铺彩种列表 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {String} shop_cooperate_id 合作店铺数据id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [ * "shop":{}, * "list":[{ * "id": 1000, // shop_cooperate_lottery_id * "opened": 0, // 是否开启 * "audit_state": 3, // 审核状态:1成功,2失败,3申请中 * "shop_cooperate_id": 1000, * "shop_id": 2000, * "cooperate_id": 2001, * "lottery_type_id": 1, * "early_minute": 10, // 提前截止投注(分钟) * "order_method": 1, // 接单模式:1自动,2手动 * "money_line": "0.0000", // 金额分割线 * "brokerage": "0.00", // 佣金 * "apply_message": "", // 申请信息 * "audit_message": "", // 审核信息 * "created_at": "2023-07-05 21:11:40", * "updated_at": "2023-07-05 21:11:40", * "deleted_at": null, * "lottery_type": { // 彩种信息 * "id": 1, * "type": "jczq", * "status": 1, * "name": "竞彩足球", * "icon": "jczq", * "info": "13场赛事可投", * "created_at": null, * "updated_at": "2023-06-24 23:00:03", * "deleted_at": null * } * } * ] * * ] * } */ public function entrustLotteryList(Request $request) { $shop_cooperate_id = $request->input('shop_cooperate_id'); $sc = ShopCooperate::where('shop_id', $this->shopId())->find($shop_cooperate_id); ThrowException::isTrue(!$sc, '数据不存在'); $shops = ShopCooperateLottery::with('lotteryType') ->where('shop_cooperate_id', $shop_cooperate_id) ->where('shop_id', $this->shopId()) ->get(); foreach ($shops as $shop) { $lottery = Lottery::where('shop_id', $shop->cooperate_id) ->where('lottery_type_id', $shop->lottery_type_id) ->where('opened', BoolEnum::YES) ->where('chupiao', BoolEnum::YES) ->first(); $shop->lottery_early_minute = $lottery ? $lottery->early_minute : 0; } return $this->jsonSuccess([ 'shop_cooperate' => $sc, 'shop' => $sc->cooperate, 'list' => $shops ]); } /** * @api {GET} /api/seller/cooperate/entrusted_lottery_list 合作-审核的店铺彩种列表 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [ * "shop":{}, * "list":[{ * "id": 1000, // shop_cooperate_lottery_id * "opened": 0, // 是否开启 * "audit_state": 3, // 审核状态:1成功,2失败,3申请中 * "shop_cooperate_id": 1000, * "shop_id": 2000, * "cooperate_id": 2001, * "lottery_type_id": 1, * "early_minute": 10, // 提前截止投注(分钟) * "order_method": 1, // 接单模式:1自动,2手动 * "money_line": "0.0000", // 金额分割线 * "brokerage": "0.00", // 佣金 * "apply_message": "", // 申请信息 * "audit_message": "", // 审核信息 * "created_at": "2023-07-05 21:11:40", * "updated_at": "2023-07-05 21:11:40", * "deleted_at": null, * "lottery_type": { // 彩种信息 * "id": 1, * "type": "jczq", * "status": 1, * "name": "竞彩足球", * "icon": "jczq", * "info": "13场赛事可投", * "created_at": null, * "updated_at": "2023-06-24 23:00:03", * "deleted_at": null * } * } * ] * * ] * } */ public function entrustedLotteryList(Request $request) { $shop_cooperate_id = $request->input('shop_cooperate_id'); $sc = ShopCooperate::where('cooperate_id', $this->shopId())->find($shop_cooperate_id); ThrowException::isTrue(!$sc, '数据不存在'); $shops = ShopCooperateLottery::with('lotteryType') ->where('cooperate_id', $this->shopId()) ->get(); return $this->jsonSuccess([ 'shop_cooperate' => $sc, 'shop' => $sc->shop, 'list' => $shops ]); } /** * @api {POST} /api/seller/cooperate/lottery_audit 合作-审核店铺彩种 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_lottery_id 合作店铺彩种id * @apiParam {Int} audit_state 审核状态:1成功,2失败 * @apiParam {String} [audit_message] 审核信息 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function lotteryAudit(Request $request) { $shopCooperateLotteryId = $request->input('shop_cooperate_lottery_id'); $auditState = $request->input('audit_state'); $auditMessage = $request->input('audit_message'); ThrowException::isTrue($shopCooperateLotteryId < 1, 'id错误'); ThrowException::isTrue(!CooperateState::hasValue($auditState), '状态不对'); $scl = ShopCooperateLottery::find($shopCooperateLotteryId); ThrowException::isTrue(!$scl, '数据不存在'); ThrowException::isTrue($scl->cooperate_id != $this->shopId(), '数据异常'); /** @var Lottery $lottery */ $lottery = Lottery::where('lottery_type_id', $scl->lottery_type_id) ->where('shop_id', $scl->cooperate_id) ->first(); ThrowException::isTrue(!$lottery, '本店未开通该彩种'); ThrowException::isTrue(!$lottery->isActive(), '本店未开启该彩种'); $scl->audit_state = $auditState; if ($scl->audit_state == CooperateState::SUCCESS) { $scl->opened = BoolEnum::YES; } $scl->audit_message = strval($auditMessage); $scl->save(); $this->bindLottery($scl->id); return $this->jsonSuccess($scl); } /** * @api {POST} /api/seller/cooperate/lottery_apply 合作-申请彩种 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作店铺id * @apiParam {Int} lottery_type_id 彩种id * @apiParam {String} [money_min] 最小金额 * @apiParam {String} [money_max] 最大金额 * @apiParam {String} [brokerage] 佣金0-7 * @apiParam {String} [apply_message] 申请信息 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function lotteryApply(Request $request) { $shopCooperateId = $request->input('shop_cooperate_id'); $lotteryTypeId = $request->input('lottery_type_id'); $moneyMin = $request->input('money_min'); $moneyMax = $request->input('money_max'); $moneyLimit = $request->input('limit_money'); $brokerage = $request->input('brokerage'); $applyMessage = $request->input('apply_message'); $shopCooperate = ShopCooperate::find($shopCooperateId); ThrowException::isTrue(!$shopCooperate, '数据不存在'); ThrowException::isTrue($shopCooperate->audit_state != CooperateState::SUCCESS, '申请店铺合作,待同意'); $lotteryType = LotteryType::find($lotteryTypeId); ThrowException::isTrue(!$lotteryType, '彩种不存在'); ThrowException::isTrue($lotteryType->status != BoolEnum::YES, '彩种未开启'); ThrowException::isTrue($shopCooperate->shop_id != $this->shopId(), '数据异常'); /** @var Lottery $lottery */ $lottery = Lottery::where('lottery_type_id', $lotteryType->id) ->where('shop_id', $shopCooperate->cooperate_id) ->first(); ThrowException::isTrue(!$lottery, '合作店铺未开通该彩种'); ThrowException::isTrue(!$lottery->isActive(), '合作店铺未开启该彩种'); if ($brokerage) { ThrowException::isTrue(bc_gt($brokerage, 7), '佣金范围0-7'); } $scl = ShopCooperateLottery::where('lottery_type_id', $lotteryTypeId) ->where('shop_id', $this->shopId()) ->first(); ThrowException::isTrue($scl && $scl->shop_cooperate_id != $shopCooperateId, '已再其他店铺申请过该彩种'); $scl = ShopCooperateLottery::where('lottery_type_id', $lotteryTypeId) ->where('shop_cooperate_id', $shopCooperateId) ->first(); if ($scl) { if ($scl && $scl->audit_state == CooperateState::SUCCESS || $scl->audit_state == CooperateState::PENDING) { ThrowException::isTrue($scl, '无法重复申请'); } } if (!$scl) { $scl = new ShopCooperateLottery(); } $scl->lottery_type_id = $lotteryTypeId; $scl->shop_cooperate_id = $shopCooperateId; $scl->shop_id = $this->shopId(); $scl->cooperate_id = $shopCooperate->cooperate_id; $scl->apply_message = strval($applyMessage); if ($brokerage) { $scl->brokerage = $brokerage; } if ($moneyLimit !== null) { $scl->money_limit = $moneyLimit; if ($moneyLimit && ($moneyMin <= 0 || $moneyMax <= 0)) { ThrowException::run('请设置金额'); } if ($moneyMin!== null) { $scl->money_min = $moneyMin; } if ($moneyMax!== null) { $scl->money_max = $moneyMax; } } $scl->audit_state = CooperateState::PENDING; $scl->save(); return $this->jsonSuccess(); } /** * @api {POST} /api/seller/cooperate/lottery_update 合作-更新彩种配置 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作店铺id * @apiParam {String} [money_min] 最小金额 * @apiParam {String} [money_max] 最大金额 * @apiParam {String} [opened] 1开启,0关闭 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function lotteryUpdate(Request $request) { $shopCooperateLotteryId = $request->input('shop_cooperate_lottery_id'); $moneyMin = $request->input('money_min'); $moneyMax = $request->input('money_max'); $opened = $request->input('opened'); $orderMethod = $request->input('order_method'); ThrowException::isTrue($shopCooperateLotteryId < 1, 'id错误'); $scl = ShopCooperateLottery::find($shopCooperateLotteryId); ThrowException::isTrue(!$scl, '数据不存在'); ThrowException::isTrue($scl->shop_id != $this->shopId(), '数据异常'); $shopCooperate = ShopCooperate::find($scl->shop_cooperate_id); ThrowException::isTrue(!$shopCooperate, '数据不存在'); ThrowException::isTrue($shopCooperate->audit_state != CooperateState::SUCCESS, '申请合作中'); $lotteryType = LotteryType::find($scl->lottery_type_id); ThrowException::isTrue(!$lotteryType, '彩种不存在'); ThrowException::isTrue($lotteryType->status != BoolEnum::YES, '彩种未开启'); /** @var Lottery $lottery */ $lottery = Lottery::where('lottery_type_id', $lotteryType->id) ->where('shop_id', $shopCooperate->cooperate_id) ->first(); ThrowException::isTrue(!$lottery, '合作店铺未开通该彩种'); ThrowException::isTrue(!$lottery->isActive(), '合作店铺未开启该彩种'); if ($moneyMin) { $scl->money_min = $moneyMin; } if ($moneyMax) { $scl->money_max = $moneyMax; } if ($opened) { $scl->opened = $opened; } if ($orderMethod) { $scl->order_method = $orderMethod; } $scl->save(); $this->bindLottery($scl->id); return $this->jsonSuccess(); } /** * @api {POST} /api/seller/cooperate/lottery_unbind 合作-解除彩种配置 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作店铺id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function lotteryUnbind(Request $request) { $shopCooperateLotteryId = $request->input('shop_cooperate_lottery_id'); ThrowException::isTrue($shopCooperateLotteryId < 1, 'id错误'); $scl = ShopCooperateLottery::find($shopCooperateLotteryId); ThrowException::isTrue(!$scl, '数据不存在'); ThrowException::isTrue($scl->shop_id != $this->shopId(), '数据异常'); $scl->forceDelete(); $bindLottery = Lottery::where('shop_id', $scl->cooperate_id) ->where('lottery_type_id', $scl->lottery_type_id) ->first(); if (!$bindLottery) { return $this->jsonSuccess(); } $lottery = Lottery::where('shop_id', $scl->shop_id) ->where('lottery_type_id', $scl->lottery_type_id) ->first(); if ($lottery) { $lottery->cooperate_id = 0; $lottery->lottery_id = 0; $lottery->shop_cooperate_lottery_id = 0; $lottery->opened = $lottery->owned; $lottery->save(); } return $this->jsonSuccess(); } private function bindLottery($shopCooperateLotteryId) { $scl = ShopCooperateLottery::find($shopCooperateLotteryId); if (!$scl) { return ; } $bindLottery = Lottery::where('shop_id', $scl->cooperate_id) ->where('lottery_type_id', $scl->lottery_type_id) ->first(); ThrowException::isTrue(!$bindLottery, '合作店铺不存在该彩种,无法操作'); $lottery = Lottery::where('shop_id', $scl->shop_id) ->where('lottery_type_id', $scl->lottery_type_id) ->first(); if ($scl->audit_state == CooperateState::SUCCESS) { if (!$lottery) { $lottery = new Lottery(); $lottery->shop_id = $scl->shop_id; $lottery->lottery_type_id = $scl->lottery_type_id; $lottery->owned = BoolEnum::NO; } $lottery->opened = BoolEnum::YES; $lottery->shop_cooperate_lottery_id = $scl->id; $lottery->cooperate_id = $scl->cooperate_id; $lottery->lottery_id = $bindLottery->id; $lottery->cooperate_min_money = $scl->money_min; $lottery->cooperate_max_money = $scl->money_max; $lottery->name = $bindLottery->name; $lottery->save(); } else { if ($lottery) { $lottery->cooperate_id = 0; $lottery->lottery_id = 0; $lottery->shop_cooperate_lottery_id = 0; $lottery->opened = $lottery->owned; $lottery->save(); } } } /** * @api {POST} /api/seller/cooperate/balance_incr 合作-加款 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Float} money 金额 * @apiParam {Int} shop_id 申请合作的店铺id * @apiParam {String} password_pay 支付密码 * @apiParam {String} remark 备注 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function balanceIncr(Request $request, SellerWalletService $service) { $money = $request->input('money'); $passwordPay = $request->input('password_pay'); ThrowException::isTrue($money <= 0, '金额不能小于0'); $seller = Seller::find($this->sellerId()); ThrowException::isTrue(!$seller->password_pay, '请先设置支付密码'); ThrowException::isTrue(!Seller::checkPassword($passwordPay,$seller->password_pay), '支付密码错误'); $service->cooperateIncr($seller, $request->all()); return $this->jsonSuccess(); } /** * @api {POST} /api/seller/cooperate/balance_reduce 合作-扣款 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Float} money 金额 * @apiParam {Int} shop_id 申请合作的店铺id * @apiParam {String} password_pay 支付密码 * @apiParam {String} remark 备注 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] * } */ public function balanceReduce(Request $request, SellerWalletService $service) { $money = $request->input('money'); $passwordPay = $request->input('password_pay'); ThrowException::isTrue($money <= 0, '金额不能小于0'); $seller = Seller::find($this->sellerId()); ThrowException::isTrue(!$seller->password_pay, '请先设置支付密码'); ThrowException::isTrue(!Seller::checkPassword($passwordPay,$seller->password_pay), '支付密码错误'); $service->cooperateReduce($seller, $request->all()); return $this->jsonSuccess(); } /** * @api {GET} /api/seller/cooperate/lotteries 合作-彩种列表 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作店铺id * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] // 调用自查 * } */ public function lotteries(Request $request) { $shopCooperateId = $request->input('shop_cooperate_id'); $sc = ShopCooperate::where('shop_id', $this->shopId())->find($shopCooperateId); ThrowException::isTrue(!$sc, '数据不存在'); $lotterys = Lottery::with('lotteryType')->where('shop_id', $sc->cooperate_id)->get(); $scls = ShopCooperateLottery::where('shop_cooperate_id', $shopCooperateId) ->get() ->keyBy('lottery_type_id'); $list = []; foreach ($lotterys as $item) { $item->cooperate_opened = BoolEnum::NO; $item->cooperate_audit_state = 0; $sclItem = Arr::get($scls, $item['lottery_type_id']); if ($sclItem) { $item->cooperate_opened = BoolEnum::YES; $item->cooperate_audit_state = Arr::get($sclItem, 'audit_state'); } $list[] = $item; } return $this->jsonSuccess($list); } /** * @api {GET} /api/seller/cooperate/bills 合作-合作余额明细 * @apiVersion 0.1.0 * @apiGroup 店主 * * @apiParam {Int} shop_cooperate_id 合作店铺id * @apiParam {String} [type] 1加款;2扣款;3出票 * @apiParam {String} [ie] -:支出;+:收入 * @apiParam {String} [date_start] 开始日期(2001-01-01),默认本月第一天 * @apiParam {String} [date_end] 结束日期(2001-01-01),默认当前 * * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": [] // 调用自查 * } */ public function bills(Request $request) { $type = $request->input('type'); $size = $request->input('size'); $ie = $request->input('ie'); $dateStart = $request->input('date_start'); $dateEnd = $request->input('date_end'); $shopCooperateId = $request->input('shop_cooperate_id'); $lotteryTypeId = $request->input('lottery_type_id'); $moneyMin = $request->input('money_min'); $moneyMax = $request->input('money_max'); if (!$dateStart) { $dateStart = date('Y-m-01 00:00:00'); } else { $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart)); } if ($dateEnd) { $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd)); } $shopCooperate = ShopCooperate::find($shopCooperateId); ThrowException::isTrue(!$shopCooperate, '店铺不存在'); if ($shopCooperate->shop_id != $this->shopId() && $shopCooperate->cooperate_id != $this->shopId()) { return $this->jsonFailed('无权查看'); } $query = ShopCooperateBill::with([ 'order:id,money,type,lottery_type_id,issue_num,type', 'order.lotteryType:id,name' ]) ->where('shop_cooperate_id', $shopCooperateId); if ($type) { $query->where('type', $type); } if ($dateStart) { $query->where('created_at', '>=', $dateStart); } if ($dateEnd) { $query->where('created_at', '<=', $dateEnd); } if ($ie == '-' || $ie == '+') { $query->where('ie', $ie); } if ($lotteryTypeId) { $query->where('lottery_type_id', $lotteryTypeId); } if ($moneyMin) { $query->where('money', '>=', $moneyMin); } if ($moneyMax) { $query->where('money', '<=', $moneyMax); } $money = $query->sum('money'); $brokerage = $query->sum('cooperate_brokerage'); $list = $query->orderBy('id', 'desc') ->paging($size); return $this->jsonSuccess([ 'list' => $list, 'money' => $money, 'brokerage' => $brokerage, ]); } }