OrderController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\Community\api\modules\v1\controllers;
  3. use addons\Community\common\enums\CommunityEnum;
  4. use addons\Community\common\service\OrderService;
  5. use api\controllers\OnAuthController;
  6. use common\enums\StatusEnum;
  7. use Yii;
  8. class OrderController extends OnAuthController
  9. {
  10. public $modelClass = '';
  11. /**
  12. * 不用进行登录验证的方法
  13. *
  14. * 例如: ['index', 'update', 'create', 'view', 'delete']
  15. * 默认全部需要验证
  16. *
  17. * @var array
  18. */
  19. protected $authOptional = [];
  20. /**
  21. * 订单列表
  22. * @return mixed|null
  23. */
  24. public function actionIndex()
  25. {
  26. $data = \Yii::$app->request->get();
  27. $valid = Yii::$app->services->validate->validate($data, [
  28. [['page', 'limit', 'order_status', 'wait_pending', 'shipping_type'], 'integer'],
  29. [['keyword'], 'string'],
  30. ]);
  31. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  32. $ret = (new OrderService())->frontPage($this->mall_id, $data, $this->mall,
  33. empty($this->platform) ? 'h5' : $this->platform, $this->user_id);
  34. $config = Yii::$app->services->setting->addons->get($this->mall_id, CommunityEnum::ADDONS_NAME, 'basic');
  35. $ret['is_enable_write_off'] = $config['is_enable_write_off'] ?? StatusEnum::DISABLED; // 默认是关闭的
  36. return $this->success('操作成功', $ret);
  37. }
  38. /**
  39. * 订单详情
  40. * @return mixed|null
  41. */
  42. public function actionDetail()
  43. {
  44. $params = \Yii::$app->request->get();
  45. $res = \Yii::$app->services->validate->validate($params, [
  46. [['order_id'], 'integer'],
  47. [['order_no'], 'string'],
  48. ]);
  49. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  50. if (empty($params['order_id']) && empty($params['order_no'])) {
  51. return $this->error('订单编号或订单ID必须要选一个');
  52. }
  53. $key = 'order_id';
  54. if (empty($params['order_id'])) $key = 'order_no';
  55. $ret = (new OrderService())->detail($this->mall_id, $params[$key],
  56. $key, $this->user_id, empty($this->platform) ? 'h5' : $this->platform);
  57. if (is_array($ret)) {
  58. $config = Yii::$app->services->setting->addons->get($this->mall_id, CommunityEnum::ADDONS_NAME, 'basic');
  59. $ret['is_enable_write_off'] = $config['is_enable_write_off'] ?? StatusEnum::DISABLED; // 默认是关闭的
  60. }
  61. return is_string($ret) ? $this->error($ret) : $this->success('操作成功', $ret);
  62. }
  63. /**
  64. * 我的订单页面所需数据
  65. *
  66. * @return mixed|null
  67. */
  68. public function actionMyOrder()
  69. {
  70. $ret = (new OrderService())->myOrder($this->mall_id, $this->user_id);
  71. return $this->success('操作成功', $ret);
  72. }
  73. }