Преглед изворни кода

后台-撤回订单-重构

Xpy пре 8 месеци
родитељ
комит
0ca35da973

+ 21 - 0
app/common/dao/backup/BackupStoreOrderDao.php

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace app\common\dao\backup;
4
+
5
+use app\common\dao\BaseDao;
6
+use app\common\model\backup\BackupStoreOrder;
7
+
8
+class BackupStoreOrderDao extends BaseDao
9
+{
10
+    protected function getModel(): string
11
+    {
12
+        return BackupStoreOrder::class;
13
+    }
14
+    /**
15
+     * 获取撤回订单列表
16
+     */
17
+    public function getKillOrderList($limit)
18
+    {
19
+        return $this->getModel()::getDB()->paginate($limit)->toArray();
20
+    }
21
+}

+ 74 - 0
app/common/dao/backup/BackupUserChangeDao.php

@@ -0,0 +1,74 @@
1
+<?php
2
+
3
+namespace app\common\dao\backup;
4
+
5
+use app\common\dao\BaseDao;
6
+use app\common\model\backup\BackupUserChange;
7
+
8
+class BackupUserChangeDao extends BaseDao
9
+{
10
+    protected function getModel(): string
11
+    {
12
+        return BackupUserChange::class;
13
+    }
14
+
15
+    /**
16
+     * @param array $dataList
17
+     * @return array批量更新
18
+     */
19
+    public function saveAll(array $dataList): array
20
+    {
21
+        try {
22
+            return $this->getModel()->getInstance()->allowField(array_keys(reset($dataList)))->saveAll($dataList)->toArray();
23
+        } catch (\Exception $e) {
24
+            return [];
25
+        }
26
+    }
27
+    /**
28
+     * 根据 order_id 获取用户本人变更数据(user=1)
29
+     */
30
+    public function getUserOneChangeFromOrderId($orderId)
31
+    {
32
+        return $this::getModel()::getDB()
33
+            ->where('order_id', '=', $orderId)
34
+            ->where('user', '=', 1)
35
+            ->field('pv, vr, score, contribute, annuity, uid')
36
+            ->find();
37
+    }
38
+
39
+    /**
40
+     * 根据 order_id 获取一级推荐人变更数据(user=2)
41
+     */
42
+    public function getUserTwoChangeFromOrderId($orderId)
43
+    {
44
+        return $this::getModel()::getDB()
45
+            ->where('order_id', '=', $orderId)
46
+            ->where('user', '=', 2)
47
+            ->field('brokerage_price, score, per_contribute, annuity, uid')
48
+            ->find();
49
+    }
50
+
51
+    /**
52
+     * 根据 order_id 获取第二推荐人佣金变更数据(user=3)
53
+     */
54
+    public function getUserThreeChangeFromOrderId($orderId)
55
+    {
56
+        return $this::getModel()::getDB()
57
+            ->where('order_id', '=', $orderId)
58
+            ->where('user', '=', 3)
59
+            ->field('brokerage_price, uid')
60
+            ->find();
61
+    }
62
+
63
+    /**
64
+     * 根据 order_id 获取扫码推荐人积分变更数据(user=4)
65
+     */
66
+    public function getUserFourChangeFromOrderId($orderId)
67
+    {
68
+        return $this::getModel()::getDB()
69
+            ->where('order_id', '=', $orderId)
70
+            ->where('user', '=', 4)
71
+            ->field('score, uid')
72
+            ->find();
73
+    }
74
+}

+ 25 - 0
app/common/dao/backup/BackupUserDao.php

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+
4
+namespace app\common\dao\backup;
5
+use app\common\dao\BaseDao;
6
+use app\common\model\BaseModel;
7
+use app\common\model\backup\BackupUser;
8
+
9
+class BackupUserDao extends BaseDao
10
+{
11
+    protected function getModel(): string
12
+    {
13
+        return BackupUser::class;
14
+    }
15
+
16
+    /**
17
+     * 备份删除的用户表数据
18
+     * @param array $spreadUser
19
+     * @return int
20
+     */
21
+    public function saveDelData(array $spreadUser)
22
+    {
23
+        return $this->getModel()::getDB()->insert($spreadUser);
24
+    }
25
+}

+ 28 - 0
app/common/dao/store/order/StoreOrderDao.php

@@ -635,4 +635,32 @@ class StoreOrderDao extends BaseDao
635 635
         }
636 636
         return $entityList;
637 637
     }
638
+
639
+    /**
640
+     * 红积分订单查询(订单ID列表)
641
+     * @param int $merId
642
+     * @param array $orderIdList
643
+     * @return array
644
+     */
645
+    public function getRedNumOrders(int $merId, array $orderIdList): array
646
+    {
647
+        try {
648
+            return StoreOrder::getDB()
649
+                ->alias('o')
650
+                ->join('user_bill u', 'u.order_sn=o.order_sn')
651
+                ->where('o.paid', 1)
652
+                ->where('o.is_red_ylj', 0)
653
+                ->where('o.mer_id', $merId)
654
+                ->where('u.commission_type', 5)
655
+                ->where('u.gzc', 3)
656
+                ->where('u.status', 0)
657
+                ->whereIn('o.pay_type', [0, 5])
658
+                ->whereIn('o.order_id', $orderIdList)
659
+                ->field('o.order_id,o.order_sn,u.number,u.mark')
660
+                ->select()
661
+                ->toArray();
662
+        } catch (\Exception $e) {
663
+            return [];
664
+        }
665
+    }
638 666
 }

+ 63 - 1
app/common/dao/user/UserBillDao.php

@@ -254,4 +254,66 @@ class UserBillDao extends BaseDao
254 254
             return [];
255 255
         }
256 256
     }
257
-}
257
+    /**
258
+     * 根据order_id与uid查找养老金值(link_id,status=1, pm=1)
259
+     */
260
+    public function getYanglaoFromUidOrderId($orderId, $uid)
261
+    {
262
+        try {
263
+            return $this::getModel()::getDB()
264
+                ->where('link_id', '=', $orderId)
265
+                ->where('status', '=', 1)
266
+                ->where('pm', '=', 1)
267
+                ->where('uid', '=', $uid)
268
+                ->value('number');
269
+        } catch (\Exception $e) {
270
+            return [];
271
+        }
272
+    }
273
+    /**
274
+     * 根据order_id与uid查找佣金(commission_type=5)
275
+     */
276
+    public function getYljFromCommissionTypeUidOrderId($orderId, $uid)
277
+    {
278
+        try {
279
+            return $this::getModel()::getDB()
280
+                ->where('link_id', '=', $orderId)
281
+                ->where('commission_type', '=', 5)
282
+                ->where('uid', '=', $uid)
283
+                ->value('number');
284
+        } catch (\Exception $e) {
285
+            return [];
286
+        }
287
+    }
288
+    /**
289
+     * 根据order_id与uid查找佣金(commission_type=3)
290
+     */
291
+    public function getYongjinFromCommissionTypeUidOrderId($orderId, $uid)
292
+    {
293
+        try {
294
+            return $this::getModel()::getDB()
295
+                ->where('link_id', '=', $orderId)
296
+                ->where('commission_type', '=', 3)
297
+                ->where('uid', '=', $uid)
298
+                ->value('number');
299
+        } catch (\Exception $e) {
300
+            return [];
301
+        }
302
+    }
303
+    /**
304
+     * 根据order_id查找第二推荐佣金uid(commission_type=3,排除当前用户和一级推荐人)
305
+     */
306
+    public function getYongjinTwoUidFromOrderId($orderId, $uid, $spreadUid)
307
+    {
308
+        try {
309
+            $value = $this::getModel()::getDB()
310
+                ->where('link_id', '=', $orderId)
311
+                ->where('commission_type', '=', 3)
312
+                ->whereNotIn('uid', [$uid, $spreadUid])
313
+                ->value('uid');
314
+            return $value ?: 0;
315
+        } catch (\Exception $e) {
316
+            return 0;
317
+        }
318
+    }
319
+}

+ 22 - 0
app/common/dao/user/UserDao.php

@@ -456,4 +456,26 @@ class UserDao extends BaseDao
456 456
     {
457 457
         return $this::getModel()::getDB()->where('level_id', '=', $userId)->column('uid');
458 458
     }
459
+    /**
460
+     * 通过uid获取spreadUid
461
+     */
462
+    public function getSpreadUidFromUid($uid)
463
+    {
464
+        try {
465
+        return $this::getModel()::getDB()->where('uid', '=', $uid)->value('spread_uid');
466
+        } catch (\Exception $e) {
467
+        return [];
468
+        }
469
+    }
470
+    /**
471
+     * 根据spread查找用户信息
472
+     */
473
+    public function getSpreadUserFromUid($spreadUid)
474
+    {
475
+        try {
476
+            return $this::getModel()::getDB()->where('uid', '=', $spreadUid)->find();
477
+        } catch (\Exception $e) {
478
+            return [];
479
+        }
480
+    }
459 481
 }

+ 27 - 1
app/common/dao/user/UserPvLogDao.php

@@ -86,4 +86,30 @@ class UserPvLogDao extends BaseDao
86 86
             return [];
87 87
         }
88 88
     }
