RechargeController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace pt\controllers;
  3. use biz\recharge\classes\RechargeClass;
  4. use biz\shop\classes\ShopClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use Yii;
  8. class RechargeController extends BaseController
  9. {
  10. public function actionBalance()
  11. {
  12. $get = Yii::$app->request->get();
  13. $amount = $get['amount'] ?? 0;
  14. $password = $get['password'] ?? '';
  15. $shopId = $get['shopId'] ?? 0;
  16. if (empty($amount) || is_numeric($amount) == false) {
  17. util::fail('请填写充值金额');
  18. }
  19. $staff = $this->staff;
  20. if (password_verify($password, $staff->password) == false) {
  21. util::fail('密码错误');
  22. }
  23. if (empty($shopId)) {
  24. util::fail('请先择门店');
  25. }
  26. $shop = ShopClass::getLockById($shopId);
  27. if (empty($shop)) {
  28. util::fail('请先择门店!');
  29. }
  30. $connection = Yii::$app->db;
  31. $transaction = $connection->beginTransaction();
  32. try {
  33. $wxPay = dict::getDict('payWay', 'unknown');
  34. $data = [
  35. 'amount' => $amount,
  36. 'payWay' => $wxPay,
  37. 'sjId' => $shop->merchantId,
  38. 'sjStyle' => $shop->ptStyle,
  39. 'shopId' => $shopId,
  40. 'modPrice' => 0,
  41. 'remark' => '',
  42. ];
  43. $order = RechargeClass::addOrder($data, true);
  44. $tx = dict::getDict('yeTx', 'canNot');
  45. $capitalType = dict::getDict('capitalType', 'xhRecharge');
  46. ShopClass::addBalance($shop, $amount, $order, $tx, $capitalType);
  47. $transaction->commit();
  48. util::complete();
  49. } catch (\Exception $exception) {
  50. Yii::info("shopId:{$shopId}充值{$amount}元,系统操作失败:" . $exception->getMessage());
  51. util::fail('操作失败');
  52. }
  53. }
  54. }