| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\Store\client\controllers;
- use backend\controllers\MallController;
- use backend\modules\mall\services\SpecsService;
- use Yii;
- use yii\helpers\Json;
- /**
- * 自定义规格控制器
- * SpecsController class
- */
- class SpecsController extends BaseController
- {
- /**
- * @var SpecsService
- */
- protected $service;
- public function init()
- {
- parent::init();
- $this->service = new SpecsService(['mall_id' => $this->mall_id]);
- }
- /**
- * 首页
- *
- * @return void
- */
- public function actionIndex()
- {
- if ($this->request->isAjax) {
- return $this->success(
- 'ok',
- $this->service->getPageList($this->request->get(), $this->store_id)
- );
- }
- return $this->render($this->action->id);
- }
- /**
- * 添加规格
- *
- * @return void
- */
- public function actionAdd()
- {
- if ($this->request->isAjax) {
- $id = $this->request->post('id', null);
- $params = $this->request->post();
- if (Yii::$app->services->validate->validate($params, [
- [['name'], 'string'],
- [['values', 'name'], 'required']
- ])) {
- $res = empty($id)
- ? $this->service->add($params['name'], $params['values'], $this->store_id)
- : $this->service->edit($id, $params['name'], $params['values'], $this->store_id);
- return $res
- ? $this->success('ok')
- : $this->error($this->service->error);
- }
- }
- }
- /**
- * 删除规格
- *
- * @return void
- */
- public function actionDel()
- {
- if ($this->request->isAjax) {
- $id = $this->request->get('id', null);
- return $this->service->del($id)
- ? $this->success('ok')
- : $this->error($this->service->error);
- }
- }
- }
|