Merge pull request 'dev' (#80) from dev into master

Reviewed-on: #80
This commit is contained in:
mkm 2023-11-30 14:26:04 +08:00
commit 520c35c751
3 changed files with 68 additions and 44 deletions

View File

@ -2507,16 +2507,6 @@ class StoreOrderRepository extends BaseRepository
$data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
if (!$data) return false;
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;
if ($type_id == 12) {
$product_type = 98; //供应链
@ -2529,6 +2519,7 @@ class StoreOrderRepository extends BaseRepository
$attr_two = explode('|', $datum['value']['attr_two']);
$attr = [];
$arr = [];
foreach ($attr_one as $key => $value) {
$attr[$value] = $attr_two[$key];
$arr[] = [
@ -2538,10 +2529,17 @@ class StoreOrderRepository extends BaseRepository
];
}
$array_values = array_values($attr);
$attr_implode= implode(',', $array_values);
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) {
$datas['product_id'] = $find['product_id'];
$datas['mer_id'] = $merId;
$datas['store_name'] = $datum['value']['store_name'];
@ -2549,10 +2547,8 @@ class StoreOrderRepository extends BaseRepository
$this->create_product_import_log($datas,0);
continue;
}
$is_update = false;
foreach ($attr as $kk => $vv) {
/**查询当前规格是否存在 */
/**查询当前规格属性是否存在 */
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
->find();
if ($attr_values_find) {
@ -2561,10 +2557,10 @@ class StoreOrderRepository extends BaseRepository
if (!in_array($vv, $attr_values)) {
$attr_values[] = $vv;
$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]);
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, implode(',', $array_values));
}
$is_update = true;
}
} else {
$datas = [
'product_id' => $find['product_id'],
@ -2574,7 +2570,7 @@ class StoreOrderRepository extends BaseRepository
}
}
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 {
//默认其他分类
@ -2640,6 +2636,10 @@ class StoreOrderRepository extends BaseRepository
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 = [
"image" => $image,
"slider_image" => $slider_image,
@ -2684,7 +2684,7 @@ class StoreOrderRepository extends BaseRepository
"cost" => $datum['value']['cost'],
"ot_price" => $datum['value']['price'],
"svip_price" => null,
"procure_price" => $datum['value']['procure_price'] ?? 0,
"procure_price" => $procure_price,
"stock" => 1,
"bar_code" => (int)$datum['value']['bar_code'],
"weight" => 0,
@ -2741,6 +2741,10 @@ class StoreOrderRepository extends BaseRepository
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;
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
$attrValue['unique'] = $unique;
@ -2751,7 +2755,7 @@ class StoreOrderRepository extends BaseRepository
$attrValue['cost'] = $datum['value']['cost'];
$attrValue['ot_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";
Db::name('store_product_attr_value')->insert($attrValue);
}

View File

@ -30,34 +30,42 @@ class Demo extends BaseController
{
public function index()
{
$mer_id = 65;
$mer_id = 104;
$file = request()->file('file');
$zip_name = explode('.', $file->getOriginalName())[0];
// 上传到本地服务器
$savename = \think\facade\Filesystem::putFile('zippic', $file);
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
$destination_path = public_path('uploads/pic/' . $dir.'_'.$zip_name);
mkdir($destination_path, 0777, true);
$zipFile = new \PhpZip\ZipFile();
$path = public_path('uploads/pic').$dir;
try {
$zipFile
->openFile(public_path('uploads').$savename) // open archive from file
->extractTo($destination_path) // add an entry from the string
// ->deleteFromRegex('~^\.~') // delete all hidden (Unix) files
->close(); // close archive
} catch (\PhpZip\Exception\ZipException $e) {
throw new \think\exception\HttpException(404,$e->getMessage());
} finally {
$zipFile->close();
$zip = new ZipArchive;
$filePath = public_path('uploads') . $savename;
$zip->open($filePath);
for ($i = 0; $i < $zip->numFiles; $i++) {
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
$filename = $this->transcoding($statInfo['name']);
$mkdFile = explode('/',$filename);
if ($statInfo['crc'] == 0) {
// 新建目录
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) {
// $zip->extractTo($destination_path);
// $zip->close();
// } else {
// throw new \think\exception\HttpException(404, '解压失败');
// }
$directory = $destination_path;
$directory = $path.'/'.$zip_name;
$files = scandir($directory);
$dir = 'def/' . date('Y-m-d');
$upload = UploadService::create();
@ -96,7 +104,7 @@ class Demo extends BaseController
}
/**详情图 */
if (is_numeric($arr[0])) {
$details[] = $directory . '/' . $file_two;
$details[] = $directory . '/' .$file.'/'. $file_two;
continue;
}
/**sku图 */
@ -128,6 +136,12 @@ class Demo extends BaseController
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
/**更新规格图片 */
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();
if ($store_product_attr_value) {
$oss = $upload->to($dir)->stream(file_get_contents($v));

View File

@ -59,7 +59,7 @@ class ImportPicJob implements JobInterface
}
/**详情图 */
if (is_numeric($arr[0])) {
$details[] = $directory . '/' . $file_two;
$details[] = $directory . '/' .$file.'/'. $file_two;
continue;
}
/**sku图 */
@ -89,6 +89,12 @@ class ImportPicJob implements JobInterface
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
/**更新规格图片 */
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();
if ($store_product_attr_value) {
$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'])) {
Db::name('store_product_content')
->where(['product_id' => $find['product_id']])
->update(['content' => json_encode($update_content)]);
->update(['content' => json_encode($update_content),'type'=>1]);
}
} else {
$update_content['product_id'] = $find['product_id'];
@ -136,7 +142,7 @@ class ImportPicJob implements JobInterface
public function create_product_import_log($data, $status = 1)
{
$data = [
'product_id' => $data['product_id'],
'product_id' => $data['product_id']??0,
'mer_id' => $data['mer_id'],
'name' => $data['store_name'],
'content' => $data['content'] ?? '',