Просмотр исходного кода

[积分][修改]:核销积分补录

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
855b40387c
2 измененных файлов: 96 добавлений и 7 удалений
  1. +3
    -1
      mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml
  2. +93
    -6
      mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java

+ 3
- 1
mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xml Просмотреть файл

@@ -795,7 +795,9 @@
select <include refid="allCouponOrderColumns" />
from wx_coupon_order co, wx_merchant_b_user mbu
where mbu.id = co.b_user_id
and mbu.merchant_id = #{merchantId}
<if test="merchantId != null">
and mbu.merchant_id = #{merchantId}
</if>
<if test="startDate != null">
AND co.update_date &gt; #{startDate,jdbcType=TIMESTAMP}
</if>


+ 93
- 6
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<WxCouponOrder> 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<String, Integer> 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);
});
}

/**
* 增加会员生日短信模板
*/


Загрузка…
Отмена
Сохранить