Browse Source

优化用户下单方法-进行中

sunxbiao 1 year ago
parent
commit
aeffe1dda5

+ 15 - 0
app/common/enum/user/UserCertificationEnum.php

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace app\common\enum\user;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class UserCertificationEnum extends CommonEnum
8
+{
9
+    // 用户认证状态枚举
10
+    const STATUS = [
11
+        'Pending' => ['code' => 0, 'name' => '未审核'],
12
+        'Approved' => ['code' => 1, 'name' => '已通过'],
13
+        'Rejected' => ['code' => 2, 'name' => '已拒绝'],
14
+    ];
15
+}

+ 27 - 12
app/common/repositories/user/UserBillRepository.php

@@ -504,37 +504,52 @@ class UserBillRepository extends BaseRepository
504 504
             }, $userBillEntityList);
505 505
             /** @var UserEntity[] $userEntityList */
506 506
             $userEntityList = [];
507
+            /** @var UserEntity[] $userEntityMapByUid */
507 508
             $userEntityMapByUid = [];
508 509
 
509 510
             if (!empty($userIdList)) {
510 511
                 /** @var UserRepository $userRepository */
511 512
                 $userRepository = app()->make(UserRepository::class);
512 513
                 $userEntityList = $userRepository->getUserEntityListByUidList($userIdList);
513
-                $userEntityMapByUid = array_map(function ($userEntity) {
514
+                /** @var UserEntity[] $userEntityMapByUid */
515
+                $userEntityMapByUid = array_column($userEntityList, null, 'uid');
516
+
514 517
 
515
-                }, $userEntityList);
516 518
             }
517 519
 
