lqmac 4 months ago
parent f1148fc5b3
commit 5ba7327e98
  1. 4
      app/api/model/Goods.php
  2. 19
      app/common/model/Goods.php

@ -595,7 +595,11 @@ class Goods extends GoodsModel
if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) { if ($goodsInfo->origin_goods_id && $goodsInfo->store_id > 0) {
$goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]); $goods_images = $this->storeUsePlatformGoodsImage([$goodsInfo->origin_goods_id]);
$goodsList = $this->storeUsePlatformGoods([$goodsInfo->origin_goods_id]);
$goodsInfo->images = $goods_images[$goodsInfo->origin_goods_id] ?? []; $goodsInfo->images = $goods_images[$goodsInfo->origin_goods_id] ?? [];
$goodsInfo->content = $goodsList[$goodsInfo->origin_goods_id]['content'] ?? "";
$goodsInfo->goods_no = $goodsList[$goodsInfo->origin_goods_id]['goods_no'] ?? "";
$goodsInfo->goods_name = $goodsList[$goodsInfo->origin_goods_id]['goods_name'] ?? "";
// echo "<pre>"; // echo "<pre>";
// print_r($goodsInfo->images); // print_r($goodsInfo->images);
// exit(); // exit();

@ -612,6 +612,18 @@ class Goods extends BaseModel
} }
return $arr; return $arr;
} }
/**
* 使用总后台的商品信息
* [storeUsePlatformGoodsImage description]
* @param array $origin_goods_ids [description]
* @return [type] [description]
*/
public function storeUsePlatformGoods(array $origin_goods_ids){
$goods = self::withoutGlobalScope()->whereIn('goods_id', $origin_goods_ids)->field('goods_id,goods_name,goods_no,content')->select()->toArray();
$goods = array_column($goods, null, "goods_id");
return $goods;
}
/** /**
* 设置商品展示的数据 * 设置商品展示的数据
* @param Collection|Paginator $list 商品列表 * @param Collection|Paginator $list 商品列表
@ -625,12 +637,17 @@ class Goods extends BaseModel
} }
//使用总后台的商品的图片作为商城商品的图片 //使用总后台的商品的图片作为商城商品的图片
$goodsList = $list->toArray()['data'] ?? $list->toArray(); $goodsList = $list->toArray()['data'] ?? $list->toArray();
$goods_images = $this->storeUsePlatformGoodsImage(array_column($goodsList, 'origin_goods_id')); $origin_goods_ids = array_column($goodsList, 'origin_goods_id');
$goods_images = $this->storeUsePlatformGoodsImage($origin_goods_ids);
$goodsList = $this->storeUsePlatformGoods($origin_goods_ids);
// 遍历商品列表整理数据 // 遍历商品列表整理数据
foreach ($list as &$goods) { foreach ($list as &$goods) {
if ($goods->origin_goods_id && $goods->store_id > 0) { if ($goods->origin_goods_id && $goods->store_id > 0) {
$goods->images = $goods_images[$goods->origin_goods_id] ?? []; $goods->images = $goods_images[$goods->origin_goods_id] ?? [];
$goods->content = $goodsList[$goods->origin_goods_id]['content'] ?? "";
$goods->goods_no = $goodsList[$goods->origin_goods_id]['goods_no'] ?? "";
$goods->goods_name = $goodsList[$goods->origin_goods_id]['goods_name'] ?? "";
} }
$goods = $this->setGoodsData($goods, $callback); $goods = $this->setGoodsData($goods, $callback);
} }

Loading…
Cancel
Save