|
|
@@ -9,6 +9,7 @@ namespace hd\controllers;
|
|
|
use bizGhs\item\classes\ItemClassClass;
|
|
|
use bizGhs\item\services\ItemClassService;
|
|
|
use bizHd\product\classes\ProductClass;
|
|
|
+use bizHd\shop\classes\ShopClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\imgUtil;
|
|
|
use common\components\util;
|
|
|
@@ -117,26 +118,62 @@ class ItemClassController extends BaseController
|
|
|
$data = Yii::$app->request->post();
|
|
|
$id = $data['id'] ?? 0;
|
|
|
$name = $data['name'] ?? '';
|
|
|
+ $inTurn = $data['inTurn'] ?? 0;
|
|
|
+ $print = $data['print'] ?? 1;
|
|
|
+ $cover = $data['cover'] ?? '';
|
|
|
$class = ItemClassClass::getById($id, true);
|
|
|
if (empty($class)) {
|
|
|
util::fail('没有找到分类');
|
|
|
}
|
|
|
- if ($class->isDefault == 1) {
|
|
|
- util::fail('不能修改默认分组');
|
|
|
- }
|
|
|
- $itemName = $class->name;
|
|
|
- if ($itemName == $name) {
|
|
|
- util::success('修改成功');
|
|
|
- }
|
|
|
if ($class->mainId != $this->mainId) {
|
|
|
- util::fail('没有权限修改');
|
|
|
+ util::fail('不是您的分类');
|
|
|
}
|
|
|
- $has = ItemClassClass::getByCondition(['mainId' => $this->mainId, 'name' => $name]);
|
|
|
- if (!empty($has)) {
|
|
|
+ $originName = $class->name ?? '';
|
|
|
+ $has = ItemClassClass::getByCondition(['mainId' => $this->mainId, 'name' => $name], true);
|
|
|
+ if (!empty($has) && $id != $has->id) {
|
|
|
util::fail('名称已经存在');
|
|
|
}
|
|
|
- $class->name = $name;
|
|
|
+ if ($class->isDefault != 1) {
|
|
|
+ $class->name = $name;
|
|
|
+ }
|
|
|
+ $class->inTurn = $inTurn;
|
|
|
+ $class->print = $print;
|
|
|
+ if (!empty($cover)) {
|
|
|
+ $class->cover = $cover;
|
|
|
+ }
|
|
|
$class->save();
|
|
|
+
|
|
|
+ //在首店修改,则父级下所有直营和加盟店,同步修改
|
|
|
+ $masterShop = $this->shop;
|
|
|
+ if (isset($masterShop->default) && $masterShop->default == 1 && isset($masterShop->dataSync) && $masterShop->dataSync == 1) {
|
|
|
+ $sjId = $masterShop->sjId ?? 0;
|
|
|
+ $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
|
|
|
+ foreach ($shopList as $shop) {
|
|
|
+ $shopId = $shop->id ?? 0;
|
|
|
+ if ($shopId == $masterShop->id) {
|
|
|
+ //前面已经修改过了
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $currentMainId = $shop->mainId ?? 0;
|
|
|
+ $chainList = ItemClassClass::getAllByCondition(['mainId' => $currentMainId], null, '*', null, true);
|
|
|
+ if (!empty($chainList)) {
|
|
|
+ foreach ($chainList as $chain) {
|
|
|
+ if ($chain->name == $originName) {
|
|
|
+ if ($chain->isDefault != 1) {
|
|
|
+ $chain->name = $name;
|
|
|
+ }
|
|
|
+ $chain->inTurn = $inTurn;
|
|
|
+ $chain->print = $print;
|
|
|
+ if (!empty($cover)) {
|
|
|
+ $chain->cover = $cover;
|
|
|
+ }
|
|
|
+ $chain->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
util::complete('修改成功');
|
|
|
}
|
|
|
|