diff --git a/application/api/controller/Devtest.php b/application/api/controller/Devtest.php index 7b6e42d1f05b97c555880df93d3c9507f913e55c..d77977bd084dc5b574f6c90d89d28eb87ba6e640 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 571ef77fb5f891bb8c845c2b6c3b152a90a69237..e0cb5682f8c98b9d78aa6841cfbe53a4315a4781 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 6e694135303efe498e438fe48c170432a6e30527..5656a372ef356fd36403c4a660d9a9b3ea8cfe55 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) {