|
|
@@ -207,25 +207,34 @@ class GoodsController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //商品排序 ssh 2020.3.11
|
|
|
+ //商品排序
|
|
|
public function actionSort()
|
|
|
{
|
|
|
- $id = Yii::$app->request->get('id', 0);
|
|
|
- $cId = Yii::$app->request->get('cId', 0);
|
|
|
- $inTurn = Yii::$app->request->get('inTurn', 0);
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $items = $post['items'];
|
|
|
+
|
|
|
//验证商品
|
|
|
- $info = GoodsService::getById($id);
|
|
|
- GoodsService::valid($info, $this->mainId);
|
|
|
- if ($cId != 0) {
|
|
|
- //验证分类
|
|
|
- $category = CategoryService::getById($cId);
|
|
|
- CategoryService::valid($category, $this->mainId);
|
|
|
- GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
|
|
|
- } else {
|
|
|
- GoodsService::updateById($id, ['inTurn' => $inTurn]);
|
|
|
- GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
|
|
|
+ // 提取所有商品ID
|
|
|
+ $categoryIds = array_map(function($item) {
|
|
|
+ return intval($item['id']);
|
|
|
+ }, $items);
|
|
|
+
|
|
|
+ // 批量获取商品信息
|
|
|
+ $goodsInfos = GoodsClass::getByIds($categoryIds);
|
|
|
+
|
|
|
+ // 批量验证商品
|
|
|
+ foreach($goodsInfos as $info) {
|
|
|
+ GoodsService::valid($info, $this->mainId);
|
|
|
}
|
|
|
- util::complete('操作成功');
|
|
|
+
|
|
|
+ // 更新商品排序
|
|
|
+ foreach($items as $item) {
|
|
|
+ $id = intval($item['id']);
|
|
|
+ $inTurn = intval($item['inTurn']);
|
|
|
+ GoodsClass::updateById($id, ['inTurn' => $inTurn]);
|
|
|
+ }
|
|
|
+
|
|
|
+ util::complete('排序完成');
|
|
|
}
|
|
|
|
|
|
//删除商品 ssh 2019.12.7
|