|
|
@@ -37,55 +37,5 @@ class GoodsStyleClass extends BaseClass
|
|
|
$new = self::groupStyleInfo($list);
|
|
|
return $new;
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- 更新商品的款式 ssh 2020.2.27
|
|
|
- 输入的数据格式 [
|
|
|
- ['styleName' => '红色1', 'price' => 0.1, 'picture' => '', 'action' => 'add', 'id' => 0],
|
|
|
- ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '', 'action' => 'update', 'id' => 1],
|
|
|
- ['styleName' => '黑色2', 'price' => 0.1, 'picture' => '', 'action' => 'delete', 'id' => 2]
|
|
|
- ];
|
|
|
- */
|
|
|
- public static function updateGoodsStyle($goodsStyleList, $goodsId)
|
|
|
- {
|
|
|
- $add = [];
|
|
|
- $update = [];
|
|
|
- $delete = [];
|
|
|
- foreach ($goodsStyleList as $goodsStyle) {
|
|
|
- $action = $goodsStyle['action'];
|
|
|
- $id = $goodsStyle['id'];
|
|
|
- switch ($action) {
|
|
|
- case 'add':
|
|
|
- unset($goodsStyle['id']);
|
|
|
- $add[] = $goodsStyle;
|
|
|
- break;
|
|
|
- case 'update':
|
|
|
- $update[] = $goodsStyle;
|
|
|
- break;
|
|
|
- case 'delete':
|
|
|
- $delete[] = $id;
|
|
|
- break;
|
|
|
- default:
|
|
|
- $add[] = $goodsStyle;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!empty($add)) {
|
|
|
- $addStyle = [];
|
|
|
- foreach ($add as $style) {
|
|
|
- $addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $goodsId, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
- }
|
|
|
- GoodsStyleClass::batchAdd($addStyle);
|
|
|
- }
|
|
|
- if (!empty($delete)) {
|
|
|
- GoodsStyleClass::deleteByIds($delete);
|
|
|
- }
|
|
|
- if (!empty($update)) {
|
|
|
- foreach ($update as $up) {
|
|
|
- $currentId = $up['id'];
|
|
|
- unset($up['id']);
|
|
|
- self::updateById($currentId, $up);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
}
|