Browse Source

fix card

release_toaliyun_real
winter 3 years ago
parent
commit
6da858567a
3 changed files with 103 additions and 91 deletions
  1. +5
    -12
      mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java
  2. +5
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxCouponPassword.java
  3. +93
    -79
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java

+ 5
- 12
mallinkCApi/src/main/java/com/iformall/controller/WxCouponPasswordController.java View File

@@ -112,7 +112,7 @@ public class WxCouponPasswordController extends BaseController {
if (null == couponPassword) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "卡未查询到");
}
couponPassword.setDefaultUser(false);
WxCardInfo cardInfo = null;
Long cardId = couponPassword.getCardId();
//如果卡已经被激活,但是绑定的用户是系统默认用户,则是线下卡进行绑定,仍然可以继续
@@ -127,6 +127,8 @@ public class WxCouponPasswordController extends BaseController {
}
if (cardInfo.getOwnerUserId().equals(Constant.defaultCUserId)) {
isDefaultUser = true;
couponPassword.setDefaultUser(true);
couponPassword.setWxCardInfo(cardInfo);
}else {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "当前卡已经绑定激活,不能进行此操作");
}
@@ -172,7 +174,7 @@ public class WxCouponPasswordController extends BaseController {
couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode());

// 3. 领取free coupon
if (null == cardInfo) {
if (null == cardInfo || couponPassword.isDefaultUser()) {
try {
WxComposeOrder composeOrder = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()).createDBMainOrder(coupon, member, 0, payWay,payVersion);
WxOrder order = orderService.saveFreeOrderForCoupon(new Date(),false,composeOrder,member, coupon, 1,
@@ -187,16 +189,7 @@ public class WxCouponPasswordController extends BaseController {
logger.error(e.getMessage(),e);
return new ResultData(500, e.getMessage());
}
}else {
try {
cardInfo.setOwnerUserId(memberId);
cardInfo.setUpdateDate(new Date());
wxCardInfoService.saveOrUpdate(cardInfo);
}catch(Exception e) {
logger.error(e.getMessage(),e);
return new ResultData(500, e.getMessage());
}
}
}
return new ResultData();
}



+ 5
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxCouponPassword.java View File

@@ -61,5 +61,10 @@ public class WxCouponPassword extends TenantEntity {

@TableField(exist = false)
private String statusStr;
@TableField(exist = false)
private boolean isDefaultUser;
@TableField(exist = false)
private WxCardInfo wxCardInfo;

}

+ 93
- 79
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java View File

@@ -1498,71 +1498,80 @@ public class WxOrderServiceImpl implements WxOrderService {
/// 储值卡信息添加
if (isCard) {
Integer fee = 0;
WxCardInfo cardInfo = new WxCardInfo();
cardInfo.setId(couponOrder.getId());
cardInfo.updateTenantInfo(order);
cardInfo.setCouponId(order.getProductId());
cardInfo.setAmount(coupon.getPrice());
cardInfo.setRemainingAmount(coupon.getPrice());
cardInfo.setSaleAmount(coupon.getSalePrice());
if (null != couponPassWord) {
cardInfo.setCouponPasswordId(couponPassWord.getId());
cardInfo.setCouponPassword(couponPassWord.getPassword());
//后置卡券可能没有面额
cardInfo.setAmount(couponPassWord.getPrice());
cardInfo.setRemainingAmount(couponPassWord.getPrice());
}
cardInfo.setCUserId(user.getId());
cardInfo.setOwnerUserId(user.getId());
if (!coupon.checkIsFree()) {
//判断该transctionId是否已经存在,如果存在,则不添加
WxCardInfo cardInfoq = new WxCardInfo();
cardInfoq.setTransactionId(payOrder.getTransactionId());
List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq);
if (null != cardInfoList && cardInfoList.size() > 0) {
//do nothing
}else {
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX);
if(cAppInfo == null){
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId());
if(payAccount == null){
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND);
}
// 有价卡
cardInfo.setTransactionId(payOrder.getTransactionId());
WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId());
fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount);
Integer shareAmount = share.getRealPayMent() - fee;
cardInfo.setShareFeeAmount(shareAmount);
cardInfo.setRemainingShareFeeAmount(shareAmount);
cardInfo.setRateAmount(0);
}
} else {
// 免费卡
cardInfo.setShareFeeAmount(0);
cardInfo.setRemainingShareFeeAmount(0);
cardInfo.setRateAmount(0);
if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) {
WxCouponPassword updateCPwd = new WxCouponPassword();
updateCPwd.setId(couponPassWord.getId());
updateCPwd.setCardId(cardInfo.getId());
updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode());
couponPasswordMapper.updateById(updateCPwd);
}
}

