evoxwht 3 лет назад
Родитель
Сommit
9537e5c2fd

+ 16 - 34
crmeb/app/adminapi/common.php

@@ -112,47 +112,29 @@ if (!function_exists('attr_format')) {
      * @param $arr
      * @return array
      */
-    function attr_format($arr)
+    function attr_format($arr): array
     {
-        $data = [];
-        $res = [];
-        $count = count($arr);
-        $arr = array_merge($arr);
-        if ($count > 1) {
-            for ($i = 0; $i < $count - 1; $i++) {
-                if ($i == 0) $data = $arr[$i]['detail'];
-                //替代变量1
-                $rep4 = [];
-                $tmp = [];
-                foreach ($data as $v) {
-                    foreach ($arr[$i + 1]['detail'] as $g) {
-                        //替代变量2
-                        $rep2 = ($i != 0 ? '' : $arr[$i]['value'] . '_$_') . $v . '-$-' . $arr[$i + 1]['value'] . '_$_' . $g;
-                        $tmp[] = $rep2;
-                        foreach (explode('-$-', $rep2) as $k => $h) {
-                            //替代变量3
-                            $rep3 = explode('_$_', $h);
-                            //替代变量4
-                            $rep4['detail'][$rep3[0]] = $rep3[1] ?? '';
-                        }
-                        if ($count == count($rep4['detail'])) {
-                            $res[] = $rep4;
-                        }
+        $len = count($arr);
+        $title = array_column($arr, 'value');
+        $result = [];
+
+        if ($len > 1) {
+            $result = $arr[0]['detail'];
+            for ($i = 0; $i < $len - 1; $i++) {
+                $temp = $result;
+                $result = [];
+                foreach ($temp as $item) {
+                    foreach ($arr[$i + 1]['detail'] as $datum) {
+                        $result[] = trim($item) . ',' . trim($datum);
                     }
                 }
-                $data = $tmp;
             }
         } else {
-            $dataArr = [];
-            foreach ($arr as $k => $v) {
-                foreach ($v['detail'] as $kk => $vv) {
-                    $dataArr[$kk] = $v['value'] . '_' . $vv;
-                    $res[$kk]['detail'][$v['value']] = $vv;
-                }
+            foreach ($arr[0]['detail'] as $item) {
+                $result[] = trim($item);
             }
-            $data[] = implode('-', $dataArr);
         }
-        return [$data, array_merge(array_unique($res, SORT_REGULAR))];
+        return [$result, $title];
     }
 }
 

+ 5 - 6
crmeb/app/services/activity/advance/StoreAdvanceServices.php

@@ -213,18 +213,17 @@ class StoreAdvanceServices extends BaseServices
     {
         /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
         $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
             $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                 }
-                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['detail'] = json_encode(array_combine($head,$detail));
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;

+ 6 - 7
crmeb/app/services/activity/bargain/StoreBargainServices.php

@@ -268,7 +268,7 @@ class StoreBargainServices extends BaseServices
     {
         /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
         $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
         if ($type == 2) {
@@ -276,16 +276,15 @@ class StoreBargainServices extends BaseServices
         } else {
             $min_price = 0;
         }
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-//            sort($item['detail'], SORT_STRING);
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
+
             $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                 }
-                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['detail'] = json_encode(array_combine($head,$detail));
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['min_price'] = $min_price ? floatval($min_price) : 0;

+ 5 - 7
crmeb/app/services/activity/combination/StoreCombinationServices.php

@@ -249,19 +249,17 @@ class StoreCombinationServices extends BaseServices
     {
         /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
         $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-//            sort($item['detail'], SORT_STRING);
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
             $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                 }
-                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['detail'] = json_encode(array_combine($head, $detail));
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;

+ 5 - 6
crmeb/app/services/activity/integral/StoreIntegralServices.php

@@ -235,18 +235,17 @@ class StoreIntegralServices extends BaseServices
     {
         /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
         $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
             $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota,quota_show', 'suk');
             if (count($sukValue)) {
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                 }
-                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['detail'] = json_encode(array_combine($head,$detail));
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;

+ 5 - 7
crmeb/app/services/activity/seckill/StoreSeckillServices.php

@@ -364,19 +364,17 @@ class StoreSeckillServices extends BaseServices
     {
         /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
         $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-//            sort($item['detail'], SORT_STRING);
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
             $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                 }
-                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['detail'] = json_encode(array_combine($head, $detail));
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;

+ 16 - 17
crmeb/app/services/product/product/StoreProductServices.php

@@ -373,15 +373,13 @@ class StoreProductServices extends BaseServices
         $attr = $data['attrs'];
         $is_virtual = $data['is_virtual']; //是否虚拟商品
         $virtual_type = $data['virtual_type']; //虚拟商品类型
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-            foreach ($detail as $v => $d) {
-                $detail[$v] = trim($d);
-            }
-            $suk = implode(',', $detail);
+
+            foreach ($value as $suk) {
+                $detail = explode(',', $suk);
+
             $types = 1;
             if ($id) {
                 $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => 0, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,vip_price,is_virtual,coupon_id,unique,disk_info', 'suk');
@@ -425,16 +423,16 @@ class StoreProductServices extends BaseServices
                 $sukValue[$suk]['brokerage_two'] = 0;
             }
             if ($types) { //编辑商品时,将没有规格的数据不生成默认值
-                foreach (array_keys($detail) as $k => $title) {
+                    foreach ($head as $k => $title) {
                     $header[$k]['title'] = $title;
                     $header[$k]['align'] = 'center';
                     $header[$k]['minWidth'] = 130;
                 }
-                foreach (array_values($detail) as $k => $v) {
+                foreach ($detail as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
                     $header[$k]['key'] = 'value' . ($k + 1);
                 }
-                $valueNew[$count]['detail'] = $detail;
+                $valueNew[$count]['detail'] = array_combine($head,$detail);
                 $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
                 $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
                 $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
@@ -498,6 +496,8 @@ class StoreProductServices extends BaseServices
     {
         if (count($data['cate_id']) < 1) throw new CommonException(AdminApiErrorCode::ERR_PLEASE_SELECT_PRODUCT_CATEGORY);
         if (!$data['store_name']) throw new CommonException(AdminApiErrorCode::ERR_PLEASE_ENTER_THE_PRODUCT_NAME);
+
+        // $data['slider_image'] = [];
         if (count($data['slider_image']) < 1) throw new CommonException(AdminApiErrorCode::ERR_PLEASE_UPLOAD_SLIDER_IMAGE);
 
         $detail = $data['attrs'];
@@ -874,24 +874,23 @@ class StoreProductServices extends BaseServices
             $attr[$key]['attrHidden'] = true;
             $attr[$key]['detail'] = $value['attr_values'];
         }
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
         $sukValue = $sukDefaultValue = $storeProductAttrValueServices->getSkuArray(['product_id' => $id, 'type' => 0]);
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
             if (!isset($sukDefaultValue[$suk])) continue;
-            foreach (array_keys($detail) as $k => $title) {
+            foreach ($head as $k => $title) {
                 $header[$k]['title'] = $title;
                 $header[$k]['align'] = 'center';
                 $header[$k]['minWidth'] = 80;
             }
-            foreach (array_values($detail) as $k => $v) {
+            foreach ($detail as $k => $v) {
                 $valueNew[$count]['value' . ($k + 1)] = $v;
                 $header[$k]['key'] = 'value' . ($k + 1);
             }
-            $valueNew[$count]['detail'] = $detail;
+            $valueNew[$count]['detail'] = array_combine($head, $detail);
             $valueNew[$count]['pic'] = $sukValue[$suk]['pic'];
             $valueNew[$count]['price'] = floatval($sukValue[$suk]['price']);
             if ($type == 2) $valueNew[$count]['min_price'] = 0;

+ 6 - 8
crmeb/crmeb/services/CopyProductService.php

@@ -589,14 +589,12 @@ class CopyProductService
      */
     public static function formatAttr(array $attr, array $sku = [])
     {
-        $value = attr_format($attr)[1];
+        list($value, $head) = attr_format($attr);
         $valueNew = [];
         $count = 0;
 
-        foreach ($value as $key => $item) {
-            $detail = $item['detail'];
-//            sort($item['detail'], SORT_STRING);
-            $suk = implode(',', $item['detail']);
+        foreach ($value as $suk) {
+            $detail = explode(',', $suk);
 
             $sukValue[$suk]['pic'] = '';
             $sukValue[$suk]['price'] = $sku[$suk]['price'] ?? 0;
@@ -609,18 +607,18 @@ class CopyProductService
             $sukValue[$suk]['brokerage'] = 0;
             $sukValue[$suk]['brokerage_two'] = 0;
 
-            foreach (array_keys($detail) as $k => $title) {
+            foreach ($head as $k => $title) {
                 if ($title == '') continue;
                 $header[$k]['title'] = $title;
                 $header[$k]['align'] = 'center';
                 $header[$k]['minWidth'] = 120;
             }
-            foreach (array_values($detail) as $k => $v) {
+            foreach ($detail as $k => $v) {
                 if ($v == '') continue;
                 $valueNew[$count]['value' . ($k + 1)] = $v;
                 $header[$k]['key'] = 'value' . ($k + 1);
             }
-            $valueNew[$count]['detail'] = $detail;
+            $valueNew[$count]['detail'] = array_combine($head, $detail);
             $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
             $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
             $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;