From f21e4de51135884fb828d7060bbbb532de1fc9f1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 10:12:48 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 53 ++++++++++++++++++++++--------------- crmeb/jobs/ImportPicJob.php | 6 ++--- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 47dbea2b..8dd59220 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -30,34 +30,42 @@ class Demo extends BaseController { public function index() { - $mer_id = 65; + $mer_id = 36; $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图 */ @@ -150,8 +158,9 @@ class Demo extends BaseController } } else { $update_content['product_id'] = $find['product_id']; - Db::name('store_product_content') + $a=Db::name('store_product_content') ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); + halt($a,2222); } } catch (Exception $e) { halt($e->getMessage(), $e->getLine()); diff --git a/crmeb/jobs/ImportPicJob.php b/crmeb/jobs/ImportPicJob.php index dce0d55c..4b39b42b 100644 --- a/crmeb/jobs/ImportPicJob.php +++ b/crmeb/jobs/ImportPicJob.php @@ -59,7 +59,7 @@ class ImportPicJob implements JobInterface } /**详情图 */ if (is_numeric($arr[0])) { - $details[] = $directory . '/' . $file_two; + $details[] = $directory . '/' .$file.'/'. $file_two; continue; } /**sku图 */ @@ -107,7 +107,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 +136,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'] ?? '', From 395492c7b718b55c36e20a914eda8f16c4fcb544 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 10:24:43 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index fb700460..32100e26 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -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; //供应链 @@ -2640,6 +2630,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 +2678,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 +2735,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 +2749,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); } From 4a57b4e344758b2aa40688da09a8e1b82d2be751 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 10:45:06 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 15 ++++++++++----- crmeb/jobs/ImportPicJob.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index 8dd59220..dedd198a 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -30,7 +30,7 @@ class Demo extends BaseController { public function index() { - $mer_id = 36; + $mer_id = 104; $file = request()->file('file'); $zip_name = explode('.', $file->getOriginalName())[0]; // 上传到本地服务器 @@ -136,11 +136,17 @@ class Demo extends BaseController Db::name('store_product')->where('product_id', $find['product_id'])->update($update); /**更新规格图片 */ foreach ($sku_arr as $k => $v) { - $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); + $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' => $sku_name])->find(); if ($store_product_attr_value) { $oss = $upload->to($dir)->stream(file_get_contents($v)); Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name]) ->update(['image' => $oss->filePath]); } } @@ -158,9 +164,8 @@ class Demo extends BaseController } } else { $update_content['product_id'] = $find['product_id']; - $a=Db::name('store_product_content') + Db::name('store_product_content') ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); - halt($a,2222); } } catch (Exception $e) { halt($e->getMessage(), $e->getLine()); diff --git a/crmeb/jobs/ImportPicJob.php b/crmeb/jobs/ImportPicJob.php index 4b39b42b..d917b296 100644 --- a/crmeb/jobs/ImportPicJob.php +++ b/crmeb/jobs/ImportPicJob.php @@ -89,11 +89,17 @@ class ImportPicJob implements JobInterface Db::name('store_product')->where('product_id', $find['product_id'])->update($update); /**更新规格图片 */ foreach ($sku_arr as $k => $v) { - $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); + $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' => $sku_name])->find(); if ($store_product_attr_value) { $oss = $upload->to($dir)->stream(file_get_contents($v)); Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name]) ->update(['image' => $oss->filePath]); } } From 2f8dc934d5c1ebc1391b9b507ee07d0a67073a2b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 11:35:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 32100e26..6f935cba 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2519,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[] = [ @@ -2528,10 +2529,16 @@ 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; + } + $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']; @@ -2539,10 +2546,11 @@ 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) { @@ -2551,20 +2559,21 @@ 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; } - $is_update = true; } else { $datas = [ 'product_id' => $find['product_id'], 'attr_name' => $kk, 'attr_values' => $vv, ]; Db::name('store_product_attr')->insert($datas); + $is_update = true; } } 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 { //默认其他分类 From fa10cad90fa4cbff1e3d43cd776e3c68b54fa075 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 11:43:13 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Demo.php | 16 ++++++++-------- crmeb/jobs/ImportPicJob.php | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index dedd198a..1dc08689 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -136,17 +136,17 @@ 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' => $sku_name])->find(); + // $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)); Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name]) + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) ->update(['image' => $oss->filePath]); } } diff --git a/crmeb/jobs/ImportPicJob.php b/crmeb/jobs/ImportPicJob.php index d917b296..fbd93758 100644 --- a/crmeb/jobs/ImportPicJob.php +++ b/crmeb/jobs/ImportPicJob.php @@ -89,17 +89,17 @@ 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' => $sku_name])->find(); + // $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)); Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name]) + ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) ->update(['image' => $oss->filePath]); } } From 6a5acd02873ce90c6f2affa18240214e9e892ed5 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 30 Nov 2023 14:01:33 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/order/StoreOrderRepository.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 6f935cba..07fca14c 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2537,6 +2537,7 @@ class StoreOrderRepository extends BaseRepository }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']; @@ -2546,10 +2547,7 @@ 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(); @@ -2569,7 +2567,6 @@ class StoreOrderRepository extends BaseRepository 'attr_name' => $kk, 'attr_values' => $vv, ]; Db::name('store_product_attr')->insert($datas); - $is_update = true; } } if ($is_update == false) {