cardInfo.setServiceFeeAmount(fee);
cardInfo.setCreateDate(curr);
cardInfo.setUpdateDate(curr);
cardInfo.setSupportTransfer(coupon.getSupportTransfer());
//检查卡是否下架,如果是,不可转赠
WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId());
if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) {
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode());
}
wxCardInfoMapper.insert(cardInfo);
WxCardInfo cardInfo = null;
if (null != couponPassWord && couponPassWord.isDefaultUser()) {
cardInfo = couponPassWord.getWxCardInfo();
cardInfo.setUpdateDate(curr);
cardInfo.setOwnerUserId(user.getId());
cardInfo.setCUserId(user.getId());
wxCardInfoMapper.updateById(cardInfo);
}else {
cardInfo = new WxCardInfo();
cardInfo.setId(couponOrder.getId());
cardInfo.updateTenantInfo(order);
cardInfo.setCouponId(order.getProductId());
cardInfo.setAmount(coupon.getPrice());
cardInfo.setRemainingAmount(coupon.getPrice());
cardInfo.setSaleAmount(coupon.getSalePrice());
if (null != couponPassWord) {
cardInfo.setCouponPasswordId(couponPassWord.getId());
cardInfo.setCouponPassword(couponPassWord.getPassword());
//后置卡券可能没有面额
cardInfo.setAmount(couponPassWord.getPrice());
cardInfo.setRemainingAmount(couponPassWord.getPrice());
}
cardInfo.setCUserId(user.getId());
cardInfo.setOwnerUserId(user.getId());
if (!coupon.checkIsFree()) {
//判断该transctionId是否已经存在,如果存在,则不添加
WxCardInfo cardInfoq = new WxCardInfo();
cardInfoq.setTransactionId(payOrder.getTransactionId());
List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq);
if (null != cardInfoList && cardInfoList.size() > 0) {
//do nothing
}else {
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX);
if(cAppInfo == null){
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND);
}
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId());
if(payAccount == null){
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND);
}
// 有价卡
cardInfo.setTransactionId(payOrder.getTransactionId());
WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId());
fee = OrderHelper.getRealRateAmount(share.getRealPayMent(), payAccount);
Integer shareAmount = share.getRealPayMent() - fee;
cardInfo.setShareFeeAmount(shareAmount);
cardInfo.setRemainingShareFeeAmount(shareAmount);
cardInfo.setRateAmount(0);
}
} else {
// 免费卡
cardInfo.setShareFeeAmount(0);
cardInfo.setRemainingShareFeeAmount(0);
cardInfo.setRateAmount(0);
if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) {
WxCouponPassword updateCPwd = new WxCouponPassword();
updateCPwd.setId(couponPassWord.getId());
updateCPwd.setCardId(cardInfo.getId());
updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode());
couponPasswordMapper.updateById(updateCPwd);
}
}
cardInfo.setServiceFeeAmount(fee);
cardInfo.setCreateDate(curr);
cardInfo.setUpdateDate(curr);
cardInfo.setSupportTransfer(coupon.getSupportTransfer());
//检查卡是否下架,如果是,不可转赠
WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId());
if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) {
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode());
}
wxCardInfoMapper.insert(cardInfo);
}
}

try{
@@ -3061,8 +3070,25 @@ public class WxOrderServiceImpl implements WxOrderService {
Integer shippingType, UserBasicInfoAddress address,boolean isPressOrder) {
WxOrderServiceImpl proxy = (WxOrderServiceImpl) AopContext.currentProxy();
// 减库存操作
StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder);
//实体卡未激活的,已经消费了,不用再扣库存
if (null != wxCouponPassword && wxCouponPassword.isDefaultUser()) {
//do nothing
}else {
// 减库存操作
StockReduceResult stockReduceResult = proxy.stockReduce(allowUnPayOrder,user, coupon,couponChannel,couponNumber,isPressOrder);
//渠道的库存和价格可以随时修改。这里需要校验一下
if (stockReduceResult.isChannelStockReduce()) {
//再查询一下,此时有可能价格已经修改
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId());
//如果这个时候渠道价格已经清空了
if (null == wxCouponChannel.getChannelPrice()) {
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单.");
}
if (wxCouponChannel.getChannelPrice().intValue() > 0 ) {
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单.");
}
}
}

// 当积分券或者积分停车券时 则进行积分支付
Integer orderType;
@@ -3073,18 +3099,6 @@ public class WxOrderServiceImpl implements WxOrderService {
orderType = EnumOrderType.COUPON.getCode();
}

//渠道的库存和价格可以随时修改。这里需要校验一下
if (stockReduceResult.isChannelStockReduce()) {
//再查询一下,此时有可能价格已经修改
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannel.getId(),coupon.getTenantId());
//如果这个时候渠道价格已经清空了
if (null == wxCouponChannel.getChannelPrice()) {
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已变动[清空],请刷新后重新下单.");
}
if (wxCouponChannel.getChannelPrice().intValue() > 0 ) {
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR.getCode(),"["+coupon.getTitle()+"]渠道价格已非免费,请刷新后重新下单.");
}
}
// 4. 保存Order
WxOrder record = new WxOrder();


Loading…
Cancel
Save