|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+namespace app\command;
|
|
|
4
|
+
|
|
|
5
|
+use app\common\model\shared\SharedProsperityPartnerConsumeUpdateLog;
|
|
|
6
|
+use app\common\repositories\shared\SharedProsperityRecommendConfigRepository;
|
|
|
7
|
+use think\console\Command;
|
|
|
8
|
+use think\console\Input;
|
|
|
9
|
+use think\console\Output;
|
|
|
10
|
+use think\facade\Db;
|
|
|
11
|
+
|
|
|
12
|
+class ProductPriceUpdate extends Command
|
|
|
13
|
+{
|
|
|
14
|
+ // 变更数量
|
|
|
15
|
+ const NUMBER = 5;
|
|
|
16
|
+
|
|
|
17
|
+ const PRODUCT_IDS = [31053, 32171];
|
|
|
18
|
+
|
|
|
19
|
+ protected function configure()
|
|
|
20
|
+ {
|
|
|
21
|
+ // 指令配置
|
|
|
22
|
+ $this->setName('ProductPriceUpdate')
|
|
|
23
|
+ ->setDescription('商品价格更新');
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
|
26
|
+ protected function execute(Input $input, Output $output)
|
|
|
27
|
+ {
|
|
|
28
|
+ $output->writeln('定时任务执行中...');
|
|
|
29
|
+
|
|
|
30
|
+ $this->priceUpdate();
|
|
|
31
|
+
|
|
|
32
|
+ $output->writeln('定时任务执行完成');
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ private function priceUpdate()
|
|
|
36
|
+ {
|
|
|
37
|
+ // 获取当前数据
|
|
|
38
|
+ $productData = Db::name('store_product')->where(['product_id' => self::PRODUCT_IDS])->field('product_id,price')->select()->toArray();
|
|
|
39
|
+ $attrData = Db::name('store_product_attr_value')->where(['product_id' => self::PRODUCT_IDS])->field('product_id,price')->select()->toArray();
|
|
|
40
|
+ Db::startTrans();
|
|
|
41
|
+ try {
|
|
|
42
|
+ foreach ($productData as $product) {
|
|
|
43
|
+ $log = [
|
|
|
44
|
+ 'product_id' => $product['product_id'],
|
|
|
45
|
+ 'old_price' => $product['price'],
|
|
|
46
|
+ 'number' => self::NUMBER,
|
|
|
47
|
+ 'new_price' => $product['price'] + self::NUMBER,
|
|
|
48
|
+ ];
|
|
|
49
|
+ Db::name('product_price_update_log')->insert($log);
|
|
|
50
|
+
|
|
|
51
|
+ Db::name('store_product')->where(['product_id' => $product['product_id']])->inc('price', self::NUMBER)->update();
|
|
|
52
|
+ Db::name('store_product_attr_value')->where(['product_id' => $product['product_id']])->inc('price', self::NUMBER)->update();
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+;
|
|
|
56
|
+ Db::commit();
|
|
|
57
|
+ return true;
|
|
|
58
|
+ } catch (\Exception $e) {
|
|
|
59
|
+ Db::rollback();
|
|
|
60
|
+ throw $e;
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+}
|