WIN-2308041133\Administrator 6 mesi fa
parent
commit
b3b93d48b2
1 ha cambiato i file con 139 aggiunte e 115 eliminazioni
  1. 139 115
      app/common/repositories/store/product/ProductRepository.php

+ 139 - 115
app/common/repositories/store/product/ProductRepository.php

@@ -49,6 +49,7 @@ use app\common\dao\store\product\ProductDao as dao;
 use app\common\repositories\store\StoreCategoryRepository;
 use app\common\repositories\store\shipping\ShippingTemplateRepository;
 use app\common\repositories\store\StoreBrandRepository;
+use think\facade\Log;
 use think\facade\Queue;
 use think\facade\Route;
 use think\contract\Arrayable;
@@ -1032,130 +1033,153 @@ class ProductRepository extends BaseRepository
      */
     public function getAdminOneProduct(int $id, ?int $activeId, $conType = 0, $is_copy = 0)
     {
-        $appcdkey = $is_copy ? ['productCdkey', 'cdkeyLibrary'] : ['productCdkey', 'reservation'];
-        $with = [
-            'attr', 'attrValue.productCdkey', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand','reservation',
-            'temp', 'seckillActive','guarantee.templateValue.value', 'getFormName','attr_result',
-            'attrValue' => function ($query) use($appcdkey) { $query->with($appcdkey)->order('value_id ASC'); },
-            'content' => function ($query) use ($conType) { $query->where('type', $conType); },
-            'merchant' => function ($query) {
-                $query->with(['typeName', 'categoryName'])->field('mer_id,category_id,type_id,mer_avatar,mer_name,is_trader');
-            },
-        ];
+        try {
 
-        $data = $this->dao->geTrashedtProduct($id)->with($with)->find();
-        $data['delivery_way'] = empty($data['delivery_way']) ? [2] : explode(',', $data['delivery_way']);
-        $where = [['coupon_id', 'in', $data['give_coupon_ids']]];
-        $data['coupon'] = app()->make(StoreCouponRepository::class)->selectWhere($where, 'coupon_id,title')->toArray();
-        $spu_make = app()->make(SpuRepository::class);
-        $append = [];
-        if ($data['product_type'] == 0) { $append = ['us_status', 'parameter_params'];$activeId = 0; }
-        if ($data['product_type'] == 1) {
-            $activeId = $data->seckillActive->seckill_active_id ?? 0;
-            $storeOrderProduct = app()->make(StoreOrderProductRepository::class);
-            $productRepository = app()->make(ProductRepository::class);
-            $make = app()->make(StoreOrderRepository::class);
-            $append = ['us_status', 'seckill_status'];
-            $data['sales'] = $storeOrderProduct->getSearch([])->where(['product_type' => 1, 'is_refund' => 0, 'product_id' => $data['product_id']])->sum('product_num');
-            $data['stock'] = $productRepository->getSearch([])->where(['product_id'=>$data['old_product_id']])->value('stock');
-        }
-        if ($data['product_type'] == 2) $make = app()->make(ProductPresellSkuRepository::class);
-        if ($data['product_type'] == 3) $make = app()->make(ProductAssistSkuRepository::class);
-        if ($data['product_type'] == 4) $make = app()->make(ProductGroupSkuRepository::class);
-
-        $spu_where = ['activity_id' => $activeId, 'product_type' => $data['product_type'], 'product_id' => $id];
-        $spu = $spu_make->getSearch($spu_where)->find();
-        if ($spu) $spu->append(['mer_labels_data', 'sys_labels_data','us_status']);
-        $data['star'] = $spu['star'] ?? '';
-        $data['mer_labels'] = $spu['mer_labels'] ?? '';
-        $data['sys_labels'] = $spu['sys_labels'] ?? '';
-        $data['mer_labels_data'] = $spu['mer_labels_data'] ?? [];
-        $data['sys_labels_data'] = $spu['sys_labels_data'] ?? [];
-        // 处理表单ID转换 兼容前端显示
-        $data['mer_form_id'] = $data['mer_form_id'] ?: null;
-        $data->append($append);
-        $mer_cat = [];
-        if (isset($data['merCateId'])) {
-            $mer_cat = array_column($data['merCateId']->toArray(), 'mer_cate_id') ;
-        }
-        $data['mer_cate_id'] = $mer_cat;
-        @file_put_contents('quanju.txt',"-测试3\r\n",8);
-        foreach ($data['attr'] as $k => $v) {
-            $data['attr'][$k] = ['value' => $v['attr_name'], 'detail' => $v['attr_values']];
-        }
-        $attrValue = (in_array($data['product_type'], [3, 4])) ? $data['oldAttrValue'] : $data['attrValue'];
-        unset($data['oldAttrValue'], $data['attrValue']);
-        $arr = [];
-        if (in_array($data['product_type'], [1, 3])) $value_make = app()->make(ProductAttrValueRepository::class);
-        $attrValue = json_decode(json_encode($attrValue,true),true);
-        @file_put_contents('quanju.txt',"-测试4\r\n",8);
-        foreach ($attrValue as $key => $item) {
-            if ($data['product_type'] == 1) {
-                $value = $value_make->getSearch(['sku' => $item['sku'], 'product_id' => $data['old_product_id']])->find();
-                if ($value){
-                    $old_stock = $value['stock'];
-                    $item['old_stock'] = $old_stock ?? $item['stock'];
-                }
-                $item['sales'] = $make->skuSalesCount($item['unique']);
+
+            $appcdkey = $is_copy ? ['productCdkey', 'cdkeyLibrary'] : ['productCdkey', 'reservation'];
+            $with = [
+                'attr', 'attrValue.productCdkey', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'reservation',
+                'temp', 'seckillActive', 'guarantee.templateValue.value', 'getFormName', 'attr_result',
+                'attrValue' => function ($query) use ($appcdkey) {
+                    $query->with($appcdkey)->order('value_id ASC');
+                },
+                'content' => function ($query) use ($conType) {
+                    $query->where('type', $conType);
+                },
+                'merchant' => function ($query) {
+                    $query->with(['typeName', 'categoryName'])->field('mer_id,category_id,type_id,mer_avatar,mer_name,is_trader');
+                },
+            ];
+
+            $data = $this->dao->geTrashedtProduct($id)->with($with)->find();
+            $data['delivery_way'] = empty($data['delivery_way']) ? [2] : explode(',', $data['delivery_way']);
+            $where = [['coupon_id', 'in', $data['give_coupon_ids']]];
+            $data['coupon'] = app()->make(StoreCouponRepository::class)->selectWhere($where, 'coupon_id,title')->toArray();
+            $spu_make = app()->make(SpuRepository::class);
+            $append = [];
+            if ($data['product_type'] == 0) {
+                $append = ['us_status', 'parameter_params'];
+                $activeId = 0;
             }
-            if ($data['product_type'] == 2) {
-                $item['presellSku'] = $make->getSearch(['product_presell_id' => $activeId, 'unique' => $item['unique']])->find();
-                if (is_null($item['presellSku'])) continue;
+            if ($data['product_type'] == 1) {
+                $activeId = $data->seckillActive->seckill_active_id ?? 0;
+                $storeOrderProduct = app()->make(StoreOrderProductRepository::class);
+                $productRepository = app()->make(ProductRepository::class);
+                $make = app()->make(StoreOrderRepository::class);
+                $append = ['us_status', 'seckill_status'];
+                $data['sales'] = $storeOrderProduct->getSearch([])->where(['product_type' => 1, 'is_refund' => 0, 'product_id' => $data['product_id']])->sum('product_num');
+                $data['stock'] = $productRepository->getSearch([])->where(['product_id' => $data['old_product_id']])->value('stock');
             }
-            if ($data['product_type'] == 3) {
-                $item['assistSku'] = $make->getSearch(['product_assist_id' => $activeId, 'unique' => $item['unique']])->find();
-                if (is_null($item['assistSku']))
-                    continue;
+            if ($data['product_type'] == 2) $make = app()->make(ProductPresellSkuRepository::class);
+            if ($data['product_type'] == 3) $make = app()->make(ProductAssistSkuRepository::class);
+            if ($data['product_type'] == 4) $make = app()->make(ProductGroupSkuRepository::class);
+
+            $spu_where = ['activity_id' => $activeId, 'product_type' => $data['product_type'], 'product_id' => $id];
+            $spu = $spu_make->getSearch($spu_where)->find();
+            if ($spu) $spu->append(['mer_labels_data', 'sys_labels_data', 'us_status']);
+            $data['star'] = $spu['star'] ?? '';
+            $data['mer_labels'] = $spu['mer_labels'] ?? '';
+            $data['sys_labels'] = $spu['sys_labels'] ?? '';
+            $data['mer_labels_data'] = $spu['mer_labels_data'] ?? [];
+            $data['sys_labels_data'] = $spu['sys_labels_data'] ?? [];
+            // 处理表单ID转换 兼容前端显示
+            $data['mer_form_id'] = $data['mer_form_id'] ?: null;
+            $data->append($append);
+            $mer_cat = [];
+            if (isset($data['merCateId'])) {
+                $mer_cat = array_column($data['merCateId']->toArray(), 'mer_cate_id');
             }
-            if ($data['product_type'] == 4) {
-                $item['_sku'] = $make->getSearch(['product_group_id' => $activeId, 'unique' => $item['unique']])->find();
-                if (is_null($item['_sku']))
-                    continue;
+            $data['mer_cate_id'] = $mer_cat;
+            @file_put_contents('quanju.txt', "-测试3\r\n", 8);
+            foreach ($data['attr'] as $k => $v) {
+                $data['attr'][$k] = ['value' => $v['attr_name'], 'detail' => $v['attr_values']];
             }
-            $sku = explode(',', $item['sku']);
-            $item['old_stock'] = $old_stock ?? $item['stock'];
-            if (isset($item['productCdkey']) && count($item['productCdkey'])) {
-                @file_put_contents('quanju.txt',"-测试5\r\n",8);
-                foreach ($item['productCdkey'] as $hasCdkey) {
-                    if ($hasCdkey['is_type']) {
-                        $cdkey['list'][] = $hasCdkey;
-                    } else {
-                        $cdkey['key'] = $hasCdkey['key'];
+            $attrValue = (in_array($data['product_type'], [3, 4])) ? $data['oldAttrValue'] : $data['attrValue'];
+            unset($data['oldAttrValue'], $data['attrValue']);
+            $arr = [];
+            if (in_array($data['product_type'], [1, 3])) $value_make = app()->make(ProductAttrValueRepository::class);
+            $attrValue = json_decode(json_encode($attrValue, true), true);
+            @file_put_contents('quanju.txt', "-测试4\r\n", 8);
+            foreach ($attrValue as $key => $item) {
+                if ($data['product_type'] == 1) {
+                    $value = $value_make->getSearch(['sku' => $item['sku'], 'product_id' => $data['old_product_id']])->find();
+                    if ($value) {
+                        $old_stock = $value['stock'];
+                        $item['old_stock'] = $old_stock ?? $item['stock'];
                     }
-                    $cdkey['is_type'] = $hasCdkey['is_type'];
+                    $item['sales'] = $make->skuSalesCount($item['unique']);
                 }
-                $item['cdkey'] = $cdkey;
+                if ($data['product_type'] == 2) {
+                    $item['presellSku'] = $make->getSearch(['product_presell_id' => $activeId, 'unique' => $item['unique']])->find();
+                    if (is_null($item['presellSku'])) continue;
+                }
+                if ($data['product_type'] == 3) {
+                    $item['assistSku'] = $make->getSearch(['product_assist_id' => $activeId, 'unique' => $item['unique']])->find();
+                    if (is_null($item['assistSku']))
+                        continue;
+                }
+                if ($data['product_type'] == 4) {
+                    $item['_sku'] = $make->getSearch(['product_group_id' => $activeId, 'unique' => $item['unique']])->find();
+                    if (is_null($item['_sku']))
+                        continue;
+                }
+                $sku = explode(',', $item['sku']);
+                $item['old_stock'] = $old_stock ?? $item['stock'];
+                if (isset($item['productCdkey']) && count($item['productCdkey'])) {
+                    @file_put_contents('quanju.txt', "-测试5\r\n", 8);
+                    foreach ($item['productCdkey'] as $hasCdkey) {
+                        if ($hasCdkey['is_type']) {
+                            $cdkey['list'][] = $hasCdkey;
+                        } else {
+                            $cdkey['key'] = $hasCdkey['key'];
+                        }
+                        $cdkey['is_type'] = $hasCdkey['is_type'];
+                    }
+                    $item['cdkey'] = $cdkey;
+                }
+                unset($item['productCdkey']);
+                @file_put_contents('quanju.txt', "-测试6\r\n", 8);
+                foreach ($sku as $k => $v) {
+                    $item['value' . $k] = $v;
+                }
+                if ($is_copy) {
+                    $item['library_id'] = 0;
+                    $item['stock'] = 0;
+                }
+                $arr[] = $item;
+            }
+            $data['attrValue'] = $arr;
+            $content = $data['content']['content'] ?? '';
+            if ($conType) $content = json_decode($content);
+            unset($data['content']);
+            $data['content'] = $content;
+            // 查找该商品积分抵扣比例
+            if (!empty($data['merchant'])) {
+                $data['merchant']['mer_integral_status'] = merchantConfig($data['merchant']['mer_id'], 'mer_integral_status');
+                $data['merchant']['mer_integral_rate'] = merchantConfig($data['merchant']['mer_id'], 'mer_integral_rate');
+            }
+            // 拼接商品分类
+            if (!empty($data['storeCategory'])) {
+                $cate_name = app()->make(StoreCategoryRepository::class)->getAllFatherName($data['storeCategory']['store_category_id']);
+                $data['storeCategory']['cate_name'] = $cate_name;
             }
-            unset($item['productCdkey']);
-            @file_put_contents('quanju.txt',"-测试6\r\n",8);
-            foreach ($sku as $k => $v) { $item['value' . $k] = $v; }
-            if ($is_copy) {$item['library_id'] = 0;$item['stock'] = 0;}
-            $arr[] = $item;
-        }
-        $data['attrValue'] = $arr;
-        $content = $data['content']['content'] ?? '';
-        if ($conType) $content = json_decode($content);
-        unset($data['content']);
-        $data['content'] = $content;
-        // 查找该商品积分抵扣比例
-        if (!empty($data['merchant'])) {
-            $data['merchant']['mer_integral_status'] = merchantConfig($data['merchant']['mer_id'], 'mer_integral_status');
-            $data['merchant']['mer_integral_rate'] = merchantConfig($data['merchant']['mer_id'], 'mer_integral_rate');
-        }
-        // 拼接商品分类
-        if (!empty($data['storeCategory'])) {
-            $cate_name = app()->make(StoreCategoryRepository::class)->getAllFatherName($data['storeCategory']['store_category_id']);
-            $data['storeCategory']['cate_name'] = $cate_name;
-        }
 
-        // 拼接商品推荐商品
-        if (!empty($data['good_ids'])) {
-            $data['goodList'] = $this->dao->getGoodList($data['good_ids'], $data['mer_id'], false);
-        }
-        $data['merchant']['mer_config'] = $this->merConfig($data['mer_id']);
-        $data = $data->toArray();
-        $data = $this->mergeReservation($data);
-        $data = $this->translateAttrResult($data);
+            // 拼接商品推荐商品
+            if (!empty($data['good_ids'])) {
+                $data['goodList'] = $this->dao->getGoodList($data['good_ids'], $data['mer_id'], false);
+            }
+            $data['merchant']['mer_config'] = $this->merConfig($data['mer_id']);
+            $data = $data->toArray();
+            $data = $this->mergeReservation($data);
+            $data = $this->translateAttrResult($data);
+        }catch (\Exception $exception){
+//                Log::info('清除冗余错误:'.$exception->getMessage());
+                var_dump($exception->getMessage());
+                var_dump($exception->getLine());
+                var_dump($exception->getFile());
+                die();
+
+            }
         return $data;
     }