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] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6=E6=9B=B4?= =?UTF-8?q?=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 22a72836..b4f24bcb 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 198660c6..aa10565b 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); + } + } + }); + } + }