| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace addons\Community\api\modules\v1\controllers;
- use addons\Community\common\enums\CommunityEnum;
- use addons\Community\common\service\OrderService;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use Yii;
- class OrderController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * 订单列表
- * @return mixed|null
- */
- public function actionIndex()
- {
- $data = \Yii::$app->request->get();
- $valid = Yii::$app->services->validate->validate($data, [
- [['page', 'limit', 'order_status', 'wait_pending', 'shipping_type'], 'integer'],
- [['keyword'], 'string'],
- ]);
- if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $ret = (new OrderService())->frontPage($this->mall_id, $data, $this->mall,
- empty($this->platform) ? 'h5' : $this->platform, $this->user_id);
- $config = Yii::$app->services->setting->addons->get($this->mall_id, CommunityEnum::ADDONS_NAME, 'basic');
- $ret['is_enable_write_off'] = $config['is_enable_write_off'] ?? StatusEnum::DISABLED; // 默认是关闭的
- return $this->success('操作成功', $ret);
- }
- /**
- * 订单详情
- * @return mixed|null
- */
- public function actionDetail()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['order_id'], 'integer'],
- [['order_no'], 'string'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- if (empty($params['order_id']) && empty($params['order_no'])) {
- return $this->error('订单编号或订单ID必须要选一个');
- }
- $key = 'order_id';
- if (empty($params['order_id'])) $key = 'order_no';
- $ret = (new OrderService())->detail($this->mall_id, $params[$key],
- $key, $this->user_id, empty($this->platform) ? 'h5' : $this->platform);
- if (is_array($ret)) {
- $config = Yii::$app->services->setting->addons->get($this->mall_id, CommunityEnum::ADDONS_NAME, 'basic');
- $ret['is_enable_write_off'] = $config['is_enable_write_off'] ?? StatusEnum::DISABLED; // 默认是关闭的
- }
- return is_string($ret) ? $this->error($ret) : $this->success('操作成功', $ret);
- }
- /**
- * 我的订单页面所需数据
- *
- * @return mixed|null
- */
- public function actionMyOrder()
- {
- $ret = (new OrderService())->myOrder($this->mall_id, $this->user_id);
- return $this->success('操作成功', $ret);
- }
- }
|