89
-}
89
+    /**
90
+     * 根据order_id和status查找pv值
91
+     */
92
+    public function getPVFromStatusOrderId($orderId)
93
+    {
94
+        try {
95
+            return $this::getModel()::getDB()->where('order_id', '=', $orderId)->where('status','=',1)->value('pv');
96
+        } catch (\Exception $e) {
97
+            return [];
98
+        }
99
+    }
100
+    /**
101
+     * 根据order_id获取pv值(用于备份用户变更记录)
102
+     */
103
+    public function getPvForBackupFromOrderId($orderId)
104
+    {
105
+        try {
106
+            $value = $this::getModel()::getDB()
107
+                ->where('order_id', '=', $orderId)
108
+                ->where('status', '=', 1)
109
+                ->value('pv');
110
+            return $value ?: 0;
111
+        } catch (\Exception $e) {
112
+            return 0;
113
+        }
114
+    }
115
+}

+ 17 - 1
app/common/dao/user/UserSignGongxianDao.php

@@ -86,4 +86,20 @@ class UserSignGongxianDao extends BaseDao
86 86
             return [];
87 87
         }
88 88
     }
89
-}
89
+    /**
90
+     * 根据order_id与uid查找贡献值(status=1, type=1)
91
+     */
92
+    public function getGongxianFromUidOrderId($orderId, $uid)
93
+    {
94
+        try {
95
+            return $this::getModel()::getDB()
96
+                ->where('order_id', '=', $orderId)
97
+                ->where('status', '=', 1)
98
+                ->where('type', '=', 1)
99
+                ->where('uid', '=', $uid)
100
+                ->value('number');
101
+        } catch (\Exception $e) {
102
+            return [];
103
+        }
104
+    }
105
+}

+ 79 - 1
app/common/dao/user/UserSignScoreDao.php

@@ -87,4 +87,82 @@ class UserSignScoreDao extends BaseDao
87 87
             return [];
88 88
         }
89 89
     }
90
-}
90
+    /**
91
+     * 根据order_id与uid查找奖励积分值(status=1, source_type=3, pm=1)
92
+     */
93
+    public function getRewardScoreFromUidOrderId($orderId, $uid)
94
+    {
95
+        try {
96
+            return $this::getModel()::getDB()
97
+                ->where('order_id', '=', $orderId)
98
+                ->where('status', '=', 1)
99
+                ->where('source_type', '=', 3)
100
+                ->where('uid', '=', $uid)
101
+                ->where('pm', '=', 1)
102
+                ->value('reward_socre');
103
+        } catch (\Exception $e) {
104
+            return [];
105
+        }
106
+    }
107
+    /**
108
+     * 根据order_id与uid查找支付积分值(status=1, pm=2)
109
+     */
110
+    public function getPayScoreFromUidOrderId($orderId, $uid)
111
+    {
112
+        try {
113
+            return $this::getModel()::getDB()
114
+                ->where('order_id', '=', $orderId)
115
+                ->where('status', '=', 1)
116
+                ->where('uid', '=', $uid)
117
+                ->where('pm', '=', 2)
118
+                ->value('reward_socre');
119
+        } catch (\Exception $e) {
120
+            return [];
121
+        }
122
+    }
123
+    /**
124
+     * 根据order_id与uid查找奖励积分值(status=1)
125
+     */
126
+    public function getRewardScoreFromStatusUidOrderId($orderId, $uid)
127
+    {
128
+        try {
129
+            return $this::getModel()::getDB()
130
+                ->where('order_id', '=', $orderId)
131
+                ->where('uid', '=', $uid)
132
+                ->where('status', '=', 1)
133
+                ->value('reward_socre');
134
+        } catch (\Exception $e) {
135
+            return [];
136
+        }
137
+    }
138
+    /**
139
+     * 根据order_id查找扫码推荐人uid(mark like '%扫码%', status=1)
140
+     */
141
+    public function getUidFromMarkLikeStatusOrderId($orderId)
142
+    {
143
+        try {
144
+            return $this::getModel()::getDB()
145
+                ->where('order_id', '=', $orderId)
146
+                ->whereLike('mark', '%扫码%')
147
+                ->where('status', '=', 1)
148
+                ->value('uid');
149
+        } catch (\Exception $e) {
150
+            return [];
151
+        }
152
+    }
153
+    /**
154
+     * 根据上面getUidFromMarkLikeStatusOrderId方法查处的Uid来确定score
155
+     */
156
+    public function getScoreFromUidOrderId($orderId, $smSpreadUid)
157
+    {
158
+        try {
159
+            return $this::getModel()::getDB()
160
+                ->where('order_id', '=', $orderId)
161
+                ->where('uid', '=', $smSpreadUid)
162
+                ->where('status', '=', 1)
163
+                ->value('reward_socre');
164
+        } catch (\Exception $e) {
165
+            return [];
166
+        }
167
+    }
168
+}

+ 27 - 1
app/common/dao/user/UserSignVrDao.php

@@ -56,4 +56,30 @@ class UserSignVrDao extends BaseDao
56 56
             return [];
57 57
         }
58 58
     }
59
-}
59
+    /**
60
+     * 根据订单id和type类型查找vr
61
+     */
62
+    public function getVrFromTypeOrderId($orderId)
63
+    {
64
+        try {
65
+            return $this::getModel()::getDB()->where('order_id', '=', $orderId)->where('type','=',2)->value('number');
66
+        } catch (\Exception $e){
67
+            return [];
68
+        }
69
+    }
70
+    /**
71
+     * 根据order_id获取vr值(用于备份用户变更记录)
72
+     */
73
+    public function getVrForBackupFromOrderId($orderId)
74
+    {
75
+        try {
76
+            $value = $this::getModel()::getDB()
77
+                ->where('order_id', '=', $orderId)
78
+                ->where('type', '=', 2)
79
+                ->value('number');
80
+            return $value ?: 0;
81
+        } catch (\Exception $e) {
82
+            return 0;
83
+        }
84
+    }
85
+}

+ 45 - 0
app/common/dao/util/TableOpsDao.php

@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+namespace app\common\dao\util;
4
+
5
+use think\facade\Db;
6
+
7
+class TableOpsDao
8
+{
9
+    public function backupAndDeleteBatch(array $ops): void
10
+    {
11
+        foreach ($ops as [$table, $where]) {
12
+        $this->backupAndDelete($table, $where);
13
+        }
14
+    }
15
+    public function backupAndDelete(string $table, array $where): void
16
+    {
17
+        $rows = Db::name($table)->where($where)->select()->toArray();
18
+        if ($rows) {
19
+            Db::name('backup_' . $table)->insertAll($rows);
20
+            Db::name($table)->where($where)->delete();
21
+        }
22
+    }
23
+
24
+    public function restore(string $table, array $where): void
25
+    {
26
+        $backupTable = 'backup_' . $table;
27
+        $rows = Db::name($backupTable)->where($where)->select()->toArray();
28
+        if ($rows) {
29
+            foreach ($rows as &$row) {
30
+                if (isset($row['del_time'])) unset($row['del_time']);
31
+            }
32
+            unset($row);
33
+            Db::name($table)->insertAll($rows);
34
+            Db::name($backupTable)->where($where)->delete();
35
+        }
36
+    }
37
+
38
+    public function restoreBatch(array $ops): void
39
+    {
40
+        foreach ($ops as [$table, $where]) {
41
+            $this->restore($table, $where);
42
+        }
43
+    }
44
+}
45
+

+ 16 - 0
app/common/model/backup/BackupStoreOrder.php

@@ -0,0 +1,16 @@
1
+<?php
2
+
3
+namespace app\common\model\backup;
4
+use app\common\model\BaseModel;
5
+
6
+class BackupStoreOrder extends BaseModel
7
+{
8
+    public static function tablePk(): ?string
9
+    {
10
+        return 'order_id';
11
+    }
12
+    public static function tableName(): string
13
+    {
14
+        return 'backup_store_order';
15
+    }
16
+}

+ 17 - 0
app/common/model/backup/BackupUser.php

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace app\common\model\backup;
4
+
5
+use app\common\model\BaseModel;
6
+
7
+class BackupUser extends BaseModel
8
+{
9
+    public static function tablePk(): string
10
+    {
11
+        return 'uid';
12
+    }
13
+    public static function tableName(): string
14
+    {
15
+        return 'backup_user';
16
+    }
17
+}

+ 17 - 0
app/common/model/backup/BackupUserChange.php

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace app\common\model\backup;
4
+
5
+use app\common\model\BaseModel;
6
+
7
+class BackupUserChange extends BaseModel
8
+{
9
+    public static function tablePk(): ?string
10
+    {
11
+        return 'id';
12
+    }
13
+    public static function tableName(): string
14
+    {
15
+        return 'backup_user_change';
16
+    }
17
+}

+ 426 - 6
app/common/repositories/store/order/StoreOrderRepository.php

@@ -12,6 +12,18 @@ namespace app\common\repositories\store\order;
12 12
 
13 13
 
14 14
 use app\common\dao\store\order\StoreOrderDao;
