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.

63 lines
1.6 KiB

  1. <?php
  2. namespace api\controllers;
  3. use yii\web\ForbiddenHttpException;
  4. use Yii;
  5. /**
  6. * @author iron
  7. * @email weiriron@gmail.com
  8. */
  9. class OrderController extends CommonController
  10. {
  11. public $modelClass = 'common\models\ars\Order';
  12. public function actions()
  13. {
  14. $action = parent::actions();
  15. unset($action['delete']);
  16. $action['index'] = [
  17. 'class' => 'yii\rest\IndexAction',
  18. 'modelClass' => $this->modelClass,
  19. 'dataFilter' => $this->getFilter()
  20. ];
  21. return $action;
  22. }
  23. protected function getFilter()
  24. {
  25. $status = Yii::$app->request->getBodyParam('status');
  26. $data = \Yii::$app->request->getBodyParams();
  27. $data['user'] = true;
  28. \Yii::$app->request->setBodyParams($data);
  29. $array = ['user_id' => Yii::$app->user->getId()];
  30. if ($status) {
  31. $array['status'] = $status;
  32. }
  33. $filter = ['class' => 'yii\data\ActiveDataFilter',
  34. 'filter' => $array,
  35. 'searchModel' => ['class' => 'common\models\searchs\OrderSearch']];
  36. return $filter;
  37. }
  38. public function actionCreate()
  39. {
  40. $originId = Yii::$app->request->getBodyParam('originId');
  41. $count = Yii::$app->request->getBodyParam('count');
  42. $skuId = Yii::$app->request->getBodyParam('skuId');
  43. return Yii::$app->orderLogic->create($originId, $count, $skuId);
  44. }
  45. /**
  46. * @return mixed
  47. * @throws \yii\base\InvalidConfigException
  48. */
  49. public function actionUpdate()
  50. {
  51. $data = Yii::$app->request->getBodyParams();
  52. return Yii::$app->orderLogic->update($data);
  53. }
  54. }