feat: 导入完成
parent
b073e44bce
commit
e5a2c57b5f
|
@ -71,10 +71,10 @@
|
||||||
console.log(res,'res')
|
console.log(res,'res')
|
||||||
layer.closeAll()
|
layer.closeAll()
|
||||||
//假设code=0代表上传成功
|
//假设code=0代表上传成功
|
||||||
|
layer.msg(res.msg)
|
||||||
if(res.code === 1){
|
if(res.code === 1){
|
||||||
//do something (比如将res返回的图片链接保存到表单的隐藏域)
|
//do something (比如将res返回的图片链接保存到表单的隐藏域)
|
||||||
} else {
|
} else {
|
||||||
layer.msg(res.msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当前触发上传的元素,一般用于 elem 绑定 class 的情况,注意:此乃 layui 2.1.0 新增
|
//获取当前触发上传的元素,一般用于 elem 绑定 class 的情况,注意:此乃 layui 2.1.0 新增
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace app\common\model\goods;
|
||||||
|
|
||||||
use app\common\basics\Models;
|
use app\common\basics\Models;
|
||||||
use app\common\model\distribution\DistributionGoods;
|
use app\common\model\distribution\DistributionGoods;
|
||||||
|
use Overtrue\Pinyin\Pinyin;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,14 +210,15 @@ class Goods extends Models
|
||||||
// 处理组图
|
// 处理组图
|
||||||
public static function handleImages()
|
public static function handleImages()
|
||||||
{
|
{
|
||||||
// 查询商品表images不为空的记录,批量插入到goods_image表,再将这些images字段置空
|
// 查询商品表images不为空的记录,批量插入到goods_image表
|
||||||
$needHandleList = self::whereNotNull('images')->column('id,images');
|
$needHandleList = self::whereNotNull('images')->column('id,images');
|
||||||
$goodsIds = [];
|
|
||||||
$insertImage = [];
|
$insertImage = [];
|
||||||
foreach ($needHandleList as $item) {
|
foreach ($needHandleList as $item) {
|
||||||
$goodsIds[] = $item['id'];
|
|
||||||
$imageArr = explode(',', $item['images']);
|
$imageArr = explode(',', $item['images']);
|
||||||
foreach ($imageArr as $img) {
|
foreach ($imageArr as $img) {
|
||||||
|
if (empty($img)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$insertImage[] = [
|
$insertImage[] = [
|
||||||
'goods_id' => $item['id'],
|
'goods_id' => $item['id'],
|
||||||
'uri' => $img,
|
'uri' => $img,
|
||||||
|
@ -224,9 +226,6 @@ class Goods extends Models
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GoodsImage::limit(2000)->insertAll($insertImage);
|
GoodsImage::limit(2000)->insertAll($insertImage);
|
||||||
self::whereIn('id', $goodsIds)->save([
|
|
||||||
'images' => null
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量插入没有的品牌
|
// 批量插入没有的品牌
|
||||||
|
@ -243,7 +242,9 @@ class Goods extends Models
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!in_array($item, $allBrandName)) {
|
if (!in_array($item, $allBrandName)) {
|
||||||
$insert[] = ['name' =>$item, 'create_time'=> $now, 'image' => '', 'initial' => ''];
|
$word = Pinyin::abbr($item)->join();
|
||||||
|
$word = substr($word, 0, 1);
|
||||||
|
$insert[] = ['name' =>$item, 'create_time'=> $now, 'image' => '', 'initial' => strtoupper($word)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GoodsBrand::limit(2000)->insertAll($insert);
|
GoodsBrand::limit(2000)->insertAll($insert);
|
||||||
|
@ -281,7 +282,6 @@ class Goods extends Models
|
||||||
$insert = [];
|
$insert = [];
|
||||||
$now = time();
|
$now = time();
|
||||||
|
|
||||||
|
|
||||||
foreach ($needHandleList1 as $item) {
|
foreach ($needHandleList1 as $item) {
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -296,7 +296,7 @@ class Goods extends Models
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!in_array($item['second_cate'], $allName)) {
|
if (!in_array($item['second_cate'], $allName)) {
|
||||||
$insert[] = ['name' =>$item['first_cate'], 'pid' => 0, 'level' => 2,'create_time'=> $now, 'parent_name' => $item['first_cate']];
|
$insert[] = ['name' =>$item['second_cate'], 'pid' => 0, 'level' => 2,'create_time'=> $now, 'parent_name' => $item['first_cate']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +309,9 @@ class Goods extends Models
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GoodsCategory::limit(2000)->insertAll($insert);
|
if (!empty($insert)) {
|
||||||
|
GoodsCategory::limit(2000)->insertAll($insert);
|
||||||
|
}
|
||||||
|
|
||||||
// 将level > 1但是pid=0且parent_name不为空的记录批量更新
|
// 将level > 1但是pid=0且parent_name不为空的记录批量更新
|
||||||
GoodsCategory::alias('main')
|
GoodsCategory::alias('main')
|
||||||
|
@ -317,7 +319,7 @@ class Goods extends Models
|
||||||
->where('main.level', '>', 1)
|
->where('main.level', '>', 1)
|
||||||
->where('main.pid', 0)
|
->where('main.pid', 0)
|
||||||
->whereNotNull('main.parent_name')
|
->whereNotNull('main.parent_name')
|
||||||
->update(['main.pid' => 'parent.id']);
|
->update(['main.pid' => Db::raw('`parent`.id')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function handleSelfInfo()
|
public static function handleSelfInfo()
|
||||||
|
@ -370,9 +372,9 @@ class Goods extends Models
|
||||||
'name' => $item['name'],
|
'name' => $item['name'],
|
||||||
'shop_id' => $shopId,
|
'shop_id' => $shopId,
|
||||||
|
|
||||||
'first_cate' => $item['first_cate'],
|
'first_cate' => $item['first_cate'] ?: null,
|
||||||
'second_cate' => $item['second_cate'],
|
'second_cate' => $item['second_cate'] ?: null,
|
||||||
'third_cate' => $item['third_cate'],
|
'third_cate' => $item['third_cate'] ?: null,
|
||||||
'brand_name' => $item['brand'],
|
'brand_name' => $item['brand'],
|
||||||
'unit_name' => $item['unit'],
|
'unit_name' => $item['unit'],
|
||||||
'images' => $item['images'],
|
'images' => $item['images'],
|
||||||
|
@ -380,12 +382,12 @@ class Goods extends Models
|
||||||
|
|
||||||
'express_money' =>0,
|
'express_money' =>0,
|
||||||
|
|
||||||
'image' => $item['image'],
|
'image' => $item['image'] ?: '',
|
||||||
'content' => $item['content'],
|
'content' => $item['content'] ?: '',
|
||||||
'spec_type' => 1,//1 统一规格
|
'spec_type' => 1,//1 统一规格
|
||||||
'max_price' => $item['price'],
|
'max_price' => $item['price'] ?: 0,
|
||||||
'min_price' => $item['price'],
|
'min_price' => $item['price'] ?: 0,
|
||||||
'stock' => $item['stock'],
|
'stock' => $item['stock'] ?: 1,
|
||||||
'create_time' => $now,
|
'create_time' => $now,
|
||||||
'update_time' => $now,
|
'update_time' => $now,
|
||||||
'custom_params' => $item['custom_params'],
|
'custom_params' => $item['custom_params'],
|
||||||
|
|
Loading…
Reference in New Issue