15
+use app\common\dao\user\UserDao;
16
+use app\common\dao\user\UserPvLogDao;
17
+use app\common\dao\user\UserSignVrDao;
18
+use app\common\dao\user\UserSignScoreDao;
19
+use app\common\dao\user\UserSignGongxianDao;
20
+use app\common\dao\user\UserBillDao;
21
+use app\common\dao\user\UserOrderKillOrRecoverRecordsDao;
22
+use app\common\dao\backup\BackupGzcLogsDao;
23
+use app\common\dao\backup\BackupUserDao;
24
+use app\common\dao\backup\BackupUserChangeDao;
25
+use app\common\dao\util\TableOpsDao;
26
+use app\common\dao\backup\BackupStoreOrderDao;
15 27
 use app\common\enum\CommonEnum;
16 28
 use app\common\enum\merchant\MerchantEnum;
17 29
 use app\common\enum\shipping\ShippingTemplateEnum;
@@ -140,6 +152,31 @@ class StoreOrderRepository extends BaseRepository
140 152
     const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', "alpay"];
141 153
     private $source;
142 154
     private $merId;
155
+    /** @var UserDao */
156
+    private $userDao;
157
+    /** @var UserPvLogDao */
158
+    private $userPvLogDao;
159
+    /** @var UserSignVrDao */
160
+    private $userSignVrDao;
161
+    /** @var UserSignScoreDao */
162
+    private $userSignScoreDao;
163
+    /** @var UserSignGongxianDao */
164
+    private $userSignGongxianDao;
165
+    /** @var UserBillDao */
166
+    private $userBillDao;
167
+    /** @var backupGzcLogsDao */
168
+    private $backupGzcLogsDao;
169
+    /** @var backupUserDao */
170
+    private $backupUserDao;
171
+    /** @var BackupUserChangeDao */
172
+    private $backupUserChangeDao;
173
+    /** @var TableOpsDao */
174
+    private $tableOpsDao;
175
+    /** @var UserOrderKillOrRecoverRecordsDao */
176
+    private $userOrderKillOrRecoverRecordsDao;
177
+    /** @var BackupStoreOrderDao */
178
+    private $backupStoreOrderDao;
179
+
143 180
 
144 181
     const commercetrade_cash_integral = 'commercetrade_cash_integral'; // 商贸区:现金+积分
145 182
     const commercetrade_cash_peking_bean = 'commercetrade_cash_peking_bean'; // 商贸区:现金+京豆
@@ -154,6 +191,18 @@ class StoreOrderRepository extends BaseRepository
154 191
         $this->dao = $dao;
155 192
         $this->source = request()->header('source');
156 193
         $this->merId = request()->header('merId');
194
+        $this->userDao = app()->make(UserDao::class);
195
+        $this->userPvLogDao = app()->make(UserPvLogDao::class);
196
+        $this->userSignVrDao = app()->make(UserSignVrDao::class);
197
+        $this->userSignScoreDao = app()->make(UserSignScoreDao::class);
198
+        $this->userSignGongxianDao = app()->make(UserSignGongxianDao::class);
199
+        $this->userBillDao = app()->make(UserBillDao::class);
200
+        $this->backupGzcLogsDao = app()->make(BackupGzcLogsDao::class);
201
+        $this->backupUserDao = app()->make(BackupUserDao::class);
202
+        $this->backupUserChangeDao = app()->make(BackupUserChangeDao::class);
203
+        $this->tableOpsDao = app()->make(TableOpsDao::class);
204
+        $this->userOrderKillOrRecoverRecordsDao = app()->make(UserOrderKillOrRecoverRecordsDao::class);
205
+        $this->backupUserChangeDao = app()->make(BackupUserChangeDao::class);
157 206
     }
158 207
 
159 208
     /**
@@ -5074,12 +5123,6 @@ class StoreOrderRepository extends BaseRepository
5074 5123
             }
5075 5124
             $query->whereIn('order_id', $ids);
5076 5125
         }
5077
-        if (!empty($where['keywords'])) {
5078
-            /** @var StoreOrderProductRepository $storeOrderProductRepository */
5079
-            $storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
5080
-            $orderIdList = $storeOrderProductRepository->getOrderIdListByKeyword($where['keywords']);
5081
-            $query->whereIn('order_id', $orderIdList);
5082
-        }
5083 5126
         $count = $query->count();
