From ad57a6f9a5371ea9335d5b9f84e9abf32b584cd3 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 23 Dec 2024 17:02:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/admin/controller/LocalController.php diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php new file mode 100644 index 000000000..6a592345d --- /dev/null +++ b/app/admin/controller/LocalController.php @@ -0,0 +1,89 @@ +request->file('file'); + $reader = IOFactory::createReader('Xlsx'); + $spreadsheet = $reader->load($file->getRealPath()); + $data = $spreadsheet->getActiveSheet()->toArray(); + $updateCount = 0; + $finishCount = Redis::get('finishCount'); + $finishCount = empty($finishCount) ? 0 : $finishCount; + if ($finishCount >= count($data)) { + echo '数据已更新完成'; + return; + } + $max = $finishCount + 100; + foreach ($data as $k => $row) { + if ($k < (1 + $finishCount) || empty($row[0])) { + continue; + } + if ($k > $max) { + break; + } + $product = StoreProduct::where('id', $row[0])->field('id,store_name,top_cate_id,two_cate_id,cate_id')->findOrEmpty()->toArray(); + if (empty($product)) { + continue; + } + $result = $this->updateProduct($product, $row); + if ($result) { + $updateCount++; + } + } + Redis::set('finishCount', 100 + $finishCount); + echo '更新成功:' . $updateCount . '条'; + } + + public function updateProduct($product, $row) + { + $topCateName = rtrim($row[1], '类'); + $secondCateName = rtrim($row[2], '类'); + $cateName = rtrim($row[3], '类'); + $topCate = StoreCategory::where('name', $topCateName)->value('id'); + $updateData = []; + if (!empty($topCate) && $topCate != $product['top_cate_id']) { + $updateData['top_cate_id'] = $topCate; + } + $secondCateId = StoreCategory::where('pid', $topCate)->where('name', $secondCateName)->value('id'); + if (empty($secondCateId)) { + $secondCate = new StoreCategory(); + $secondCate->name = $secondCateName; + $secondCate->pid = $topCate; + $secondCate->save(); + $secondCateId = $secondCate->id; + } + if ($secondCateId != $product['two_cate_id']) { + $updateData['two_cate_id'] = $secondCateId; + } + $cateId = StoreCategory::where('pid', $secondCateId)->where('name', $cateName)->value('id'); + if (empty($cateId)) { + $cate = new StoreCategory(); + $cate->name = $cateName; + $cate->pid = $secondCateId; + $cate->save(); + $cateId = $cate->id; + } + if ($cateId != $product['cate_id']) { + $updateData['cate_id'] = $cateId; + } + if (!empty($updateData)) { + StoreProduct::where('id', $row[0])->update($updateData); + echo '更新成功ID:' . $row[0] . PHP_EOL; + return true; + } + return false; + } + +} \ No newline at end of file From a8acf3ae6742ce06b6b634866fb3d4b9020332ce Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sat, 15 Mar 2025 11:18:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beforehand_order/BeforehandOrderLogic.php | 25 ++++++++++++------- .../WarehouseProductLogic.php | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index fc89ae7a6..75579b135 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -431,6 +431,7 @@ class BeforehandOrderLogic extends BaseLogic // } else { // $price = StoreProductGroupPrice::where('product_id', $arr['product_id'])->where('group_id', $user_ship)->value('price') ?? 0; // } + $cost = StoreProduct::where('id', $arr['product_id'])->withTrashed()->value('cost') ?? 0; $data = [ 'warehouse_id' => $warehouse_id, 'product_id' => $arr['product_id'], @@ -443,6 +444,7 @@ class BeforehandOrderLogic extends BaseLogic 'admin_id' => $admin_id, 'total_price' => $arr['total_price'], 'price' => $arr['price'], + 'cost' => $cost, 'vip_price' => StoreProduct::where('id',$arr['product_id'])->withTrashed()->value('vip_price') ?? 0, 'purchase' => $arr['purchase'], 'oid' => $res['id'], @@ -958,18 +960,23 @@ class BeforehandOrderLogic extends BaseLogic $v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $v['store_name'] = $find['store_name']; $v['mark'] = $find['after_sales']; - if ($v['vip_price'] > 0) { - $v['pay_price'] = bcmul($v['vip_price'], $v['nums'], 2); - $price =$v['vip_price']; + if (isset($params['type']) && $params['type'] == 2) { + $price = $v['cost']; + $v['pay_price'] = bcmul($price, $v['nums'], 2); } else { - $price = StoreProductGroupPrice::where('product_id', $v['product_id'])->where('group_id', $user_ship)->value('price'); - if ($price > 0) { - $v['pay_price'] = bcmul($price, $v['nums'], 2); + if ($v['vip_price'] > 0) { + $v['pay_price'] = bcmul($v['vip_price'], $v['nums'], 2); + $price = $v['vip_price']; } else { - $price = $find['cost']; - $v['pay_price'] = bcmul($price, $v['nums'], 2); + $price = StoreProductGroupPrice::where('product_id', $v['product_id'])->where('group_id', $user_ship)->value('price'); + if ($price > 0) { + $v['pay_price'] = bcmul($price, $v['nums'], 2); + } else { + $price = $find['cost']; + $v['pay_price'] = bcmul($price, $v['nums'], 2); + } + WarehouseProduct::where('id', $v['id'])->update(['vip_price' => $price]); } - WarehouseProduct::where('id', $v['id'])->update(['vip_price' => $price]); } $v['purchase'] = $price; diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 01d4f5918..735ffe7a6 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -176,6 +176,7 @@ class WarehouseProductLogic extends BaseLogic 'price' => $params['price'] ?? 0, 'purchase' => $params['purchase'] ?? 0, 'vip_price' => $params['vip_price'] ?? 0, + 'cost' => $params['cost'] ?? 0, 'total_price' => $params['total_price'] ?? 0, 'admin_id' => $params['admin_id'], 'code' => $params['code'] ?? '',