diff --git a/server/app/api/logic/GoodsLogic.php b/server/app/api/logic/GoodsLogic.php index 3e8172d8..f74e16d9 100644 --- a/server/app/api/logic/GoodsLogic.php +++ b/server/app/api/logic/GoodsLogic.php @@ -58,7 +58,7 @@ class GoodsLogic extends Logic ]; $goodsDetail = Goods::with(['goods_image', 'goods_item', 'shop']) - ->field('id,type,name,image,video,remark,content,market_price,min_price,max_price,is_show_stock,stock,sales_actual,sales_virtual,clicks,shop_id,poster') + ->field('id,type,name,image,video,remark,content,market_price,min_price,max_price,is_show_stock,stock,sales_actual,sales_virtual,clicks,shop_id,poster,custom_params') ->where($onSaleWhere) ->where('id', $goodsId) ->findOrEmpty(); @@ -96,6 +96,13 @@ class GoodsLogic extends Logic $goodsDetail->clicks += 1; $goodsDetail->save(); + // 自定义规格转换 + if (!empty($goodsDetail->custom_params)) { + $goodsDetail->custom_params = self::str2arr($goodsDetail->custom_params); + } else { + $goodsDetail->custom_params = []; + } + // 转数组 $goodsDetailArr = $goodsDetail->toArray(); $goodsDetailArr['poster'] = !empty($goodsDetailArr['poster']) ? UrlServer::getFileUrl($goodsDetailArr['poster']) : ''; @@ -286,6 +293,28 @@ class GoodsLogic extends Logic } } + protected static function str2arr(string $str): array + { +// $str = "参数1:值1;参数2:值2"; + + // 使用分号分割数组 + $params = explode(";", $str); + + // 遍历每个参数对,并使用冒号分割键与值 + $result = array(); + foreach ($params as $param) { + // 使用冒号分割键与值 + $paramPair = explode(":", $param); + if (count($paramPair) === 2) { + $key = trim($paramPair[0]); + $value = trim($paramPair[1]); + $result[] = [$key => $value]; + } + } + + return $result; + } + /** * 热销榜单 */ diff --git a/server/app/shop/logic/goods/GoodsLogic.php b/server/app/shop/logic/goods/GoodsLogic.php index 57c11da6..ca203c71 100644 --- a/server/app/shop/logic/goods/GoodsLogic.php +++ b/server/app/shop/logic/goods/GoodsLogic.php @@ -345,6 +345,7 @@ class GoodsLogic extends Logic $data = [ 'name' => $post['name'], 'code' => $post['code'], + 'custom_params' => $post['custom_params'] ?? '', 'shop_cate_id' => $post['shop_cate_id'], 'first_cate_id' => $post['first_cate_id'], 'second_cate_id' => $post['second_cate_id'], @@ -655,6 +656,7 @@ class GoodsLogic extends Logic 'name' => trim($post['name']), 'code' => trim($post['code']) ? trim($post['code']) : create_goods_code($shop_id), 'shop_id' => $shop_id, + 'custom_params' => $post['custom_params'] ?? '', 'shop_cate_id' => $post['shop_cate_id'], 'first_cate_id' => $post['first_cate_id'], 'second_cate_id' => $post['second_cate_id'], diff --git a/server/app/shop/view/goods/goods/add.html b/server/app/shop/view/goods/goods/add.html index 79d3a80e..ad5f3272 100644 --- a/server/app/shop/view/goods/goods/add.html +++ b/server/app/shop/view/goods/goods/add.html @@ -49,7 +49,7 @@ , likeedit = layui.likeedit; //---------------------------------------平台分类联动 begin ---------------------------------- - var categorys = {$category_lists | raw}; + var categorys = {$category_lists | raw}; setSelectFirst(); function setSelectFirst(default_id) { @@ -727,6 +727,7 @@ $('input[name="goods_id"]').val(goods_info['base']['id']); $('input[name="name"]').val(goods_info['base']['name']); $('input[name="code"]').val(goods_info['base']['code']); + $('textarea[name="custom_params"]').val(goods_info['base']['custom_params']); setSelectFirst(goods_info['base']['first_cate_id']); setSelectSecond(goods_info['base']['second_cate_id']); setSelectThird(goods_info['base']['third_cate_id']); diff --git a/server/app/shop/view/goods/goods/goods_base.html b/server/app/shop/view/goods/goods/goods_base.html index 9fa57546..f89aca66 100644 --- a/server/app/shop/view/goods/goods/goods_base.html +++ b/server/app/shop/view/goods/goods/goods_base.html @@ -31,6 +31,15 @@ + + +
+ +
+ +
+
+