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/3] =?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/3] =?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'] ?? '', From 8bfe65cea9eec4b1f596d40c3b7479051f2c2906 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 17 Mar 2025 11:00:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=94=B9=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeforehandOrderCartInfoLogic.php | 2 +- .../PurchaseProductOfferLogic.php | 6 +++--- .../store_product_price/StoreProductPriceLogic.php | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php index 83fece739..061bcbdbd 100644 --- a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -459,7 +459,7 @@ class BeforehandOrderCartInfoLogic extends BaseLogic $product = StoreProduct::where('id', $purchaseProductOffer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find(); if (!in_array($beforehandOrder['order_type'], [6, 9])) { - PurchaseProductOfferLogic::setProductGroupPrice($purchaseProductOffer, $product, $params['warehouse_id']); + PurchaseProductOfferLogic::setProductPrice($purchaseProductOffer, $product, $params['warehouse_id']); } Db::commit(); diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index e5f838599..c1f5a5745 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -324,7 +324,7 @@ class PurchaseProductOfferLogic extends BaseLogic BeforehandOrder::where('id', $offer['bhoid'])->update(['pay_price' => $pay_price]); $product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('id,store_name,top_cate_id,two_cate_id,cate_id')->find(); $offer['purchase']=$price; - self::setProductGroupPrice($offer, $product); + self::setProductPrice($offer, $product); Db::commit(); return true; } catch (\Throwable $e) { @@ -380,7 +380,7 @@ class PurchaseProductOfferLogic extends BaseLogic } /** - * 设置商品分组价格 + * 设置商品价格 * @param $params * @param $product * @return void @@ -388,7 +388,7 @@ class PurchaseProductOfferLogic extends BaseLogic * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function setProductGroupPrice($params, $product, $warehouseId = 0) + public static function setProductPrice($params, $product, $warehouseId = 0) { $priceConfig = []; $data = [ diff --git a/app/admin/logic/store_product_price/StoreProductPriceLogic.php b/app/admin/logic/store_product_price/StoreProductPriceLogic.php index e3d850d07..6d54fedca 100644 --- a/app/admin/logic/store_product_price/StoreProductPriceLogic.php +++ b/app/admin/logic/store_product_price/StoreProductPriceLogic.php @@ -99,15 +99,16 @@ class StoreProductPriceLogic extends BaseLogic 'purchase' => $find['purchase'], 'cost' => $find['cost'], 'vip_price' => $find['vip_price'], - 'price' => $find['price'] + 'price' => $find['vip_price'], + 'ot_price' => $find['price'] ]); StoreBranchProduct::where('product_id', $find['product_id'])->update([ 'purchase' => $find['purchase'], 'cost' => $find['cost'], 'vip_price' => $find['vip_price'], - 'price' => $find['price'] + 'price' => $find['vip_price'], + 'ot_price' => $find['price'] ]); -// self::setProductGroupPrice($find); } Db::commit(); return true; @@ -172,15 +173,16 @@ class StoreProductPriceLogic extends BaseLogic 'purchase' => $find['purchase'] ?? 0, 'cost' => $find['cost'] ?? 0, 'vip_price' => $find['vip_price'] ?? 0, - 'price' => $find['price'] ?? 0 + 'price' => $find['vip_price'] ?? 0, + 'ot_price' => $find['price'] ?? 0, ]); StoreBranchProduct::where('product_id', $find['product_id'])->update([ 'purchase' => $find['purchase'] ?? 0, 'cost' => $find['cost'] ?? 0, 'vip_price' => $find['vip_price'] ?? 0, - 'price' => $find['price'] ?? 0 + 'price' => $find['vip_price'] ?? 0, + 'ot_price' => $find['price'] ?? 0, ]); -// self::setProductGroupPrice($find); } Db::commit(); return true;