| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\HiGo\api\modules\v1\controllers;
- use addons\HiGo\common\enums\HiGoEnum;
- use addons\HiGo\common\models\HigoRechargeOrders;
- use Yii;
- use api\controllers\OnAuthController;
- use common\helpers\ApiCode;
- /**
- *
- *
- * Class RechargeController
- * @package addons\HiGo\api\modules\v1\controllers
- */
- class RechargeController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * @Description: 获取嗨贝充值设置
- * @Author: qi
- * @DateTime 2022-11-19 09:51:07
- * @return mixed
- */
- public function actionGetSetting()
- {
- if (!Yii::$app->request->isGet) {
- return $this->error('请求方式非法');
- }
- $basic = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'basic');
- $hi_bei_name = $basic['hi_bei_name'] ?? '嗨贝';
- $is_enable = $basic['is_enable'] ?? 0;
- if (!$is_enable) {
- return $this->error('系统未开启' . $hi_bei_name . '充值');
- }
- $recharge = Yii::$app->services->setting->addons->get($this->mall_id, HiGoEnum::ADDONS_NAME, 'recharge');
- $price_setting_method = $recharge['price_setting_method'] ?? 1;
- $price_setting_ratio = $recharge['price_setting_ratio'] ?? 0;
- $price_ladder = isset($recharge['price_ladder']) ? json_decode($recharge['price_ladder'], true) : [];
- $data = [
- 'hi_bei_name' => $hi_bei_name,
- 'price_setting_method' => $price_setting_method
- ];
- if ($price_setting_method == 1) {
- $data['price_setting_ratio'] = $price_setting_ratio;
- }
- if ($price_setting_method == 0) {
- $data['price_ladder'] = $price_ladder;
- }
- return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
- }
- /**
- * @Description: 充值
- * @Author: qi
- * @DateTime 2022-11-19 11:41:49
- * @return mixed
- */
- public function actionRecharge()
- {
- if (!Yii::$app->request->isPost) {
- return $this->error('请求方式非法');
- }
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['pay_price', 'price_setting_method', 'hi_bei', 'uuid'], 'required'],
- [['price_setting_method'], 'in', 'range' => [0, 1]],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $data = HigoRechargeOrders::createOrder($params);
- if ($data === false) return $this->error(HigoRechargeOrders::getStaticError());
- return $this->success(ApiCode::CODE_SUCCESS_TITLE, $data);
- }
- }
|