520
+            $updateUserDataList = [];
521
+            $updateUserBillDataList = [];
518 522
             foreach ($userBillEntityList as $userBillEntity) {
519 523
                 if (empty($userBillEntity->getBillId()) || empty($userBillEntity->getUid())) {
520
-                    throw new ValidateException('无效的账单记录');
524
+                    // throw new ValidateException('无效的账单记录');
525
+                    continue;
521 526
                 }
522 527
                 if (!empty($userBillEntity->getTakeTime())) {
523
-                    throw new ValidateException('该账单记录已更新,请勿重复操作');
528
+                    throw new ValidateException("该账单记录已更新,请勿重复操作({$userBillEntity->getBillId()})");
524 529
                 }
525 530
 
526
-                $userEntity = $userRepository->getUserEntityByUid($userBillEntity->getUid());
527
-                if (empty($userEntity->getUid())) {
528
-                    throw new ValidateException('未查询到用户信息');
531
+                $userEntity = $userEntityMapByUid[$userBillEntity->getUid()];
532
+                if (empty($userEntity) || empty($userEntity->getUid())) {
533
+                    throw new ValidateException("未查询到用户信息({$userBillEntity->getBillId()})");
529 534
                 }
530 535
                 if ($userBillEntity->getType() == UserBillEnum::COMMISSION_TYPE['DIRECT_REFERRAL']['code']) {
531 536
                     // 直推奖
532
-                    $surplus = bcsub($userEntity->getVr(), $userBillEntity->getNumber(), 2);
533
-                    if ($surplus < 0.00) {
534
-                        throw new ValidateException('用户VR不足');
537
+                    if (!isset($updateUserDataList[$userEntity->getUid()]['brokerage_price'])) {
538
+                        $updateUserDataList[$userEntity->getUid()]['brokerage_price'] = $userEntity->getBrokeragePrice();
535 539
                     }
536
-                } else {
537
-                    $surplus = bcadd($userEntity->getVr(), $userBillEntity->getNumber(), 2);
540
+                    // 更新用户 信息
541
+                    if ($userBillEntity->getPm() == UserBillEnum::PM['EXPEND']['code']) {
542
+                        if ($updateUserDataList[$userBillEntity->getUid()]['brokerage_price'] < $userBillEntity->getNumber()) {
543
+                            throw new ValidateException('用户佣金不足');
544
+                        }
545
+                        $updateUserDataList[$userBillEntity->getUid()]['brokerage_price'] -= $userBillEntity->getNumber();
546
+                    } else {
547
+                        $updateUserDataList[$userBillEntity->getUid()]['brokerage_price'] += $userBillEntity->getNumber();
548
+                    }
549
+                    // 更新佣金记录
550
+                    $updateUserBillDataList[$userBillEntity->getBillId()] = ['status' => UserBillEnum::STATUS['VALID']['code']];
551
+                } else if ($userBillEntity->getType() == UserBillEnum::COMMISSION_TYPE['PENSION']['code']) {
552
+
538 553
                 }
539 554
 
540 555
 

+ 3 - 0
app/entity/CommonEntity.php

@@ -60,6 +60,9 @@ class CommonEntity
60 60
         $camelArray = $this->toArray(); // 先获取驼峰格式的数组
61 61
 
62 62
         foreach ($camelArray as $key => $value) {
63
+            if (is_null($value)) {
64
+                continue;
65
+            }
63 66
             // 将驼峰键名转为下划线格式
64 67
             $underlineKey = $this->camelToUnderline($key);
65 68
             $result[$underlineKey] = $value;

+ 237 - 0
app/entity/data/user/UserCertificationEntity.php

@@ -0,0 +1,237 @@
1
+<?php
2
+
3
+namespace app\entity\data\user;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class UserCertificationEntity extends DataEntity
8
+{
9
+    public $id = null;  // 用户认证ID
10
+    public $userName = null;  // 认证姓名
11
+    public $mobile = null;  // 认证手机号
12
+    public $userCard = null;  // 身份证号
13
+    public $cardPositive = null;  // 身份证正面照
14
+    public $cardReverse = null;  // 身份证反面照
15
+    public $status = null;  // 认证状态:0未审核,1已通过,2已拒绝
16
+    public $reason = null;  // 拒绝原因
17
+    public $auditTime = null;  // 审核时间
18
+    public $createTime = null;  // 提交审核时间
19
+    public $updateTime = null;  // 修改时间
20
+    public $uid = null;  // 用户ID
21
+
22
+    /**
23
+     * @return mixed
24
+     */
25
+    public function getId()
26
+    {
27
+        return $this->id;
28
+    }
29
+
30
+    /**
31
+     * @param mixed $id
32
+     * @return UserCertificationEntity
33
+     */
34
+    public function setId($id): UserCertificationEntity
35
+    {
36
+        $this->id = $id;
37
+        return $this;
38
+    }
39
+
40
+    /**
41
+     * @return mixed
42
+     */
43
+    public function getUserName()
44
+    {
45
+        return $this->userName;
46
+    }
47
+
48
+    /**
49
+     * @param mixed $userName
50
+     * @return UserCertificationEntity
51
+     */
52
+    public function setUserName($userName): UserCertificationEntity
53
+    {
54
+        $this->userName = $userName;
55
+        return $this;
56
+    }
57
+
58
+    /**
59
+     * @return mixed
60
+     */
61
+    public function getMobile()
62
+    {
63
+        return $this->mobile;
64
+    }
65
+
66
+    /**
67
+     * @param mixed $mobile
68
+     * @return UserCertificationEntity
69
+     */
70
+    public function setMobile($mobile): UserCertificationEntity
71
+    {
72
+        $this->mobile = $mobile;
73
+        return $this;
74
+    }
75
+
76
+    /**
77
+     * @return mixed
78
+     */
79
+    public function getUserCard()
80
+    {
81
+        return $this->userCard;
82
+    }
83
+
84
+    /**
85
+     * @param mixed $userCard
86
+     * @return UserCertificationEntity
87
+     */
88
+    public function setUserCard($userCard): UserCertificationEntity
89
+    {
90
+        $this->userCard = $userCard;
91
+        return $this;
92
+    }
93
+
94
+    /**
95
+     * @return mixed
96
+     */
97
+    public function getCardPositive()
98
+    {
99
+        return $this->cardPositive;
100
+    }
101
+
102
+    /**
103
+     * @param mixed $cardPositive
104
+     * @return UserCertificationEntity
105
+     */
106
+    public function setCardPositive($cardPositive): UserCertificationEntity
107
+    {
108
+        $this->cardPositive = $cardPositive;
109
+        return $this;
110
+    }
111
+
112
+    /**
113
+     * @return mixed
114
+     */
115
+    public function getCardReverse()
116
+    {
117
+        return $this->cardReverse;
118
+    }
119
+
120
+    /**
121
+     * @param mixed $cardReverse
122
+     * @return UserCertificationEntity
123
+     */
124
+    public function setCardReverse($cardReverse): UserCertificationEntity
125
+    {
126
+        $this->cardReverse = $cardReverse;
127
+        return $this;
128
+    }
129
+
130
+    /**
131
+     * @return mixed
132
+     */
133
+    public function getStatus()
134
+    {
135
+        return $this->status;
136
+    }
137
+
138
+    /**
139
+     * @param mixed $status
140
+     * @return UserCertificationEntity
141
+     */
142
+    public function setStatus($status): UserCertificationEntity
143
+    {
144
+        $this->status = $status;
145
+        return $this;
146
+    }
147
+
148
+    /**
149
+     * @return mixed
150
+     */
151
+    public function getReason()
152
+    {
153
+        return $this->reason;
154
+    }
155
+
156
+    /**
157
+     * @param mixed $reason
158
+     * @return UserCertificationEntity
159
+     */
160
+    public function setReason($reason): UserCertificationEntity
161
+    {
162
+        $this->reason = $reason;
163
+        return $this;
164
+    }
165
+
166
+    /**
167
+     * @return mixed
168
+     */
169
+    public function getAuditTime()
170
+    {
171
+        return $this->auditTime;
172
+    }
173
+
174
+    /**
175
+     * @param mixed $auditTime
176
+     * @return UserCertificationEntity
177
+     */
178
+    public function setAuditTime($auditTime): UserCertificationEntity
179
+    {
180
+        $this->auditTime = $auditTime;
181
+        return $this;
182
+    }
183
+
184
+    /**
185
+     * @return mixed
186
+     */
187
+    public function getCreateTime()
188
+    {
189
+        return $this->createTime;
190
+    }
191
+
192
+    /**
193
+     * @param mixed $createTime
194
+     * @return UserCertificationEntity
195
+     */
196
+    public function setCreateTime($createTime): UserCertificationEntity
197
+    {
198
+        $this->createTime = $createTime;
199
+        return $this;
200
+    }
201
+
202
+    /**
203
+     * @return mixed
204
+     */
205
+    public function getUpdateTime()
206
+    {
207
+        return $this->updateTime;
208
+    }
209
+
210
+    /**
211
+     * @param mixed $updateTime
212
+     * @return UserCertificationEntity
213
+     */
214
+    public function setUpdateTime($updateTime): UserCertificationEntity
215
+    {
216
+        $this->updateTime = $updateTime;
217
+        return $this;
218
+    }
219
+
220
+    /**
221
+     * @return mixed
222
+     */
223
+    public function getUid()
224
+    {
225
+        return $this->uid;
226
+    }
227
+
228
+    /**
229
+     * @param mixed $uid
230
+     * @return UserCertificationEntity
231
+     */
232
+    public function setUid($uid): UserCertificationEntity
233
+    {
234
+        $this->uid = $uid;
235
+        return $this;
236
+    }
237
+}