|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -17,6 +18,7 @@ import com.zbkj.common.constants.DateConstants;
|
|
|
import com.zbkj.common.constants.IntegralRecordConstants;
|
|
|
import com.zbkj.common.exception.CrmebException;
|
|
|
import com.zbkj.common.model.user.User;
|
|
|
+import com.zbkj.common.model.user.UserEnterprise;
|
|
|
import com.zbkj.common.model.user.UserIntegralRecord;
|
|
|
import com.zbkj.common.page.CommonPage;
|
|
|
import com.zbkj.common.request.IntegralPageSearchRequest;
|
|
@@ -25,6 +27,7 @@ import com.zbkj.common.response.IntegralRecordPageResponse;
|
|
|
import com.zbkj.common.utils.CrmebDateUtil;
|
|
|
import com.zbkj.common.vo.DateLimitUtilVo;
|
|
|
import com.zbkj.service.dao.UserIntegralRecordDao;
|
|
|
+import com.zbkj.service.service.UserEnterpriseService;
|
|
|
import com.zbkj.service.service.UserIntegralRecordService;
|
|
|
import com.zbkj.service.service.UserService;
|
|
|
import org.slf4j.Logger;
|
|
@@ -55,6 +58,9 @@ public class UserIntegralRecordServiceImpl extends ServiceImpl<UserIntegralRecor
|
|
|
private UserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private UserEnterpriseService userEnterpriseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private TransactionTemplate transactionTemplate;
|
|
|
|
|
|
/**
|
|
@@ -102,6 +108,8 @@ public class UserIntegralRecordServiceImpl extends ServiceImpl<UserIntegralRecor
|
|
|
if (ObjectUtil.isNull(user)) {
|
|
|
continue ;
|
|
|
}
|
|
|
+ // 检测是否是企业子账户,如果企业子账户结算到企业主账户
|
|
|
+ user = checkUser(user);
|
|
|
record.setStatus(IntegralRecordConstants.INTEGRAL_RECORD_STATUS_COMPLETE);
|
|
|
// 计算积分余额
|
|
|
Integer balance = user.getIntegral() + record.getIntegral();
|
|
@@ -109,9 +117,10 @@ public class UserIntegralRecordServiceImpl extends ServiceImpl<UserIntegralRecor
|
|
|
record.setUpdateTime(DateUtil.date());
|
|
|
|
|
|
// 解冻
|
|
|
+ User finalUser = user;
|
|
|
Boolean execute = transactionTemplate.execute(e -> {
|
|
|
updateById(record);
|
|
|
- userService.updateIntegral(record.getUid(), record.getIntegral(), Constants.OPERATION_TYPE_ADD);
|
|
|
+ userService.updateIntegral(finalUser.getId(), record.getIntegral(), Constants.OPERATION_TYPE_ADD);
|
|
|
return Boolean.TRUE;
|
|
|
});
|
|
|
if (!execute) {
|
|
@@ -120,6 +129,38 @@ public class UserIntegralRecordServiceImpl extends ServiceImpl<UserIntegralRecor
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * TODO: 解冻积分将企业子账号下单获取的积分计算到企业账号上
|
|
|
+ * 获取 User.isEnterpriseUser 是否等于 3,等于3 就查询企业主用户
|
|
|
+ * 查询用户企业账户方法:com.zbkj.service.service.UserService#getParentById(java.lang.Integer sub_user_id)
|
|
|
+ * @param user 企业子账户
|
|
|
+ * @return 当是企业子账户时返回企业主账户,其他账户直接返回不做处理
|
|
|
+ */
|
|
|
+ private User checkUser(User user) {
|
|
|
+ if (user.getIsEnterpriseUser() != null && user.getIsEnterpriseUser() == 3) {
|
|
|
+ // 是企业子用户查询主用户
|
|
|
+ List<Integer> parentId = userService.getParentById(user.getId());
|
|
|
+ if (parentId != null && !parentId.isEmpty()) {
|
|
|
+ LambdaQueryWrapper<UserEnterprise> queryWrapper = new LambdaQueryWrapper<UserEnterprise>();
|
|
|
+ queryWrapper.in(UserEnterprise::getId, parentId);
|
|
|
+ UserEnterprise parent = userEnterpriseService.getOne(queryWrapper);
|
|
|
+
|
|
|
+ if (parent != null) {
|
|
|
+ User byId = userService.getById(parent.getUserId());
|
|
|
+ if (byId == null) {
|
|
|
+ throw new CrmebException("企业子账户积分结算异常,找不到企业子用户的企业主用户");
|
|
|
+ }
|
|
|
+ // 企业主用户
|
|
|
+ return byId;
|
|
|
+ }
|
|
|
+ // 2023年11月7日 无需递归直接抛出异常,企业子用户不会拥有下级
|
|
|
+ throw new CrmebException("企业子账户积分结算异常,找不到企业子用户的企业主用户");
|
|
|
+ }
|
|
|
+ throw new CrmebException("企业子账户积分结算异常,找不到企业子用户的企业主用户");
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
// /**
|
|
|
// * PC后台列表
|
|
|
// * @param request 搜索条件
|