diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 6e5006e6..30955fab 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -59,7 +59,7 @@ class Goods extends Controller // wmc商品详情 $model = new GoodsModel; $goodsInfo = $model->getDetails($goodsId, $verifyStatus); - + if (!empty($goodsInfo['content'])) { $goodsInfo['content'] = str_ireplace('onload="if(this.width>750){this.height=this.height*(750.0/this.width); this.width = 750;}', '', $goodsInfo['content']); } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index 35e672dd..af5cc521 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -154,17 +154,27 @@ class Goods extends GoodsModel $model = new GoodsBrowseLog; $end_time = date('Y-m-d'); $start_time = date('Y-m-d', strtotime($end_time . ' - 15 days')); - $list = $model->with(['sku', 'goods', 'images.file']) + $list = $model->with(['goods', 'images.file']) ->whereBetween('ctime', [$start_time, $end_time]) -// ->where('ctime', '>=', $start_time) -// ->where('ctime', '<=', $end_time) ->order('ctime', 'desc') ->where(['user_id' => $userId]) ->select(); + $goodsList = $list->toArray()['data'] ?? $list->toArray(); + + // + $origin_goods_ids = []; + foreach ($list as $key => $value) { + $origin_goods_ids[] = $value['goods']['origin_goods_id'] ?? 0; + } + $goods_images = $this->storeUsePlatformGoodsImage($origin_goods_ids); + $data = []; $array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; if (!$list->isEmpty()) { foreach ($list as $value) { + if ($value['goods']['origin_goods_id'] && $value['store_id'] > 0) { + $value['images'] = $goods_images[$value['goods']['origin_goods_id']] ?? []; + } $data[$value['ctime']]['name'] = date('m-d', strtotime($value['ctime'])); $data[$value['ctime']]['week'] = $array[date("w", strtotime($value['ctime']))]; $data[$value['ctime']]['list'][] = $value; @@ -436,7 +446,6 @@ class Goods extends GoodsModel } // 获取商品记录 $goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus); - //$this->dealGoodsImage($goodsInfo); // 商品规格列表 @@ -581,6 +590,16 @@ class Goods extends GoodsModel $value->goods_sku_no = $goodsInfo['goods_no_other']; } } + //使用总后台的商品的图片作为商城商品的图片 + + if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) { + + $goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]); + $goodsInfo->images = $goods_images[$goodsInfo->origin_goods_id] ?? []; + // echo "
";
+            // print_r($goodsInfo->images);
+            // exit();
+        }
         //是否展示看同款按钮
         $goodsInfo->is_show_ktk = 1;
         if (in_array($goodsInfo['channel'], ['sn','sn1']) && !$goodsInfo['link_other']) {
diff --git a/app/api/model/Order.php b/app/api/model/Order.php
index 27c384f3..07a47cd8 100644
--- a/app/api/model/Order.php
+++ b/app/api/model/Order.php
@@ -133,22 +133,28 @@ class Order extends OrderModel
             ->where($where)
             ->where('is_delete', '=', 0)
             ->order(['create_time' => 'desc']);
-        $list = $query->paginate(15)->toArray();
+        $list = $query->paginate(10)->toArray();
         //这边后面改成多商户的话需要根据storeid去获取信息
         $service = new StoreService;
+        $goodsModel = new GoodsModel;
         $info = $service->data();
-        if (!empty($info['storeInfo'])) {
+        //if (!empty($info['storeInfo'])) {
             $info = $info['storeInfo']->toArray();
             foreach ($list['data'] as &$v) {
                 $v['storeInfo'] = $info;
                 $total_num = 0;
-                foreach ($v['goods'] as $value) {
+                $goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($v['goods'], 'origin_goods_id'));
+                foreach ($v['goods'] as &$value) {
+                    //使用总后台的商品图片
+                    if ($value['origin_goods_id'] && $v['store_id'] > 0) {
+                        $value['goods_image'] = $goods_images[$value['origin_goods_id']][0]['file']['preview_url'] ?? "";
+                    }
                     $total_num += $value['total_num'] ?? 0;
                 }
                 $v['total_num'] = $total_num;
                 $v['delivery'] = DeliveryModel::where('order_id', $v['order_id'])->find();
             }
-        }
+        //}
         return $list;
     }
 
