From 844c085df52beba8567932294835b58d4f360fa4 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 30 Dec 2024 16:31:28 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E5=88=97=E8=A1=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BB=B7=E6=A0=BC=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 101 ++++++++++++++++++++- app/admin/lists/supplier/SupplierLists.php | 2 +- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index 485cd662f..11841001a 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -4,13 +4,112 @@ namespace app\admin\controller; use app\common\model\store_category\StoreCategory; use app\common\model\store_product\StoreProduct; +use app\common\model\store_product_price\StoreProductPrice; use PhpOffice\PhpSpreadsheet\IOFactory; use support\Redis; +use think\facade\Db; class LocalController extends BaseAdminController { - public $notNeedLogin = []; + public $notNeedLogin = ['setPrice']; + + public function setPrice() + { + $file = $this->request->file('file'); + $reader = IOFactory::createReader('Xlsx'); + $spreadsheet = $reader->load($file->getRealPath()); + $data = $spreadsheet->getActiveSheet()->toArray(); + $insert = []; + $productIds = []; + foreach ($data as $k => $row) { + if ($k < 2) { + continue; + } + if (empty($row[0])) { + continue; + } + $productId = intval($row[0]); + if (empty($productId)) { + continue; + } + $productIds[] = $productId; + } + $products = StoreProduct::whereIn('id', $productIds)->field('id,store_name')->select()->toArray(); + $products = reset_index($products, 'id'); + $lastPurchasePrices = StoreProductPrice::whereIn('product_id', $productIds)->where('status', 1)->order('id desc')->select()->toArray(); + $lastPurchasePrices = reset_index($lastPurchasePrices, 'product_id'); + foreach ($data as $k => $row) { + if ($k < 2) { + continue; + } + if (empty($row[0])) { + continue; + } + $productId = intval($row[0]); + if (empty($productId)) { + continue; + } + $product = $products[$productId] ?? []; + if (empty($product)) { + continue; + } + $lastPurchasePrice = $lastPurchasePrices[$productId] ?? []; + if (empty($lastPurchasePrice)) { + continue; + } + $storeRate = rtrim($row[4] ?? 0, '%'); + $row[5] = rtrim($row[5] ?? 0, '%'); + $row[7] = rtrim($row[7] ?? 0, '%'); + $row[9] = rtrim($row[9] ?? 0, '%'); + $row[11] = rtrim($row[11] ?? 0, '%'); + $row[13] = rtrim($row[13] ?? 0, '%'); + $row[15] = rtrim($row[15] ?? 0, '%'); + $row[17] = rtrim($row[17] ?? 0, '%'); + $row[19] = rtrim($row[19] ?? 0, '%'); + $row[21] = rtrim($row[21] ?? 0, '%'); + $row[23] = rtrim($row[23] ?? 0, '%'); + $row[25] = rtrim($row[25] ?? 0, '%'); + $row[27] = rtrim($row[27] ?? 0, '%'); + $row[29] = rtrim($row[29] ?? 0, '%'); + $row[31] = rtrim($row[31] ?? 0, '%'); + $row[33] = rtrim($row[33] ?? 0, '%'); + $row[35] = rtrim($row[35] ?? 0, '%'); + $row[37] = rtrim($row[37] ?? 0, '%'); + $row[39] = rtrim($row[39] ?? 0, '%'); + $row[41] = rtrim($row[41] ?? 0, '%'); + $storePrice = $lastPurchasePrice['purchase_price'] * (1 + $storeRate / 100); + $item = [ + 'product_id' => $product['id'], + 'product_name' => $product['store_name'], + 'store_price' => $storePrice, + 'price_set' => json_encode([ + ['user_ship' => 23, 'rate' => $row[5], 'price' => bcmul($storePrice, (1 + $row[5] / 100), 2)], + ['user_ship' => 24, 'rate' => $row[7], 'price' => bcmul($storePrice, (1 + $row[7] / 100), 2)], + ['user_ship' => 25, 'rate' => $row[9], 'price' => bcmul($storePrice, (1 + $row[9] / 100), 2)], + ['user_ship' => 26, 'rate' => $row[11], 'price' => bcmul($storePrice, (1 + $row[11] / 100), 2)], + ['user_ship' => 27, 'rate' => $row[13], 'price' => bcmul($storePrice, (1 + $row[13] / 100), 2)], + ['user_ship' => 28, 'rate' => $row[15], 'price' => bcmul($storePrice, (1 + $row[15] / 100), 2)], + ['user_ship' => 29, 'rate' => $row[17], 'price' => bcmul($storePrice, (1 + $row[17] / 100), 2)], + ['user_ship' => 30, 'rate' => $row[19], 'price' => bcmul($storePrice, (1 + $row[19] / 100), 2)], + ['user_ship' => 31, 'rate' => $row[21], 'price' => bcmul($storePrice, (1 + $row[21] / 100), 2)], + ['user_ship' => 32, 'rate' => $row[23], 'price' => bcmul($storePrice, (1 + $row[23] / 100), 2)], + ['user_ship' => 33, 'rate' => $row[25], 'price' => bcmul($storePrice, (1 + $row[25] / 100), 2)], + ['user_ship' => 34, 'rate' => $row[27], 'price' => bcmul($storePrice, (1 + $row[27] / 100), 2)], + ['user_ship' => 35, 'rate' => $row[29], 'price' => bcmul($storePrice, (1 + $row[29] / 100), 2)], + ['user_ship' => 36, 'rate' => $row[31], 'price' => bcmul($storePrice, (1 + $row[31] / 100), 2)], + ['user_ship' => 37, 'rate' => $row[33], 'price' => bcmul($storePrice, (1 + $row[33] / 100), 2)], + ['user_ship' => 38, 'rate' => $row[35], 'price' => bcmul($storePrice, (1 + $row[35] / 100), 2)], + ['user_ship' => 39, 'rate' => $row[37], 'price' => bcmul($storePrice, (1 + $row[37] / 100), 2)], + ['user_ship' => 40, 'rate' => $row[39], 'price' => bcmul($storePrice, (1 + $row[39] / 100), 2)], + ['user_ship' => 41, 'rate' => $row[41], 'price' => bcmul($storePrice, (1 + $row[41] / 100), 2)], + ], JSON_UNESCAPED_UNICODE), + ]; + $insert[] = $item; + } + $count = Db::name('product_price_set')->insertAll($insert); + return $this->success('插入成功:' . $count . '条'); + } public function fixCategory() { diff --git a/app/admin/lists/supplier/SupplierLists.php b/app/admin/lists/supplier/SupplierLists.php index c0757cda9..9d829980a 100644 --- a/app/admin/lists/supplier/SupplierLists.php +++ b/app/admin/lists/supplier/SupplierLists.php @@ -45,7 +45,7 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface { return Supplier::where($this->searchWhere) ->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark']) - ->limit($this->limitOffset, $this->limitLength) + ->limit($this->limitOffset, 100) ->order(['id' => 'desc']) ->select()->each(function ($item) { $item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price'); From c2a5ee0fdc3ec1c073427a470c1fdf71517badfb Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 30 Dec 2024 17:57:27 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 122 ++++++++++++----------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index 11841001a..bba0ebdd3 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -4,7 +4,7 @@ namespace app\admin\controller; use app\common\model\store_category\StoreCategory; use app\common\model\store_product\StoreProduct; -use app\common\model\store_product_price\StoreProductPrice; +use app\common\model\store_product_group_price\StoreProductGroupPrice; use PhpOffice\PhpSpreadsheet\IOFactory; use support\Redis; use think\facade\Db; @@ -21,6 +21,7 @@ class LocalController extends BaseAdminController $spreadsheet = $reader->load($file->getRealPath()); $data = $spreadsheet->getActiveSheet()->toArray(); $insert = []; + $update = []; $productIds = []; foreach ($data as $k => $row) { if ($k < 2) { @@ -35,10 +36,8 @@ class LocalController extends BaseAdminController } $productIds[] = $productId; } - $products = StoreProduct::whereIn('id', $productIds)->field('id,store_name')->select()->toArray(); + $products = StoreProduct::whereIn('id', $productIds)->field('id,store_name,purchase')->select()->toArray(); $products = reset_index($products, 'id'); - $lastPurchasePrices = StoreProductPrice::whereIn('product_id', $productIds)->where('status', 1)->order('id desc')->select()->toArray(); - $lastPurchasePrices = reset_index($lastPurchasePrices, 'product_id'); foreach ($data as $k => $row) { if ($k < 2) { continue; @@ -54,60 +53,71 @@ class LocalController extends BaseAdminController if (empty($product)) { continue; } - $lastPurchasePrice = $lastPurchasePrices[$productId] ?? []; - if (empty($lastPurchasePrice)) { - continue; - } - $storeRate = rtrim($row[4] ?? 0, '%'); - $row[5] = rtrim($row[5] ?? 0, '%'); - $row[7] = rtrim($row[7] ?? 0, '%'); - $row[9] = rtrim($row[9] ?? 0, '%'); - $row[11] = rtrim($row[11] ?? 0, '%'); - $row[13] = rtrim($row[13] ?? 0, '%'); - $row[15] = rtrim($row[15] ?? 0, '%'); - $row[17] = rtrim($row[17] ?? 0, '%'); - $row[19] = rtrim($row[19] ?? 0, '%'); - $row[21] = rtrim($row[21] ?? 0, '%'); - $row[23] = rtrim($row[23] ?? 0, '%'); - $row[25] = rtrim($row[25] ?? 0, '%'); - $row[27] = rtrim($row[27] ?? 0, '%'); - $row[29] = rtrim($row[29] ?? 0, '%'); - $row[31] = rtrim($row[31] ?? 0, '%'); - $row[33] = rtrim($row[33] ?? 0, '%'); - $row[35] = rtrim($row[35] ?? 0, '%'); - $row[37] = rtrim($row[37] ?? 0, '%'); - $row[39] = rtrim($row[39] ?? 0, '%'); - $row[41] = rtrim($row[41] ?? 0, '%'); - $storePrice = $lastPurchasePrice['purchase_price'] * (1 + $storeRate / 100); - $item = [ - 'product_id' => $product['id'], - 'product_name' => $product['store_name'], - 'store_price' => $storePrice, - 'price_set' => json_encode([ - ['user_ship' => 23, 'rate' => $row[5], 'price' => bcmul($storePrice, (1 + $row[5] / 100), 2)], - ['user_ship' => 24, 'rate' => $row[7], 'price' => bcmul($storePrice, (1 + $row[7] / 100), 2)], - ['user_ship' => 25, 'rate' => $row[9], 'price' => bcmul($storePrice, (1 + $row[9] / 100), 2)], - ['user_ship' => 26, 'rate' => $row[11], 'price' => bcmul($storePrice, (1 + $row[11] / 100), 2)], - ['user_ship' => 27, 'rate' => $row[13], 'price' => bcmul($storePrice, (1 + $row[13] / 100), 2)], - ['user_ship' => 28, 'rate' => $row[15], 'price' => bcmul($storePrice, (1 + $row[15] / 100), 2)], - ['user_ship' => 29, 'rate' => $row[17], 'price' => bcmul($storePrice, (1 + $row[17] / 100), 2)], - ['user_ship' => 30, 'rate' => $row[19], 'price' => bcmul($storePrice, (1 + $row[19] / 100), 2)], - ['user_ship' => 31, 'rate' => $row[21], 'price' => bcmul($storePrice, (1 + $row[21] / 100), 2)], - ['user_ship' => 32, 'rate' => $row[23], 'price' => bcmul($storePrice, (1 + $row[23] / 100), 2)], - ['user_ship' => 33, 'rate' => $row[25], 'price' => bcmul($storePrice, (1 + $row[25] / 100), 2)], - ['user_ship' => 34, 'rate' => $row[27], 'price' => bcmul($storePrice, (1 + $row[27] / 100), 2)], - ['user_ship' => 35, 'rate' => $row[29], 'price' => bcmul($storePrice, (1 + $row[29] / 100), 2)], - ['user_ship' => 36, 'rate' => $row[31], 'price' => bcmul($storePrice, (1 + $row[31] / 100), 2)], - ['user_ship' => 37, 'rate' => $row[33], 'price' => bcmul($storePrice, (1 + $row[33] / 100), 2)], - ['user_ship' => 38, 'rate' => $row[35], 'price' => bcmul($storePrice, (1 + $row[35] / 100), 2)], - ['user_ship' => 39, 'rate' => $row[37], 'price' => bcmul($storePrice, (1 + $row[37] / 100), 2)], - ['user_ship' => 40, 'rate' => $row[39], 'price' => bcmul($storePrice, (1 + $row[39] / 100), 2)], - ['user_ship' => 41, 'rate' => $row[41], 'price' => bcmul($storePrice, (1 + $row[41] / 100), 2)], - ], JSON_UNESCAPED_UNICODE), + $groupIds = [ + 5 => 23, + 7 => 24, + 9 => 25, + 11 => 26, + 13 => 27, + 15 => 28, + 17 => 29, + 19 => 30, + 21 => 31, + 23 => 32, + 25 => 33, + 27 => 34, + 29 => 35, + 31 => 36, + 33 => 37, + 35 => 1, + 37 => 18, + 39 => 22, ]; - $insert[] = $item; + for ($i = 5; $i < 35; $i = $i + 2) { + $rate = intval(rtrim($row[$i] ?? 0, '%')); + if (empty($rate)) { + continue; + } + $price = $row[$i + 1] ?? 0; + if (empty($price)) { + $price = $product['purchase'] * (1 + $rate / 100); + } + $item = [ + 'product_id' => $productId, + 'group_id' => $groupIds[$i], + 'price_type' => 3, + 'base_rate' => 100 + $rate, + 'price' => $price + ]; + $insert[] = $item; + } + $productGroupPrices = StoreProductGroupPrice::where('product_id', $productId)->whereIn('group_id', [1, 18, 22])->select()->toArray(); + $groupIds = array_flip($groupIds); + foreach ($productGroupPrices as $productGroupPrice) { + $cellId = $groupIds[$productGroupPrice['group_id']] ?? 0; + $rate = intval(rtrim($row[$cellId] ?? 0, '%')); + if (empty($rate)) { + continue; + } + $price = $row[$cellId + 1] ?? 0; + if (empty($price)) { + $price = $product['purchase'] * (1 + $rate / 100); + } + if ($price != $productGroupPrice['price']) { + $update[] = [ + 'id' => $productGroupPrice['id'], + 'base_rate' => $rate, + 'price' => $price, + ]; + } + } + } + if (count($insert) > 0) { + StoreProductGroupPrice::insertAll($insert); + } + if (count($update) > 0) { + (new StoreProductGroupPrice())->saveAll($update); } - $count = Db::name('product_price_set')->insertAll($insert); return $this->success('插入成功:' . $count . '条'); } From aee0609d171b84e8fb95d6ad2f07036712672323 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Tue, 31 Dec 2024 11:29:25 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/LocalController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index bba0ebdd3..173bd8536 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -7,7 +7,6 @@ use app\common\model\store_product\StoreProduct; use app\common\model\store_product_group_price\StoreProductGroupPrice; use PhpOffice\PhpSpreadsheet\IOFactory; use support\Redis; -use think\facade\Db; class LocalController extends BaseAdminController { @@ -118,7 +117,7 @@ class LocalController extends BaseAdminController if (count($update) > 0) { (new StoreProductGroupPrice())->saveAll($update); } - return $this->success('插入成功:' . $count . '条'); + return $this->success('插入成功:' . count($insert) . '条,更新成功:' . count($update) . '条'); } public function fixCategory() From 733adc5091beae593181b8dc1db28df910076016 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Tue, 31 Dec 2024 13:35:42 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BB=B7=E6=A0=BC=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseProductOfferLogic.php | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 7caa7a63f..d1c286d2a 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -431,14 +431,30 @@ class PurchaseProductOfferLogic extends BaseLogic public static function getProductCatePriceRate($product) { $productCatePriceRate = StoreCategory::where('id', $product['cate_id'])->value('price_rate'); - if (!empty($productCatePriceRate)) { + if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) { return $productCatePriceRate; } $productCatePriceRate = StoreCategory::where('id', $product['two_cate_id'])->value('price_rate'); - if (!empty($productCatePriceRate)) { + if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) { return $productCatePriceRate; } - return StoreCategory::where('id', $product['top_cate_id'])->value('price_rate'); + $productCatePriceRate = StoreCategory::where('id', $product['top_cate_id'])->value('price_rate'); + if (!empty($productCatePriceRate) && self::hasPurchase($productCatePriceRate)) { + return $productCatePriceRate; + } + return []; + } + + public static function hasPurchase(array $productCatePriceRate): bool + { + $res = true; + foreach ($productCatePriceRate as $item) { + if ($item['id'] == 21 && empty($item['rate'])) { + $res = false; + break; + } + } + return $res; } } From 77a1b62bb3ca7d3a684940dfb57c00b24669d2c2 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Tue, 31 Dec 2024 14:13:35 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BB=B7=E6=A0=BC=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../purchase_product_offer/PurchaseProductOfferLogic.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index d1c286d2a..fd04f6b2a 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -378,7 +378,13 @@ class PurchaseProductOfferLogic extends BaseLogic break; } } + if (empty($storeProductGroupPrice)) { + return; + } foreach ($productCatePriceRate as $k => $v) { + if (empty($v['rate'])) { + continue; + } if ($v['id'] == 4 &&$purchase>0) { //商户 $data['cost_lv'] = bcdiv($v['rate'], 100, 2); From ec78cd49538b1e17bb3e151e711d97b979722f43 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Tue, 31 Dec 2024 16:07:44 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/lists/store_category/StoreCategoryLists.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/admin/lists/store_category/StoreCategoryLists.php b/app/admin/lists/store_category/StoreCategoryLists.php index e9e672069..459f3e5e0 100644 --- a/app/admin/lists/store_category/StoreCategoryLists.php +++ b/app/admin/lists/store_category/StoreCategoryLists.php @@ -57,6 +57,9 @@ class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterf unset($priceRate[100003], $priceRate[100004]); $temp = []; foreach ($userGroups as $userGroup) { + if (!isset($priceRate[$userGroup['id']])) { + continue; + } if ($userGroup['id'] == 21 && !empty($priceRate[100001]) && empty($userGroup['rate'])) { $userGroup['rate'] = $priceRate[100001]['rate']; unset($priceRate[100001]); From 2666241796fec8eae3c7f358e40fd93b1282c8e3 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Tue, 31 Dec 2024 17:41:13 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/dict/DictData.php | 10 ++++++++ process/Task.php | 39 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/app/common/model/dict/DictData.php b/app/common/model/dict/DictData.php index 22a72836b..b4f24bcbb 100644 --- a/app/common/model/dict/DictData.php +++ b/app/common/model/dict/DictData.php @@ -44,4 +44,14 @@ class DictData extends BaseModel return $data['status'] ? '正常' : '停用'; } + public static function getDictValue($type, $key) + { + $dictType = DictType::where('type', $type)->where('status', 1)->find(); + if ($dictType) { + $dictData = DictData::where('type_id', $dictType['id'])->where('name', $key)->where('status', 1)->value('value'); + return empty($dictData) ? '' : $dictData; + } + return ''; + } + } \ No newline at end of file diff --git a/process/Task.php b/process/Task.php index 198660c65..aa10565b3 100644 --- a/process/Task.php +++ b/process/Task.php @@ -4,11 +4,14 @@ namespace process; use app\common\enum\OrderEnum; use app\common\logic\PayNotifyLogic; +use app\common\model\dict\DictData; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\store_product_price\StoreProductPrice; use app\common\model\user_recharge\UserRecharge; +use support\Cache; use think\facade\Db; use Webman\RedisQueue\Redis; use Workerman\Crontab\Crontab; @@ -62,5 +65,41 @@ class Task } } }); + + $this->updateProductPrice(); } + + /** + * 将商品价格更改列表的价格同步至商品 + * @return void + */ + public function updateProductPrice() + { + new Crontab('0 */10 * * * *', function () { + $value = DictData::getDictValue('update_product_price_task', 'status'); + if ($value == 1) { + $lastProductId = Cache::get('update_product_price_last_product_id', 0); + $productIds = StoreProduct::where('purchase', 0)->where('id', '>', $lastProductId)->limit(200)->column('id'); + $lastProductId = end($productIds); + if (count($productIds) < 200) { + $lastProductId = 0; + } + Cache::set('update_product_price_last_product_id', $lastProductId); + $productPrices = StoreProductPrice::whereIn('product_id', $productIds)->where('status', 1)->distinct('product_id')->order('id desc')->select()->toArray(); + $update = []; + foreach ($productPrices as $productPrice) { + $update[] = [ + 'id' => $productPrice['product_id'], + 'purchase' => $productPrice['purchase'] ?? 0, + 'cost' => $productPrice['cost'] ?? 0, + 'price' => $productPrice['purchase'] ?? 0, + ]; + } + if (count($update) > 0) { + (new StoreProduct())->saveAll($update); + } + } + }); + } + }