| @@ -1,8 +1,5 @@ | |||
| package com.iformall.service.impl; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| @@ -10,12 +7,12 @@ import com.github.pagehelper.PageInfo; | |||
| import com.google.common.collect.Lists; | |||
| import com.google.common.collect.Maps; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxCreditHistoryVo; | |||
| import com.iformall.enums.EnumBusiness; | |||
| import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import com.iformall.enums.EnumUserType; | |||
| import com.iformall.exception.MallinkException; | |||
| @@ -26,10 +23,14 @@ import com.iformall.utils.RedisLock; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.IdWorker; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| @Slf4j | |||
| public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| @@ -160,31 +161,30 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| //计算出需要新增或减少的积分 | |||
| int creditChangeNum = creditIncrement(record); | |||
| if (creditChangeNum == 0) { | |||
| throw new MallinkException(ErrorCode.CREDIT_ZERO); | |||
| } | |||
| if (currentCreditAmount + creditChangeNum < 0) { | |||
| throw new MallinkException(ErrorCode.CREDIT_NOT_ENOUGH); | |||
| } | |||
| record.setCreditNum(creditChangeNum); | |||
| record.setCreditAmount(currentCreditAmount + creditChangeNum); | |||
| if (record.getId() == null) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setCreateDate(new Date()); | |||
| wxCreditHistoryMapper.insertSelective(record); | |||
| //将计算出来新的总积分 更新到两张用户表里 | |||
| if (wxCUser != null) { | |||
| wxCUser.setCredit(record.getCreditAmount()); | |||
| wxCUserMapper.updateByPrimaryKeySelective(wxCUser); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| wxCUserBasicInfo.setCredit(record.getCreditAmount()); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(wxCUserBasicInfo); | |||
| if (creditChangeNum != 0) { | |||
| //throw new MallinkException(ErrorCode.CREDIT_ZERO); | |||
| record.setCreditNum(creditChangeNum); | |||
| record.setCreditAmount(currentCreditAmount + creditChangeNum); | |||
| if (record.getId() == null) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| record.setCreateDate(new Date()); | |||
| wxCreditHistoryMapper.insertSelective(record); | |||
| //将计算出来新的总积分 更新到两张用户表里 | |||
| if (wxCUser != null) { | |||
| wxCUser.setCredit(record.getCreditAmount()); | |||
| wxCUserMapper.updateByPrimaryKeySelective(wxCUser); | |||
| } | |||
| if (wxCUserBasicInfo != null) { | |||
| wxCUserBasicInfo.setCredit(record.getCreditAmount()); | |||
| wxCUserBasicInfoMapper.updateByPrimaryKeySelective(wxCUserBasicInfo); | |||
| } | |||
| } else { | |||
| //wxCreditHistoryMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } else { | |||
| //wxCreditHistoryMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| return new ResultData(Result.SUCCESS,"积分操作成功"); | |||
| } | |||