diff --git a/application/api/controller/Devtest.php b/application/api/controller/Devtest.php index 7b6e42d1f..d77977bd0 100644 --- a/application/api/controller/Devtest.php +++ b/application/api/controller/Devtest.php @@ -200,7 +200,7 @@ class Devtest extends Common $spec = array_column($res['value'], 'value'); foreach($spec as $k=>$v) { - $arr = explode(',', $v); + $arr = explode(GoodsService::$goods_spec_to_string_separator, $v); $inventory_spec[] = [ 'name' => implode(' / ', $arr), 'spec' => json_encode(WarehouseGoodsService::GoodsSpecMuster($v, $res['title']), JSON_UNESCAPED_UNICODE), diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index 571ef77fb..e0cb5682f 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -26,6 +26,9 @@ use app\service\WarehouseGoodsService; */ class GoodsService { + // 规格转成字符串分割符号 + public static $goods_spec_to_string_separator = '{|}'; + /** * 根据id获取一条商品分类 * @author Devil @@ -752,7 +755,7 @@ class GoodsService } foreach($group as &$gv) { - $gv['value'] = implode(',', $gv['value']); + $gv['value'] = implode(self::$goods_spec_to_string_separator, $gv['value']); } sort($group); } diff --git a/application/service/WarehouseGoodsService.php b/application/service/WarehouseGoodsService.php index 6e6941353..5656a372e 100644 --- a/application/service/WarehouseGoodsService.php +++ b/application/service/WarehouseGoodsService.php @@ -523,7 +523,7 @@ class WarehouseGoodsService $spec = array_column($res['value'], 'value'); foreach($spec as $v) { - $arr = explode(',', $v); + $arr = explode(GoodsService::$goods_spec_to_string_separator, $v); $inventory_spec[] = [ 'name' => implode(' / ', $arr), 'spec' => json_encode(self::GoodsSpecMuster($v, $res['title']), JSON_UNESCAPED_UNICODE), @@ -583,7 +583,7 @@ class WarehouseGoodsService public static function GoodsSpecMuster($spec_str, $spec_title) { $result = []; - $arr = explode(',', $spec_str); + $arr = explode(GoodsService::$goods_spec_to_string_separator, $spec_str); if(count($arr) == count($spec_title)) { foreach($arr as $k=>$v) @@ -759,7 +759,7 @@ class WarehouseGoodsService $data = []; foreach($res['value'] as $v) { - $md5_key = md5(empty($v['value']) ? 'default' : str_replace(',', '', $v['value'])); + $md5_key = md5(empty($v['value']) ? 'default' : str_replace(GoodsService::$goods_spec_to_string_separator, '', $v['value'])); $inventory = (int) Db::name('WarehouseGoodsSpec')->where(['warehouse_id'=>$wg['warehouse_id'], 'md5_key'=>$md5_key])->value('inventory'); $data[] = [ 'warehouse_goods_id' => $wg['id'], @@ -822,7 +822,7 @@ class WarehouseGoodsService // 商品规格库存 foreach($res['value'] as $v) { - $inventory = self::WarehouseGoodsSpecInventory($goods_id, str_replace(',', '', $v['value'])); + $inventory = self::WarehouseGoodsSpecInventory($goods_id, str_replace(GoodsService::$goods_spec_to_string_separator, '', $v['value'])); if(Db::name('GoodsSpecBase')->where(['id'=>$v['base_id'], 'goods_id'=>$goods_id])->update(['inventory'=>$inventory]) === false) {