xieruidong il y a 2 ans
Parent
commit
ff39362eac

+ 33 - 1
application/admin/controller/Goods.php

@@ -442,6 +442,7 @@ class Goods extends Backend
         if(!$old){
             $this->error('商品不存在');
         }
+        Db::startTrans();
         $clone=$old->toArray();
         $clone['status']=$old::STATUS_DOWN;
         unset($clone['id'],$clone['num_sell'],$clone['create_time'],$clone['update_time']);
@@ -453,14 +454,45 @@ class Goods extends Backend
         foreach ($skus as $_sku){
             $oldSkuId=$_sku['id'];
             unset($_sku['id'],$_sku['num_sell']);
+            dd($_sku);
             $newSku=$newGoods->sku()->save($_sku);
             $partner[$oldSkuId]=$newSku['id'];
         }
 
-        $binds=$old->binds()->select();
+        $binds=$old->binds()->select()->toArray();
         foreach ($binds as $bind){
             unset($bind['goods_bind_id']);
             $bind['goods_id']=$newGoods['id'];
+            $bind['goods_sku_id']=$partner[$bind['goods_sku_id']];
+            $newGoods->binds()->save($bind);
+        }
+
+        $details=$old->detail()->select()->toArray();
+        foreach ($details as $detail){
+            $detail['goods_id']=$newGoods['id'];
+            $newGoods->detail()->save($detail);
         }
+
+        $installLinks=$old->installLink()->select()->toArray();
+        foreach ($installLinks as $link){
+            $link['goods_id']=$newGoods['id'];
+            $link['goods_sku_id']=$partner[$link['goods_sku_id']];
+            $newGoods->installLink()->save($link);
+        }
+
+        $services=$old->service()->select()->toArray();
+        foreach ($services as $service){
+            $service['goods_id']=$newGoods['id'];
+            $newGoods->service()->save($service);
+        }
+
+        $sizes=$old->size()->select()->toArray();
+        foreach ($sizes as $size){
+            $size['goods_id']=$newGoods['id'];
+            $newGoods->size()->save($size);
+        }
+
+        Db::commit();
+        $this->success();
     }
 }

+ 1 - 25
application/admin/model/Goods.php

@@ -3,6 +3,7 @@
 namespace app\admin\model;
 
 use app\common\model\Category;
+use app\common\model\GoodsInstallLink;
 use think\Model;
 use think\model\relation\HasMany;
 
@@ -11,32 +12,7 @@ class Goods extends \app\common\model\Goods
 {
     // 追加属性
     protected $append = [
-        'create_time_text',
-        'update_time_text',
     ];
-
-    public function getCreateTimeTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
-        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
-    }
-
-
-    public function getUpdateTimeTextAttr($value, $data)
-    {
-        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
-        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
-    }
-
-    protected function setCreateTimeAttr($value)
-    {
-        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
-    }
-
-    protected function setUpdateTimeAttr($value)
-    {
-        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
-    }
     /**
      * @return HasMany|GoodsViewFavCart
      */

+ 3 - 0
application/common/model/Goods.php

@@ -34,6 +34,9 @@ class Goods Extends Model
     public function binds(){
         return $this->hasMany(GoodsBind::class);
     }
+    public function installLink(){
+        return $this->hasMany(GoodsInstallLink::class);
+    }
     public function category(){
         return $this->belongsTo(Category::class);
     }

+ 0 - 3
application/common/model/GoodsSku.php

@@ -53,9 +53,6 @@ class GoodsSku Extends Model
         }
         return $model['amount'];
     }
-    public function getNameArrAttr($_,$model){
-        return explode(',',$model['name']);
-    }
     public function getTempIdsAttr($_,$model){
         return explode(',',$model['temp_ids']);
     }

+ 2 - 0
public/assets/js/backend/goods.js

@@ -134,11 +134,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     name: 'detail',
                                     text: __('复制商品'),
                                     title: __('复制商品'),
+                                    confirm: __('复制此商品?'),
                                     classname: 'btn btn-xs btn-danger btn-ajax btn-operation btn-operation-mt10',
                                     icon: 'fa',
                                     url: extend.copy_url,
                                     extend:`data-area='["800px","80%"]'`,
                                     callback: function (data) {
+                                        $('.btn-refresh').trigger('click')
                                     },
                                     visible: function (row) {
                                         return table.data('operate-copy');