5084 5127
         $list = $query->with([
5085 5128
             'orderProduct', 'merchant' => function ($query) {
@@ -12428,4 +12471,381 @@ class StoreOrderRepository extends BaseRepository
12428 12471
 
12429 12472
         return $postage;
12430 12473
     }
12474
+    public function useKillOrderRewards($groupOrderId, $orderId, $uid,$adminId)
12475
+    {
12476
+        if (empty($orderId) || empty($groupOrderId) || empty($uid)) {
12477
+            return false;
12478
+        }
12479
+        try {
12480
+            Db::startTrans();
12481
+            //$spreadUid = Db::name('user')->where('uid', $uid)->value('spread_uid');
12482
+            //$pv = $this->getTableValue('user_pv_log', [['order_id', '=', $orderId], ['status', '=', 1]], 'pv');
12483
+//            $payVr = $this->getTableValue('user_sign_vr', [['order_id', '=', $orderId], ['type', '=', 2]], 'number');
12484
+//            $score = $this->getTableValue('user_sign_score', [['order_id', '=', $orderId], ['status', '=', 1], ['source_type', '=', 3], ['uid', '=', $uid], ['pm', '=', 1]], 'reward_socre');
12485
+//            $payScore = $this->getTableValue('user_sign_score', [['order_id', '=', $orderId], ['status', '=', 1], ['pm', '=', 2], ['uid', '=', $uid]], 'reward_socre');
12486
+//            $gongXian = $this->getTableValue('user_sign_gongxian', [['order_id', '=', $orderId], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $uid]], 'number');
12487
+//            $yangLaoJin = $this->getTableValue('user_bill', [['link_id', '=', $orderId], ['status', '=', 1], ['pm', '=', 1], ['uid', '=', $uid]], 'number');
12488
+            //查找是否有推荐人
12489
+            $spreadUid = $this->userDao->getSpreadUidFromUid($uid);
12490
+            //取出pv
12491
+            $pv = $this->userPvLogDao->getPVFromStatusOrderId($orderId);
12492
+            //取出 vr
12493
+            $payVr = $this->userSignVrDao->getVrFromTypeOrderId($orderId);
12494
+            //取出购买赠送积分 / 支出积分
12495
+            $score = $this->userSignScoreDao->getRewardScoreFromUidOrderId($orderId, $uid);
12496
+            $payScore = $this->userSignScoreDao->getPayScoreFromUidOrderId($orderId, $uid);
12497
+            // 贡献值
12498
+            $gongXian = $this->userSignGongxianDao->getGongxianFromUidOrderId($orderId, $uid);
12499
+            // 养老金
12500
+            $yangLaoJin = $this->userBillDao->getYanglaoFromUidOrderId($orderId, $uid);
12501
+            if ($spreadUid) {
12502
+                //如果有推荐人就执行
12503
+//                $spreadScore = $this->getTableValue('user_sign_score', [['order_id', '=', $orderId], ['uid', '=', $spreadUid], ['status', '=', 1]], 'reward_socre');
12504
+//                $spreadGongXian = $this->getTableValue('user_sign_gongxian', [['order_id', '=', $orderId], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $spreadUid]], 'number');
12505
+//                $spreadYlj = $this->getTableValue('user_bill', [['link_id', '=', $orderId], ['commission_type', '=', 5], ['uid', '=', $spreadUid]], 'number');
12506
+//                $spreadYongJin = $this->getTableValue('user_bill', [['link_id', '=', $orderId], ['commission_type', '=', 3], ['uid', '=', $spreadUid]], 'number');
12507
+//                $spreadUser = Db::name('user')->where('uid', $spreadUid)->find();
12508
+//                Db::name('backup_user')->insert($spreadUser);
12509
+                //                Db::name('user')->where('uid', $spreadUid)->update([
12510
+                //                    'score' => Db::raw("score - {$spreadScore}"),
12511
+                //                    'per_contribute' => Db::raw("per_contribute - {$spreadGongXian}"),
12512
+                //                    'brokerage_price' => Db::raw("brokerage_price - {$spreadYongJin}"),
12513
+                //                    'annuity' => Db::raw("annuity - {$spreadYlj}"),
12514
+                //                ]);
12515
+//                Db::name('backup_user_change')->insert([
12516
+//                    'uid' => $spreadUid,
12517
+//                    'order_id' => $orderId,
12518
+//                    'score' => $spreadScore ?: 0,
12519
+//                    'per_contribute' => $spreadGongXian ?: 0,
12520
+//                    'brokerage_price' => $spreadYongJin ?: 0,
12521
+//                    'user' => 2,
12522
+//                ]);
12523
+
12524
+                $spreadScore = $this->userSignScoreDao->getRewardScoreFromStatusUidOrderId($orderId, $spreadUid);//积分
12525
+                $spreadGongXian = $this->userSignGongxianDao->getGongxianFromUidOrderId($orderId, $spreadUid);//贡献
12526
+                $spreadYlj = $this->userBillDao->getYljFromCommissionTypeUidOrderId($orderId, $spreadUid);//养老金
12527
+                $spreadYongJin = $this->userBillDao->getYongjinFromCommissionTypeUidOrderId($orderId, $spreadUid);//佣金
12528
+//                $spreadUser = $this->userDao->getSpreadUserFromUid($spreadUid);//找到推荐人的user表数据
12529
+//                $this->backupUserDao->saveDelData($spreadUser);//备份原始的user大概是没必要的,user更新数据都靠具体数目加减操作
12530
+                $userUpdateList = [//减去各奖励数目
12531
+                    'id' => $uid,
12532
+                    'score' => Db::raw("score - {$spreadScore}"),
12533
+                    'per_contribute' => Db::raw("per_contribute - {$spreadGongXian}"),
12534
+                    'brokerage_price' => Db::raw("brokerage_price - {$spreadYongJin}"),
12535
+                    'annuity' => Db::raw("annuity - {$spreadYlj}"),
12536
+                ];
12537
+                $this->userDao->saveAll($userUpdateList);
12538
+                $saveSpreaadUserChangeList = [//将奖励数目进行备份
12539
+                    'uid' => $spreadUid,
12540
+                    'order_id' => $orderId,
12541
+                    'score' => $spreadScore ?: 0,
12542
+                    'per_contribute' => $spreadGongXian ?: 0,
12543
+                    'brokerage_price' => $spreadYongJin ?: 0,
12544
+                    'user' => 2,
12545
+                ];
12546
+                $this->backupUserChangeDao->saveAll($saveSpreaadUserChangeList);
12547
+            }
12548
+//            $smSpreadUid = $this->getTableValue('user_sign_score', [['order_id', '=', $orderId], ['mark', 'like', '%扫码%'], ['status', '=', 1]], 'uid');
12549
+//            $smSpreadScore = $this->getTableValue('user_sign_score', [['order_id', '=', $orderId], ['uid', '=', $smSpreadUid], ['status', '=', 1]], 'reward_socre');
12550
+//            $spreadYongJinTwoUid = $this->getTableValue('user_bill', [['link_id', '=', $orderId], ['commission_type', '=', 3], ['uid', 'not in', [$uid, $spreadUid]]], 'uid');
12551
+//            $spreadYongJinTwo = $this->getTableValue('user_bill', [['link_id', '=', $orderId], ['commission_type', '=', 3], ['uid', '=', $spreadYongJinTwoUid]], 'number');
12552
+            $smSpreadUid = $this->userSignScoreDao->getUidFromMarkLikeStatusOrderId($orderId);//查找扫码消费的uid
12553
+            $smSpreadScore = $this->userSignScoreDao->getScoreFromUidOrderId($orderId,$smSpreadUid);
12554
+            $spreadYongJinTwoUid = $this->userBillDao->getYongjinTwoUidFromOrderId($orderId, $uid, $spreadUid);
12555
+            $spreadYongJinTwo = $this->userBillDao->getYongjinFromCommissionTypeUidOrderId($orderId, $spreadYongJinTwoUid);
12556
+            $useScore = $payScore - $score;//将花费的积分减去购买获得的积分
12557
+//            $user = Db::name('user')->where('uid', $uid)->find();
12558
+//            Db::name('backup_user')->insert($user);//用户信息备份,大概也是不需要
12559
+            $updateUserOrderAwardList = [//吧奖励和花费撤回
12560
+                'uid' => $uid,
12561
+                'pv' => Db::raw("pv - {$pv}"),
12562
+                'vr' => Db::raw("vr + {$payVr}"),
12563
+                'score' => Db::raw("score + {$useScore}"),
12564
+                'contribute' => Db::raw("contribute - {$gongXian}"),
12565
+                'annuity' => Db::raw("annuity - {$yangLaoJin}"),
12566
+            ];
12567
+            $this->userDao->saveAll($updateUserOrderAwardList);
12568
+//            Db::name('user')->where('uid', $uid)->update([
12569
+//                'pv' => Db::raw("pv - {$pv}"),
12570
+//                'vr' => Db::raw("vr + {$payVr}"),
12571
+//                'score' => Db::raw("score + {$uscore}"),
12572
+//                'contribute' => Db::raw("contribute - {$gongXian}"),
12573
+//                'annuity' => Db::raw("annuity - {$yangLaoJin}"),
12574
+//            ]);
12575
+//            Db::name('backup_user_change')->insert([
12576
+//                'uid' => $uid,
12577
+//                'order_id' => $orderId,
12578
+//                'pv' => $pv ?: 0,
12579
+//                'vr' => $payVr ?: 0,
12580
+//                'score' => $uscore ?: 0,
12581
+//                'contribute' => $gongXian ?: 0,
12582
+//                'annuity' => $yangLaoJin ?: 0,
12583
+//                'user' => 1,
12584
+//            ]);
12585
+            $saveUserChangeList = [
12586
+                'uid' => $uid,
12587
+                'order_id' => $orderId,
12588
+                'pv' => $pv ?: 0,
12589
+                'vr' => $payVr ?: 0,
12590
+                'score' => $useScore ?: 0,
12591
+                'contribute' => $gongXian ?: 0,
12592
+                'annuity' => $yangLaoJin ?: 0,
12593
+                'user' => 1,
12594
+            ];
12595
+            $this->backupUserChangeDao->saveAll($saveUserChangeList);
12596
+            if ($spreadYongJinTwoUid) {
12597
+//                $spreadUserTwo = Db::name('user')->where('uid', $spreadYongJinTwoUid)->find();
12598
+//                Db::name('backup_user')->insert($spreadUserTwo);//同理,不需要备份原user表数
12599
+///               Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
12600
+                ///                 Db::name('backup_user_change')->insert([
12601
+                ////                    'uid' => $spreadYongJinTwoUid,
12602
+                ////                    'order_id' => $orderId,
12603
+                ////                    'brokerage_price' => $spreadYongJinTwo ?: 0,
12604
+                ////                    'user' => 3,
12605
+                ////                ]);
12606
+                $updateSpreadUserTwoList = [
12607
+                    'uid' => $spreadYongJinTwoUid,
12608
+                    'brokerage_price' => $spreadYongJinTwo
12609
+                ];
12610
+                $this->userDao->saveAll($updateSpreadUserTwoList);
12611
+                $saveSpreadUserTwoChangeList = [
12612
+                    'uid' => $spreadYongJinTwoUid,
12613
+                    'order_id' => $orderId,
12614
+                    'brokerage_price' => $spreadYongJinTwo ?: 0,
12615
+                    'user' => 3,
12616
+                ];
12617
+                $this->backupUserChangeDao->saveAll($saveSpreadUserTwoChangeList);
12618
+            }
12619
+            if ($smSpreadUid) {
12620
+//                $smUserTwo = Db::name('user')->where('uid', $smSpreadUid)->find();
12621
+//                Db::name('backup_user')->insert($smUserTwo);//同理
12622
+//                Db::name('user')->where('uid', $smSpreadUid)->dec('score', $smSpreadScore)->update();
12623
+//                Db::name('backup_user_change')->insert([
12624
+//                    'uid' => $smSpreadUid,
12625
+//                    'order_id' => $orderId,
12626
+//                    'score' => $smSpreadScore ?: 0,
12627
+//                    'user' => 4,
12628
+//                ]);
12629
+                $updateSpreadSMUserList = [
12630
+                    'uid' => $smSpreadUid,
12631
+                    'score' => $smSpreadScore
12632
+                ];
12633
+                $this->userDao->saveAll($updateSpreadSMUserList);
12634
+                $saveSpreadSMUserChangeList = [
12635
+                    'uid' => $smSpreadUid,
12636
+                    'order_id' => $orderId,
12637
+                    'score' => $smSpreadScore ?: 0,
12638
+                    'user' => 4,
12639
+                ];
12640
+                $this->backupUserChangeDao->saveAll($saveSpreadSMUserChangeList);
12641
+            }
12642
+            // $this->backupAndDelete('store_order', ['group_order_id' => $groupOrderId]);
12643
+            // $this->backupAndDelete('store_group_order', ['group_order_id' => $groupOrderId]);
12644
+            // $this->backupAndDelete('user_pv_log', ['order_id' => $orderId]);
12645
+            // $this->backupAndDelete('user_sign_vr', ['order_id' => $orderId]);
12646
+            // $this->backupAndDelete('user_sign_score', ['order_id' => $orderId]);
12647
+            // $this->backupAndDelete('user_sign_gongxian', ['order_id' => $orderId]);
12648
+            // $this->backupAndDelete('user_bill', ['link_id' => $orderId]);
12649
+            // $this->backupAndDelete('gzc_logs', ['link_id' => $orderId]);
12650
+            $ops = [
12651
+                ['store_order', ['group_order_id' => $groupOrderId]],
12652
+                ['store_group_order', ['group_order_id' => $groupOrderId]],
12653
+                ['user_pv_log', ['order_id' => $orderId]],
12654
+                ['user_sign_vr', ['order_id' => $orderId]],
12655
+                ['user_sign_score', ['order_id' => $orderId]],
12656
+                ['user_sign_gongxian', ['order_id' => $orderId]],
12657
+                ['user_bill', ['link_id' => $orderId]],
12658
+                ['gzc_logs', ['link_id' => $orderId]],
12659
+            ];
12660
+            $this->tableOpsDao->backupAndDeleteBatch($ops);
12661
+            Db::commit();
12662
+        } catch (\Exception $e) {
12663
+            Db::rollback();
12664
+            return false;
12665
+        }
12666
+        // Db::name('user_order_kill_records')->insert([
12667
+        //     'operation_id' => $adminId,
12668
+        //     'uid' => $uid,
12669
+        //     'order_id' => $orderId,
12670
+        //     'mark' => '后台管理员撤销订单记录',
12671
+        // ]);
12672
+        $this->userOrderKillOrRecoverRecordsDao->insertKillOrRecoverRecord([
12673
+            'operation_id' => $adminId,
12674
+            'uid' => $uid,
12675
+            'order_id' => $orderId,
12676
+            'mark' => '后台管理员撤销订单记录',
12677
+        ]);
12678
+        return true;
12679
+    }
12680
+    public function getKillOrderList()
12681
+    {
12682
+        return $this->backupStoreOrderDao->getKillOrderList(20);
12683
+    }
12684
+    public function recoverOrderByAdmin($groupOrderId, $orderId)
12685
+    {
12686
+        if (empty($orderId) || empty($groupOrderId)) {
12687
+            return false;
12688
+        }
12689
+        try {
12690
+            /** @var easterOrder $model */
12691
+            Db::startTrans();
12692
+            // $this->easterOrder('store_order', ['group_order_id' => $groupOrderId]);
12693
+            // $this->easterOrder('store_group_order', ['group_order_id' => $groupOrderId]);
12694
+            // $this->easterOrder('user_pv_log', ['order_id' => $orderId]);
12695
+            // $this->easterOrder('user_sign_vr', ['order_id' => $orderId]);
12696
+            // $this->easterOrder('user_sign_score', ['order_id' => $orderId]);
12697
+            // $this->easterOrder('user_sign_gongxian', ['order_id' => $orderId]);
12698
+            // $this->easterOrder('user_bill', ['link_id' => $orderId]);
12699
+            // $this->easterOrder('gzc_logs', ['link_id' => $orderId]);
12700
+            $restoreOps = [
12701
+                ['store_order', ['group_order_id' => $groupOrderId]],
12702
+                ['store_group_order', ['group_order_id' => $groupOrderId]],
12703
+                ['user_pv_log', ['order_id' => $orderId]],
12704
+                ['user_sign_vr', ['order_id' => $orderId]],
12705
+                ['user_sign_score', ['order_id' => $orderId]],
12706
+                ['user_sign_gongxian', ['order_id' => $orderId]],
12707
+                ['user_bill', ['link_id' => $orderId]],
12708
+                ['gzc_logs', ['link_id' => $orderId]],
12709
+            ];
12710
+            $this->tableOpsDao->restoreBatch($restoreOps);
12711
+            $this->easterUserAward(['order_id' => $orderId]);
12712
+            Db::commit();
12713
+        } catch (\Exception $e) {
12714
+            Db::rollback();
12715
+            return false;
12716
+        }
12717
+//        Db::name('user_order_recover_records')->insert([
12718
+//            'operation_id' => $adminId,
12719
+//            'order_id' => $orderId,
12720
+//            'mark' => '恢复订单记录',
12721
+//        ]);
12722
+        $this->userOrderKillOrRecoverRecordsDao->insertKillOrRecoverRecord([
12723
+            'operation_id' => null,
12724
+            'uid' => null,
12725
+            'order_id' => $orderId,
12726
+            'mark' => '后台管理员恢复订单记录',
12727
+        ]);
12728
+        return true;
12729
+    }
12730
+//    private function backupAndDelete(string $table, array $where): void
12731
+//    {
12732
+//        $backupTable = 'backup_' . $table;
12733
+//        $rows = Db::name($table)->where($where)->select()->toArray();
12734
+//        if ($rows) {
12735
+//            Db::name($backupTable)->insertAll($rows);
12736
+//            Db::name($table)->where($where)->delete();
12737
+//        }
12738
+//    }
12739
+//
12740
+//    private function getTableValue(string $table, array $where, string $field, $default = 0)
12741
+//    {
12742
+//        $value = Db::name($table)->where($where)->value($field);
12743
+//        return $value ?? $default;
12744
+//    }
12745
+//
12746
+//    private function easterOrder(string $table, array $where): void
12747
+//    {
12748
+//        $backupTable = 'backup_' . $table;
12749
+//        $rows = Db::name($backupTable)->where($where)->select()->toArray();
12750
+//        if ($rows) {
12751
+//            foreach ($rows as &$row) {
12752
+//                if (isset($row['del_time'])) unset($row['del_time']);
12753
+//            }
12754
+//            unset($row);
12755
+//            Db::name($table)->insertAll($rows);
12756
+//            Db::name($backupTable)->where($where)->delete();
12757
+//        }
12758
+//    }
12759
+//    private function easterUserAward(array $where): void
12760
+//    {
12761
+//        $row = Db::name('backup_user_change')->where($where)->where('user', 1)->field('pv, vr, score, contribute, annuity,uid')->find();
12762
+//        if ($row) {
12763
+//            $uid = $row['uid'];
12764
+//            $pv = $row['pv'];
12765
+//            $vr = $row['vr'];
12766
+//            $score = $row['score'];
12767
+//            $contribute = $row['contribute'];
12768
+//            $annuity = $row['annuity'];
12769
+//            Db::name('user')->where('uid', $uid)->update([
12770
+//                'pv' => Db::raw("pv + {$pv}"),
12771
+//                'vr' => Db::raw("vr - {$vr}"),
12772
+//                'score' => Db::raw("score - {$score}"),
12773
+//                'contribute' => Db::raw("contribute + {$contribute}"),
12774
+//                'annuity' => Db::raw("annuity + {$annuity}"),
12775
+//            ]);
12776
+//        }
12777
+//        $row2 = Db::name('backup_user_change')->where($where)->where('user', 2)->field('brokerage_price, score, per_contribute, annuity,uid')->find();
12778
+//        if ($row2) {
12779
+//            $spreadUid = $row2['uid'];
12780
+//            $spreadScore = $row2['score'];
12781
+//            $per_contribute = $row2['per_contribute'];
12782
+//            $spreadAnnuity = $row2['annuity'];
12783
+//            $spreadYongJin = $row2['brokerage_price'];
12784
+//            Db::name('user')->where('uid', $spreadUid)->update([
12785
+//                'score' => Db::raw("score + {$spreadScore}"),
12786
+//                'contribute' => Db::raw("contribute + {$per_contribute}"),
12787
+//                'annuity' => Db::raw("annuity + {$spreadAnnuity}"),
12788
+//                'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin}"),
12789
+//                'per_contribute' => Db::raw("per_contribute + {$per_contribute}"),
12790
+//            ]);
12791
+//        }
12792
+//        $row3 = Db::name('backup_user_change')->where($where)->where('user', 3)->field('brokerage_price,uid')->find();
12793
+//        if ($row3) {
12794
+//            $spreadUidTwo = $row3['uid'];
12795
+//            $spreadYongJin2 = $row3['brokerage_price'];
12796
+//            Db::name('user')->where('uid', $spreadUidTwo)->update([
12797
+//                'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin2}"),
12798
+//            ]);
12799
+//        }
12800
+//        $row4 = Db::name('backup_user_change')->where($where)->where('user', 4)->field('score,uid')->find();
12801
+//        if ($row4) {
12802
+//            $spreadUidThree = $row4['uid'];
12803
+//            $spreadScore3 = $row4['score'];
12804
+//            Db::name('user')->where('uid', $spreadUidThree)->update([
12805
+//                'score' => Db::raw("score + {$spreadScore3}"),
12806
+//            ]);
12807
+//        }
12808
+//    }
12809
+    public function easterUserAward(array $where): void
12810
+    {
12811
+        $orderId = $where['order_id'];
12812
+        $row1 = $this->backupUserChangeDao->getUserOneChangeFromOrderId($orderId);
12813
+        if (!empty($row1)) {
12814
+            $this->userDao->saveAll([
12815
+            'uid' => $row1['uid'],
12816
+            'pv' => Db::raw("pv + {$row1['pv']}"),
12817
+            'vr' => Db::raw("vr - {$row1['vr']}"),
12818
+            'score' => Db::raw("score - {$row1['score']}"),
12819
+            'contribute' => Db::raw("contribute + {$row1['contribute']}"),
12820
+            'annuity' => Db::raw("annuity + {$row1['annuity']}"),
12821
+            ]);
12822
+        }
12823
+        $row2 = $this->backupUserChangeDao->getUserTwoChangeFromOrderId($orderId);
12824
+        if (!empty($row2)) {
12825
+            $this->userDao->saveAll([
12826
+                'uid' => $row2['uid'],
12827
+                'score' => Db::raw("score + {$row2['score']}"),
12828
+                'contribute' => Db::raw("contribute + {$row2['per_contribute']}"),
12829
+                'annuity' => Db::raw("annuity + {$row2['annuity']}"),
12830
+                'brokerage_price' => Db::raw("brokerage_price + {$row2['brokerage_price']}"),
12831
+                'per_contribute' => Db::raw("per_contribute + {$row2['per_contribute']}"),
12832
+            ]);
12833
+        }
12834
+        $row3 = $this->backupUserChangeDao->getUserThreeChangeFromOrderId($orderId);
12835
+        if (!empty($row3)) {
12836
+            $this->userDao->saveAll([
12837
+                'uid' => $row3['uid'],
12838
+                'brokerage_price' => Db::raw("brokerage_price + {$row3['brokerage_price']}"),
12839
+            ]);
12840
+        }
12841
+        $row4 = $this->backupUserChangeDao->getUserFourChangeFromOrderId($orderId);
12842
+        if (!empty($row4)) {
12843
+            $this->userDao->saveAll([
12844
+                'uid' => $row4['uid'],
12845
+                'score' => Db::raw("score + {$row4['score']}")
12846
+            ]);
12847
+        }
12848
+    }
12431 12849
 }
12850
+
12851
+

+ 243 - 233
app/controller/admin/order/Order.php

@@ -348,254 +348,264 @@ class Order extends BaseController
348 348
         if (!in_array($adminId, [1,28,29])) {//超级管理员,财务,老总
349 349
             return app('json')->fail('后台权限不足');
350 350
         }
351
-        try {
352
-            Db::startTrans();
353
-            //查找是否有推荐人
354
-            $spreadUid = Db::name('user')->where('uid', $uid)->value('spread_uid');
355
-            //取出pv
356
-            $pv = $this->getValue('user_pv_log', [['order_id', '=', $order_id], ['status', '=', 1],], 'pv');
357
-            //取出 vr
358
-            $payVr = $this->getValue('user_sign_vr', [['order_id', '=', $order_id], ['type', '=', 2],], 'number');
359
-            //取出购买赠送积分 / 支出积分
360
-            $score = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['source_type', '=', 3], ['uid', '=', $uid], ['pm', '=', 1],], 'reward_socre');
361
-            $payScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 2], ['uid', '=', $uid],], 'reward_socre');
362
-            // 贡献值
363
-            $gongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $uid],], 'number');
364
-            // 养老金
365
-            $yangLaoJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 1], ['uid', '=', $uid],], 'number');
366
-            if($spreadUid){  //如果有推荐人就执行
367
-                $spreadScore = 0;
368
-                $spreadGongXian = 0;
369
-                $spreadYlj = 0;
370
-                $spreadYongJin = 0;
371
-                $spreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid', '=', $spreadUid], ['status', '=', 1],], 'reward_socre');
372
-                $spreadGongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $spreadUid],], 'number');
373
-                $spreadYlj = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 5], ['uid', '=', $spreadUid],], 'number'); //推荐获得养老金
374
-                $spreadYongJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadUid],], 'number');  //推荐获得佣金
375
-                $spreadUser = Db::name('user')->where('uid', $spreadUid)->find();
376
-                Db::name('backup_user')->insert($spreadUser);  //插入备份表
377
-                Db::name('user')->where('uid', $spreadUid)   //更新数据
378
-                    ->update([
379
-                        'score' => Db::raw("score - {$spreadScore}"),
380
-                        'per_contribute' => Db::raw("per_contribute - {$spreadGongXian}"),
381
-                        'brokerage_price' => Db::raw("brokerage_price - {$spreadYongJin}"),
382
-                        'annuity' => Db::raw("annuity - {$spreadYlj}"),
383
-                    ]);
384
-                $userhjm1 =[
385
-                    'uid' => $spreadUid,
386
-                    'order_id' => $order_id,
387
-                    'score' => $spreadScore??0,
388
-                    'per_contribute' => $spreadGongXian??0,
389
-                    'brokerage_price' => $spreadYongJin??0,
390
-                    'user' => 2,
391
-                ];
392
-                Db::name('backup_user_change')->insert($userhjm1);   //插入更新数据记录表
393
-            }
394
-            //扫吗消费
395
-            $smSpreadUid = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['mark','like','%扫码%'], ['status', '=', 1],], 'uid');
396
-            $smSpreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid','=',$smSpreadUid], ['status', '=', 1],], 'reward_socre');
397
-            //第二推荐
398
-            $spreadYongJinTwoUid = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', 'not in', [$uid, $spreadUid]],], 'uid');
399
-            $spreadYongJinTwo = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadYongJinTwoUid],], 'number');
400
-            //更新购买用户的user表
401
-            $uscore = $payScore - $score;
402
-            $user = Db::name('user')->where('uid', $uid)->find();
403
-            Db::name('backup_user')->insert($user);
404
-            Db::name('user')->where('uid', $uid)
405
-                ->update([
406
-                    'pv'         => Db::raw("pv - {$pv}"),
407
-                    'vr'         => Db::raw("vr + {$payVr}"),
408
-                    'score'      => Db::raw("score + {$uscore}"),
409
-                    'contribute' => Db::raw("contribute - {$gongXian}"),
410
-                    'annuity'    => Db::raw("annuity - {$yangLaoJin}"),
411
-                ]);
412
-            $userhjm =[
413
-                'uid' => $uid,
414
-                'order_id' => $order_id,
415
-                'pv' => $pv??0,
416
-                'vr' => $payVr??0,
417
-                'score' => $uscore??0,
418
-                'contribute' => $gongXian??0,
419
-                'annuity' => $yangLaoJin??0,
420
-                'user' => 1,
421
-            ];
422
-            Db::name('backup_user_change')->insert($userhjm);//具体修改插入对应表
423
-            //第二推荐
424
-            if($spreadYongJinTwoUid) {
425
-                $spreadUserTwo = Db::name('user')->where('uid', $spreadYongJinTwoUid)->find();
426
-                Db::name('backup_user')->insert($spreadUserTwo);
427
-                Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
428
-                $userhjm2 =[
429
-                    'uid' => $spreadYongJinTwoUid,
430
-                    'order_id' => $order_id,
431
-                    'brokerage_price' => $spreadYongJinTwo??0,
432
-                    'user' => 3,
433
-                ];
434
-                Db::name('backup_user_change')->insert($userhjm2);
435
-            }//扫码消费
436
-            if($smSpreadUid){
437
-                $smUserTwo = Db::name('user')->where('uid', $smSpreadUid)->find();
438
-                Db::name('backup_user')->insert($smUserTwo);
439
-                Db::name('user')->where('uid', $smSpreadUid)->dec('score', $smSpreadScore)->update();
440
-                $userhjm3 =[
441
-                    'uid' => $smSpreadUid,
442
-                    'order_id' => $order_id,
443
-                    'score' => $smSpreadScore??0,
444
-                    'user' => 4,
445
-                ];
446
-                Db::name('backup_user_change')->insert($userhjm3);
447
-            }
448
-            // 删除订单相关表p;
449
-            $this->backupAndDelete('store_order', ['group_order_id' => $group_order_id]);
450
-            $this->backupAndDelete('store_group_order', ['group_order_id' => $group_order_id]);
451
-            $this->backupAndDelete('user_pv_log', ['order_id' => $order_id]);
452
-            $this->backupAndDelete('user_sign_vr', ['order_id' => $order_id]);
453
-            $this->backupAndDelete('user_sign_score', ['order_id' => $order_id]);
454
-            $this->backupAndDelete('user_sign_gongxian', ['order_id' => $order_id]);
455
-            $this->backupAndDelete('user_bill', ['link_id' => $order_id]);
456
-            $this->backupAndDelete('gzc_logs', ['link_id' => $order_id]);
457
-            Db::commit();
458
-        } catch (\Exception $e) {
459
-            Db::rollback();
460
-            return app('json')->fail('操作失败'. $e->getMessage());
351
+        $ok = $this->repository->useKillOrderRewards($group_order_id, $order_id, $uid,$adminId);
352
+        if (!$ok) {
353
+            return app('json')->fail('操作失败');
461 354
         }
462
-        Db::name("user_order_kill_records")->insert([//记录哪位管理员撤销的订单
463
-            'operation_id' => $adminId,
464
-            'uid' => $uid,
465
-            'order_id' => $order_id,
466
-            'mark' => '后台管理员撤销订单记录'
467
-        ]);
468 355
         return app('json')->success('操作成功');
356
+//        try {
357
+//            Db::startTrans();
358
+//            //查找是否有推荐人
359
+//            $spreadUid = Db::name('user')->where('uid', $uid)->value('spread_uid');
360
+//            //取出pv
361
+//            $pv = $this->getValue('user_pv_log', [['order_id', '=', $order_id], ['status', '=', 1],], 'pv');
362
+//            //取出 vr
363
+//            $payVr = $this->getValue('user_sign_vr', [['order_id', '=', $order_id], ['type', '=', 2],], 'number');
364
+//            //取出购买赠送积分 / 支出积分
365
+//            $score = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['source_type', '=', 3], ['uid', '=', $uid], ['pm', '=', 1],], 'reward_socre');
366
+//            $payScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 2], ['uid', '=', $uid],], 'reward_socre');
367
+//            // 贡献值
368
+//            $gongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $uid],], 'number');
369
+//            // 养老金
370
+//            $yangLaoJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 1], ['uid', '=', $uid],], 'number');
371
+//            if($spreadUid){  //如果有推荐人就执行
372
+//                $spreadScore = 0;
373
+//                $spreadGongXian = 0;
374
+//                $spreadYlj = 0;
375
+//                $spreadYongJin = 0;
376
+//                $spreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid', '=', $spreadUid], ['status', '=', 1],], 'reward_socre');
377
+//                $spreadGongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $spreadUid],], 'number');
378
+//                $spreadYlj = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 5], ['uid', '=', $spreadUid],], 'number'); //推荐获得养老金
379
+//                $spreadYongJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadUid],], 'number');  //推荐获得佣金
380
+//                $spreadUser = Db::name('user')->where('uid', $spreadUid)->find();
381
+//                Db::name('backup_user')->insert($spreadUser);  //插入备份表
382
+//                Db::name('user')->where('uid', $spreadUid)   //更新数据
383
+//                    ->update([
384
+//                        'score' => Db::raw("score - {$spreadScore}"),
385
+//                        'per_contribute' => Db::raw("per_contribute - {$spreadGongXian}"),
386
+//                        'brokerage_price' => Db::raw("brokerage_price - {$spreadYongJin}"),
387
+//                        'annuity' => Db::raw("annuity - {$spreadYlj}"),
388
+//                    ]);
389
+//                $userhjm1 =[
390
+//                    'uid' => $spreadUid,
391
+//                    'order_id' => $order_id,
392
+//                    'score' => $spreadScore??0,
393
+//                    'per_contribute' => $spreadGongXian??0,
394
+//                    'brokerage_price' => $spreadYongJin??0,
395
+//                    'user' => 2,
396
+//                ];
397
+//                Db::name('backup_user_change')->insert($userhjm1);   //插入更新数据记录表
398
+//            }
399
+//            //扫吗消费
400
+//            $smSpreadUid = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['mark','like','%扫码%'], ['status', '=', 1],], 'uid');
401
+//            $smSpreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid','=',$smSpreadUid], ['status', '=', 1],], 'reward_socre');
402
+//            //第二推荐
403
+//            $spreadYongJinTwoUid = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', 'not in', [$uid, $spreadUid]],], 'uid');
404
+//            $spreadYongJinTwo = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadYongJinTwoUid],], 'number');
405
+//            //更新购买用户的user表
406
+//            $uscore = $payScore - $score;
407
+//            $user = Db::name('user')->where('uid', $uid)->find();
408
+//            Db::name('backup_user')->insert($user);
409
+//            Db::name('user')->where('uid', $uid)
410
+//                ->update([
411
+//                    'pv'         => Db::raw("pv - {$pv}"),
412
+//                    'vr'         => Db::raw("vr + {$payVr}"),
413
+//                    'score'      => Db::raw("score + {$uscore}"),
414
+//                    'contribute' => Db::raw("contribute - {$gongXian}"),
415
+//                    'annuity'    => Db::raw("annuity - {$yangLaoJin}"),
416
+//                ]);
417
+//            $userhjm =[
418
+//                'uid' => $uid,
419
+//                'order_id' => $order_id,
420
+//                'pv' => $pv??0,
421
+//                'vr' => $payVr??0,
422
+//                'score' => $uscore??0,
423
+//                'contribute' => $gongXian??0,
424
+//                'annuity' => $yangLaoJin??0,
425
+//                'user' => 1,
426
+//            ];
427
+//            Db::name('backup_user_change')->insert($userhjm);//具体修改插入对应表
428
+//            //第二推荐
429
+//            if($spreadYongJinTwoUid) {
430
+//                $spreadUserTwo = Db::name('user')->where('uid', $spreadYongJinTwoUid)->find();
431
+//                Db::name('backup_user')->insert($spreadUserTwo);
432
+//                Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
433
+//                $userhjm2 =[
434
+//                    'uid' => $spreadYongJinTwoUid,
435
+//                    'order_id' => $order_id,
436
+//                    'brokerage_price' => $spreadYongJinTwo??0,
437
+//                    'user' => 3,
438
+//                ];
439
+//                Db::name('backup_user_change')->insert($userhjm2);
440
+//            }//扫码消费
441
+//            if($smSpreadUid){
442
+//                $smUserTwo = Db::name('user')->where('uid', $smSpreadUid)->find();
443
+//                Db::name('backup_user')->insert($smUserTwo);
444
+//                Db::name('user')->where('uid', $smSpreadUid)->dec('score', $smSpreadScore)->update();
445
+//                $userhjm3 =[
446
+//                    'uid' => $smSpreadUid,
447
+//                    'order_id' => $order_id,
448
+//                    'score' => $smSpreadScore??0,
449
+//                    'user' => 4,
450
+//                ];
451
+//                Db::name('backup_user_change')->insert($userhjm3);
452
+//            }
453
+//            // 删除订单相关表p;
454
+//            $this->backupAndDelete('store_order', ['group_order_id' => $group_order_id]);
455
+//            $this->backupAndDelete('store_group_order', ['group_order_id' => $group_order_id]);
456
+//            $this->backupAndDelete('user_pv_log', ['order_id' => $order_id]);
457
+//            $this->backupAndDelete('user_sign_vr', ['order_id' => $order_id]);
458
+//            $this->backupAndDelete('user_sign_score', ['order_id' => $order_id]);
459
+//            $this->backupAndDelete('user_sign_gongxian', ['order_id' => $order_id]);
460
+//            $this->backupAndDelete('user_bill', ['link_id' => $order_id]);
461
+//            $this->backupAndDelete('gzc_logs', ['link_id' => $order_id]);
462
+//            Db::commit();
463
+//        } catch (\Exception $e) {
464
+//            Db::rollback();
465
+//            return app('json')->fail('操作失败'. $e->getMessage());
466
+//        }
467
+//        Db::name("user_order_kill_records")->insert([//记录哪位管理员撤销的订单
468
+//            'operation_id' => $adminId,
469
+//            'uid' => $uid,
470
+//            'order_id' => $order_id,
471
+//            'mark' => '后台管理员撤销订单记录'
472
+//        ]);
473
+//        return app('json')->success('操作成功');
469 474
     }
