| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace hd\controllers;
- use bizHd\goods\classes\KindClass;
- use bizHd\goods\services\CategoryService;
- use bizHd\goods\services\GoodsCategoryService;
- use Yii;
- use common\components\util;
- class KindController extends BaseController
- {
- //获取所有种类 ssh 20230318
- public function actionGetAllKind()
- {
- $get = Yii::$app->request->get();
- $flower = $get['flower'] ?? '';
- $where = [];
- if (is_numeric($flower)) {
- $where['flower'] = $flower;
- }
- $mainId = $this->mainId;
- $list = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => $flower], null, '*');
- util::success(['list' => $list]);
- }
- //品类列表
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $mainId = $this->mainId ?? 0;
- $where = ['mainId' => $mainId, 'delStatus' => 0];
- $name = isset($get['name']) ? $get['name'] : '';
- $name = trim($name);
- if (!empty($name)) {
- $where['name'] = ['like', $name];
- }
- $flower = $get['flower'] ?? '';
- if (is_numeric($flower)) {
- $where['flower'] = $flower;
- }
- $list = KindClass::getKindList($where);
- util::success($list);
- }
- //查看详情 ssh 2019.12.8
- public function actionDetail()
- {
- $id = Yii::$app->request->get('categoryId', 0);
- $category = CategoryService::getById($id);
- CategoryService::valid($category, $this->mainId);
- $info = CategoryService::getInfo($id);
- util::success($info);
- }
- //添加品类 ssh 2019.12.8
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['mainId'] = $this->mainId;
- KindClass::addData($post);
- util::complete();
- }
- //更新种类 ssh 20230220
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- $kindId = isset($post['kindId']) ? $post['kindId'] : 0;
- $kind = KindClass::getById($kindId, true);
- if (empty($kind)) {
- util::fail('没有找到种类');
- }
- if ($kind->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- $inTurn = $post['inTurn'] ?? 0;
- $name = $post['name'] ?? '';
- $name = trim($name);
- $list = KindClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, '*', null, true);
- foreach ($list as $key => $item) {
- $currentName = $item->name ?? '';
- if ($currentName == $name && $item->id != $kind->id) {
- util::fail('名称已经存在了');
- }
- }
- $kind->inTurn = $inTurn;
- $kind->name = $name;
- $kind->save();
- util::complete('修改成功');
- }
- //品类启用停用 ssh 2019.12.8
- public function actionChangeStatus()
- {
- $get = Yii::$app->request->get();
- $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
- $status = isset($get['status']) ? $get['status'] : 0;
- $category = CategoryService::getById($categoryId);
- CategoryService::valid($category, $this->mainId);
- CategoryService::changeStatus($categoryId, $status);
- util::complete();
- }
- //删除品类 ssh 2019.12.28
- public function actionDelete()
- {
- $get = Yii::$app->request->get();
- $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
- $category = CategoryService::getById($categoryId);
- CategoryService::valid($category, $this->mainId);
- if ($category['goodsNum'] > 0) {
- util::fail('品类下还有商品');
- }
- $count = \bizHd\goods\classes\CategoryClass::deleteCategory($categoryId);
- if (!$count) {
- util::fail('删除失败');
- }
- util::complete('删除成功');
- }
- //品类排序 ssh 2020.3.11
- public function actionSort()
- {
- $id = Yii::$app->request->get('id', 0);
- $inTurn = Yii::$app->request->get('inTurn', 0);
- $category = CategoryService::getById($id);
- CategoryService::valid($category, $this->mainId);
- CategoryService::updateById($id, ['inTurn' => $inTurn]);
- util::complete();
- }
- //获取品类 ssh 2019.12.2
- public function actionMallList()
- {
- $return = CategoryService::getEnableList($this->sjId);
- util::success($return);
- }
- }
|