|
|
@@ -48,6 +48,16 @@ class UserSignScoreRepository extends BaseRepository
|
|
48
|
48
|
}
|
|
49
|
49
|
|
|
50
|
50
|
/**
|
|
|
51
|
+ * @param string $orderType
|
|
|
52
|
+ * @param array $orderIdList
|
|
|
53
|
+ * @return UserSignScoreEntity[]
|
|
|
54
|
+ */
|
|
|
55
|
+ public function getStoreSignScoreEntityListByOrderIdListAndPending(string $orderType, array $orderIdList): array
|
|
|
56
|
+ {
|
|
|
57
|
+ return $this->dao->getUserBillEntityListByOrderIdListAndPending($orderType, $orderIdList);
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ /**
|
|
51
|
61
|
* 写入积分记录
|
|
52
|
62
|
* @param UserSignScoreEntity $userSignScoreEntity
|
|
53
|
63
|
* @return UserSignScoreEntity
|
|
|
@@ -150,4 +160,67 @@ class UserSignScoreRepository extends BaseRepository
|
|
150
|
160
|
}
|
|
151
|
161
|
return $userSignScoreEntity;
|
|
152
|
162
|
}
|
|
|
163
|
+
|
|
|
164
|
+ /**
|
|
|
165
|
+ * 将 积分 记录设置为生效状态 并对用户的 积分 字段进行增减
|
|
|
166
|
+ * @param int $id
|
|
|
167
|
+ * @return UserSignScoreEntity
|
|
|
168
|
+ */
|
|
|
169
|
+ public function executeByIdList(array $idList): UserSignScoreEntity
|
|
|
170
|
+ {
|
|
|
171
|
+ $userSignScoreEntityList = $this->getStoreSignScoreEntityListByIdList($idList);
|
|
|
172
|
+
|
|
|
173
|
+ // 忽略 已经生效的 记录 todo 把要获取的 用户列表等信息 从这里获取 use ()
|
|
|
174
|
+ $userSignScoreEntityList = array_filter($userSignScoreEntityList, function($entity) {
|
|
|
175
|
+ // 用户不为空 状态属于待结算 并且结算字段为空
|
|
|
176
|
+ return (!empty($entity->getId()) && !empty($entity->getUid()) && ($entity->getStatus() == UserSignScoreEnum::STATUS['Pending']['code']) && empty($entity->getSettlementTime()));
|
|
|
177
|
+ });
|
|
|
178
|
+
|
|
|
179
|
+ if (!empty($userSignScoreEntityList)) {
|
|
|
180
|
+
|
|
|
181
|
+ }
|
|
|
182
|
+
|
|
|
183
|
+ foreach ($userSignScoreEntityList as $userSignScoreEntity) {
|
|
|
184
|
+ // if (empty($userSignScoreEntity->getId()) || empty($userSignScoreEntity->getUid())) {
|
|
|
185
|
+ // throw new ValidateException('无效的积分记录');
|
|
|
186
|
+ // }
|
|
|
187
|
+ // if ($userSignScoreEntity->getStatus() == UserSignScoreEnum::STATUS['Invalid']['code']) {
|
|
|
188
|
+ // throw new ValidateException('该积分记录已失效');
|
|
|
189
|
+ // }
|
|
|
190
|
+ // if (!empty($userSignScoreEntity->getSettlementTime()) || $userSignScoreEntity->getStatus() == UserSignScoreEnum::STATUS['Valid']['code']) {
|
|
|
191
|
+ // throw new ValidateException('该积分记录已更新,请勿重复操作');
|
|
|
192
|
+ // }
|
|
|
193
|
+
|
|
|
194
|
+ /** @var UserRepository $userRepository */
|
|
|
195
|
+ $userRepository = app()->make(UserRepository::class);
|
|
|
196
|
+ $userEntity = $userRepository->getUserEntityByUid($userSignScoreEntity->getUid());
|
|
|
197
|
+ if (empty($userEntity->getUid())) {
|
|
|
198
|
+ throw new ValidateException('未查询到用户信息');
|
|
|
199
|
+ }
|
|
|
200
|
+ if ($userSignScoreEntity->getPm() == UserSignScoreEnum::PM['Expend']['code']) {
|
|
|
201
|
+ $surplus = bcsub($userEntity->getScore(), $userSignScoreEntity->getRewardScore(), 2);
|
|
|
202
|
+ if ($surplus < 0.00) {
|
|
|
203
|
+ throw new ValidateException('用户积分不足');
|
|
|
204
|
+ }
|
|
|
205
|
+ } else {
|
|
|
206
|
+ $surplus = bcadd($userEntity->getScore(), $userSignScoreEntity->getRewardScore(), 2);
|
|
|
207
|
+ }
|
|
|
208
|
+ try {
|
|
|
209
|
+ $userSignScoreEntity
|
|
|
210
|
+ ->setSurplus($surplus)
|
|
|
211
|
+ ->setSettlementTime(date('Y-m-d H:i:s'))
|
|
|
212
|
+ ->setStatus(UserSignScoreEnum::STATUS['Valid']['code']);
|
|
|
213
|
+ $userRepository->update($userEntity->getUid(), ['score' => $surplus]);
|
|
|
214
|
+ $this->dao->update($userSignScoreEntity->getId(), [
|
|
|
215
|
+ 'surplus' => $userSignScoreEntity->getSurplus(),
|
|
|
216
|
+ 'settlement_time' => $userSignScoreEntity->getSettlementTime(),
|
|
|
217
|
+ 'status' => $userSignScoreEntity->getStatus()
|
|
|
218
|
+ ]);
|
|
|
219
|
+ } catch (DbException $e) {
|
|
|
220
|
+
|
|
|
221
|
+ }
|
|
|
222
|
+ return $userSignScoreEntity;
|
|
|
223
|
+ }
|
|
|
224
|
+
|
|
|
225
|
+ }
|
|
153
|
226
|
}
|