model = new Admin(); $this->storeModel = new Store(); $this->areaModel = new Area(); $this->orderModel = new Order(); $this->massagerModel = new Massager(); $this->visaModel = new Visa(); $this->massagerCommentModel = new Comment(); $this->massagerClosingModel = new Closing(); } private function fetchPermissionIds($admin_id) { $permission = $this->fetchPermission($admin_id); return [ "allowable_area_codes" => array_map(function ($data) { return $data["area_code"]; }, $permission["allowable_areas"]), "allowable_store_ids" => array_map(function ($data) { return $data["id"]; }, $permission["allowable_stores"]) ]; } private function checkAuth($params) { $permission = $this->fetchPermissionIds($params["admin_id"]); if (is_null($params["city_code"]) && is_null($params["store_id"])) return true; return $params["city_code"] > 0 ? in_array($params["city_code"], $permission["allowable_area_codes"]) : in_array($params["store_id"], $permission["allowable_store_ids"]); } public function login($account, $password) { $admin = $this->model ->where("mobile|username", $account) ->where("type", "in", [\E_IDENTITY_TYPE::Agency, \E_IDENTITY_TYPE::Store]) ->find(); if (null === $admin) return $this->fail("账号错误!"); if (md5(md5($password) . $admin["salt"]) !== $admin["password"]) return $this->fail("密码错误!"); if (\E_BASE_STATUS::Normal !== $admin["status"]) return $this->fail([ \E_BASE_STATUS::Hidden => "账号被封!", \E_BASE_STATUS::Checking => "账号正在审核!", ][$admin["status"]]); $token = $this->refreshAdminToken($admin["id"]); $admin["token"] = $token; unset($admin["password"]); unset($admin["session_token"]); unset($admin["salt"]); return $this->ok($admin); } public function loginByMobile($mobile, $sms_code) { $check = \app\common\library\Sms::check($mobile, $sms_code, "agency_login"); if (!$check) return $this->fail("短信验证码不正确!"); $agency = $this->model->findByMobile($mobile); if (null === $agency) return $this->fail("账号不存在!"); if (\E_BASE_STATUS::Normal !== $agency->status) return $this->fail("账号异常!"); $token = $this->refreshAdminToken($agency["id"]); $agency["token"] = $token; unset($agency["password"]); unset($agency["session_token"]); unset($agency["salt"]); return $this->ok($agency); } public function wxAppLogin($openid, $union_id) { $admin = $this->model->findByUnionId($union_id); if (!$admin) { return $this->fail("请先用手机号码登录并绑定微信!"); } if (\E_BASE_STATUS::Normal !== $admin["status"]) return $this->fail("账号异常!"); $this->model->update([ "app_openid" => $openid, ], ["id" => $admin['id']]); $token = $this->refreshAdminToken($admin["id"]); $admin["token"] = $token; unset($admin["password"]); unset($admin["session_token"]); unset($admin["salt"]); return $this->ok($admin); } public function bindAppWx($u_id, $openid, $union_id) { $admin = $this->model->findByUnionId($union_id); if (!$admin) { return $this->fail("请先用手机号码登录并绑定微信!"); } $this->model->update([ "app_openid" => $openid, "union_id" => $union_id, ], ["id" => $u_id]); return $this->ok(true); } public function fetchPermission($admin_id) { $permission = [ "allowable_areas" => [], "allowable_stores" => [], ]; $admin = $this->model ->where("id", $admin_id) ->where("type", "in", [\E_IDENTITY_TYPE::Agency, \E_IDENTITY_TYPE::Store]) ->find(); if (null === $admin) return $permission; if (\E_IDENTITY_TYPE::Agency === $admin["type"]) { $permission["allowable_areas"] = $this->areaModel ->where("area_code", "in", explode(",", $admin["city_codes"])) ->where("use", 1) ->field("id,area_code,name") ->select(); $permission["allowable_stores"] = $this->storeModel ->where("city_code", "in", explode(",", $admin["city_codes"])) ->where("status", \E_BASE_STATUS::Normal) ->field("id,name") ->select(); } if (\E_IDENTITY_TYPE::Store === $admin["type"]) { $permission["allowable_stores"] = $this->storeModel ->where("city_code", "in", explode(",", $admin["city_codes"])) ->where("status", \E_BASE_STATUS::Normal) ->select(); } return $permission; } public function updateBankInfo($admin, $opening_bank_name, $bank_real_name, $bank_no) { $this->model->update([ "opening_bank_name" => $opening_bank_name, "bank_real_name" => $bank_real_name, "bank_no" => $bank_no ], ["id" => $admin["id"]]); return $this->ok(); } /** * @param $admin * @param null $city_code * @param null $store_id * @return \SResult * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function fetchTodayPerformance($admin, $city_code = null, $store_id = null) { $allow = $this->checkAuth(["admin_id" => $admin["id"], "city_code" => $city_code, "store_id" => $store_id]); if (!$allow) return $this->fail("暂无权限"); // 当日销售金额 当日分润金额 当日订单量 当日新增助教 当日新增评论 $order_total_service_amount_query = $this->orderModel ->where("TO_DAYS(FROM_UNIXTIME(createtime)) = TO_DAYS(NOW())") ->where("status", "in", [ \E_ORDER_STATUS::Proceed, \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::WaitFeedback, \E_ORDER_STATUS::Finish ]); $order_count_query = Order::where("TO_DAYS(FROM_UNIXTIME(createtime)) = TO_DAYS(NOW())") ->where("status", "in", [ \E_ORDER_STATUS::Proceed, \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::WaitFeedback, \E_ORDER_STATUS::Finish ]); $massger_count_query = $this->massagerModel ->where("TO_DAYS(FROM_UNIXTIME(createtime)) = TO_DAYS(NOW())") ->where("status", "NOT IN", [\E_MASSAGER_STATUS::Close, \E_MASSAGER_STATUS::Hidden]); $today_profit_amounts_query = (new Bill())->field("id,`change`")->where("TO_DAYS(FROM_UNIXTIME(createtime)) = TO_DAYS(NOW())") ->where("identity_type", $admin["type"]) ->where("target_id", $admin["id"]) ->where("change_type", "profit"); if (!$city_code && !$store_id) { $permission = $this->fetchPermissionIds($admin["id"]); if (\E_IDENTITY_TYPE::Agency === $admin["type"]) { $order_total_service_amount_query->where("city_code", "in", $permission["allowable_area_codes"]); $order_count_query->where("city_code", "in", $permission["allowable_area_codes"]); $massger_count_query->where("city_code", "in", $permission["allowable_area_codes"]); $today_profit_amounts_query->where("city_code", "in", $permission["allowable_area_codes"]); } else { $order_total_service_amount_query->where("store_id", "in", $permission["allowable_store_ids"]); $order_count_query->where("store_id", "in", $permission["allowable_store_ids"]); $massger_count_query->where("store_id", "in", $permission["allowable_store_ids"]); $today_profit_amounts_query->where("target_id", "in", $permission["allowable_store_ids"]); } } else { if ($city_code) { $order_total_service_amount_query->where("city_code", $city_code); $order_count_query->where("city_code", $city_code); $massger_count_query->where("city_code", $city_code); $today_profit_amounts_query->where("city_code", $city_code); } else { $order_total_service_amount_query->where("store_id", $store_id); $order_count_query->where("store_id", $store_id); $massger_count_query->where("store_id", $store_id); $today_profit_amounts_query->where("target_id", $store_id); } } $today_profit_amounts = $today_profit_amounts_query->select(); return $this->ok([ "today_order_total_amount" => $order_total_service_amount_query->sum("total_service_amount"), "today_order_count" => $order_count_query->count(), "today_profit_amount" => array_reduce($today_profit_amounts, function ($p, $cur) { $p += $cur["change"]; return $p; }, 0), "today_massger_count" => $massger_count_query->count() ]); } public function fetchOrders($admin, $city_code = null, $store_id = null, $page = 1, $size = 10) { $query = $this->orderModel ->where("order.status", "in", [ \E_ORDER_STATUS::Proceed, \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::WaitFeedback, \E_ORDER_STATUS::Finish ]); if (!$city_code && !$store_id) { $permission = $this->fetchPermissionIds($admin["id"]); \E_IDENTITY_TYPE::Agency === $admin["type"] ? $query->where("order.city_code", "in", $permission["allowable_area_codes"]) : $query->where("order.store_id", "in", $permission["allowable_store_ids"]); } else { $city_code ? $query->where("order.city_code", $city_code) : $query->where("order.store_id", $store_id); } return $query ->with(["massager", "services"]) ->order("updatetime", "desc") ->page($page) ->paginate($size); } public function fetchBill($admin, $city_code = null, $store_id = null, $page = 1, $size = 10) { $query = (new Bill())->where("identity_type", $admin["type"]) ->where("target_id", $admin["id"]) ->where("change_type", "profit"); if (!$city_code && !$store_id) { $permission = $this->fetchPermissionIds($admin["id"]); \E_IDENTITY_TYPE::Agency === $admin["type"] ? $query->where("city_code", "in", $permission["allowable_area_codes"]) : $query->where("target_id", "in", $permission["allowable_store_ids"]); } else { $city_code ? $query->where("city_code", $city_code) : $query->where("target_id", $store_id); } return $query->order("createtime", "desc") ->page($page) ->paginate($size); } public function fetchMassger($admin, $city_code = null, $store_id = null, $page = 1, $size = 10) { $query = $this->massagerModel; if (!$city_code && !$store_id) { $permission = $this->fetchPermissionIds($admin["id"]); \E_IDENTITY_TYPE::Agency === $admin["type"] ? $query->where("city_code", "in", $permission["allowable_area_codes"]) : $query->where("store_id", "in", $permission["allowable_store_ids"]); } else { $city_code ? $query->where("city_code", $city_code) : $query->where("store_id", $store_id); } return $query->order("createtime", "desc") ->page($page) ->paginate($size); } /** * 待办事项 * @param $admin */ public function backlog($admin) { $permission = $this->fetchPermissionIds($admin['id']); if (count($permission["allowable_area_codes"]) > 0) { return [ "comment_check_count" => $this->massagerCommentModel ->where("city_code", "in", $permission["allowable_area_codes"]) ->where(["negative" => 1, "allegedly" => 1, "allegedly_status" => \E_BASE_STATUS::Default]) ->count(), "massager_check_count" => $this->massagerModel ->where("city_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->count(), "visa_check_count" => $this->visaModel ->where("old_area_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->count(), "closing_check_count" => $this->massagerClosingModel ->where("city_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->count(), ]; } else { return [ "comment_check_count" => $this->massagerCommentModel ->where("store_id", "in", $permission["allowable_store_ids"]) ->where(["negative" => 1, "allegedly" => 1, "allegedly_status" => \E_BASE_STATUS::Default]) ->count(), "massager_check_count" => 0, "visa_check_count" => 0, ]; } } public function fetchCheckComment($admin) { $permission = $this->fetchPermissionIds($admin['id']); return $this->massagerCommentModel ->where("comment.city_code", "in", $permission["allowable_area_codes"]) ->where(["comment.negative" => 1, "comment.allegedly" => 1, "comment.allegedly_status" => \E_BASE_STATUS::Default]) ->with(["user", "massager"]) ->order("comment.createtime", "desc") ->select(); } public function commentCheck($admin, $id, $check) { $comment = $this->massagerCommentModel->where([ "id" => $id, "allegedly" => 1, "allegedly_status" => \E_BASE_STATUS::Default, ])->find(); if (!$comment) return $this->fail("申诉记录不存在!"); $is_pass = $check === "pass"; $this->massagerCommentModel->update([ "updatetime" => time(), "negative" => (int)$is_pass, "allegedly_status" => $check ], ["id" => $id]); $total_count = $this->massagerCommentModel->where([ 'massager_id' => $comment["massager_id"], "status" => \E_BASE_STATUS::Normal ])->count(); $gte_3_count = $this->massagerCommentModel ->where([ 'massager_id' => $comment["massager_id"], "negative" => 1, "status" => \E_BASE_STATUS::Normal ]) ->count(); $praise_rate = 100; if ($total_count > 0 && $gte_3_count > 0) $praise_rate = fixed2Float((($gte_3_count / $total_count)) * 100); $this->massagerModel->update([ "updatetime" => time(), "praise_rate" => $praise_rate, ], ["id" => $id]); Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $id], "助教审核", "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); return $this->ok($is_pass ? "审核通过!" : "审核驳回!"); } public function fetchCheckMassager($admin) { $permission = $this->fetchPermissionIds($admin['id']); return $this->massagerModel ->where("city_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->select(); } public function massagerCheck($admin, $id, $check) { if (!$id || !$check) return $this->fail("参数错误!"); $massager = $this->massagerModel->where([ "id" => $id, "status" => \E_BASE_STATUS::Checking, ])->find(); if (!$massager) return $this->fail("申请记录不存在!"); $is_pass = $check === "pass"; $this->massagerModel->update([ "updatetime" => time(), "status" => $is_pass ? \E_MASSAGER_STATUS::Normal : \E_MASSAGER_STATUS::Hidden ], ["id" => $id]); Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $id], "助教审核", "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); return $this->ok("审核成功!"); } public function fetchCheckVisa($admin) { $permission = $this->fetchPermissionIds($admin['id']); return $this->visaModel ->where("old_area_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->order("createtime", "desc") ->select(); } public function visaCheck($admin, $id = null, $check = null) { if (!$id || !$check) return $this->fail("参数错误!"); $record = $this->visaModel->where([ "id" => $id, "status" => \E_MASSAGER_STATUS::Default, ])->find(); if (!$record) return $this->fail("申请记录不存在!"); $new_area = (new \app\admin\model\Area())->where([ "area_code" => $record["new_area_code"], "use" => 1, "level" => 2 ])->find(); if (!$new_area) return $this->fail("申请迁入的地址不存在!"); $is_pass = $check === "pass"; $this->model->update([ "updatetime" => time(), "status" => $is_pass ? "pass" : "reject" ], ["id" => $id]); if ($is_pass) { $this->massagerModel->update([ "updatetime" => time(), "city_code" => $new_area["area_code"], "lng" => $record["lng"], "lat" => $record["lat"], ], ["id" => $record["massager_id"]] ); } Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $record["massager_id"]], "异地签证提醒", "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); return $this->ok("审核成功!"); } public function fetchCheckClosing($admin) { $permission = $this->fetchPermissionIds($admin['id']); return $this->massagerClosingModel ->where("city_code", "in", $permission["allowable_area_codes"]) ->where("status", \E_BASE_STATUS::Checking) ->select(); } public function closingCheck($admin, $id = null, $check = null) { if (!$id || !$check) return $this->fail("参数错误!"); $record = $this->massagerClosingModel->where([ "id" => $id, "status" => \E_MASSAGER_STATUS::Checking, ])->find(); if (!$record) return $this->fail("申请记录不存在!"); $massager = (new \app\api\model\massager\Massager())->findById($record["massager_id"]); if (!$massager) return $this->fail("助教不存在!"); $is_pass = $check === "pass"; $redLock = RedLock::of(); $massagerLock = $redLock->lock(\app\api\model\massager\Wallet::MWKey($massager["id"])); if (!is_array($massagerLock)) return $this->fail("请稍后再试!"); $agency = (new Admin())->findAgency($record["city_code"]); $agencyLock = false; $pLock = false; if ($agency) { $agencyLock = $redLock->lock(Admin::AgencyKey($agency->id)); if (!is_array($agencyLock)) return $this->fail("请稍后再试!"); } else { $pLock = $redLock->lock(Admin::PlatformKey()); if (!is_array($pLock)) return $this->fail("请稍后再试!"); } $locks = [$massagerLock, $agencyLock, $pLock]; $mWallet = (new \app\api\model\massager\Wallet())->getWallet($massager["id"]); Db::startTrans(); try { if ($is_pass) { $s_result = (new MassagerActionService())->fetchDiffAmountDetailsByYm($massager["id"], $record["city_code"], $record["year"], $record["month"]); if (0 === $s_result->code()) return $this->fail("获取数据异常"); $details = $s_result->data(); $m_profit_amount = $mWallet["profit_amount"]; $p_bills = []; $m_bills = []; if ($agency) { // 代理商存在 支付的钱由代理商支付 if ($agency["profit_amount"] < $details["diff_total_amount"]) return $this->fail("代理商钱包余额不足!"); $agency_profit_amount = $agency["profit_amount"]; foreach ($details["month_orders"] as $order) { array_push($p_bills, [ "identity_type" => \E_IDENTITY_TYPE::Agency, "target_id" => $agency["id"], "target_name" => $agency["nickname"], "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::ClosingExpend, "order_no" => $order["no"], "total_amount" => $order["total_real_amount"] - $order["trip_amount"], "rate" => $order["bill"]["diff_rate"], "change" => -$order["bill"]["diff_amount"], "before" => $agency_profit_amount, "after" => fixed2Float($agency_profit_amount - $order["bill"]["diff_amount"]), "createtime" => time(), "city_code" => $order["city_code"] ], [ "identity_type" => \E_IDENTITY_TYPE::Massager, "target_id" => $massager["id"], "target_name" => $massager["name"], "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::ClosingIncome, "order_no" => $order["no"], "total_amount" => $order["total_real_amount"] - $order["trip_amount"], "rate" => $order["bill"]["diff_rate"], "change" => $order["bill"]["diff_amount"], "before" => $m_profit_amount, "after" => fixed2Float($m_profit_amount + $order["bill"]["diff_amount"]), "createtime" => time(), "city_code" => $order["city_code"] ]); array_push($m_bills, [ "massager_id" => $massager["id"], "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_M_BILL_CHANGE_TYPE::ClosingIncome, "change" => $order["bill"]["diff_amount"], "before" => $m_profit_amount, "after" => fixed2Float($m_profit_amount + $order["bill"]["diff_amount"]), "reason" => "业绩结算", "relation_no" => $order["no"], "createtime" => time() ]); $agency_profit_amount -= $order["bill"]["diff_amount"]; $m_profit_amount += $order["bill"]["diff_amount"]; } (new Admin())->where("id", $agency["id"])->setDec("profit_amount", $details["diff_total_amount"]); } else { // 不存在则平台发放 $platform = (new Admin())->where("id", 1)->find(); if (!$platform) return $this->fail("平台账号异常!"); $platform_profit_amount = $platform["profit_amount"]; if ($platform_profit_amount < $details["diff_total_amount"]) return $this->fail("平台钱包余额不足!"); foreach ($details["month_orders"] as $order) { array_push($p_bills, [ "identity_type" => \E_IDENTITY_TYPE::Platform, "target_id" => 1, "target_name" => "平台", "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::ClosingExpend, "order_no" => $order["no"], "total_amount" => $order["total_real_amount"] - $order["trip_amount"], "rate" => $order["bill"]["diff_rate"], "change" => -$order["bill"]["diff_amount"], "before" => $platform_profit_amount, "after" => fixed2Float($platform_profit_amount - $order["bill"]["diff_amount"]), "createtime" => time(), "city_code" => $order["city_code"] ], [ "identity_type" => \E_IDENTITY_TYPE::Massager, "target_id" => $massager["id"], "target_name" => $massager["name"], "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::ClosingIncome, "order_no" => $order["no"], "total_amount" => $order["total_real_amount"] - $order["trip_amount"], "rate" => $order["bill"]["diff_rate"], "change" => $order["bill"]["diff_amount"], "before" => $m_profit_amount, "after" => fixed2Float($m_profit_amount + $order["bill"]["diff_amount"]), "createtime" => time(), "city_code" => $order["city_code"] ]); array_push($m_bills, [ "massager_id" => $massager["id"], "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_M_BILL_CHANGE_TYPE::ClosingIncome, "change" => $order["bill"]["diff_amount"], "before" => $m_profit_amount, "after" => fixed2Float($m_profit_amount + $order["bill"]["diff_amount"]), "reason" => "业绩结算", "relation_no" => $order["no"], "createtime" => time() ]); $platform_profit_amount -= $order["bill"]["diff_amount"]; $m_profit_amount += $order["bill"]["diff_amount"]; } (new Admin())->where("id", 1)->setDec("profit_amount", $details["diff_total_amount"]); } (new \app\api\model\massager\Wallet())->where("id", $mWallet["id"])->setInc("profit_amount", $details["diff_total_amount"]); $this->massagerClosingModel->update([ "status" => "allow", "closing_rate" => $details["current_rate"], "closing_amount" => $details["diff_total_amount"], "updatetime" => time() ], ["id" => $record["id"]]); (new \app\api\model\profit\Bill())->saveAll($p_bills); (new \app\api\model\massager\Bill())->saveAll($m_bills); } else { // 拒绝 $this->massagerClosingModel->update([ "status" => "reject" ], ["id" => $record["id"]]); } \app\api\model\system\Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $record["massager_id"]], "业绩结算", "您的业绩结算申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); Db::commit(); } catch (Exception $e) { Db::rollback(); return $this->fail($e->getMessage()); } finally { foreach ($locks as $lock) { if (is_array($lock)) $redLock->unlock($lock); } } return $this->ok(null, "审核成功!"); } public function fetchStore($admin, $page = 1, $size = 10) { $permission = $this->fetchPermissionIds($admin['id']); $paginate = $this->storeModel ->where("status", \E_BASE_STATUS::Normal) ->where("id", "in", $permission["allowable_store_ids"]) ->page($page) ->paginate($size); return [ $paginate->items(), $paginate->total() ]; } public function fetchSystemMessage($m_id, $page, $size) { $messageModel = new Message(); $paginate = $messageModel->fetchAgencySystemMessage($m_id, $page, $size); $messageModel->update(["is_read" => 1], [ "to_massager_id" => $m_id, "is_read" => 0, "identity_type" => \E_IDENTITY_TYPE::Massager ]); return [ $paginate->items(), $paginate->total() ]; } public function deposit($admin_id, $platform, $amount) { $admin = $this->model->where("id", $admin_id)->find(); if ($admin["status"] != \E_BASE_STATUS::Normal) return $this->fail("状态异常无法发起提现!"); if (0 == $admin["allow_deposit"]) return $this->fail("请联系管理员开放提现权限!"); if (mb_strlen($admin["opening_bank_name"] ?? '') == 0 || mb_strlen($admin["bank_real_name"] ?? '') == 0 || mb_strlen($admin["bank_no"] ?? '') == 0 ) return $this->fail("未绑定银行卡信息,无法发起提现"); $to_day = (int)date("d"); $c = config("site.date_of_deposit"); $date_of_deposit = explode("|", $c); if (false === $date_of_deposit) return $this->fail("无法提现,管理员设置提现日期错误"); $allow_deposit = false; foreach ($date_of_deposit as $item) { if ((int)$item === $to_day) { $allow_deposit = true; break; } } if (false === $allow_deposit) return $this->fail("提现日期为: ${$c}日,其他时间无法发起提现!"); if (!$admin || !$admin["applet_openid"]) return $this->fail("未绑定微信,无法发起提现!"); if (1 !== $admin["allow_deposit"]) return $this->fail("暂无提现权限!"); $where = [ "apply_status" => \E_BASE_STATUS::Default, "deposit_status" => \E_BASE_STATUS::Default ]; $city_code = null; if (\E_IDENTITY_TYPE::Agency === $admin["type"]) { if ($amount > $admin["profit_amount"]) { return $this->fail("数额不足,无法发起提现"); } $agency_deposit_rate = config("site.agency_deposit_rate") ?? 50; $allow_deposit_amount = $admin["profit_amount"] * ($agency_deposit_rate / 100); if ($amount > $allow_deposit_amount) { return $this->fail("您最高可提现{$allow_deposit_amount}!可提现比例为 ${$agency_deposit_rate}%"); } array_merge($where, [ "identity_type" => \E_IDENTITY_TYPE::Agency, "agency_id" => $admin_id ]); $city_code = explode(",", $admin["city_codes"])[0]; } else { $store = $this->storeModel->findById($admin["store_id"]); if (!$store) return $this->fail("球房信息不存在!"); if ($store["profit_amount"] < $amount) { return $this->fail("数额不足,无法发起提现"); } array_merge($where, [ "identity_type" => \E_IDENTITY_TYPE::Store, "store_id" => $admin["store_id"], ]); $city_code = $store["city_code"]; } $record = (new Record())->where($where)->find(); if ($record) { return $this->fail("您上一笔提现未通过审核,等待上一笔提现后再次发起"); } (new Record())->save([ "no" => "TX" . (\E_IDENTITY_TYPE::Agency === $admin["type"] ? "A" : "S") . time() . rand(10000, 99999), "platform" => $platform, "identity_type" => $admin["type"], "store_id" => \E_IDENTITY_TYPE::Agency === $admin["type"] ? null : $admin["store_id"], "agency_id" => \E_IDENTITY_TYPE::Agency === $admin["type"] ? $admin["id"] : null, "massager_id" => null, "city_code" => $city_code, "deposit_amount" => $amount, "service_charge_rate" => config("site.service_charge_rate"), "apply_status" => \E_BASE_STATUS::Default, "deposit_status" => \E_BASE_STATUS::Default, "operation_id" => $admin["id"], "opening_bank_name" => $admin["opening_bank_name"], "bank_real_name" => $admin["bank_real_name"], "bank_no" => $admin["bank_no"], "createtime" => time(), "updatetime" => time() ]); return $this->ok(true, "申请提现成功,请耐心等待管理员审核!"); } }