470
-
471
-    private function backupAndDelete($table, array $where)//备份并删除
472
-    {
473
-        $backupTable = 'backup_' . $table;
474
-        $rows = Db::name($table)->where($where)->select()->toArray();
475
-        if ($rows) {
476
-            Db::name($backupTable)->insertAll($rows);
477
-            Db::name($table)->where($where)->delete();
478
-        }
479
-    }
480
-    private function getValue($table, array $where, string $field, $default = 0)//查找
481
-    {
482
-        $value = Db::name($table)->where($where)->value($field);
483
-        return $value ?? $default;
484
-    }
485
-
475
+//
476
+//    private function backupAndDelete($table, array $where)//备份并删除
477
+//    {
478
+//        $backupTable = 'backup_' . $table;
479
+//        $rows = Db::name($table)->where($where)->select()->toArray();
480
+//        if ($rows) {
481
+//            Db::name($backupTable)->insertAll($rows);
482
+//            Db::name($table)->where($where)->delete();
483
+//        }
484
+//    }
485
+//    private function getValue($table, array $where, string $field, $default = 0)//查找
486
+//    {
487
+//        $value = Db::name($table)->where($where)->value($field);
488
+//        return $value ?? $default;
489
+//    }
486 490
     /**
487 491
      * 展示撤回订单列表,恢复订单
488 492
      */
