xxxrrrdddd %!s(int64=2) %!d(string=hai) anos
pai
achega
521520eb97

+ 5 - 0
extend/datamodel/Goods.php

@@ -19,4 +19,9 @@ class Goods extends BaseDataModel
     {
         return $this->hasMany(GoodsMerge::class, 'goods_id');
     }
+
+    public function buy()
+    {
+        return $this->hasMany(GoodsBuy::class, 'goods_id');
+    }
 }

+ 13 - 0
extend/datamodel/GoodsBuy.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace datamodel;
+
+use think\Model;
+
+
+class GoodsBuy extends Model
+{
+    public function goods(){
+        return $this->belongsTo(Goods::class,'source_goods_id');
+    }
+}

+ 8 - 0
extend/logicmodel/GoodsLogic.php

@@ -282,12 +282,17 @@ class GoodsLogic
         $where['g.is_show'] = 1;
         $where['g.id'] = $id;
         $field = ['g.*','gc.name goods_category_name','a.name author_name','a.image author_image','n.name network_name','gc.is_convert'];
+        $field[] = 'c.name as buy_goods_name';
+        $field[] = 'b.num as buy_need_num';
+
         $goodsData =  new Goods();
         $data = $goodsData
             ->alias('g')
             ->join('author a','a.id = g.author_id')
             ->join('goods_category gc','gc.id = g.goods_category_id')
             ->join('network n','n.id = g.network_id')
+            ->join('goods_buy b','g.id=b.goods_id','left')
+            ->join('goods c','c.id=b.source_goods_id','left')
             ->where($where)
             ->field($field)
             ->find();
@@ -849,4 +854,7 @@ class GoodsLogic
         if($result) return Response::success($is_show == 1?'上架成功':'下架成功');
         return Response::fail($is_show == 1?'上架失败':'下架失败');
     }
+    public function preOrder($id,$uid){
+
+    }
 }