| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace addons\ElectronCoupon\api\modules\v1\controllers;
- use addons\ElectronCoupon\common\enums\ElectronCouponEnums;
- use addons\ElectronCoupon\common\models\ElectronCouponOrder;
- use addons\ElectronCoupon\common\models\ElectronCouponUserCoupon;
- use Yii;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- class OrderController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- * @var array
- */
- protected $authOptional = ['index'];
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * 提交激活订单
- */
- public function actionActiveOrder()
- {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['user_coupon_id', 'number'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if ($params['number'] <= 0) {
- return $this->error('请输入正确的激活数量');
- }
- // 创建订单
- $active_order = ElectronCouponOrder::createActiveOrder($params['user_coupon_id'], $this->user_id, $this->mall_id, $params['number']);
- if ($active_order == false) return $this->error(ElectronCouponOrder::getStaticError());
- $result = $active_order->toArray();
- $config = Yii::$app->services->setting->addons->get($this->mall_id, ElectronCouponEnums::ADDONS_NAME, 'basic');
- // 支付完成时跳转的链接
- $result['success_page'] = $config['payed_url'] ?? '';
- $is_payed_url = $config['is_payed_url'] ?? 0;
- $result['success_page'] = $is_payed_url ? $result['success_page'] : '';
- unset($result['pay_type']);
- return $this->success("成功", compact('result'));
- }
- }
- }
|