489 493
     public function killOrderLst()  //撤回订单的列表
490 494
     {
491
-        $query = Db::name('backup_store_order')->paginate(20)->toArray();
492
-        return app('json')->success($query, '获取成功');
495
+//        $query = Db::name('backup_store_order')->paginate(20)->toArray();
496
+//        return app('json')->success($query, '获取成功');
497
+        $list = $this->repository->getKillOrderList();
498
+        return app('json')->success($list, '获取成功');
493 499
     }
494 500
     public function easterKillOrder(){   //恢复订单
495 501
         $group_order_id = request()->param('group_order_id');
496 502
         $order_id = request()->param('order_id');
497
-        $adminId = $this->request->adminId();
498 503
         if (empty($order_id) || empty($group_order_id)) {
499 504
             return app('json')->fail('参数缺失');
500 505
         }
501
-        try {
502
-            Db::startTrans();
503
-            // 恢复订单相关表
504
-            $this->easterOrder('store_order', ['group_order_id' => $group_order_id]);
505
-            $this->easterOrder('store_group_order', ['group_order_id' => $group_order_id]);
506
-            // 恢复 pv
507
-            $this->easterOrder('user_pv_log', ['order_id' => $order_id]);
508
-            // 恢复 vr
509
-            $this->easterOrder('user_sign_vr', ['order_id' => $order_id]);
510
-            // 恢复 积分
511
-            $this->easterOrder('user_sign_score', ['order_id' => $order_id]);
512
-            // 恢复 贡献值
513
-            $this->easterOrder('user_sign_gongxian', ['order_id' => $order_id]);
514
-            // 恢复 佣金/养老金等
515
-            $this->easterOrder('user_bill', ['link_id' => $order_id]);
516
-            // 恢复 公证处
517
-            $this->easterOrder('gzc_logs', ['link_id' => $order_id]);
518
-            //恢复用户奖励
519
-            $this->easterUserAward(['order_id' => $order_id]);
520
-            Db::commit();
521
-        } catch (\Exception $e) {
522
-            Db::rollback();
523
-            return app('json')->fail('撤回失败: '.$e->getMessage());
524
-        }
525
-        Db::name("user_order_recover_records")->insert([//记录恢复的订单
526
-            'operation_id' => $adminId,
527
-            'order_id' => $order_id,
528
-            'mark' => '恢复订单记录'
529
-        ]);
530
-        return app('json')->success('撤回成功');
531
-    }
532
-    private function easterOrder($table, array $where)  //恢复表数据
533
-    {
534
-        $backupTable = 'backup_' . $table;
535
-        $rows = Db::name($backupTable)->where($where)->select()->toArray();
536
-
537
-        if ($rows) {
538
-            foreach ($rows as &$row) {
539
-                if (isset($row['del_time'])) unset($row['del_time']);
540
-            }
541
-            unset($row);
542
-            Db::name($table)->insertAll($rows);
543
-            Db::name($backupTable)->where($where)->delete();
544
-        }
545
-    }
546
-    private function easterUserAward(array $where){  //恢复奖励
547
-        $row = Db::name('backup_user_change')->where($where)->where('user', 1)->field('pv, vr, score, contribute, annuity,uid')->find();
548
-        $uid = $row['uid'];
549
-        $pv   = $row['pv'];
550
-        $vr   = $row['vr'];
551
-        $score= $row['score'];
552
-        $contribute = $row['contribute'];
553
-        $annuity = $row['annuity'];
554
-        Db::name('user') //更新订单用户
555
-            ->where('uid', $uid)
556
-            ->update([
557
-                'pv'         => Db::raw("pv + {$pv}"),
558
-                'vr'         => Db::raw("vr - {$vr}"),
559
-                'score'      => Db::raw("score - {$score}"),
560
-                'contribute' => Db::raw("contribute + {$contribute}"),
561
-                'annuity'    => Db::raw("annuity + {$annuity}"),
562
-            ]);
563
-        $row2 = Db::name('backup_user_change')->where($where)->where('user', 2)->field('brokerage_price, score, per_contribute, annuity,uid')->find();
564
-        if ($row2) {
565
-            $spreadUid = $row2['uid'];
566
-            $spreadScore = $row2['score'];
567
-            $per_contribute = $row2['per_contribute'];
568
-            $spreadAnnuity = $row2['annuity'];
569
-            $spreadYongJin = $row2['brokerage_price'];
570
-            Db::name('user')     //更新推荐人
571
-            ->where('uid', $spreadUid)
572
-                ->update([
573
-                    'score' => Db::raw("score + {$spreadScore}"),
574
-                    'contribute' => Db::raw("contribute + {$per_contribute}"),
575
-                    'annuity' => Db::raw("annuity + {$spreadAnnuity}"),
576
-                    'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin}"),
577
-                    'per_contribute'=> Db::raw("per_contribute + {$per_contribute}"),
578
-                ]);
579
-        }
580
-        $row3 = Db::name('backup_user_change')->where($where)->where('user', 3)->field('brokerage_price,uid')->find();
581
-        if ($row3) {
582
-            $spreadUidTwo = $row3['uid']; //第二推荐人
583
-            $spreadYongJin2 = $row3['brokerage_price'];
584
-            Db::name('user')
585
-                ->where('uid', $spreadUidTwo)
586
-                ->update([
587
-                    'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin2}"),
588
-                ]);
589
-        }
590
-        $row4 = Db::name('backup_user_change')->where($where)->where('user', 4)->field('score,uid')->find();
591
-        if ($row4) {
592
-            $spreadUidThree = $row4['uid'];   //扫码
593
-            $spreadScore3 = $row4['score'];
594
-            Db::name('user')
595
-                ->where('uid', $spreadUidThree)
596
-                ->update([
597
-                    'score' => Db::raw("score + {$spreadScore3}"),
598
-                ]);
506
+        $ok = $this->repository->recoverOrderByAdmin($group_order_id, $order_id);
507
+        if (!$ok) {
508
+            return app('json')->fail('操作失败');
599 509
         }
510
+        return app('json')->success('操作成功');
511
+//        try {
512
+//            Db::startTrans();
513
+//            // 恢复订单相关表
514
+//            $this->easterOrder('store_order', ['group_order_id' => $group_order_id]);
515
+//            $this->easterOrder('store_group_order', ['group_order_id' => $group_order_id]);
516
+//            // 恢复 pv
517
+//            $this->easterOrder('user_pv_log', ['order_id' => $order_id]);
518
+//            // 恢复 vr
519
+//            $this->easterOrder('user_sign_vr', ['order_id' => $order_id]);
520
+//            // 恢复 积分
521
+//            $this->easterOrder('user_sign_score', ['order_id' => $order_id]);
522
+//            // 恢复 贡献值
523
+//            $this->easterOrder('user_sign_gongxian', ['order_id' => $order_id]);
524
+//            // 恢复 佣金/养老金等
525
+//            $this->easterOrder('user_bill', ['link_id' => $order_id]);
526
+//            // 恢复 公证处
527
+//            $this->easterOrder('gzc_logs', ['link_id' => $order_id]);
528
+//            //恢复用户奖励
529
+//            $this->easterUserAward(['order_id' => $order_id]);
530
+//            Db::commit();
531
+//        } catch (\Exception $e) {
532
+//            Db::rollback();
533
+//            return app('json')->fail('撤回失败: '.$e->getMessage());
534
+//        }
535
+//        Db::name("user_order_recover_records")->insert([//记录恢复的订单
536
+//            'operation_id' => $adminId,
537
+//            'order_id' => $order_id,
538
+//            'mark' => '恢复订单记录'
539
+//        ]);
540
+//        return app('json')->success('撤回成功');
600 541
     }
542
+//    private function easterOrder($table, array $where)  //恢复表数据
543
+//    {
544
+//        $backupTable = 'backup_' . $table;
545
+//        $rows = Db::name($backupTable)->where($where)->select()->toArray();
546
+//
547
+//        if ($rows) {
548
+//            foreach ($rows as &$row) {
549
+//                if (isset($row['del_time'])) unset($row['del_time']);
550
+//            }
551
+//            unset($row);
552
+//            Db::name($table)->insertAll($rows);
553
+//            Db::name($backupTable)->where($where)->delete();
554
+//        }
555
+//    }
556
+//    private function easterUserAward(array $where){  //恢复奖励
557
+//        $row = Db::name('backup_user_change')->where($where)->where('user', 1)->field('pv, vr, score, contribute, annuity,uid')->find();
558
+//        $uid = $row['uid'];
559
+//        $pv   = $row['pv'];
560
+//        $vr   = $row['vr'];
561
+//        $score= $row['score'];
562
+//        $contribute = $row['contribute'];
563
+//        $annuity = $row['annuity'];
564
+//        Db::name('user') //更新订单用户
565
+//            ->where('uid', $uid)
566
+//            ->update([
567
+//                'pv'         => Db::raw("pv + {$pv}"),
568
+//                'vr'         => Db::raw("vr - {$vr}"),
569
+//                'score'      => Db::raw("score - {$score}"),
570
+//                'contribute' => Db::raw("contribute + {$contribute}"),
571
+//                'annuity'    => Db::raw("annuity + {$annuity}"),
572
+//            ]);
573
+//        $row2 = Db::name('backup_user_change')->where($where)->where('user', 2)->field('brokerage_price, score, per_contribute, annuity,uid')->find();
574
+//        if ($row2) {
575
+//            $spreadUid = $row2['uid'];
576
+//            $spreadScore = $row2['score'];
577
+//            $per_contribute = $row2['per_contribute'];
578
+//            $spreadAnnuity = $row2['annuity'];
579
+//            $spreadYongJin = $row2['brokerage_price'];
580
+//            Db::name('user')     //更新推荐人
581
+//            ->where('uid', $spreadUid)
582
+//                ->update([
583
+//                    'score' => Db::raw("score + {$spreadScore}"),
584
+//                    'contribute' => Db::raw("contribute + {$per_contribute}"),
585
+//                    'annuity' => Db::raw("annuity + {$spreadAnnuity}"),
586
+//                    'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin}"),
587
+//                    'per_contribute'=> Db::raw("per_contribute + {$per_contribute}"),
588
+//                ]);
589
+//        }
590
+//        $row3 = Db::name('backup_user_change')->where($where)->where('user', 3)->field('brokerage_price,uid')->find();
591
+//        if ($row3) {
592
+//            $spreadUidTwo = $row3['uid']; //第二推荐人
593
+//            $spreadYongJin2 = $row3['brokerage_price'];
594
+//            Db::name('user')
595
+//                ->where('uid', $spreadUidTwo)
596
+//                ->update([
597
+//                    'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin2}"),
598
+//                ]);
599
+//        }
600
+//        $row4 = Db::name('backup_user_change')->where($where)->where('user', 4)->field('score,uid')->find();
601
+//        if ($row4) {
602
+//            $spreadUidThree = $row4['uid'];   //扫码
603
+//            $spreadScore3 = $row4['score'];
604
+//            Db::name('user')
605
+//                ->where('uid', $spreadUidThree)
606
+//                ->update([
607
+//                    'score' => Db::raw("score + {$spreadScore3}"),
608
+//                ]);
609
+//        }
610
+//    }
601 611
 }