package com.hx.phip.service.userMoney.impl;
|
|
import javax.annotation.Resource;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.hx.common.service.CommonService;
|
import com.hx.phiappt.common.OperationReasonConstants;
|
import com.hx.phiappt.common.OrderItemConstants;
|
import com.hx.phiappt.common.OriginChannelConstants;
|
import com.hx.phiappt.common.PlatformConstants;
|
import com.hx.phiappt.model.order.OrdersTotal;
|
import com.hx.phip.enums.SysFunctionLimitEnum;
|
import com.hx.phiappt.constants.tool.TimerHandleTool;
|
import com.hx.phiappt.constants.tool.UserInfoTool;
|
import com.hx.phiappt.constants.tool.money.UserMoneyTool;
|
import com.hx.phiappt.dto.money.MoneyRuleValueDto;
|
import com.hx.phiappt.model.*;
|
import com.hx.phiappt.model.giving.TurnAdd;
|
import com.hx.phiappt.model.money.MoneyRule;
|
import com.hx.phip.config.CustomParameter;
|
import com.hx.phip.dao.mapper.*;
|
import com.hx.phip.entity.enums.UserMoneyEnum;
|
import com.hx.phip.model.ApplyParameter;
|
import com.hx.phip.model.SysParameter;
|
import com.hx.phip.service.SystemParameterService;
|
import com.hx.phip.service.UserIntegralRecordService;
|
import com.hx.phip.service.UserMoneyService;
|
import com.hx.phip.service.UserValueAddedFundRecordService;
|
import com.hx.phip.tool.ApplyParameterTool;
|
import com.hx.phip.tool.SendSMSTool;
|
import com.hx.util.DateUtil;
|
import com.hx.util.StringUtils;
|
import com.hz.his.dto.user.money.UserTurnDto;
|
import com.platform.constants.PlatformPattern;
|
import com.platform.exception.PlatTipsException;
|
import com.platform.resultTool.PlatformCode;
|
import com.platform.resultTool.SystemCode;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.hx.exception.TipsException;
|
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
|
import com.hx.phip.service.userMoney.UserMoneyUnclaimedService;
|
import com.hx.mybatisTool.SqlSentence;
|
|
import java.lang.reflect.Field;
|
import java.lang.reflect.Modifier;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Transactional
|
@Service
|
public class UserMoneyUnclaimedServiceImpl implements UserMoneyUnclaimedService {
|
|
private static final Logger logger = LoggerFactory.getLogger(UserMoneyUnclaimedServiceImpl.class);
|
|
@Resource
|
private UserMapper userMapper;
|
@Resource
|
private CommonService commonService;
|
@Resource
|
private CustomParameter customParameter;
|
@Resource
|
private UserInfoMapper userInfoMapper;
|
@Resource
|
private UserMoneyService userMoneyService;
|
@Resource
|
private SystemParameterService systemParameterService;
|
@Resource
|
private UserMoneyUnclaimedMapper userMoneyUnclaimedMapper;
|
@Resource
|
private UserIntegralRecordService userIntegralRecordService;
|
@Resource
|
private UserValueAddedFundRecordService userValueAddedFundRecordService;
|
@Resource
|
private TurnAddMapper turnAddMapper;
|
@Resource
|
private MoneyRuleMapper moneyRuleMapper;
|
|
/**
|
* 查询列表
|
*/
|
@Override
|
public List<UserMoneyUnclaimed> selectList(SqlSentence sqlSentence) {
|
return userMoneyUnclaimedMapper.selectList(sqlSentence);
|
}
|
|
/**
|
* 查询列表
|
*/
|
@Override
|
public List<Map<String, Object>> selectListMap(SqlSentence sqlSentence) {
|
return userMoneyUnclaimedMapper.selectListMap(sqlSentence);
|
}
|
|
/**
|
* 查询单个
|
*/
|
@Override
|
public UserMoneyUnclaimed selectOne(SqlSentence sqlSentence) {
|
return userMoneyUnclaimedMapper.selectOne(sqlSentence);
|
}
|
|
/**
|
* 查询单个
|
*/
|
@Override
|
public Map<String, Object> selectOneMap(SqlSentence sqlSentence) {
|
return userMoneyUnclaimedMapper.selectOneMap(sqlSentence);
|
}
|
|
/**
|
* 查询单个,大数据不拿取
|
*/
|
@Override
|
public UserMoneyUnclaimed selectOneByKey(Object object) {
|
return userMoneyUnclaimedMapper.selectOneByKey(object);
|
}
|
|
/**
|
* 查询单个,大数据拿取
|
*/
|
@Override
|
public UserMoneyUnclaimed selectOneByKeyBlob(Object object) {
|
return userMoneyUnclaimedMapper.selectOneByKeyBlob(object);
|
}
|
|
/**
|
* 获取操作用户资金信息消息
|
* @param userMoneyUnclaimed 参数
|
* @param type 是否领取资金
|
* @return 返回
|
*/
|
private JSONObject getOpInfo(UserMoneyUnclaimed userMoneyUnclaimed, Integer type) {
|
BigDecimal before = BigDecimal.ZERO;
|
BigDecimal after = BigDecimal.ZERO;
|
JSONObject jsonObject = new JSONObject();
|
// 获取处理信息
|
StringBuilder info = new StringBuilder();
|
info.append(userMoneyUnclaimed.getOriginSubject());
|
// 查询用户资金信息
|
UserMoney userMoney = userMoneyService.selectUserIdDecrypt(userMoneyUnclaimed.getUserId());
|
switch (userMoneyUnclaimed.getFundType()) {
|
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND:
|
info.append(", 储值金");
|
before = new BigDecimal(userMoney.getStoredValueFund());
|
after = before.add(userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND:
|
info.append(", 增值金");
|
before = new BigDecimal(userMoney.getValueAddedFund());
|
after = before.add(userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL:
|
info.append(", 积分");
|
before = new BigDecimal(userMoney.getIntegral());
|
after = before.add(userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT:
|
info.append(", 预定金");
|
before = new BigDecimal(userMoney.getDeposit());
|
after = before.add(userMoneyUnclaimed.getOpNumber());
|
break;
|
}
|
info.append(", 操作数量:").append(userMoneyUnclaimed.getOpNumber());
|
if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) {
|
// 增值金添加是否需要领取
|
int opType = userMoneyUnclaimed.getOpType() == null ? BaseEntity.YES : userMoneyUnclaimed.getOpType();
|
info.append(", 是否需要领取:").append(BaseEntity.YES.equals(opType) ? "是" : "否");
|
if (BaseEntity.NO.equals(type)){
|
before = null;
|
after = null;
|
}
|
}
|
if (BaseEntity.YES.equals(type)){
|
info.append(", 领取资金: ").append(userMoneyUnclaimed.getOpNumber());
|
}
|
if (3 == type){
|
info.append(", 作废待领取资金: ").append(userMoneyUnclaimed.getOpNumber());
|
before = null;
|
after = null;
|
}
|
jsonObject.put("key", info.toString());
|
if (before != null) {
|
jsonObject.put("before", before);
|
jsonObject.put("after", after);
|
}
|
return jsonObject;
|
}
|
|
/**
|
* 添加用户日志
|
* @param userMoneyUnclaimed 用户资金对象
|
* @param type 是否领取资金
|
*/
|
private void addUserLog(UserMoneyUnclaimed userMoneyUnclaimed, Integer type){
|
// 处理用户日志
|
User user = userMapper.selectOneByKey(userMoneyUnclaimed.getUserId());
|
if (user != null) {
|
// 用户日志
|
JSONArray logArray = new JSONArray();
|
JSONObject jsonObject = getOpInfo(userMoneyUnclaimed, type);
|
logArray.add(jsonObject);
|
// 操作人转换
|
UserUpdateLog userUpdateLog = new UserUpdateLog();
|
// 来源渠道
|
userUpdateLog.setSourceAppCode(userMoneyUnclaimed.getOriginChannel());
|
if (!StringUtils.isEmpty(userMoneyUnclaimed.getOriginChannel())){
|
String name = PlatformConstants.getName(userMoneyUnclaimed.getOriginChannel());
|
userUpdateLog.setSourceAppName(name);
|
}
|
switch (userMoneyUnclaimed.getOperatorType()) {
|
case UserMoneyUnclaimed.OPERATOR_TYPE_USER:
|
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_USER);
|
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId());
|
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName());
|
break;
|
case UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE:
|
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_EMPLOYEE);
|
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId());
|
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName());
|
break;
|
case UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN:
|
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_ADMIN);
|
userUpdateLog.setOperatorId(userMoneyUnclaimed.getOperatorId());
|
userUpdateLog.setOperatorName(userMoneyUnclaimed.getOperatorName());
|
break;
|
case UserMoneyUnclaimed.OPERATOR_TYPE_SYSTEM:
|
userUpdateLog.setOperatorType(UserUpdateLog.OPERATOR_TYPE_SYSTEM);
|
break;
|
}
|
// 记录编号
|
String recordNo = systemParameterService.createUSLGNo(user.getId(), user.getCIQ());
|
// 添加用户日志
|
UserInfoTool.addUserUpdateLogOp(commonService, user, user.getShopId(), userUpdateLog, "用户资金调整", logArray, userMoneyUnclaimed.getRemarks(), recordNo);
|
}
|
}
|
|
/**
|
* 发送企业微信资金到账消息
|
* @param userMoneyUnclaimed 参数
|
*/
|
private void sentCorpNotice(UserMoneyUnclaimed userMoneyUnclaimed) {
|
// 开始处理添加发送通知任务 到账提醒
|
if (userMoneyUnclaimed.getOpNumber().compareTo(BigDecimal.ZERO) > 0) {
|
// 添加发送通知任务
|
TimerHandleTool.addTask(commonService, TimerHandleItem.TYPE_USER_MONEY_CORP_NOTICE, userMoneyUnclaimed.getId(), null);
|
}
|
}
|
|
/**
|
* 新增
|
*/
|
@Override
|
public void insert(UserMoneyUnclaimed userMoneyUnclaimed) {
|
int count = userMoneyUnclaimedMapper.insert(userMoneyUnclaimed);
|
if (count != 1) {
|
throw new TipsException("新增失败!");
|
} else {
|
// 重新获取下数据
|
UserMoneyUnclaimed checkUserMoneyUnclaimed = userMoneyUnclaimedMapper.selectOneByKey(userMoneyUnclaimed.getId());
|
if(checkUserMoneyUnclaimed != null) {
|
// 添加用户日志
|
addUserLog(userMoneyUnclaimed, BaseEntity.NO);
|
// 过滤待领取的数据
|
this.handlerReceiveData(checkUserMoneyUnclaimed, BaseEntity.YES);
|
// 处理发送顾问通知消息
|
this.sentCorpNotice(checkUserMoneyUnclaimed);
|
}
|
}
|
}
|
|
/**
|
* 修改
|
*/
|
@Override
|
public void updateAll(UserMoneyUnclaimed userMoneyUnclaimed) {
|
// 作废了记录处理
|
if(BaseEntity.YES.equals(userMoneyUnclaimed.getIsDel())){
|
// 添加用户日志
|
addUserLog(userMoneyUnclaimed, 3);
|
}
|
int count = userMoneyUnclaimedMapper.updateAll(userMoneyUnclaimed);
|
if (count != 1) {
|
throw new TipsException("保存失败!");
|
}
|
}
|
|
/**
|
* 修改
|
*/
|
@Override
|
public void updateWhere(SqlSentence sqlSentence) {
|
int count = userMoneyUnclaimedMapper.updateWhere(sqlSentence);
|
if (count != 1) {
|
throw new TipsException("保存失败!");
|
}
|
}
|
|
/**
|
* 删除一个
|
*/
|
@Override
|
public void deleteOne(String delId) {
|
int count = userMoneyUnclaimedMapper.deleteById(delId);
|
if (count != 1) {
|
throw new TipsException("删除失败!");
|
}
|
}
|
|
/**
|
* 查询条数
|
*/
|
@Override
|
public int selectCount(SqlSentence sqlSentence) {
|
int count = userMoneyUnclaimedMapper.selectCount(sqlSentence);
|
return count;
|
}
|
|
/**
|
* 校验参数
|
*
|
* @param userMoneyUnclaimed 用户待领取列表
|
*/
|
@Override
|
public void checkParam(UserMoneyUnclaimed userMoneyUnclaimed) {
|
// 用户校验
|
if (StringUtils.isEmpty(userMoneyUnclaimed.getUserId())) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户id不能为空");
|
}
|
// 资金类型判断
|
if (userMoneyUnclaimed.getFundType() == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "资金类型不能为空");
|
} else {
|
// 资金类型判断是否匹配
|
switch (userMoneyUnclaimed.getFundType()) {
|
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND:
|
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND:
|
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL:
|
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT:
|
break;
|
default:
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "资金类型错误,类型不存在");
|
}
|
}
|
|
// 操作原因
|
if (StringUtils.isEmpty(userMoneyUnclaimed.getOperationReason())) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因不能为空");
|
}
|
if (checkConstantNotHaveValue(OperationReasonConstants.class, userMoneyUnclaimed.getOperationReason())) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作原因错误,原因不存在");
|
}
|
|
// 获取金额配置,(有传标识则拿对应的配置,否则拿默认配置)
|
MoneyRule moneyRule = getMoneyRule(userMoneyUnclaimed.getMoneyRuleId(),userMoneyUnclaimed.getFundType());
|
logger.info("操作资金-moneyRule规则数据:"+JSON.toJSONString(moneyRule));
|
|
//获得操作类型
|
logger.info("操作待领取资金-请求的类型(0系统1领取):"+userMoneyUnclaimed.getOpType());
|
checkGetOpType(userMoneyUnclaimed,moneyRule);
|
logger.info("操作待领取资金-最终的类型(0系统1领取):"+userMoneyUnclaimed.getOpType());
|
|
// 判断操作数量或金额
|
if (userMoneyUnclaimed.getOpNumber() == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作数量或金额不能为空");
|
} else {
|
// 判断操作数量或金额 是否为 0
|
if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) == 0) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作数量或金额不能为0");
|
} else if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) < 0) {
|
// 资金操作类型-增加
|
userMoneyUnclaimed.setFundOpType(UserMoneyUnclaimed.FUND_OP_TYPE_INCREASE);
|
} else if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) > 0) {
|
// 资金操作类型-减少
|
userMoneyUnclaimed.setFundOpType(UserMoneyUnclaimed.FUND_OP_TYPE_REDUCE);
|
}
|
|
// 用户资金数据校验
|
UserMoney userMoney = userMoneyService.selectUserIdDecrypt(userMoneyUnclaimed.getUserId());
|
if (userMoney == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户的资产数据不存在");
|
} else {
|
// 判断数量减扣数量是否充足
|
if (UserMoneyUnclaimed.FUND_OP_TYPE_REDUCE == userMoneyUnclaimed.getFundOpType()) {
|
// 资金类型判断是否匹配
|
switch (userMoneyUnclaimed.getFundType()) {
|
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND:
|
// 金额操作
|
BigDecimal storedValueFund = new BigDecimal(userMoney.getStoredValueFund());
|
// 判断是否足够扣减
|
this.checkCanOperation(userMoneyUnclaimed.getFundType(), storedValueFund, userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND:
|
// 金额操作 不做校验可以减成负数
|
BigDecimal valueAddedFund = new BigDecimal(userMoney.getValueAddedFund());
|
// 判断是否足够扣减
|
this.checkCanOperation(userMoneyUnclaimed.getFundType(), valueAddedFund, userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL:
|
// 积分操作
|
BigDecimal integral = new BigDecimal(userMoney.getIntegral());
|
// 判断是否足够扣减
|
this.checkCanOperation(userMoneyUnclaimed.getFundType(), integral, userMoneyUnclaimed.getOpNumber());
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT:
|
// 金额操作
|
BigDecimal deposit = new BigDecimal(userMoney.getDeposit());
|
// 判断是否足够扣减
|
this.checkCanOperation(userMoneyUnclaimed.getFundType(), deposit, userMoneyUnclaimed.getOpNumber());
|
break;
|
}
|
}
|
}
|
}
|
|
// 操作人信息判断
|
if (userMoneyUnclaimed.getOperatorType() == null) {
|
// 操作人类型默认为员工
|
userMoneyUnclaimed.setOperatorType(UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE);
|
} else {
|
// 操作人类型判断是否匹配
|
switch (userMoneyUnclaimed.getOperatorType()) {
|
case UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN:
|
case UserMoneyUnclaimed.OPERATOR_TYPE_USER:
|
case UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE:
|
break;
|
default:
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人类型错误");
|
}
|
}
|
|
// 判断是否传了操作人id
|
if (StringUtils.isEmpty(userMoneyUnclaimed.getOperatorId())) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人id不能为空");
|
}
|
|
// 操作人为员工
|
if (UserMoneyUnclaimed.OPERATOR_TYPE_EMPLOYEE == userMoneyUnclaimed.getOperatorType()) {
|
Employee employee = commonService.selectOneByKey(EmployeeMapper.class, userMoneyUnclaimed.getOperatorId());
|
if (employee == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
// 填充名称
|
userMoneyUnclaimed.setOperatorName(employee.getCnName());
|
}
|
}
|
|
// 操作人为后台用户
|
if (UserMoneyUnclaimed.OPERATOR_TYPE_ADMIN == userMoneyUnclaimed.getOperatorType()) {
|
SysAdmin sysAdmin = commonService.selectOneByKey(SysAdminMapper.class, userMoneyUnclaimed.getOperatorId());
|
if (sysAdmin == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
// 填充名称
|
userMoneyUnclaimed.setOperatorName(sysAdmin.getName());
|
}
|
}
|
|
// 操作人为用户
|
if (UserMoneyUnclaimed.OPERATOR_TYPE_USER == userMoneyUnclaimed.getOperatorType()) {
|
User user = commonService.selectOneByKey(UserMapper.class, userMoneyUnclaimed.getOperatorId());
|
if (user == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作人的信息不存在");
|
} else {
|
// 填充名称
|
userMoneyUnclaimed.setOperatorName(user.getName());
|
}
|
}
|
|
//---数据填充
|
// 判断订单 先不判断订单
|
if(UserMoneyUnclaimed.ORDER_TYPE_ORDER.equals(userMoneyUnclaimed.getOrderType()) &&!StringUtils.isEmpty(userMoneyUnclaimed.getOrderId())){
|
OrdersTotal ordersTotal = commonService.selectOneByKey(OrdersTotalMapper.class, userMoneyUnclaimed.getOrderId());
|
if(ordersTotal != null){
|
userMoneyUnclaimed.setOrderNo(ordersTotal.getOrderNo());
|
}
|
}
|
|
/*
|
// 判断子订单
|
if(!StringUtils.isEmpty(userMoneyUnclaimed.getOrderItemId())){
|
if(StringUtils.isEmpty(userMoneyUnclaimed.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "主订单id不能为空!");
|
}
|
OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class, userMoneyUnclaimed.getOrderItemId());
|
if(orderItem == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "子订单的信息不存在");
|
} else {
|
if(!orderItem.getOrderId().equals(userMoneyUnclaimed.getOrderId())){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "子订单的信息与主订单的信息不匹配");
|
}
|
}
|
}*/
|
logger.info("设置有效时间前打印金额规则{},资金信息{}",JSON.toJSONString(moneyRule),JSON.toJSONString(userMoneyUnclaimed));
|
//设置待领取的有效时间
|
if (moneyRule != null){
|
if (moneyRule.getWaitReceiveLimit().equals(BaseEntity.YES)){
|
userMoneyUnclaimed.setIsLimitTime(BaseEntity.YES);
|
// 获取有效期时间配置 待领取默认30天领取
|
int validityPeriod = moneyRule.getWaitReceiveLimitDay();
|
// 获取时间
|
Date limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(), validityPeriod);
|
// 设置有效期时间
|
userMoneyUnclaimed.setLimitEndTime(limitEndTime);
|
}else if (moneyRule.getWaitReceiveLimit().equals(BaseEntity.NO)){
|
userMoneyUnclaimed.setIsLimitTime(BaseEntity.NO);
|
// 获取时间(这里默认给100年,实际上是需要判断是否限制的字段)
|
Date limitEndTime = DateUtil.addYear(userMoneyUnclaimed.getLimitStartTime(),100);
|
// 设置有效期时间
|
userMoneyUnclaimed.setLimitEndTime(limitEndTime);
|
}
|
}else {
|
// 走原本默认的设置
|
userMoneyUnclaimed.setIsLimitTime(BaseEntity.YES);
|
// 获取有效期时间配置 待领取默认30天领取
|
int validityPeriod = UserMoneyTool.getUnclaimedValidityTime(commonService);
|
// 获取时间
|
Date limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(), validityPeriod);
|
// 设置有效期时间
|
userMoneyUnclaimed.setLimitEndTime(limitEndTime);
|
}
|
// 默认来源渠道为 预约后台
|
if (StringUtils.isEmpty(userMoneyUnclaimed.getOriginChannel())) {
|
userMoneyUnclaimed.setOriginChannel(OriginChannelConstants.ORIGIN_CHANNEL_PHIS);
|
}
|
// 填充金额规则数据
|
if (moneyRule != null){
|
userMoneyUnclaimed.setMoneyRuleId(moneyRule.getId());
|
userMoneyUnclaimed.setIsNeedReceive(moneyRule.getIsNeedReceive());
|
userMoneyUnclaimed.setIsUserReceive(moneyRule.getIsUserReceive());
|
userMoneyUnclaimed.setWaitReceiveLimit(moneyRule.getWaitReceiveLimit());
|
userMoneyUnclaimed.setWaitReceiveLimitDay(moneyRule.getWaitReceiveLimitDay());
|
userMoneyUnclaimed.setIsReceiveLimit(moneyRule.getIsReceiveLimit());
|
userMoneyUnclaimed.setReceiveLimitType(moneyRule.getReceiveLimitType());
|
userMoneyUnclaimed.setReceiveLimitData(moneyRule.getReceiveLimitData());
|
userMoneyUnclaimed.setReceiveMoneyLimit(moneyRule.getReceiveMoneyLimit());
|
userMoneyUnclaimed.setReceiveMoneyLimitDay(moneyRule.getReceiveMoneyLimitDay());
|
}
|
//要领取的资金填充发送短信信息
|
if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()){
|
//暂时默认增值金会发送短信
|
if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()) {
|
checkIsNeedSentSMS(userMoneyUnclaimed);
|
}
|
//其他处理
|
|
}
|
}
|
|
/**校验并获得资金操作类型(系统/领取)*/
|
private void checkGetOpType(UserMoneyUnclaimed userMoneyUnclaimed, MoneyRule moneyRule) {
|
// 负数默认系统处理
|
if (BigDecimal.ZERO.compareTo(userMoneyUnclaimed.getOpNumber()) > 0) {
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
|
return;
|
}
|
// 如果是请求需要系统处理,则直接返回
|
if (userMoneyUnclaimed.getOpType() != null && UserMoneyUnclaimed.OP_TYPE_SYSTEM == userMoneyUnclaimed.getOpType()){
|
return;
|
}
|
|
// 未有操作类型默认为系统处理(其中增值金默认需要领取)
|
if (userMoneyUnclaimed.getOpType() == null) {
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
|
}
|
// 判断是否是支持的类型
|
if (UserMoneyUnclaimed.OP_TYPE_SYSTEM != userMoneyUnclaimed.getOpType() && UserMoneyUnclaimed.OP_TYPE_RECEIVE != userMoneyUnclaimed.getOpType()) {
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作类型错误");
|
}
|
|
// 有规则,且规则不需要校验用户勾选,则校验基础规则中是否需要领取
|
if (moneyRule != null && moneyRule.getIsUserReceive().equals(BaseEntity.NO)){
|
logger.info("操作用户资金(待领取记录)-不校验用户设置是否需要领取状态");
|
logger.info("操作用户资金(待领取记录)-是否需要用户领取:"+moneyRule.getIsNeedReceive());
|
if (moneyRule.getIsNeedReceive().equals(BaseEntity.NO)){
|
//不需要领取,设置为系统处理
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
|
}else {
|
//需要领取
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_RECEIVE);
|
}
|
}else {
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_SYSTEM);
|
// 需要判断用户是否勾选(暂时只有增值金需要判断用户是否勾选)
|
if (UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND == userMoneyUnclaimed.getFundType()){
|
UserInfo userInfo = userInfoMapper.selectOneByUserId(userMoneyUnclaimed.getUserId());
|
if (userInfo != null){
|
logger.info("操作用户资金(待领取记录)-用户设置增值金是否需要领取状态:{}", userInfo.getIsReceiveValueAddedFund());
|
if (userInfo.getIsReceiveValueAddedFund() != null && BaseEntity.YES.equals(userInfo.getIsReceiveValueAddedFund())){
|
// 设置要领取设置为领取
|
userMoneyUnclaimed.setOpType(UserMoneyUnclaimed.OP_TYPE_RECEIVE);
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 获取金额规则信息
|
* @param moneyRuleId 金额规则
|
* @param fundType 操作的金额类型
|
* */
|
private MoneyRule getMoneyRule(String moneyRuleId,Integer fundType) {
|
MoneyRule moneyRule = null;
|
if (StringUtils.noNull(moneyRuleId)){
|
moneyRule = moneyRuleMapper.selectOneByKey(moneyRuleId);
|
if (moneyRule == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "标识错误,金额规则信息查询失败");
|
}
|
if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_ADDED_FUND)){
|
//增值金校验
|
if (!fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND)){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型不匹配,当前操作【增值金】");
|
}
|
}else if (moneyRule.getMoneyType().equals(MoneyRule.MONEY_TYPE_INTEGRAL)){
|
//积分校验
|
if (!fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "操作资金类型与金额规则类型不匹配,当前操作【积分】");
|
}
|
}
|
}else {
|
//查找增值金/积分默认配置信息
|
if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND) || fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
|
SqlSentence sqlSentence = new SqlSentence();
|
Map<String,Object> sqlMap = new HashMap<>();
|
sqlMap.put("isDel",BaseEntity.NO);
|
sqlMap.put("isUp",BaseEntity.YES);
|
sqlMap.put("isDefault",BaseEntity.YES);
|
sqlMap.put("moneyType",-1);
|
if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND)){
|
//增值金
|
sqlMap.put("moneyType",MoneyRule.MONEY_TYPE_ADDED_FUND);
|
}else if (fundType.equals(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL)){
|
//积分
|
sqlMap.put("moneyType",MoneyRule.MONEY_TYPE_INTEGRAL);
|
}
|
sqlSentence.sqlSentence("SELECT * FROM money_rule WHERE isDel = #{m.isDel} " +
|
" AND isUp = #{m.isUp} AND isDefault = #{m.isDefault} AND moneyType = #{m.moneyType} ",sqlMap);
|
moneyRule = moneyRuleMapper.selectOne(sqlSentence);
|
}
|
}
|
return moneyRule;
|
}
|
|
/**
|
* 校验常量值是否存在
|
* @param classObj 类对象
|
* @param value 校验值
|
* @return 返回
|
*/
|
@Override
|
public boolean checkConstantNotHaveValue(Class classObj, String value) {
|
boolean flag = true;
|
// 判断是否存在这个来源渠道
|
Field[] fields = classObj.getDeclaredFields();
|
for (Field field : fields) {
|
field.setAccessible(true);
|
// 获取常量名称
|
String fieldName = field.getName();
|
// 判断常量值是否存在
|
if (field.getType().toString().endsWith("java.lang.String") && Modifier.isStatic(field.getModifiers())) {
|
try {
|
// 获取常量值
|
String fieldValue = field.get(classObj).toString();
|
if (fieldValue.equals(value)) {
|
flag = false;
|
break;
|
}
|
}catch (Exception ex){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "常量获取配置出现错误");
|
|
}
|
}
|
}
|
return flag;
|
}
|
|
/**
|
* 判断数据是否支持减扣
|
*/
|
private void checkCanOperation(Integer fundType, BigDecimal value, BigDecimal opNumber) {
|
// 负数取反计算
|
if (BigDecimal.ZERO.compareTo(opNumber) > 0) {
|
opNumber = opNumber.negate();
|
}
|
// 计算账户余额是否支持减扣
|
BigDecimal subtractValue = value.subtract(opNumber);
|
if (subtractValue.compareTo(BigDecimal.ZERO) < 0) {
|
// 获取资金名称
|
String fundTypeName = UserMoneyUnclaimed.getFundTypeName(fundType);
|
// 提示错误
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, String.format("用户资金账户%s不足扣减!", fundTypeName));
|
}
|
}
|
|
/**
|
* 根据平台判断是否需要发送短信
|
* @param userMoneyUnclaimed 用户待领取信息
|
*/
|
private void checkIsNeedSentSMS(UserMoneyUnclaimed userMoneyUnclaimed) {
|
// CRM不用发送短信领取其他平台需要发送短信领取
|
// if(!OriginChannelConstants.ORIGIN_CHANNEL_CRM.equals(userMoneyUnclaimed.getOriginChannel())) {
|
userMoneyUnclaimed.setIsSentSMS(BaseEntity.YES);
|
String url = getSMSUrl();
|
if (StringUtils.isEmpty(url)) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "获取发送短信链接地址出现异常!");
|
}
|
userMoneyUnclaimed.setSMSUrl(url);
|
//}
|
}
|
|
/**
|
* 生成需要发送短信的地址
|
* @return 返回
|
*/
|
private String getSMSUrl() {
|
// 生成小程序链接
|
String urlLink = null;
|
// 正式区在拿取链接
|
if (PlatformPattern.PROD.equals(customParameter.getPlatformPatternMoney())) {
|
// 获取用户CRM小程序token
|
ApplyParameter applyParameter = ApplyParameterTool.getMpParameter("wx71e6babac80abcee", commonService);
|
if (applyParameter == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "mpId is error");
|
}
|
// 获取范围密钥
|
SysParameter sysParameter = systemParameterService.getAccessToken(applyParameter.getMpAppId(), applyParameter.getMpSecretKey());
|
if (sysParameter == null) {
|
throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "服务错误" + SystemCode.ERROR_GET_CORP_TOKEN);
|
}
|
|
// 更换链接 原CRM 1.0 /pages/recharge/incrementInfo
|
String result = SendSMSTool.getAooLetUrl(sysParameter.getParamValue(), "/pages/portClient_me/incrementValue/incrementValue", "", "release");
|
if (!StringUtils.isEmpty(result)) {
|
JSONObject jsonObject = JSON.parseObject(result);
|
if (jsonObject.getInteger("errcode") != 0) {
|
throw new PlatTipsException(PlatformCode.ERROR_SYSTEM, "生成短信小程序路径错误:" + jsonObject.getString("msg") + SystemCode.ERROR_GET_CORP_TOKEN);
|
}
|
urlLink = jsonObject.getString("url_link");
|
}
|
} else {
|
// 测试区跳转百度
|
urlLink = "https://wxaurl.cn/6666";
|
}
|
return urlLink;
|
}
|
|
/**
|
* 待领取资产处理
|
* @param userMoneyUnclaimed 待领取数据
|
* @param isReceive 是否过滤领取数据 0 否 1 是
|
*/
|
@Override
|
public void handlerReceiveData(UserMoneyUnclaimed userMoneyUnclaimed, Integer isReceive) {
|
if (userMoneyUnclaimed != null) {
|
// 多线程添加锁
|
synchronized (this) {
|
// 判断是不是要领取的数据
|
if (BaseEntity.YES.equals(isReceive)) {
|
if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()) {
|
logger.info("待领取资产处理跳过,数据id:{},原因:需要领取数据", userMoneyUnclaimed.getId());
|
return;
|
}
|
}
|
// 判断是否处理了
|
if (UserMoneyUnclaimed.STATUS_SUCCEED == userMoneyUnclaimed.getStatus()) {
|
logger.info("待领取资产处理跳过,数据id:{},原因:数据已领取不需要再处理", userMoneyUnclaimed.getId());
|
return;
|
}
|
// 判断数据是否有效
|
if (UserMoneyUnclaimed.NO.equals(userMoneyUnclaimed.getIsValid())) {
|
logger.info("待领取资产处理跳过,数据id:{},原因:数据已失效无法领取", userMoneyUnclaimed.getId());
|
return;
|
}
|
//计算有效结束时间,操作资金处理用到结束时间
|
Date limitEndTime = null;
|
//有限制时间规则
|
if (StringUtils.noNull(userMoneyUnclaimed.getMoneyRuleId())){
|
//需要领取,有领取限制 则校验是否满足条件
|
if (UserMoneyUnclaimed.OP_TYPE_RECEIVE == userMoneyUnclaimed.getOpType()){
|
if (userMoneyUnclaimed.getReceiveMoneyLimit() != null
|
&& userMoneyUnclaimed.getReceiveMoneyLimit().equals(BaseEntity.YES)
|
&& checkCanNotReceive(userMoneyUnclaimed)) {
|
logger.info("操作待领取资金-但是有领取限制-进行限制校验");
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS, "领取失败,未满足领取条件");
|
}
|
}
|
//有领取后的时间限制,限制结束时间计算
|
logger.info("操作待领取资金-是否有效时间限制:" + userMoneyUnclaimed.getReceiveMoneyLimit());
|
if (userMoneyUnclaimed.getReceiveMoneyLimit() != null && userMoneyUnclaimed.getReceiveMoneyLimit().equals(BaseEntity.YES)){
|
logger.info("操作待领取资金-限制有效天数:" + userMoneyUnclaimed.getReceiveMoneyLimitDay());
|
//为空默认处理
|
if (userMoneyUnclaimed.getReceiveMoneyLimitDay() == null) {
|
userMoneyUnclaimed.setReceiveMoneyLimitDay(UserMoneyTool.getReceivedValidityTime(commonService));
|
}
|
limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(), userMoneyUnclaimed.getReceiveMoneyLimitDay());
|
}else {
|
logger.info("操作待领取资金-未设置有效时间限制-默认给100年");
|
//无限制,默认100年
|
limitEndTime = DateUtil.addYear(userMoneyUnclaimed.getLimitStartTime(), 100);
|
}
|
}else {
|
// 默认处理
|
int validityPeriod = UserMoneyTool.getReceivedValidityTime(commonService);
|
limitEndTime = DateUtil.addDay(userMoneyUnclaimed.getLimitStartTime(), validityPeriod);
|
}
|
// 传进去下面的资金处理
|
userMoneyUnclaimed.setLimitEndTime(limitEndTime);
|
// 操作资金处理
|
switch (userMoneyUnclaimed.getFundType()) {
|
case UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND:
|
case UserMoneyUnclaimed.FUND_TYPE_DEPOSIT:
|
// 储值金和预定金只处理总资金信息
|
userMoneyService.handleMoneyData(userMoneyUnclaimed);
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND:
|
// 处理增值金
|
userValueAddedFundRecordService.handleData(userMoneyUnclaimed);
|
break;
|
case UserMoneyUnclaimed.FUND_TYPE_INTEGRAL:
|
// 处理积分
|
userIntegralRecordService.handleData(userMoneyUnclaimed);
|
break;
|
}
|
// 添加用户日志
|
if (BaseEntity.NO.equals(isReceive)) {
|
addUserLog(userMoneyUnclaimed, BaseEntity.YES);
|
}
|
// 更新状态成已处理
|
SqlSentence sqlSentence = new SqlSentence();
|
String sql = " status=#{m.status},receiveTime=#{m.nowTime},limitEndTime=#{m.limitEndTime},editTime=#{m.nowTime} WHERE id=#{m.id}";
|
Map<String, Object> sqlValue = new HashMap<>();
|
sqlValue.put("limitEndTime", limitEndTime);
|
sqlValue.put("status", UserMoneyUnclaimed.STATUS_SUCCEED);
|
sqlValue.put("nowTime", new Date());
|
sqlValue.put("id", userMoneyUnclaimed.getId());
|
sqlSentence.sqlSentence(sql, sqlValue);
|
if (commonService.updateWhere(UserMoneyUnclaimedMapper.class, sqlSentence) != 1){
|
logger.error("领取金额状态修改失败,sql{},map{}",sqlSentence.getSqlSentence(),JSON.toJSONString(sqlValue));
|
throw new TipsException("金额领取处理失败,错误代码[01]");
|
}
|
}
|
}
|
}
|
|
/**
|
* 判断是不是 不可领取的状态
|
* @param userMoneyUnclaimed 参数
|
* @return true是不可领取
|
* */
|
private boolean checkCanNotReceive(UserMoneyUnclaimed userMoneyUnclaimed) {
|
//无限制可以领取
|
if (userMoneyUnclaimed.getIsReceiveLimit() == null || !userMoneyUnclaimed.getIsReceiveLimit().equals(BaseEntity.YES)){
|
return false;
|
}
|
List<MoneyRuleValueDto> limitList = JSONArray.parseArray(userMoneyUnclaimed.getReceiveLimitData(), MoneyRuleValueDto.class);
|
logger.info("待领取资产处理,数据id:{},限制数据{},解析的数据{}"
|
,userMoneyUnclaimed.getId(),userMoneyUnclaimed.getReceiveLimitData(),JSON.toJSONString(limitList));
|
if (limitList == null || limitList.size() < 1){
|
return false;
|
}
|
// 无具体限制类型
|
if (userMoneyUnclaimed.getReceiveLimitType() == null){
|
return false;
|
}
|
//判断校验逻辑
|
if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.YES)){
|
//满足其一
|
for (MoneyRuleValueDto moneyRuleValueDto : limitList) {
|
//满足一个则设为通过,退出循环
|
if (SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode()
|
,userMoneyUnclaimed.getUserId(),userMoneyUnclaimed.getOrderId())){
|
return false;
|
}
|
}
|
} else if (userMoneyUnclaimed.getReceiveLimitType().equals(BaseEntity.NO)){
|
//都要满足
|
for (MoneyRuleValueDto moneyRuleValueDto : limitList) {
|
//存在一个不满足则退出循环
|
if (!SysFunctionLimitEnum.checkPassByCode(moneyRuleValueDto.getFunctionCode()
|
,userMoneyUnclaimed.getUserId(),userMoneyUnclaimed.getOrderId())){
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
/**转赠*/
|
@Override
|
public void turn(UserTurnDto userTurnDto) {
|
logger.info("转赠参数"+ JSONObject.toJSONString(userTurnDto));
|
//1.参数校验
|
turnParameterCheck(userTurnDto);
|
|
//2.判断用户是否有资金信息
|
//查询转出用户
|
User turnUser = userMapper.selectOneByKey(userTurnDto.getTurnPeopleId());
|
if (turnUser == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到转出客户信息");
|
}
|
//查询转入用户
|
User doneeUser = userMapper.selectOneByKey(userTurnDto.getDoneeId());
|
if (doneeUser == null){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到转入客户信息");
|
}
|
//3.转赠操作
|
//增值金
|
if (userTurnDto.getIncrementMoney() != null) {
|
//操作资金
|
moneyTurn(0,userTurnDto);
|
//生成转赠记录
|
newTurnAdd(UserMoneyEnum.INCREMENT.getCode(), userTurnDto,turnUser,doneeUser);
|
}
|
//储值金
|
if (userTurnDto.getStoredMoney() != null){
|
//操作资金
|
moneyTurn(1,userTurnDto);
|
//生成转赠记录
|
newTurnAdd(UserMoneyEnum.STORED.getCode(), userTurnDto,turnUser,doneeUser);
|
}
|
//积分
|
if (userTurnDto.getIntegral() != null){
|
//操作资金
|
moneyTurn(2,userTurnDto);
|
//生成转赠记录
|
newTurnAdd(UserMoneyEnum.INTEGRAL.getCode(), userTurnDto,turnUser,doneeUser);
|
}
|
}
|
|
/**
|
* @param moneyType 操作金额类型:0增值金,1储值金,2积分
|
* @param userTurnDto 参数
|
* */
|
private void moneyTurn(Integer moneyType,UserTurnDto userTurnDto) {
|
//增值金转出人金额校验
|
UserMoneyUnclaimed userMoneyUnclaimed = new UserMoneyUnclaimed();
|
//金额类型
|
if (moneyType == 0){
|
userMoneyUnclaimed.setFundType(UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND);
|
userMoneyUnclaimed.setOpNumber(new BigDecimal(userTurnDto.getIncrementMoney()).negate());
|
}else if (moneyType == 1){
|
userMoneyUnclaimed.setFundType(UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND);
|
userMoneyUnclaimed.setOpNumber(new BigDecimal(userTurnDto.getStoredMoney()).negate());
|
}else if (moneyType == 2){
|
userMoneyUnclaimed.setFundType(UserMoneyUnclaimed.FUND_TYPE_INTEGRAL);
|
userMoneyUnclaimed.setOpNumber(new BigDecimal(userTurnDto.getIntegral()).negate());
|
}
|
userMoneyUnclaimed.setOpType(0);
|
userMoneyUnclaimed.setOriginChannel(userTurnDto.getAppIdCode());
|
userMoneyUnclaimed.setOperatorId(userTurnDto.getCreateId());
|
userMoneyUnclaimed.setOperatorName(userTurnDto.getCreateName());
|
userMoneyUnclaimed.setOperationReason(OperationReasonConstants.OP_TURN_MONTY);
|
userMoneyUnclaimed.setOriginSubject(userTurnDto.getOriginSubject());
|
userMoneyUnclaimed.setCommonId(userTurnDto.getCommonId());
|
userMoneyUnclaimed.setRemarks(userTurnDto.getRemarks());
|
//转出用户
|
userMoneyUnclaimed.setUserId(userTurnDto.getTurnPeopleId());
|
|
//转入用户
|
UserMoneyUnclaimed intoUserMoneyUnclaimed = new UserMoneyUnclaimed();
|
BeanUtils.copyProperties(userMoneyUnclaimed,intoUserMoneyUnclaimed);
|
intoUserMoneyUnclaimed.setUserId(userTurnDto.getDoneeId());
|
intoUserMoneyUnclaimed.setOpNumber(userMoneyUnclaimed.getOpNumber().negate());
|
intoUserMoneyUnclaimed.setOpType(0);
|
|
//转出
|
checkParam(userMoneyUnclaimed);
|
insert(userMoneyUnclaimed);
|
//转入
|
checkParam(intoUserMoneyUnclaimed);
|
insert(intoUserMoneyUnclaimed);
|
}
|
|
/**转赠记录新增*/
|
private void newTurnAdd(Integer type, UserTurnDto userTurnDto, User turnOutUser, User turnIntoUser) {
|
//转赠记录
|
TurnAdd turnAdd = new TurnAdd();
|
turnAdd.setCreateId(userTurnDto.getCreateId());
|
turnAdd.setCreateName(userTurnDto.getCreateName());
|
turnAdd.setRemarks(userTurnDto.getRemarks());
|
turnAdd.setTurnPeopleId(userTurnDto.getTurnPeopleId());
|
turnAdd.setTurnPeopleName(userTurnDto.getTurnPeopleName());
|
turnAdd.setTurnShopId(userTurnDto.getTurnShopId());
|
turnAdd.setTurnShopName(userTurnDto.getTurnShopName());
|
// 转增人其他信息
|
if (turnOutUser != null){
|
turnAdd.setTurnPeopleCIQ(turnOutUser.getCIQ());
|
turnAdd.setTurnPeopleLevel(turnOutUser.getUserLevel());
|
turnAdd.setTurnPeopleUserStatus(turnOutUser.getUserStatus());
|
}
|
turnAdd.setDoneeId(userTurnDto.getDoneeId());
|
turnAdd.setDoneeName(userTurnDto.getDoneeName());
|
turnAdd.setDoneeShopId(userTurnDto.getDoneeShopId());
|
turnAdd.setDoneeShopName(userTurnDto.getDoneeShopName());
|
// 受赠人其他信息
|
if (turnIntoUser != null){
|
turnAdd.setDoneeCIQ(turnIntoUser.getCIQ());
|
turnAdd.setDoneeLevel(turnIntoUser.getUserLevel());
|
turnAdd.setDoneeUserStatus(turnIntoUser.getUserStatus());
|
}
|
//消费/实际金额给默认0值
|
turnAdd.setConsumptionMoney(BigDecimal.ZERO);
|
turnAdd.setActualMoney(BigDecimal.ZERO);
|
if (UserMoneyEnum.INCREMENT.getCode().equals(type)){
|
turnAdd.setTurnMoney(new BigDecimal(userTurnDto.getIncrementMoney()));
|
turnAdd.setRechargeMoney(new BigDecimal(userTurnDto.getIncrementMoney()));
|
turnAdd.setType(OrderItemConstants.TYPE_TURN_INCREMENT);
|
}else if (UserMoneyEnum.STORED.getCode().equals(type)){
|
turnAdd.setTurnMoney(new BigDecimal(userTurnDto.getStoredMoney()));
|
turnAdd.setRechargeMoney(new BigDecimal(userTurnDto.getStoredMoney()));
|
turnAdd.setType(OrderItemConstants.TYPE_TURN_STORED);
|
}else if (UserMoneyEnum.INTEGRAL.getCode().equals(type)){
|
turnAdd.setTurnMoney(new BigDecimal(userTurnDto.getIntegral()));
|
turnAdd.setRechargeMoney(new BigDecimal(userTurnDto.getIntegral()));
|
turnAdd.setType(OrderItemConstants.TYPE_TURN_INTEGRAL);
|
}
|
if (turnAddMapper.insert(turnAdd) != 1){
|
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"新增转赠记录失败!");
|
}
|
}
|
|
/**转赠参数判断*/
|
private void turnParameterCheck(UserTurnDto userTurnDto) {
|
if (StringUtils.isEmpty(userTurnDto.getTurnPeopleId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠人标识不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getTurnPeopleName())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠人名称不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getTurnShopId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠人门店标识不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getTurnShopName())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠人门店名称不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getDoneeId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "受赠人标识不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getDoneeName())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "受赠人名称不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getDoneeShopId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "受赠人门店标识不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getDoneeShopName())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "受赠人门店名称不能为空!");
|
}
|
if (userTurnDto.getIncrementMoney() == null && userTurnDto.getStoredMoney() == null && userTurnDto.getIntegral() == null){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠资金不能为空!");
|
}
|
if(userTurnDto.getIncrementMoney() != null && new BigDecimal(userTurnDto.getIncrementMoney()).compareTo(BigDecimal.ZERO) < 0){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠增值金数值错误!");
|
}
|
if(userTurnDto.getStoredMoney() != null && new BigDecimal(userTurnDto.getStoredMoney()).compareTo(BigDecimal.ZERO) < 0){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠储值金金额错误!");
|
}
|
if(userTurnDto.getIntegral() != null && new BigDecimal(userTurnDto.getIntegral()).compareTo(BigDecimal.ZERO) < 0){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠积分数值错误!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getCreateId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人标识不能为空!");
|
}
|
if (StringUtils.isEmpty(userTurnDto.getCreateName())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人名称不能为空!");
|
}
|
if (userTurnDto.getTurnPeopleId().equals(userTurnDto.getDoneeId())){
|
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "转赠人与受赠人不能为同一人!");
|
}
|
|
}
|
|
}
|