diff --git a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml index 8663c25d8..5359563fe 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml @@ -795,7 +795,9 @@ select from wx_coupon_order co, wx_merchant_b_user mbu where mbu.id = co.b_user_id - and mbu.merchant_id = #{merchantId} + + and mbu.merchant_id = #{merchantId} + AND co.update_date > #{startDate,jdbcType=TIMESTAMP} diff --git a/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java b/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java index fb8cfeeab..6c0b18d6a 100644 --- a/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java +++ b/mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java @@ -6,20 +6,20 @@ import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; import com.iformall.domain.po.*; import com.iformall.enums.EnumMsgModel; +import com.iformall.enums.EnumScoreType; +import com.iformall.enums.EnumUserType; import com.iformall.mapper.*; import com.iformall.service.WxCreditHistoryService; import com.iformall.utils.DateUtils; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -47,14 +47,25 @@ public class DataInitController extends BaseController { @Resource private WxCUserBasicInfoMapper cUserBasicInfoMapper; + @Resource + private WxCouponMapper couponMapper; + + @Resource + private WxCouponOrderMapper couponOrderMapper; + + @Resource + private WxMerchantBUserMapper merchantBUserMapper; + + @GetMapping("/init") public ResultData init() { try { MallUserInfo userInfo = getUser(); if (userInfo.isFmSuperAdmin()) { + addBirthDayMsgModel(); return new ResultData(); } - addBirthDayMsgModel(); + } catch (Exception e) { log.error("DataInitController::init error ", e); return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); @@ -73,9 +84,30 @@ public class DataInitController extends BaseController { try { MallUserInfo userInfo = getUser(); if(userInfo.isFmSuperAdmin()) { + doFixCredit(); + return new ResultData(); + } + } catch (Exception e) { + log.error("DataInitController::fixCredit error ", e); + return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); + } + + return new ResultData(); + } + + /** + * 核销积分数据修复 + * + * @return + */ + @GetMapping("/fixVerifyCredit") + public ResultData fixVerifyCredit() { + try { + MallUserInfo userInfo = getUser(); + if(userInfo.isFmSuperAdmin()) { + doFixVerifyCredit(); return new ResultData(); } - doFixCredit(); } catch (Exception e) { log.error("DataInitController::fixCredit error ", e); return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); @@ -131,6 +163,61 @@ public class DataInitController extends BaseController { }); } + @Transactional(rollbackFor = Exception.class) + public void doFixVerifyCredit() { + // 1 获取券码 + Map dateMap = new HashMap(); + dateMap.put("startDate", "2019-09-16 22:00:00"); + List coList = couponOrderMapper.findListOfVerifiedByDate(dateMap); + // 2 重新计算积分,比较是否需要修复 + coList.forEach(co -> { + WxCUser cuUser = cUserMapper.selectByPrimaryKey(co.getcUserId()); + WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(co.getcUserId()); + //排查不存在的用户 + if (Objects.isNull(cuUser) && Objects.isNull(userBasicInfo)) { + log.debug("用户不存在 id: {}", co.getId()); + return; + } + + WxCoupon coupon = couponMapper.selectByPrimaryKey(co.getCouponId()); + + WxMerchantBUser buUser = merchantBUserMapper.selectByPrimaryKey(co.getBUserId()); + + Map result = creditHistoryService.findByMerchantIdAndSpend(buUser.getMerchantId(), String.valueOf(co.getCouponPriceStr()), co.getCUserId(), co.getTenantId()); + Integer credit = result.get("credit"); + + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); + creditHistory.setOperatorId(buUser.getId()); + creditHistory.setCUserId(co.getcUserId()); + creditHistory.setCreateDate(co.getUpdateDate()); + creditHistory.setTenantId(co.getTenantId()); + creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); + creditHistory.setCouponId(coupon.getId()); + creditHistory.setBusinessId(coupon.getBusiness()); + creditHistory.setSpend(co.getCouponPrice()); + //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 + 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); + }); + } + /** * 增加会员生日短信模板 */