| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\AttrLibrary;
- use app\modules\admin\models\AttrLibraryForm;
- /**
- * Class AttrLibraryController
- * @package app\modules\admin\controllers
- */
- class AttrLibraryController extends BaseController
- {
- /**
- * 保存分类
- * @return \yii\web\Response
- */
- public function actionSave()
- {
- $data = post_params();
- $form = new AttrLibraryForm();
- $attr = $data['id'] ? (AttrLibrary::findOne($data['id']) ?: new AttrLibrary()) : new AttrLibrary();
- $form->model = $attr;
- $form->store_id = get_store_id();
- $form->supplier_id = get_supplier_id();
- $form->attributes = $data;
- return $this->asJson($form->save());
- }
- /**
- * 获取规格库列表
- * @return \yii\web\Response
- */
- public function actionList()
- {
- $store_id = get_store_id();
- $supplier_id = get_supplier_id();
- $list = AttrLibrary::getList($store_id, 0, $supplier_id);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- /**
- * 批量删除
- * @return \yii\web\Response
- */
- public function actionStatus()
- {
- $res = AttrLibrary::updateAll(['is_delete' => 1], ['id' => get_params('id',[])]);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'updateCount' => $res
- ]
- ]);
- }
- /**
- * 删除分类
- * @return \yii\web\Response
- */
- public function actionDel()
- {
- $attr = AttrLibrary::findOne(get_params('id'));
- if (empty($attr)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '查无此分类'
- ]);
- }
- $attr->is_delete = 1;
- if ($attr->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- }else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败'
- ]);
- }
- }
- }
|