@@ -499,8 +505,13 @@ class Order extends OrderModel
             $order->storeInfo = $info['storeInfo']->toArray();
         }
         $total_num = 0;
+        $goodsModel = new GoodsModel;
+        $goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($order->goods->toArray(), 'origin_goods_id'));
         if (isset($order->goods) && $order->goods) {
-            foreach ($order->goods as $value) {
+            foreach ($order->goods as &$value) {
+                if ($value['origin_goods_id'] && $order['store_id'] > 0) {
+                    $value['goods_image'] = $goods_images[$value['origin_goods_id']][0]['file']['preview_url'] ?? "";
+                }
                 $total_num += $value->total_num ?? 0;
             }
         }
diff --git a/app/api/model/OrderRefund.php b/app/api/model/OrderRefund.php
index f2de8a6c..c4dc01d1 100644
--- a/app/api/model/OrderRefund.php
+++ b/app/api/model/OrderRefund.php
@@ -19,7 +19,7 @@ use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
 use app\common\enum\order\refund\RefundType as RefundTypeEnum;
 use app\common\model\OrderRefund as OrderRefundModel;
 use cores\exception\BaseException;
-
+use app\common\model\Goods as GoodsModel;
 /**
  * 售后单模型
  * Class OrderRefund
@@ -103,11 +103,24 @@ class OrderRefund extends OrderRefundModel
         // 当前用户ID
         $userId = UserService::getCurrentLoginUserId();
         // 查询列表记录
-        return $this->with(['orderGoods.image'])
-            ->where($filter)
-            ->where('user_id', '=', $userId)
-            ->order(['create_time' => 'desc'])
-            ->paginate(15);
+        $list = $this->with(['orderGoods.image'])
+                    ->where($filter)
+                    ->where('user_id', '=', $userId)
+                    ->order(['create_time' => 'desc'])
+                    ->paginate(15);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+        $goodsModel = new GoodsModel;
+        foreach ($list->items() as $key => &$value) {
+            if ($value->orderGoods->origin_goods_id > 0) {
+                $goods_images = $goodsModel->storeUsePlatformGoodsImage([$value->orderGoods->origin_goods_id]);
+                $value['orderGoods']['goods_image'] = $goods_images[$value->orderGoods->origin_goods_id][0]['file']['preview_url'] ?? "";
+            }
+            
+
+        }
+        return $list;
     }
 
     /**
@@ -127,6 +140,15 @@ class OrderRefund extends OrderRefundModel
             'order_refund_id' => $orderRefundId
         ], $with);
         empty($detail) && throwError('未找到该售后单');
+
+        $goodsModel = new GoodsModel;
+        if ($detail->orderGoods->origin_goods_id > 0) {
+            $goods_images = $goodsModel->storeUsePlatformGoodsImage([$detail->orderGoods->origin_goods_id]);
+            $detail['orderGoods']['goods_image'] = $goods_images[$detail->orderGoods->origin_goods_id][0]['file']['preview_url'] ?? "";
+        }
+            
+
+        
         return $detail;
     }
 
diff --git a/app/api/service/order/Checkout.php b/app/api/service/order/Checkout.php
index a2c06cf6..ebe07bbb 100644
--- a/app/api/service/order/Checkout.php
+++ b/app/api/service/order/Checkout.php
@@ -922,6 +922,7 @@ class Checkout extends BaseService
                 'user_id' => $this->user['user_id'],
                 'store_id' => $this->storeId,
                 'goods_id' => $goods['goods_id'],
+                'origin_goods_id' => $goods['origin_goods_id'] ?? 0,
                 'goods_type' => $goods['goods_type'],
                 'goods_name' => $goods['goods_name'],
                 'goods_no' => $goods['goods_no'] ?: '',
diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php
index 14ba981c..efa8f559 100644
--- a/app/common/model/Goods.php
+++ b/app/common/model/Goods.php
@@ -25,7 +25,8 @@ use think\model\relation\BelongsTo;
 use think\model\relation\HasMany;
 use think\model\relation\HasOne;
 use think\Paginator;
-
+use app\store\model\GoodsImage as GoodsImageModel;
+use app\store\model\UploadFile as UploadFileModel;
 /**
  * 商品模型
  * Class Goods
@@ -589,7 +590,25 @@ class Goods extends BaseModel
         // 实例化新查询对象
         return $query->where($filter);
     }
-
+    /**
+     * 使用总后台的商品的图片作为商城商品的图片
+     * [storeUsePlatformGoodsImage description]
+     * @param  array  $origin_goods_ids [description]
+     * @return [type]                   [description]
+     */
+    public function storeUsePlatformGoodsImage(array $origin_goods_ids){
+        $goods_images = GoodsImageModel::withoutGlobalScope()->whereIn('goods_id', $origin_goods_ids)->select()->toArray();
+        $goods_image_ids = array_column($goods_images, "image_id");
+        $files = UploadFileModel::withoutGlobalScope()->whereIn('file_id', $goods_image_ids)->select()->toArray();
+
+        $files = array_column($files, null, "file_id");
+        $arr = [];
+        foreach ($goods_images as &$goods_image) {
+            $goods_image['file'] = $files[$goods_image['image_id']] ?? [];
+            $arr[$goods_image['goods_id']][] = $goods_image;
+        }
+        return $arr;
+    }
     /**
      * 设置商品展示的数据
      * @param Collection|Paginator $list 商品列表
@@ -601,10 +620,15 @@ class Goods extends BaseModel
         if ($list->isEmpty()) {
             return $list;
         }
-
+        //使用总后台的商品的图片作为商城商品的图片
+        $goodsList = $list->toArray()['data'] ?? $list->toArray();
+        $goods_images = $this->storeUsePlatformGoodsImage(array_column($goodsList, 'origin_goods_id'));
+        
         // 遍历商品列表整理数据
         foreach ($list as &$goods) {
-
+            if ($goods->origin_goods_id && $goods->store_id > 0) {
+                $goods->images = $goods_images[$goods->origin_goods_id] ?? [];
+            }
             $goods = $this->setGoodsData($goods, $callback);
         }
 
diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php
index bee32c96..2f51f001 100644
--- a/app/store/controller/Order.php
+++ b/app/store/controller/Order.php
@@ -13,6 +13,7 @@ declare (strict_types=1);
 namespace app\store\controller;
 
 use app\store\model\Order as OrderModel;
+use app\store\model\Goods as GoodsModel;
 use think\response\Json;
 use app\common\model\UploadFile as UploadFileModel;
 /**
@@ -35,11 +36,17 @@ class Order extends Controller
         $params['merchantId'] = $this->merchantId;
         $result = $model->getList($params);
         $data = $result->items();
+        $goodsModel = new GoodsModel;
         if (!empty($data)) {
             foreach ($data as $key => $value) {
                 $data[$key]['address_match_text'] = '--';
                 $copy_text = "订单号:{$value['order_no']}\n";
+                $goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($value['goods']->toArray(), 'origin_goods_id'));
                 foreach ($value['goods'] as $good) {
+                    //使用总后台的商品图片
+                    if ($good['origin_goods_id'] && $value['store_id'] > 0) {
+                        $good['goods_image'] = $goods_images[$good['origin_goods_id']][0]['file']['preview_url'] ?? "";
+                    }
                     $copy_text .= "商品名称:{$good['goods_name']}\n";
                     if (!empty($good['goods_no'])) {
                         $copy_text .= "商品编码:{$good['goods_no']}\n";
diff --git a/app/store/model/Goods.php b/app/store/model/Goods.php
index 5e36f7dd..f1d44732 100644
--- a/app/store/model/Goods.php
+++ b/app/store/model/Goods.php
@@ -76,6 +76,11 @@ class Goods extends GoodsModel
         // $goodsInfo->rules = [];
         // 获取商品记录
         $goodsInfo = static::detail($goodsId, $with);
+        //使用总后台的商品的图片作为商城商品的图片
+        if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) {
+            $goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]);
+            $goodsInfo->images = $goods_images[$goodsInfo->origin_goods_id] ?? [];
+        }
         if ($goodsInfo->region && $goodsInfo->region_text) {
             $goodsInfo->rules = [['key' => 0, 'region' => json_decode($goodsInfo->region), 'region_text' => json_decode($goodsInfo->region_text)]];
         }
diff --git a/app/store/model/Order.php b/app/store/model/Order.php
index a9d0ebde..9e4ea1fc 100644
--- a/app/store/model/Order.php
+++ b/app/store/model/Order.php
@@ -25,6 +25,7 @@ use app\common\service\Order as OrderService;
 use app\common\service\order\Printer as PrinterService;
 use app\common\service\order\Refund as RefundService;
 use cores\exception\BaseException;
+use app\store\model\Goods as GoodsModel;
 
 /**
  * 订单管理
@@ -48,9 +49,17 @@ class Order extends OrderModel
             'trade',
         ]);
         $order->merchant_remark = $order->merchant_remark ? htmlspecialchars_decode($order->merchant_remark) : "";
-        $goods = $order->goods ? $order->goods->toArray() : [];
 
-        if ($goods) {
+        $goodsModel = new GoodsModel;
+        $goods_images = $goodsModel->storeUsePlatformGoodsImage(array_column($order->goods->toArray(), 'origin_goods_id'));
+        if ($order->goods) {
+            //使用总后台的商品图片
+            foreach ($order->goods as &$value) {
+                if ($value->origin_goods_id && $order->store_id > 0) {
+                    $value->goods_image = $goods_images[$value->origin_goods_id][0]['file']['preview_url'] ?? "";
+                }
+            }
+            $goods = $order->goods ? $order->goods->toArray() : [];
             $goods = array_column($goods, null, 'goods_id');
             if ($order->delivery) {
                 foreach ($order->delivery as &$val) {
@@ -102,8 +111,7 @@ class Order extends OrderModel
         if (!empty($filterOr)) {
             $query = $query->whereOr($filterOr);
         }
-        $list = $query->order(['order.create_time' => 'desc'])
-            ->paginate($param['pageSize'] ?? 15);
+        $list = $query->order(['order.create_time' => 'desc'])->paginate($param['pageSize'] ?? 15);
         return $list;
     }
 
diff --git a/app/store/model/OrderRefund.php b/app/store/model/OrderRefund.php
index 8596446b..b128fc23 100644
--- a/app/store/model/OrderRefund.php
+++ b/app/store/model/OrderRefund.php
@@ -27,6 +27,7 @@ use app\common\service\order\Refund as RefundService;
 use app\store\model\User as UserModel;
 use app\store\model\Order as OrderModel;
 use app\store\model\OrderGoods as OrderGoodsMOdel;
+use app\common\model\Goods as GoodsModel;
 
 /**
  * 售后单模型
@@ -62,10 +63,22 @@ class OrderRefund extends OrderRefundModel
         if (!empty($filterOr)) {
             $query = $query->whereOr($filterOr);
         }
-        $list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
-            ->paginate(10);
+        $list = $query->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])->paginate($param['pageSize'] ?? 15);
+        if ($list->isEmpty()) {
+            return $list;
+        }
+        $list = static::preload($list, ['orderGoods.image', 'orderData', 'user.avatar']);
+        $goodsModel = new GoodsModel;
+        foreach ($list->items() as $key => &$value) {
+            if ($value->orderGoods->origin_goods_id > 0) {
+                $goods_images = $goodsModel->storeUsePlatformGoodsImage([$value->orderGoods->origin_goods_id]);
+                $value->orderGoods->goods_image = $goods_images[$value->orderGoods->origin_goods_id][0]['file']['preview_url'] ?? "";
+            }
+            
+
+        }
         // 加载关联订单数据
-        return static::preload($list, ['orderGoods.image', 'orderData', 'user.avatar']);
+        return $list;
     }
 
     /**
@@ -133,9 +146,15 @@ class OrderRefund extends OrderRefundModel
      */
     public function getDetail(int $orderRefundId)
     {
-        return static::detail($orderRefundId, [
+        $detail = static::detail($orderRefundId, [
             'orderData', 'images.file', 'orderGoods.image', 'express', 'address', 'user'
         ]) ?: false;
+        $goodsModel = new GoodsModel;
+        if ($detail->orderGoods->origin_goods_id > 0) {
+            $goods_images = $goodsModel->storeUsePlatformGoodsImage([$detail->orderGoods->origin_goods_id]);
+            $detail['orderGoods']['goods_image'] = $goods_images[$detail->orderGoods->origin_goods_id][0]['file']['preview_url'] ?? "";
+        }
+        return $detail;
     }
 
     /**