|
|
<?php
namespace api\controllers;
use Yii; use yii\base\InvalidConfigException; use Throwable; use backend\modules\shop\models\ars\Order; /** * @author iron * @email weiriron@gmail.com */ class OrderController extends CommonController { public $modelClass = 'backend\modules\shop\models\ars\Order'; public $className = 'api\logic\OrderLogic';
/** * @return array * @throws InvalidConfigException */ public function actions() { $action = parent::actions(); unset($action['delete']); $action['index'] = [ 'class' => 'yii\rest\IndexAction', 'modelClass' => $this->modelClass, 'dataFilter' => $this->getFilter() ]; return $action; }
/** * @return array * @throws InvalidConfigException */ protected function getFilter() { if (empty(Yii::$app->request->getBodyParams())) { Yii::$app->request->setBodyParams(['user' => true]); } $array = ['user_id' => Yii::$app->user->getId()]; $status = Yii::$app->request->getBodyParam('status'); if ($status) { $array['status'] = $status; } return ['class' => 'yii\data\ActiveDataFilter', 'filter' => $array, 'searchModel' => ['class' => 'backend\modules\shop\models\searchs\OrderSearch'] ]; }
/** * @return Order * @throws yii\base\Exception * @throws yii\web\BadRequestHttpException */ public function actionCreate() { return $this->object->create(); }
/** * @return bool * @throws InvalidConfigException * @throws Throwable * @throws yii\base\Exception * @throws yii\web\BadRequestHttpException * @throws yii\web\NotFoundHttpException * @throws yii\web\ServerErrorHttpException */ public function actionUpdate() { return $this->object->update(); }
}
|