SpecTemplateController.php 2.8 KB

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