commit
520c35c751
@ -2507,16 +2507,6 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
$data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
|
$data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
|
||||||
if (!$data) return false;
|
if (!$data) return false;
|
||||||
unset($data[0]);
|
unset($data[0]);
|
||||||
// $mer_cate_id = Db::name('store_category')->where('mer_id', $merId)->where('cate_name', '默认分类')->value('store_category_id');
|
|
||||||
// if (!$mer_cate_id || $mer_cate_id == 0) {
|
|
||||||
// $mer_cate = ['pid' => 0, 'cate_name' => '默认分类', 'path' => '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
|
||||||
// $mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
|
|
||||||
// $mer_cate['pid'] = $mer_cate_id;
|
|
||||||
// $mer_cate['path'] = '/' . $mer_cate_id . '/';
|
|
||||||
// $mer_cate['level'] = 1;
|
|
||||||
// $mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
|
|
||||||
// }
|
|
||||||
// $typeCode = Db::name('merchant_type')->where('mer_type_id', $merId)->value('type_code');
|
|
||||||
$product_type = 0;
|
$product_type = 0;
|
||||||
if ($type_id == 12) {
|
if ($type_id == 12) {
|
||||||
$product_type = 98; //供应链
|
$product_type = 98; //供应链
|
||||||
@ -2529,6 +2519,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
$attr_two = explode('|', $datum['value']['attr_two']);
|
$attr_two = explode('|', $datum['value']['attr_two']);
|
||||||
$attr = [];
|
$attr = [];
|
||||||
$arr = [];
|
$arr = [];
|
||||||
|
|
||||||
foreach ($attr_one as $key => $value) {
|
foreach ($attr_one as $key => $value) {
|
||||||
$attr[$value] = $attr_two[$key];
|
$attr[$value] = $attr_two[$key];
|
||||||
$arr[] = [
|
$arr[] = [
|
||||||
@ -2538,10 +2529,17 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
$array_values = array_values($attr);
|
$array_values = array_values($attr);
|
||||||
|
$attr_implode= implode(',', $array_values);
|
||||||
if ($find) {
|
if ($find) {
|
||||||
$store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find();
|
$store_product_attr_value_where['product_id']=$find['product_id'];
|
||||||
|
if($datum['value']['bar_code']!=''){
|
||||||
|
$store_product_attr_value_where['bar_code']=$datum['value']['bar_code'];
|
||||||
|
}else{
|
||||||
|
$store_product_attr_value_where['sku']=$attr_implode;
|
||||||
|
}
|
||||||
|
$is_update = false;
|
||||||
|
$store_product_attr_value = Db::name('store_product_attr_value')->where($store_product_attr_value_where)->find();
|
||||||
if ($store_product_attr_value) {
|
if ($store_product_attr_value) {
|
||||||
|
|
||||||
$datas['product_id'] = $find['product_id'];
|
$datas['product_id'] = $find['product_id'];
|
||||||
$datas['mer_id'] = $merId;
|
$datas['mer_id'] = $merId;
|
||||||
$datas['store_name'] = $datum['value']['store_name'];
|
$datas['store_name'] = $datum['value']['store_name'];
|
||||||
@ -2549,10 +2547,8 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
$this->create_product_import_log($datas,0);
|
$this->create_product_import_log($datas,0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$is_update = false;
|
|
||||||
foreach ($attr as $kk => $vv) {
|
foreach ($attr as $kk => $vv) {
|
||||||
|
/**查询当前规格属性是否存在 */
|
||||||
/**查询当前规格是否存在 */
|
|
||||||
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
|
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
|
||||||
->find();
|
->find();
|
||||||
if ($attr_values_find) {
|
if ($attr_values_find) {
|
||||||
@ -2561,10 +2557,10 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
if (!in_array($vv, $attr_values)) {
|
if (!in_array($vv, $attr_values)) {
|
||||||
$attr_values[] = $vv;
|
$attr_values[] = $vv;
|
||||||
$attr_values = implode('-!-', $attr_values);
|
$attr_values = implode('-!-', $attr_values);
|
||||||
|
//更新规格属性
|
||||||
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
|
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
|
||||||
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, implode(',', $array_values));
|
|
||||||
}
|
|
||||||
$is_update = true;
|
$is_update = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$datas = [
|
$datas = [
|
||||||
'product_id' => $find['product_id'],
|
'product_id' => $find['product_id'],
|
||||||
@ -2574,7 +2570,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($is_update == false) {
|
if ($is_update == false) {
|
||||||
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, implode(',', $array_values));
|
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, $attr_implode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//默认其他分类
|
//默认其他分类
|
||||||
@ -2640,6 +2636,10 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
|
0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
$procure_price=0;
|
||||||
|
if(!empty($datum['value']['procure_price'])){
|
||||||
|
$procure_price=$datum['value']['procure_price'];
|
||||||
|
}
|
||||||
$datas = [
|
$datas = [
|
||||||
"image" => $image,
|
"image" => $image,
|
||||||
"slider_image" => $slider_image,
|
"slider_image" => $slider_image,
|
||||||
@ -2684,7 +2684,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
"cost" => $datum['value']['cost'],
|
"cost" => $datum['value']['cost'],
|
||||||
"ot_price" => $datum['value']['price'],
|
"ot_price" => $datum['value']['price'],
|
||||||
"svip_price" => null,
|
"svip_price" => null,
|
||||||
"procure_price" => $datum['value']['procure_price'] ?? 0,
|
"procure_price" => $procure_price,
|
||||||
"stock" => 1,
|
"stock" => 1,
|
||||||
"bar_code" => (int)$datum['value']['bar_code'],
|
"bar_code" => (int)$datum['value']['bar_code'],
|
||||||
"weight" => 0,
|
"weight" => 0,
|
||||||
@ -2741,6 +2741,10 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
|
|
||||||
public function create_product_attr_value($find, $datum, $product_type, $attr_values, $merId, $sku)
|
public function create_product_attr_value($find, $datum, $product_type, $attr_values, $merId, $sku)
|
||||||
{
|
{
|
||||||
|
$procure_price=0;
|
||||||
|
if(!empty($datum['value']['procure_price'])){
|
||||||
|
$procure_price=$datum['value']['procure_price'];
|
||||||
|
}
|
||||||
$attrValue['stock'] = 1;
|
$attrValue['stock'] = 1;
|
||||||
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
|
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
|
||||||
$attrValue['unique'] = $unique;
|
$attrValue['unique'] = $unique;
|
||||||
@ -2751,7 +2755,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
$attrValue['cost'] = $datum['value']['cost'];
|
$attrValue['cost'] = $datum['value']['cost'];
|
||||||
$attrValue['ot_price'] = $datum['value']['price'];
|
$attrValue['ot_price'] = $datum['value']['price'];
|
||||||
$attrValue['price'] = $datum['value']['price'];
|
$attrValue['price'] = $datum['value']['price'];
|
||||||
$attrValue['procure_price'] = $datum['value']['procure_price'];
|
$attrValue['procure_price'] = $procure_price;
|
||||||
$attrValue["image"] = "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png";
|
$attrValue["image"] = "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png";
|
||||||
Db::name('store_product_attr_value')->insert($attrValue);
|
Db::name('store_product_attr_value')->insert($attrValue);
|
||||||
}
|
}
|
||||||
|
@ -30,34 +30,42 @@ class Demo extends BaseController
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$mer_id = 65;
|
$mer_id = 104;
|
||||||
$file = request()->file('file');
|
$file = request()->file('file');
|
||||||
$zip_name = explode('.', $file->getOriginalName())[0];
|
$zip_name = explode('.', $file->getOriginalName())[0];
|
||||||
// 上传到本地服务器
|
// 上传到本地服务器
|
||||||
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
||||||
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
|
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
|
||||||
$destination_path = public_path('uploads/pic/' . $dir.'_'.$zip_name);
|
$path = public_path('uploads/pic').$dir;
|
||||||
mkdir($destination_path, 0777, true);
|
|
||||||
$zipFile = new \PhpZip\ZipFile();
|
|
||||||
try {
|
try {
|
||||||
$zipFile
|
$zip = new ZipArchive;
|
||||||
->openFile(public_path('uploads').$savename) // open archive from file
|
$filePath = public_path('uploads') . $savename;
|
||||||
->extractTo($destination_path) // add an entry from the string
|
$zip->open($filePath);
|
||||||
// ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
|
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||||
->close(); // close archive
|
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
|
||||||
} catch (\PhpZip\Exception\ZipException $e) {
|
$filename = $this->transcoding($statInfo['name']);
|
||||||
throw new \think\exception\HttpException(404,$e->getMessage());
|
$mkdFile = explode('/',$filename);
|
||||||
} finally {
|
if ($statInfo['crc'] == 0) {
|
||||||
$zipFile->close();
|
// 新建目录
|
||||||
|
if (!file_exists($path . '/' . $filename)) {
|
||||||
|
mkdir($path . '/' . $filename, 0777, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 拷贝文件
|
||||||
|
if(count($mkdFile)==3){
|
||||||
|
if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) {
|
||||||
|
mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true);
|
||||||
|
}
|
||||||
|
copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ($zip->open(public_path('uploads').$savename) === TRUE) {
|
$directory = $path.'/'.$zip_name;
|
||||||
// $zip->extractTo($destination_path);
|
|
||||||
// $zip->close();
|
|
||||||
// } else {
|
|
||||||
// throw new \think\exception\HttpException(404, '解压失败');
|
|
||||||
// }
|
|
||||||
$directory = $destination_path;
|
|
||||||
$files = scandir($directory);
|
$files = scandir($directory);
|
||||||
$dir = 'def/' . date('Y-m-d');
|
$dir = 'def/' . date('Y-m-d');
|
||||||
$upload = UploadService::create();
|
$upload = UploadService::create();
|
||||||
@ -96,7 +104,7 @@ class Demo extends BaseController
|
|||||||
}
|
}
|
||||||
/**详情图 */
|
/**详情图 */
|
||||||
if (is_numeric($arr[0])) {
|
if (is_numeric($arr[0])) {
|
||||||
$details[] = $directory . '/' . $file_two;
|
$details[] = $directory . '/' .$file.'/'. $file_two;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/**sku图 */
|
/**sku图 */
|
||||||
@ -128,6 +136,12 @@ class Demo extends BaseController
|
|||||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||||
/**更新规格图片 */
|
/**更新规格图片 */
|
||||||
foreach ($sku_arr as $k => $v) {
|
foreach ($sku_arr as $k => $v) {
|
||||||
|
// $sku = explode(',', $k);
|
||||||
|
// if(count($sku)==2){
|
||||||
|
// $sku_name=$sku[0];
|
||||||
|
// }else{
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
||||||
if ($store_product_attr_value) {
|
if ($store_product_attr_value) {
|
||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||||
|
@ -59,7 +59,7 @@ class ImportPicJob implements JobInterface
|
|||||||
}
|
}
|
||||||
/**详情图 */
|
/**详情图 */
|
||||||
if (is_numeric($arr[0])) {
|
if (is_numeric($arr[0])) {
|
||||||
$details[] = $directory . '/' . $file_two;
|
$details[] = $directory . '/' .$file.'/'. $file_two;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/**sku图 */
|
/**sku图 */
|
||||||
@ -89,6 +89,12 @@ class ImportPicJob implements JobInterface
|
|||||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||||
/**更新规格图片 */
|
/**更新规格图片 */
|
||||||
foreach ($sku_arr as $k => $v) {
|
foreach ($sku_arr as $k => $v) {
|
||||||
|
// $sku = explode(',', $k);
|
||||||
|
// if(count($sku)==2){
|
||||||
|
// $sku_name=$sku[0];
|
||||||
|
// }else{
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
||||||
if ($store_product_attr_value) {
|
if ($store_product_attr_value) {
|
||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||||
@ -107,7 +113,7 @@ class ImportPicJob implements JobInterface
|
|||||||
if (isset($update_content['image']) && !empty($update_content['image'])) {
|
if (isset($update_content['image']) && !empty($update_content['image'])) {
|
||||||
Db::name('store_product_content')
|
Db::name('store_product_content')
|
||||||
->where(['product_id' => $find['product_id']])
|
->where(['product_id' => $find['product_id']])
|
||||||
->update(['content' => json_encode($update_content)]);
|
->update(['content' => json_encode($update_content),'type'=>1]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$update_content['product_id'] = $find['product_id'];
|
$update_content['product_id'] = $find['product_id'];
|
||||||
@ -136,7 +142,7 @@ class ImportPicJob implements JobInterface
|
|||||||
public function create_product_import_log($data, $status = 1)
|
public function create_product_import_log($data, $status = 1)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'product_id' => $data['product_id'],
|
'product_id' => $data['product_id']??0,
|
||||||
'mer_id' => $data['mer_id'],
|
'mer_id' => $data['mer_id'],
|
||||||
'name' => $data['store_name'],
|
'name' => $data['store_name'],
|
||||||
'content' => $data['content'] ?? '',
|
'content' => $data['content'] ?? '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user