|
|
@@ -0,0 +1,66 @@
|
|
|
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 SharedPartnerConsumeUpdate extends Command
|
|
|
13
|
+{
|
|
|
14
|
+ // 变更数量
|
|
|
15
|
+ const NUMBER = 5;
|
|
|
16
|
+
|
|
|
17
|
+ const CONFIG_ID = 2;
|
|
|
18
|
+
|
|
|
19
|
+ protected function configure()
|
|
|
20
|
+ {
|
|
|
21
|
+ // 指令配置
|
|
|
22
|
+ $this->setName('sharedPartnerConsumeUpdate')
|
|
|
23
|
+ ->setDescription('共富区一星合伙人消费额更新');
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
|
26
|
+ protected function execute(Input $input, Output $output)
|
|
|
27
|
+ {
|
|
|
28
|
+ $output->writeln('定时任务执行中...');
|
|
|
29
|
+
|
|
|
30
|
+ $this->consumeUpdate();
|
|
|
31
|
+
|
|
|
32
|
+ $output->writeln('定时任务执行完成');
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ private function consumeUpdate()
|
|
|
36
|
+ {
|
|
|
37
|
+ // 获取当前数据
|
|
|
38
|
+ /** @var SharedProsperityRecommendConfigRepository $repository */
|
|
|
39
|
+ $repository = app()->make(SharedProsperityRecommendConfigRepository::class);
|
|
|
40
|
+ $data = $repository->getDetail(self::CONFIG_ID);
|
|
|
41
|
+
|
|
|
42
|
+ $logData = [
|
|
|
43
|
+ 'partner_level' => $data->level,
|
|
|
44
|
+ 'old_consume' => $data->consume,
|
|
|
45
|
+ 'number' => self::NUMBER,
|
|
|
46
|
+ 'new_consume' => $data->consume + self::NUMBER
|
|
|
47
|
+ ];
|
|
|
48
|
+
|
|
|
49
|
+ Db::startTrans();
|
|
|
50
|
+ try {
|
|
|
51
|
+ // 更新数据
|
|
|
52
|
+ $data->consume += self::NUMBER;
|
|
|
53
|
+ $data->save();
|
|
|
54
|
+ // 记录日志
|
|
|
55
|
+ $logModel = new SharedProsperityPartnerConsumeUpdateLog();
|
|
|
56
|
+ $logModel->save($logData);
|
|
|
57
|
+ Db::commit();
|
|
|
58
|
+ return true;
|
|
|
59
|
+ } catch (\Exception $e) {
|
|
|
60
|
+ Db::rollback();
|
|
|
61
|
+ throw $e;
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+}
|