| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace pt\controllers;
- use biz\recharge\classes\RechargeClass;
- use biz\shop\classes\ShopClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- class RechargeController extends BaseController
- {
- public function actionBalance()
- {
- $get = Yii::$app->request->get();
- $amount = $get['amount'] ?? 0;
- $password = $get['password'] ?? '';
- $shopId = $get['shopId'] ?? 0;
- if (empty($amount) || is_numeric($amount) == false) {
- util::fail('请填写充值金额');
- }
- $staff = $this->staff;
- if (password_verify($password, $staff->password) == false) {
- util::fail('密码错误');
- }
- if (empty($shopId)) {
- util::fail('请先择门店');
- }
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('请先择门店!');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $wxPay = dict::getDict('payWay', 'unknown');
- $data = [
- 'amount' => $amount,
- 'payWay' => $wxPay,
- 'sjId' => $shop->merchantId,
- 'sjStyle' => $shop->ptStyle,
- 'shopId' => $shopId,
- 'modPrice' => 0,
- 'remark' => '',
- ];
- $order = RechargeClass::addOrder($data, true);
- $tx = dict::getDict('yeTx', 'canNot');
- $capitalType = dict::getDict('capitalType', 'xhRecharge');
- ShopClass::addBalance($shop, $amount, $order, $tx, $capitalType);
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- Yii::info("shopId:{$shopId}充值{$amount}元,系统操作失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- }
|