EvaluateController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\order\controllers;
  3. use Yii;
  4. use common\traits\MerchantCurd;
  5. use common\enums\StatusEnum;
  6. use common\models\base\SearchModel;
  7. use addons\TinyShop\common\models\product\Evaluate;
  8. use addons\TinyShop\merchant\controllers\BaseController;
  9. /**
  10. * Class EvaluateController
  11. * @package addons\TinyShop\merchant\modules\order\controllers
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class EvaluateController extends BaseController
  15. {
  16. use MerchantCurd;
  17. /**
  18. * @var Evaluate
  19. */
  20. public $modelClass = Evaluate::class;
  21. /**
  22. * 首页
  23. *
  24. * @return string
  25. * @throws \yii\web\NotFoundHttpException
  26. */
  27. public function actionIndex()
  28. {
  29. $searchModel = new SearchModel([
  30. 'model' => Evaluate::class,
  31. 'scenario' => 'default',
  32. 'partialMatchAttributes' => ['title'], // 模糊查询
  33. 'defaultOrder' => [
  34. 'id' => SORT_DESC,
  35. ],
  36. 'pageSize' => $this->pageSize,
  37. ]);
  38. $dataProvider = $searchModel
  39. ->search(Yii::$app->request->queryParams);
  40. $dataProvider->query
  41. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  42. ->andFilterWhere(['merchant_id' => $this->getMerchantId()]);
  43. return $this->render($this->action->id, [
  44. 'dataProvider' => $dataProvider,
  45. 'searchModel' => $searchModel,
  46. ]);
  47. }
  48. /**
  49. * ajax编辑/创建
  50. *
  51. * @return mixed|string|\yii\web\Response
  52. * @throws \yii\base\ExitException
  53. */
  54. public function actionAjaxEdit()
  55. {
  56. $id = Yii::$app->request->get('id');
  57. $model = $this->findModel($id);
  58. // ajax 校验
  59. $this->activeFormValidate($model);
  60. if ($model->load(Yii::$app->request->post())) {
  61. return $model->save()
  62. ? $this->redirect(['index'])
  63. : $this->message($this->getError($model), $this->redirect(['index']), 'error');
  64. }
  65. return $this->renderAjax($this->action->id, [
  66. 'model' => $model,
  67. 'type' => Yii::$app->request->get('type'),
  68. ]);
  69. }
  70. /**
  71. * 返回模型
  72. *
  73. * @param $id
  74. * @return \yii\db\ActiveRecord
  75. */
  76. protected function findModel($id)
  77. {
  78. /* @var $model \yii\db\ActiveRecord */
  79. if (empty($id) || empty(($model = $this->modelClass::find()->where(['id' => $id])->andFilterWhere(['merchant_id' => $this->getMerchantId()])->one()))) {
  80. $model = new $this->modelClass;
  81. return $model->loadDefaultValues();
  82. }
  83. return $model;
  84. }
  85. }
粤ICP备19079148号