| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <?php
- namespace app\admin\controller\deposit;
- use app\admin\model\Admin;
- use app\admin\model\profit\Bill;
- use app\admin\model\Store;
- use app\api\model\system\Message;
- use app\api\model\User;
- use app\api\model\user\Wallet;
- use app\common\controller\Backend;
- use redis\RedLock;
- use think\Db;
- use think\Exception;
- use think\Request;
- /**
- * 提现记录管理
- *
- * @icon fa fa-circle-o
- */
- class Record extends Backend
- {
- /**
- * Record模型对象
- * @var \app\admin\model\deposit\Record
- */
- protected $model = null;
- private $mBillModel;
- private $mWalletModel;
- private $userModel;
- private $uBillModel;
- private $uWalletModel;
- private $pBillModel;
- public function __construct(Request $request = null)
- {
- parent::__construct($request);
- $this->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("同意提现");
- }
- }
|