Browse Source

直播间商品列表

lizhen_gitee 2 months ago
parent
commit
707b95f140
1 changed files with 42 additions and 5 deletions
  1. 42 5
      addons/shopro/controller/goods/Goods.php

+ 42 - 5
addons/shopro/controller/goods/Goods.php

@@ -14,6 +14,7 @@ class Goods extends Common
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
+    //商品列表
     public function index()
     {
         $params = $this->request->param();
@@ -25,11 +26,7 @@ class Goods extends Common
         $sort = $params['sort'] ?? 'weigh';
         $order = $params['order'] ?? 'desc';
 
-        $service = new GoodsService(function ($goods) {
-            $goods->activities = $goods->activities;
-            $goods->promos = $goods->promos;
-            return $goods;
-        });
+        $service = new GoodsService();
 
         /*$service->up()->with(['max_sku_price' => function ($query) {      // 计算价格区间用(不知道为啥 with 必须再 show 后面)
             $query->where('status', 'up');
@@ -59,6 +56,46 @@ class Goods extends Common
         $this->success('获取成功', $goods);
     }
 
+    //直播间商品列表
+    public function liveroom_index(){
+        $room_no = input('room_no','','trim');
+        $keyword = input('keyword','','trim');
+
+        $goods_list = Db::name('live_room_goods')->field('goods_id,goods_no,is_top')->where('room_no',$room_no)->where('status','up')->order('is_top desc,goods_no asc,id desc')->select();
+        if(empty($goods_list))
+        {
+            $this->success(1,null);
+        }
+
+        $goods_ids = array_column($goods_list,'goods_id');
+
+        $service = new GoodsService();
+
+        $service->up();
+
+        if ($keyword) {
+            $service->search($keyword);
+        }
+
+        $service->whereIds($goods_ids);
+
+        $goods = $service->select_autopage();
+        $goods = collection($goods)->toArray();
+        $goods = list_domain_image($goods,['image']);//主图
+
+        foreach($goods as $key => $good){
+            foreach($goods_list as $k => $v){
+                if($good['id'] == $v['goods_id']){
+                    $good['is_top'] = $v['is_top'];
+                    $good['goods_no'] = $v['goods_no'];
+                }
+            }
+            $goods[$key] = $good;
+        }
+
+        $this->success('获取成功', $goods);
+    }
+
 
     /**
      * 通过 ids 获取商品(不分页)