|
|
|
@ -17,7 +17,9 @@ use app\admin\model\store\User as StoreUserModel; |
|
|
|
|
use app\admin\model\user\User; |
|
|
|
|
use app\common\model\Store as StoreModel; |
|
|
|
|
use app\common\model\User as UserModel; |
|
|
|
|
|
|
|
|
|
use think\facade\Db; |
|
|
|
|
use app\store\model\Category as CategoryModel; |
|
|
|
|
use app\common\model\UploadFile; |
|
|
|
|
/** |
|
|
|
|
* 商家记录表模型 |
|
|
|
|
* Class Store |
|
|
|
@ -67,11 +69,80 @@ class Store extends StoreModel |
|
|
|
|
if ($user_id) { |
|
|
|
|
(new StoreUserModel)->where(['store_id' => $this['store_id']])->save(['user_id' => $user_id]); |
|
|
|
|
} |
|
|
|
|
$this->copyCategory((int)$this['store_id']); |
|
|
|
|
} |
|
|
|
|
return $status; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
public function copyCategory(int $new_store_id){ |
|
|
|
|
$store_id = 0; |
|
|
|
|
$model = new CategoryModel; |
|
|
|
|
$list = $model->getList(['store_id' =>$store_id]); |
|
|
|
|
if (!$list) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
foreach ($list as $value) { |
|
|
|
|
$value = $value->toArray(); |
|
|
|
|
$value['store_id'] = $new_store_id; |
|
|
|
|
$value['create_time'] = time(); |
|
|
|
|
$value['update_time'] = time(); |
|
|
|
|
$value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; |
|
|
|
|
$temp = $value; |
|
|
|
|
unset($temp['children']); |
|
|
|
|
unset($temp['image']); |
|
|
|
|
unset($temp['category_id']); |
|
|
|
|
|
|
|
|
|
$firstid = Db::table('yoshop_category')->insertGetId($temp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($value['children']) || !$value['children']) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
foreach ($value['children'] as $value1) { |
|
|
|
|
$value1 = $value1->toArray(); |
|
|
|
|
$value1['parent_id'] = $firstid; |
|
|
|
|
$value1['store_id'] = $new_store_id; |
|
|
|
|
$value1['create_time'] = time(); |
|
|
|
|
$value1['update_time'] = time(); |
|
|
|
|
$value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; |
|
|
|
|
$temp1 = $value1; |
|
|
|
|
unset($temp1['children']); |
|
|
|
|
unset($temp1['image']); |
|
|
|
|
unset($temp1['category_id']); |
|
|
|
|
|
|
|
|
|
$secondid = Db::table('yoshop_category')->insertGetId($temp1); |
|
|
|
|
if (!isset($value1['children']) || !$value1['children']) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
foreach ($value1['children'] as $value2) { |
|
|
|
|
$value2 = $value2->toArray(); |
|
|
|
|
$value2['parent_id'] = $secondid; |
|
|
|
|
$value2['store_id'] = $new_store_id; |
|
|
|
|
$value2['create_time'] = time(); |
|
|
|
|
$value2['update_time'] = time(); |
|
|
|
|
$value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; |
|
|
|
|
$temp2 = $value2; |
|
|
|
|
unset($temp2['children']); |
|
|
|
|
unset($temp2['image']); |
|
|
|
|
unset($temp2['category_id']); |
|
|
|
|
|
|
|
|
|
Db::table('yoshop_category')->insertGetId($temp2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function copyImage($image_id, $store_id){ |
|
|
|
|
$upload_file = DB::table("yoshop_upload_file")->where('file_id', $image_id)->find(); |
|
|
|
|
if (!$upload_file) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
$upload_file['store_id'] = $store_id; |
|
|
|
|
$upload_file['create_time'] = time(); |
|
|
|
|
unset($upload_file['file_id']); |
|
|
|
|
$new_image_id = DB::table("yoshop_upload_file")->insertGetId($upload_file); |
|
|
|
|
return $new_image_id; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 移入移出回收站 |
|
|
|
|
* @param bool $isRecycle |
|
|
|
|