RechargeController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\HiGo\api\modules\v1\controllers;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use addons\HiGo\common\models\HigoRechargeOrders;
  5. use Yii;
  6. use api\controllers\OnAuthController;
  7. use common\helpers\ApiCode;
  8. /**
  9. *
  10. *
  11. * Class RechargeController
  12. * @package addons\HiGo\api\modules\v1\controllers
  13. */
  14. class RechargeController extends OnAuthController
  15. {
  16. public $modelClass = '';
  17. /**
  18. * 不用进行登录验证的方法
  19. *
  20. * 例如: ['index', 'update', 'create', 'view', 'delete']
  21. * 默认全部需要验证
  22. *
  23. * @var array
  24. */
  25. protected $authOptional = [];
  26. /**
  27. * @Description: 获取嗨贝充值设置
  28. * @Author: qi
  29. * @DateTime 2022-11-19 09:51:07
  30. * @return mixed
  31. */
  32. public function actionGetSetting()
  33. {
  34. if (!Yii::$app->request->isGet) {
  35. return $this->error('请求方式非法');
  36. }
  37. $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
  38. $hi_bei_name = $basic['hi_bei_name'] ?? '嗨贝';
  39. $is_enable = $basic['is_enable'] ?? 0;
  40. if (!$is_enable) {
  41. return $this->error('系统未开启' . $hi_bei_name . '充值');
  42. }
  43. $recharge = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'recharge');
  44. $price_setting_method = $recharge['price_setting_method'] ?? 1;
  45. $price_setting_ratio = $recharge['price_setting_ratio'] ?? 0;
  46. $price_ladder = isset($recharge['price_ladder']) ? json_decode($recharge['price_ladder'], true) : [];
  47. $data = [
  48. 'hi_bei_name' => $hi_bei_name,
  49. 'price_setting_method' => $price_setting_method
  50. ];
  51. if ($price_setting_method == 1) {
  52. $data['price_setting_ratio'] = $price_setting_ratio;
  53. }
  54. if ($price_setting_method == 0) {
  55. $data['price_ladder'] = $price_ladder;
  56. }
  57. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
  58. }
  59. /**
  60. * @Description: 充值
  61. * @Author: qi
  62. * @DateTime 2022-11-19 11:41:49
  63. * @return mixed
  64. */
  65. public function actionRecharge()
  66. {
  67. if (!Yii::$app->request->isPost) {
  68. return $this->error('请求方式非法');
  69. }
  70. $params = Yii::$app->request->post();
  71. $res = Yii::$app->services->validate->validate($params, [
  72. [['pay_price', 'price_setting_method', 'hi_bei', 'uuid'], 'required'],
  73. [['price_setting_method'], 'in', 'range' => [0, 1]],
  74. ]);
  75. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  76. $params['mall_id'] = $this->mall_id;
  77. $params['user_id'] = $this->user_id;
  78. $data = HigoRechargeOrders::createOrder($params);
  79. if ($data === false) return $this->error(HigoRechargeOrders::getStaticError());
  80. return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
  81. }
  82. }