xieruidong 2 years ago
parent
commit
4a8b611781

+ 9 - 2
application/admin/controller/Goods.php

@@ -194,14 +194,21 @@ class Goods extends Backend
             $goodsId=input('goods_id');
             if($e=='get'){
                 $goods=$this->model->find($goodsId);
-                $bindId=$goods->binds()->where('sku_id',$skuId)->column('bind_goods_id');
+                $bindId=$goods->binds()->where('goods_sku_id',$skuId)->column('bind_goods_id');
                 $this->success('','',$bindId);
             }
             $goods=$this->model->find($ids);
             $skuId=input('row.sku_id');
             $bindGoods=input('row.goods_id');
             $sku=GoodsSku::find($skuId);
-            $sku->bindGoods()->sync(array_filter(explode(',',$bindGoods)));
+            $goodsIds=array_filter(explode(',',$bindGoods));
+            $goods->binds()->where('goods_sku_id',$skuId)->delete();
+            foreach ($goodsIds as $_id){
+                $goods->binds()->save([
+                    'goods_sku_id'=>$sku['id'],
+                    'bind_goods_id'=>$_id,
+                ]);
+            }
             $this->success();
         }
     }

+ 1 - 1
application/common/model/GoodsBind.php

@@ -9,7 +9,7 @@ use think\model\Pivot;
  */
 class GoodsBind Extends Pivot
 {
-
+    protected $pk='goods_bind_id';
 
 
 

+ 1 - 1
application/common/model/GoodsSku.php

@@ -14,6 +14,6 @@ class GoodsSku Extends Model
         $query->where('is_del',0);
     }
     public function bindGoods(){
-        return $this->belongsToMany(Goods::class,GoodsBind::class);
+        return $this->belongsToMany(Goods::class,GoodsBind::class,'bind_goods_id','goods_sku_id');
     }
 }

+ 1 - 1
thinkphp/library/think/db/Connection.php

@@ -349,7 +349,7 @@ abstract class Connection
         if (!$this->linkID) {
             return false;
         }
-
+dump($sql);
         // 记录SQL语句
         $this->queryStr = $sql;
         if ($bind) {