@Transactional
@Override
public Result<SysIntegralStatement> refundDeductionPoints(Map<String, String> params) {
String msgData = params.get("msgData");
ParamIntegral entity = new Gson().fromJson(msgData, ParamIntegral.class);
if (Common.isNull(entity)) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("请求参数不能为空");
}
if (Common.isEmpty(entity.getBitems())) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("请求参数不能为空");
}
int row = 0;
for (ParamIntegral bitem : entity.getBitems()) {
if (Common.isEmpty(bitem.getDdh())) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("订单号为必传参数");
}
if (null == bitem.getJfz()) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("扣减积分不能为空");
}
List<MallOrderInfo> orderInfo = mallOrderInfoMapper.selectByDdh(bitem.getDdh());
if (orderInfo == null) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR)
.setReason("订单号为" + bitem.getDdh() + "没有此订单请联系客服核对信息。");
}
if (orderInfo != null && orderInfo.size() > 1) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR)
.setReason("订单号为" + bitem.getDdh() + "有多个相同订单请联系客服核对信息。");
}
if (!"E".equals(orderInfo.get(0).getDdzt())) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR)
.setReason("订单号为" + bitem.getDdh() + "未确认收货还没产生积分不允许退货。");
}
SysIntegral integral = Common.first(integralMapper.selectByMdbm(orderInfo.get(0).getMdbm()));
if (integral == null) {
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR)
.setReason("门店编码为" + orderInfo.get(0).getMdbm() + "积分汇总没有找到此门店,请联系客服核实");
}
BigDecimal kyjf = BigDecimal.ZERO;
if (entity.getReturnGoods() == true) {
// 可用积分小于扣减积分不够扣ERP使用前抵扣
if (bitem.getJfz().compareTo(integral.getKyjf()) == 1) {
kyjf = BigDecimal.ZERO;
} else {
// 可用积分 = 当前可用积分-扣减积分
kyjf = Common.nvl(integral.getKyjf(), BigDecimal.ZERO).subtract(bitem.getJfz());
}
} else {
// 可用积分 = 当前可用积分+退还积分
kyjf = Common.nvl(integral.getKyjf(), BigDecimal.ZERO).add(bitem.getJfz());
}
// 更新积分汇总
SysIntegral dataMap = new SysIntegral();
dataMap.setIntegralId(integral.getIntegralId());
dataMap.setMdbm(integral.getMdbm());
dataMap.setKyjf(kyjf);
dataMap.setUpdateTime(new Date());
dataMap.setUpdateUser(entity.getUserName());
dataMap.setUpdateUserid(entity.getUserId().intValue());
row = integralMapper.updateByPrimaryKeySelective(dataMap);
if (row == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("更新积分失败");
}
//推送到ERP门店信息
BdMdxxH mdxx =new BdMdxxH();
mdxx.setMdbm(integral.getMdbm());
mdxx.setMdjf(kyjf);
com.lkfs.cw.common.Result<BdMdxxH> bdMdxxh = dataBaseServiceApi.updateStorePoints(mdxx);
if (!bdMdxxh.isComplete()) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new Result<SysIntegralStatement>().setCode(bdMdxxh.getCode()).setReason(bdMdxxh.getReason());
}
SysIntegralStatement statement = new SysIntegralStatement();
if (entity.getReturnGoods() == true) {
statement.setJfz(bitem.getJfz().negate());// 消费的积分值
if (bitem.getJfz().compareTo(integral.getKyjf()) == 1) {// 可用积分小于扣减积分不够扣ERP使用前抵扣
statement.setTzhjfz(BigDecimal.ZERO);// 调整后积分值
} else {
statement.setTzhjfz(Common.nvl(integral.getKyjf(), BigDecimal.ZERO).subtract(bitem.getJfz()));// 调整后积分值
}
statement.setJfxflx("E");// 积分支出
statement.setXxsm("退货扣减积分(订单号为:" + bitem.getDdh() + "," + "退货单号为:" + entity.getDjh() + ")" + "已扣除:"
+ bitem.getJfz().negate() + ":积分");
} else {// 取消退货
statement.setJfxflx("I");// 积分收入
statement.setJfz(bitem.getJfz());// 取消退货把积分赠送回来
statement.setTzhjfz(Common.nvl(integral.getKyjf(), BigDecimal.ZERO).add(bitem.getJfz()));// 调整后积分值
statement.setXxsm("取消退货(订单号为:" + bitem.getDdh() + "," + "退货单号为:" + entity.getDjh() + ")" + "已退还:"
+ bitem.getJfz() + ":积分");
}
statement.setIntegralId(integral.getIntegralId());// 该门店积分编码
statement.setTzqjfz(integral.getKyjf());// 调整前积分值
statement.setDdh(entity.getDdh());
statement.setCreateTime(new Date());// 流水生成时间
statement.setCreateUser(entity.getUserName());
statement.setCreateUserid(entity.getUserId().intValue());
statement.setJftz("T");// 积分扣减为T
statement.setZt("Y");// 状态 Y:有效
row = mapper.insert(statement);
if (row == 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return new Result<SysIntegralStatement>().setCode(ErrorCodes.INNER_ERROR).setReason("插入积分流水失败");
}
}
return new Result<SysIntegralStatement>().setCode(ErrorCodes.SUCCESS).setReason("操作成功");
}
|