RechargeController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if (getenv('YII_ENV', 'local') == 'production') {
  31. if ($staff->mobile != '15280215347') {
  32. util::fail('线上只有超管才能发起充值');
  33. }
  34. }
  35. $connection = Yii::$app->db;
  36. $transaction = $connection->beginTransaction();
  37. try {
  38. $wxPay = dict::getDict('payWay', 'unknown');
  39. $data = [
  40. 'amount' => $amount,
  41. 'payWay' => $wxPay,
  42. 'sjId' => $shop->sjId,
  43. 'sjStyle' => $shop->ptStyle,
  44. 'shopId' => $shopId,
  45. 'modPrice' => 0,
  46. 'remark' => '',
  47. ];
  48. $order = RechargeClass::addOrder($data, true);
  49. $tx = dict::getDict('yeTx', 'canNot');
  50. $capitalType = dict::getDict('capitalType', 'xhRecharge');
  51. ShopClass::rechargeAddBalance($shop, $amount, $order, $tx, $capitalType);
  52. $transaction->commit();
  53. util::complete();
  54. } catch (\Exception $exception) {
  55. Yii::info("shopId:{$shopId}充值{$amount}元,系统操作失败:" . $exception->getMessage());
  56. util::fail('操作失败');
  57. }
  58. }
  59. }