OrderController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace addons\ElectronCoupon\api\modules\v1\controllers;
  3. use addons\ElectronCoupon\common\enums\ElectronCouponEnums;
  4. use addons\ElectronCoupon\common\models\ElectronCouponOrder;
  5. use addons\ElectronCoupon\common\models\ElectronCouponUserCoupon;
  6. use Yii;
  7. use api\controllers\OnAuthController;
  8. use common\enums\StatusEnum;
  9. class OrderController extends OnAuthController
  10. {
  11. public $modelClass = '';
  12. /**
  13. * 不用进行登录验证的方法
  14. * @var array
  15. */
  16. protected $authOptional = ['index'];
  17. public function actionIndex()
  18. {
  19. return 'Hello world';
  20. }
  21. /**
  22. * 提交激活订单
  23. */
  24. public function actionActiveOrder()
  25. {
  26. if (Yii::$app->request->isPost) {
  27. $params = Yii::$app->request->post();
  28. $res = Yii::$app->services->validate->validate($params, [
  29. [['user_coupon_id', 'number'], 'integer'],
  30. ]);
  31. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  32. if ($params['number'] <= 0) {
  33. return $this->error('请输入正确的激活数量');
  34. }
  35. // 创建订单
  36. $active_order = ElectronCouponOrder::createActiveOrder($params['user_coupon_id'], $this->user_id, $this->mall_id, $params['number']);
  37. if ($active_order == false) return $this->error(ElectronCouponOrder::getStaticError());
  38. $result = $active_order->toArray();
  39. $config = Yii::$app->services->setting->addons->get($this->mall_id, ElectronCouponEnums::ADDONS_NAME, 'basic');
  40. // 支付完成时跳转的链接
  41. $result['success_page'] = $config['payed_url'] ?? '';
  42. $is_payed_url = $config['is_payed_url'] ?? 0;
  43. $result['success_page'] = $is_payed_url ? $result['success_page'] : '';
  44. unset($result['pay_type']);
  45. return $this->success("成功", compact('result'));
  46. }
  47. }
  48. }