|
|
@@ -38,14 +38,31 @@ class KindController extends BaseController
|
|
|
util::complete();
|
|
|
}
|
|
|
|
|
|
- //更新品类 ssh 20220404
|
|
|
+ //更新种类 ssh 20230220
|
|
|
public function actionUpdate()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
|
|
|
- $category = CategoryService::getById($categoryId);
|
|
|
- CategoryService::valid($category, $this->mainId);
|
|
|
- CategoryService::updateCategory($category, $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, '*', 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('修改成功');
|
|
|
}
|
|
|
|