$val) { //大中小图片转化 $val = business::formatGoodsStyleImg($val); $list[$key] = $val; } return $list; } //取商品的款式和价格 public static function getStyleList($id) { $list = self::getAllByCondition(['goodsId' => $id], 'inTurn DESC', '*', 'id'); if (empty($list)) { return $list; } $new = self::groupStyleInfo($list); return $new; } /* 更新商品的款式 shish 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); } } } }