| @@ -171,6 +171,25 @@ public class DataInitController extends BaseController { | |||||
| List<WxCouponOrder> coList = couponOrderMapper.findListOfVerifiedByDate(dateMap); | List<WxCouponOrder> coList = couponOrderMapper.findListOfVerifiedByDate(dateMap); | ||||
| // 2 重新计算积分,比较是否需要修复 | // 2 重新计算积分,比较是否需要修复 | ||||
| coList.forEach(co -> { | coList.forEach(co -> { | ||||
| WxCoupon coupon = couponMapper.selectByPrimaryKey(co.getCouponId()); | |||||
| WxMerchantBUser buUser = merchantBUserMapper.selectByPrimaryKey(co.getBUserId()); | |||||
| WxCreditHistory q = new WxCreditHistory(); | |||||
| q.setTenantId(co.getTenantId()); | |||||
| q.setCUserId(co.getcUserId()); | |||||
| q.setMerchantId(buUser.getMerchantId()); | |||||
| q.setCouponId(co.getCouponId()); | |||||
| WxCreditHistory ret = null; | |||||
| try { | |||||
| ret = creditHistoryMapper.selectOne(q); | |||||
| } catch (Exception e) { | |||||
| } | |||||
| if (ret != null) { | |||||
| log.debug("用户已有积分历史id: {}", ret.getId()); | |||||
| return; | |||||
| } | |||||
| WxCUser cuUser = cUserMapper.selectByPrimaryKey(co.getcUserId()); | WxCUser cuUser = cUserMapper.selectByPrimaryKey(co.getcUserId()); | ||||
| WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(co.getcUserId()); | WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(co.getcUserId()); | ||||
| //排查不存在的用户 | //排查不存在的用户 | ||||
| @@ -179,13 +198,6 @@ public class DataInitController extends BaseController { | |||||
| return; | return; | ||||
| } | } | ||||
| WxCoupon coupon = couponMapper.selectByPrimaryKey(co.getCouponId()); | |||||
| WxMerchantBUser buUser = merchantBUserMapper.selectByPrimaryKey(co.getBUserId()); | |||||
| Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(buUser.getMerchantId(), String.valueOf(co.getCouponPriceStr()), co.getCUserId(), co.getTenantId()); | |||||
| Integer credit = result.get("credit"); | |||||
| WxCreditHistory creditHistory = new WxCreditHistory(); | WxCreditHistory creditHistory = new WxCreditHistory(); | ||||
| creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | ||||
| creditHistory.setOperatorId(buUser.getId()); | creditHistory.setOperatorId(buUser.getId()); | ||||
| @@ -198,23 +210,7 @@ public class DataInitController extends BaseController { | |||||
| creditHistory.setSpend(co.getCouponPrice()); | creditHistory.setSpend(co.getCouponPrice()); | ||||
| //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | ||||
| creditHistory.setMerchantId(buUser.getMerchantId()); | creditHistory.setMerchantId(buUser.getMerchantId()); | ||||
| creditHistoryService.saveOrUpdate(creditHistory); | |||||
| //用户新积分 | |||||
| Integer newCredit = cuUser.getCredit() + credit; | |||||
| // 4 更新积分 | |||||
| WxCUser toUpdateCUser = new WxCUser(); | |||||
| toUpdateCUser.setId(co.getCUserId()); | |||||
| toUpdateCUser.setCredit(newCredit); | |||||
| toUpdateCUser.setUpdateDate(new Date()); | |||||
| cUserMapper.updateByPrimaryKeySelective(toUpdateCUser); | |||||
| WxCUserBasicInfo toUpdateBasicInfo = new WxCUserBasicInfo(); | |||||
| toUpdateBasicInfo.setId(co.getCUserId()); | |||||
| toUpdateBasicInfo.setCredit(newCredit); | |||||
| toUpdateBasicInfo.setUpdateDate(new Date()); | |||||
| cUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdateBasicInfo); | |||||
| creditHistory = creditHistoryService.saveOrUpdate(creditHistory); | |||||
| }); | }); | ||||
| } | } | ||||