ソースを参照

feat(console): 添加共富区线下扫码订单分账回撤功能

- 新增 sharedOfflineOrderProfitDelete 控制台命令
- 实现订单相关数据删除逻辑,包括用户账单、红包、积分、贡献值等
- 添加事务处理确保数据一致性
- 支持批量订单ID处理和多种佣金类型的删除操作
shichen 4 ヶ月 前
コミット
1652f55658
共有2 個のファイルを変更した141 個の追加0 個の削除を含む
  1. 140 0
      app/command/SharedOfflineOrderProfitDelete.php
  2. 1 0
      config/console.php

+ 140 - 0
app/command/SharedOfflineOrderProfitDelete.php

@@ -0,0 +1,140 @@
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 SharedOfflineOrderProfitDelete extends Command
13
+{
14
+    // 变更数量
15
+    const NUMBER = 5;
16
+
17
+    const CONFIG_ID = 2;
18
+
19
+    protected function configure()
20
+    {
21
+        // 指令配置
22
+        $this->setName('sharedOfflineOrderProfitDelete')
23
+            ->setDescription('共富区线下扫码订单分账回撤');
24
+    }
25
+
26
+    protected function execute(Input $input, Output $output)
27
+    {
28
+        $output->writeln('定时任务执行中...');
29
+
30
+        $this->delete();
31
+
32
+        $output->writeln('定时任务执行完成');
33
+    }
34
+
35
+    private function delete()
36
+    {
37
+        $ids = [
38
+            13799,
39
+            13798,
40
+            13795,
41
+            13784,
42
+            13775,
43
+            13774,
44
+            13773,
45
+            13754,
46
+            13753,
47
+            13750,
48
+            13749
49
+        ];
50
+        $orderData = Db::name('order_merchant')
51
+            ->where(['id' => $ids])
52
+            ->select()
53
+            ->toArray();
54
+
55
+        Db::startTrans();
56
+        try {
57
+            foreach ($orderData as $order) {
58
+                // bill表
59
+                $billData = Db::name('user_bill')->where(['order_sn' => $order['out_trade_no']])->select()->toArray();
60
+                foreach ($billData as $bill) {
61
+                    // 消费者本人和推荐人养老金数据删除
62
+                    if ($bill['commission_type'] == 5) {
63
+                        Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
64
+                    }
65
+
66
+                    // 商户跨店佣金删除
67
+                    if ($bill['commission_type'] == 7) {
68
+                        Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
69
+                        Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
70
+                    }
71
+
72
+                    // 佣金删除
73
+                    if ($bill['commission_type'] == 3) {
74
+                        Db::name('user_bill')->where(['bill_id' => $bill['bill_id']])->delete();
75
+                        Db::name("user")->where("uid", $bill['uid'])->dec('brokerage_price', $bill['number'])->update();
76
+                    }
77
+                }
78
+
79
+                // 删除红包数据和用户表字段数据
80
+                $red = Db::name('user_sign_hongbao')->where(['order_id' => $order['id']])->find();
81
+                if ($red) {
82
+                    Db::name('user_sign_hongbao')->where(['id' => $red['id']])->delete();
83
+                    Db::name('user')->where(['uid' => $red['uid']])->dec('hongbao', $red['number'])->update();
84
+                }
85
+
86
+                // 删除积分数据和用户表字段数据
87
+                $scoreData = Db::name('user_sign_score')->where(['order_id' => $order['id']])->select()->toArray();
88
+                if ($scoreData) {
89
+                    foreach ($scoreData as $score) {
90
+                        Db::name('user_sign_score')->where(['id' => $score['id']])->delete();
91
+                        Db::name('user')->where(['uid' => $score['uid']])->dec('score', $score['reward_socre'])->update();
92
+                    }
93
+                }
94
+
95
+                // 删除贡献值数据和用户表字段数据
96
+                $contributionData = Db::name('user_sign_gongxian')->where(['order_id' => $order['id']])->select()->toArray();
97
+                if ($contributionData) {
98
+                    foreach ($contributionData as $contribution) {
99
+                        Db::name('user_sign_gongxian')->where(['id' => $contribution['id']])->delete();
100
+                        Db::name('user')->where(['uid' => $contribution['uid']])->dec('contribute', $contribution['number'])->update();
101
+                    }
102
+                }
103
+
104
+                // pv
105
+                $pvData = Db::name('user_pv_log')->where(['order_id' => $order['id']])->find();
106
+                if ($pvData) {
107
+                    Db::name('user_pv_log')->where(['id' => $pvData['id']])->delete();
108
+                    Db::name('user')->where(['uid' => $pvData['uid']])->dec('pv', $pvData['pv'])->update();
109
+                }
110
+
111
+                // 复购金
112
+                $rebuyData = Db::name('user_sign_fugou')->where(['order_id' => $order['id']])->find();
113
+                if ($rebuyData) {
114
+                    Db::name('user_sign_fugou')->where(['id' => $rebuyData['id']])->delete();
115
+                    Db::name('user')->where(['uid' => $rebuyData['uid']])->dec('fugou', $rebuyData['number'])->update();
116
+                }
117
+
118
+                // 商户得到的京豆
119
+                $beanData = Db::name('user_sign_jingdou')->where(['order_id' => $order['id']])->find();
120
+                if ($beanData) {
121
+                    Db::name('user_sign_jingdou')->where(['id' => $beanData['id']])->delete();
122
+                    Db::name('user')->where(['uid' => $beanData['uid']])->dec('jingdou', $beanData['number'])->update();
123
+                }
124
+
125
+                //扫码下单产生分润值
126
+                $profitData = Db::name('user_sign_fenrun')->where(['order_id' => $order['id']])->find();
127
+                if ($profitData) {
128
+                    Db::name('user_sign_fenrun')->where(['id' => $profitData['id']])->delete();
129
+                }
130
+            }
131
+            Db::commit();
132
+            return true;
133
+        } catch (\Exception $e) {
134
+            Db::rollback();
135
+            dd($e->getFile(),$e->getMessage(),$e->getLine());
136
+        }
137
+
138
+    }
139
+
140
+}

+ 1 - 0
config/console.php

@@ -37,5 +37,6 @@ return [
37 37
         'sharedPartnerConsumeUpdate' => 'app\command\SharedPartnerConsumeUpdate',
38 38
         'productPriceUpdate' => 'app\command\ProductPriceUpdate',
39 39
         'deleteApiLog' => 'app\command\DeleteApiLog',
40
+        'sharedOfflineOrderProfitDelete' => 'app\command\SharedOfflineOrderProfitDelete',
40 41
     ],
41 42
 ];