You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9 KiB

  1. <?php
  2. namespace api\controllers;
  3. use Yii;
  4. use yii\base\InvalidConfigException;
  5. use Throwable;
  6. use backend\modules\shop\models\ars\Order;
  7. /**
  8. * @author iron
  9. * @email weiriron@gmail.com
  10. */
  11. class OrderController extends CommonController
  12. {
  13. public $modelClass = 'backend\modules\shop\models\ars\Order';
  14. public $className = 'api\logic\OrderLogic';
  15. /**
  16. * @return array
  17. * @throws InvalidConfigException
  18. */
  19. public function actions()
  20. {
  21. $action = parent::actions();
  22. unset($action['delete']);
  23. $action['index'] = [
  24. 'class' => 'yii\rest\IndexAction',
  25. 'modelClass' => $this->modelClass,
  26. 'dataFilter' => $this->getFilter()
  27. ];
  28. return $action;
  29. }
  30. /**
  31. * @return array
  32. * @throws InvalidConfigException
  33. */
  34. protected function getFilter()
  35. {
  36. if (empty(Yii::$app->request->getBodyParams())) {
  37. Yii::$app->request->setBodyParams(['user' => true]);
  38. }
  39. $array = ['user_id' => Yii::$app->user->getId()];
  40. $status = Yii::$app->request->getBodyParam('status');
  41. if ($status) {
  42. $array['status'] = $status;
  43. }
  44. return ['class' => 'yii\data\ActiveDataFilter',
  45. 'filter' => $array,
  46. 'searchModel' => ['class' => 'backend\modules\shop\models\searchs\OrderSearch']
  47. ];
  48. }
  49. /**
  50. * @return Order
  51. * @throws yii\base\Exception
  52. * @throws yii\web\BadRequestHttpException
  53. */
  54. public function actionCreate()
  55. {
  56. return $this->object->create();
  57. }
  58. /**
  59. * @return bool
  60. * @throws InvalidConfigException
  61. * @throws Throwable
  62. * @throws yii\base\Exception
  63. * @throws yii\web\BadRequestHttpException
  64. * @throws yii\web\NotFoundHttpException
  65. * @throws yii\web\ServerErrorHttpException
  66. */
  67. public function actionUpdate()
  68. {
  69. return $this->object->update();
  70. }
  71. }