mBillModel = new \app\api\model\massager\Bill(); $this->mWalletModel = new \app\api\model\massager\Wallet(); $this->userModel = new User(); $this->pBillModel = new Bill(); $this->uBillModel = new \app\api\model\user\Bill(); $this->uWalletModel = new \app\api\model\user\Wallet(); } public function _initialize() { parent::_initialize(); $this->model = new \app\admin\model\deposit\Record; $this->view->assign("platformList", $this->model->getPlatformList()); $this->view->assign("identityTypeList", $this->model->getIdentityTypeList()); $this->view->assign("applyStatusList", $this->model->getApplyStatusList()); $this->view->assign("depositStatusList", $this->model->getDepositStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['store', 'massager', 'admin', 'user']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->visible(["opening_bank_name", "bank_real_name", "bank_no", 'id', 'no', 'platform', 'identity_type', 'deposit_amount', 'service_charge_rate', 'apply_status', 'deposit_status', 'createtime', 'updatetime']); $row->visible(['store']); $row->getRelation('store')->visible(['name']); $row->visible(['massager']); $row->getRelation('massager')->visible(['name']); $row->visible(['admin']); $row->getRelation('admin')->visible(['nickname']); $row->visible(['user']); $row->getRelation('user')->visible(['nickname']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } public function check($id = null, $check = null) { $is_pass = $check === "pass"; if (!$id || !$check) $this->error("参数错误!"); $redLock = new RedLock(); $deposit = $this->model->where([ "id" => $id, "apply_status" => \E_MASSAGER_STATUS::Default, ])->find(); if (!$deposit) $this->error("申请记录不存在!"); if (false === $is_pass) { switch ($deposit["identity_type"]) { case \E_IDENTITY_TYPE::Massager: Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $deposit["massager_id"]], "提现审核", "您的提现申请已被管理员拒绝!" ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); break; case \E_IDENTITY_TYPE::Agency: Message::sendSystemMessage( \E_IDENTITY_TYPE::Agency, ["to_agency_id" => $deposit->agency_id], "提现审核", "您的提现申请已被管理员拒绝!" ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); break; case \E_IDENTITY_TYPE::Store: Message::sendSystemMessage( \E_IDENTITY_TYPE::Agency, ["to_user_id" => $deposit->operation_id], "提现审核", "您的提现申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); break; case \E_IDENTITY_TYPE::User: Message::sendSystemMessage( \E_IDENTITY_TYPE::Agency, ["to_user_id" => $deposit->user_id], "提现审核", "您的提现申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); break; } $this->success("驳回申请"); } switch ($deposit["identity_type"]) { case \E_IDENTITY_TYPE::Massager: $mLock = $redLock->lock(\app\api\model\massager\Wallet::MWKey($deposit->massager_id)); $mWallet = $this->mWalletModel->getWallet($deposit->massager_id); if ($mWallet->profit_amount < $deposit->deposit_amount) $this->error("账户剩余{$mWallet->profit_amount}!"); if (!is_array($mLock)) $this->error("请稍后再试"); Db::startTrans(); try { $this->mBillModel->save([ "massager_id" => $deposit["massager_id"], "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_M_BILL_CHANGE_TYPE::Deposit, "change" => -$deposit->deposit_amount, "before" => $mWallet->profit_amount, "after" => $mWallet->profit_amount - $deposit->deposit_amount, "reason" => "提现", "relation_no" => $deposit->no, "createtime" => time() ]); $this->mWalletModel->where("id", $mWallet->id)->setDec("profit_amount", $deposit->deposit_amount); Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $deposit["massager_id"]], "提现审核", "您的提现申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } finally { $redLock->unlock($mLock); } break; case \E_IDENTITY_TYPE::Agency: $aLock = $redLock->lock(Admin::AgencyKey($deposit->agency_id)); $admin = (new \app\admin\model\Admin())->get($deposit->agency_id); if (!$admin) $this->error("账户不存在!"); if ($admin->profit_amount < $deposit->deposit_amount) $this->error("账户剩余{$admin->profit_amount}!"); if (!is_array($aLock)) $this->error("请稍后再试"); Db::startTrans(); try { $this->pBillModel->save([ "identity_type" => \E_IDENTITY_TYPE::Agency, "target_id" => $admin->id, "target_name" => $admin->nickname, "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::Drawings, "order_no" => $deposit->no, "total_amount" => 0, "rate" => 0, "change" => -$deposit->deposit_amount, "before" => $admin->profit_amount, "after" => fixed2Float($admin->profit_amount - $deposit->deposit_amount), "createtime" => time(), "city_code" => 0 ]); (new Admin())->where("id", 1)->setDec("profit_amount", $deposit->deposit_amount); Message::sendSystemMessage( \E_IDENTITY_TYPE::Agency, ["to_agency_id" => $deposit->agency_id], "提现审核", "您的提现申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } finally { $redLock->unlock($aLock); } break; case \E_IDENTITY_TYPE::Store: $sLock = $redLock->lock(\app\api\model\Store::SWKey($deposit->store_id)); $store = (new Store())->get($deposit->store_id); if (!$store) $this->error("账户不存在!"); if ($store->profit_amount < $deposit->deposit_amount) $this->error("账户剩余{$store->profit_amount}!"); if (!is_array($sLock)) $this->error("请稍后再试"); Db::startTrans(); try { $this->pBillModel->save([ "identity_type" => \E_IDENTITY_TYPE::Store, "target_id" => $store->id, "target_name" => $store->name, "change_type" => \E_PROFIT_BILL_CHANGE_TYPE::Drawings, "order_no" => $deposit->no, "total_amount" => 0, "rate" => 0, "change" => -$deposit->deposit_amount, "before" => $store->profit_amount, "after" => $store->profit_amount - $deposit->deposit_amount, "createtime" => time(), "city_code" => $store->city_code ]); (new Store())->where("id", $store->id)->setDec("profit_amount", $deposit->deposit_amount); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } finally { $redLock->unlock($sLock); } break; case \E_IDENTITY_TYPE::User: $uLock = $redLock->lock(Wallet::UWKey($deposit->user_id)); $uWallet = (new Wallet())->get($deposit->user_id); if (!$uWallet) $this->error("账户不存在!"); if ($uWallet->money < $deposit->deposit_amount) $this->error("账户剩余{$uWallet->money}!"); if (!is_array($uLock)) $this->error("请稍后再试"); Db::startTrans(); try { $this->uBillModel->save([ "user_id" => $deposit["user_id"], "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_USER_BILL_CHANGE_TYPE::Deposit[0], "change" => -$deposit->deposit_amount, "before" => $uWallet->money, "after" => fixed2Float($uWallet->money - $deposit->deposit_amount), "reason" => \E_USER_BILL_CHANGE_TYPE::Deposit[1], "money" => 0, "give_money" => 0, "relation_no" => $deposit->no, "createtime" => time() ]); $this->uWalletModel->where("id", $uWallet->id)->setDec("money", $deposit->deposit_amount); Message::sendSystemMessage( \E_IDENTITY_TYPE::Agency, ["to_user_id" => $deposit->user_id], "提现审核", "您的提现申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->model->update([ "apply_status" => $check, "updatetime" => time(), ], ["id" => $deposit["id"]]); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } finally { $redLock->unlock($uLock); } break; } $this->success("同意提现"); } }