记得上下班打卡 | git大法好,push需谨慎

Commit 5308cd66 authored by jiangxiulong's avatar jiangxiulong

下单完善

parent d2de582d
......@@ -196,6 +196,10 @@ public class GoblinStatusConst {
ORDER_REFUND_STATUS_2(2, "退款成功"),
ORDER_REFUND_STATUS_3(3, "退款失败"),
ORDER_TYPE_1(1, "购买订单"),
ORDER_TYPE_2(2, "兑换订单"),
ORDER_TYPE_3(3, "演出赠送订单"),
;
private final int value;
......
......@@ -84,13 +84,13 @@ public class GoblinNftOrderDetailsVo implements Serializable, Cloneable {
@ApiModelProperty(value = "红包code")
private String redEnvelopeCode;
@ApiModelProperty(value = "订单状态 0-待付款(用户刚下单)|1-已付款|2-已取消(未付款取消订单)|3-已退款(超时支付)")
@ApiModelProperty(value = "订单状态 1待付款 2已付款 3未付款取消订单 4退款中 5已退款")
private Integer status;
@ApiModelProperty(value = "订单来源 app|h5|applet")
private String source;
@ApiModelProperty(value = "订单类型 0-购买订单|1-兑换订单|2-演出赠送订单")
@ApiModelProperty(value = "订单类型 1购买订单 2兑换订单 3演出赠送订单")
private Integer orderType;
@ApiModelProperty(value = "支付时间")
......@@ -99,10 +99,10 @@ public class GoblinNftOrderDetailsVo implements Serializable, Cloneable {
@ApiModelProperty(value = "支付单号")
private String payCode;
@ApiModelProperty(value = "支付类型 wepay-微信支付|alipay-阿里支付|douyinpay-抖音支付|unionpay-银联支付")
@ApiModelProperty(value = "支付类型 wepay微信 alipay阿里 douyinpay抖音 unionpay银联")
private String payType;
@ApiModelProperty(value = "支付类型来源[wap|js]")
@ApiModelProperty(value = "支付终端 app wap js applet")
private String deviceFrom;
@ApiModelProperty(value = "支付中心返回实际支付类型")
......
......@@ -85,13 +85,13 @@ public class GoblinNftOrderVo implements Serializable, Cloneable {
@ApiModelProperty(value = "红包code")
private String redEnvelopeCode;
@ApiModelProperty(value = "订单状态 0-待付款(用户刚下单)|1-已付款|2-已取消(未付款取消订单)|3-已退款(超时支付)")
@ApiModelProperty(value = "订单状态 1待付款 2已付款 3未付款取消订单 4退款中 5已退款")
private Integer status;
@ApiModelProperty(value = "订单来源 app|h5|applet")
private String source;
@ApiModelProperty(value = "订单类型 0-购买订单|1-兑换订单|2-演出赠送订单")
@ApiModelProperty(value = "订单类型 1购买订单 2兑换订单 3演出赠送订单")
private Integer orderType;
@ApiModelProperty(value = "支付时间")
......@@ -100,10 +100,10 @@ public class GoblinNftOrderVo implements Serializable, Cloneable {
@ApiModelProperty(value = "支付单号")
private String payCode;
@ApiModelProperty(value = "支付类型 wepay-微信支付|alipay-阿里支付|douyinpay-抖音支付|unionpay-银联支付")
@ApiModelProperty(value = "支付类型 wepay微信 alipay阿里 douyinpay抖音 unionpay银联")
private String payType;
@ApiModelProperty(value = "支付类型来源[wap|js]")
@ApiModelProperty(value = "支付终端 app wap js applet")
private String deviceFrom;
@ApiModelProperty(value = "支付中心返回实际支付类型")
......
......@@ -19,7 +19,7 @@ public class GoblinNftPayResultVo implements Serializable, Cloneable {
@ApiModelProperty(position = 15, value = "订单ID")
private String orderId;
@ApiModelProperty(position = 11, value = "code")
@ApiModelProperty(position = 11, value = "code payCode")
private String code;
@ApiModelProperty(position = 12, value = "orderCode")
......
package com.liquidnet.service.goblin.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* <p>
* NFT下单所需商品相关参数
* </p>
*
* @author jiangxiulong
* @since 2022-03-24
*/
@ApiModel(value = "GoblinNftOrderPayGoodsParam", description = "下单所需商品相关参数")
@Data
public class GoblinNftOrderPayGoodsParam {
@ApiModelProperty(position = 10, required = true, value = "商铺id")
@NotBlank(message = "storeId不能为空")
private String storeId;
@ApiModelProperty(position = 11, required = true, value = "spuId")
@NotBlank(message = "spuId不能为空")
private String spuId;
@ApiModelProperty(position = 12, required = true, value = "skuId")
@NotBlank(message = "skuId不能为空")
private String skuId;
@ApiModelProperty(position = 13, value = "平台券码")
private String platVoucherCode;
@ApiModelProperty(position = 14, value = "商品券码")
private String storeVoucherCode;
}
......@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
......@@ -16,24 +15,31 @@ public class GoblinNftOrderPayParam {
@ApiModelProperty(position = 10, value = "openId微信内网页及小程序支付必传")
private String openId;
@ApiModelProperty(position = 11, required = true, value = "支付方式", allowableValues = "alipay,wepay,douyinpay,unionpay")
@ApiModelProperty(position = 11, required = true, value = "skuId")
@NotBlank(message = "skuId不能为空")
private String skuId;
@ApiModelProperty(position = 12, value = "平台券码")
private String platVoucherCode;
@ApiModelProperty(position = 13, value = "商品券码")
private String storeVoucherCode;
@ApiModelProperty(position = 14, required = true, value = "支付方式", allowableValues = "alipay,wepay,douyinpay,unionpay")
@Pattern(regexp = LnsRegex.Valid.TRIPLE_PF_FOR_PAY, message = "支付方式无效")
@NotBlank(message = "支付方式不能为空")
private String payType;
@ApiModelProperty(position = 12, required = true, value = "支付终端", allowableValues = "app,wap,js,applet")
@ApiModelProperty(position = 15, required = true, value = "支付终端", allowableValues = "app,wap,js,applet")
@Pattern(regexp = LnsRegex.Valid.TRIPLE_PF_FOR_PAY_TERMINAL, message = "支付终端类型无效")
@NotBlank(message = "支付终端不能为空")
private String deviceFrom;
@ApiModelProperty(position = 13, value = "showUrl 之前h5需要 app不需要再说")
@ApiModelProperty(position = 16, value = "showUrl 之前h5需要 app不需要再说")
private String showUrl;
@ApiModelProperty(position = 14, value = "returnUrl 之前h5需要 app不需要再说")
@ApiModelProperty(position = 17, value = "returnUrl 之前h5需要 app不需要再说")
private String returnUrl;
@ApiModelProperty(position = 15, required = true, value = "下单所需商品相关参数")
@Valid
private GoblinNftOrderPayGoodsParam goblinNtfOrderPayGoodsParam;
}
......@@ -126,7 +126,7 @@ public class GoblinNftOrder implements Serializable, Cloneable {
private String redEnvelopeCode;
/**
* 订单状态 0-待付款(用户刚下单)|1-已付款|2-已取消(未付款取消订单)|3-已退款(超时支付)
* 订单状态 1待付款 2已付款 3未付款取消订单 4退款中 5已退款
*/
private Integer status;
......@@ -136,7 +136,7 @@ public class GoblinNftOrder implements Serializable, Cloneable {
private String source;
/**
* 订单类型 0-购买订单|1-兑换订单|2-演出赠送订单
* 订单类型 1购买订单 2兑换订单 3演出赠送订单
*/
private Integer orderType;
......@@ -151,12 +151,12 @@ public class GoblinNftOrder implements Serializable, Cloneable {
private String payCode;
/**
* 支付类型 wepay-微信支付|alipay-阿里支付|douyinpay-抖音支付|unionpay-银联支付
* 支付类型 wepay微信 alipay阿里 douyinpay抖音 unionpay银联
*/
private String payType;
/**
* 支付类型来源[wap|js]
* 支付终端 app wap js applet
*/
private String deviceFrom;
......
......@@ -27,6 +27,7 @@ db.createCollection("GoblinOrderLogVo");
db.createCollection("GoblinOrderSkuVo");
db.createCollection("GoblinSelfMarketingVo");
db.createCollection("GoblinStoreOrderVo");
db.createCollection("GoblinNftOrderVo");
// ================================================== 创建索引
......@@ -71,6 +72,11 @@ db.GoblinStoreOrderVo.createIndex({orderId:"hashed"});
db.GoblinStoreOrderVo.createIndex({storeId:"hashed"});
db.GoblinStoreOrderVo.createIndex({status:"hashed"});
db.GoblinStoreOrderVo.createIndex({orderCode:"hashed"});
db.GoblinNftOrderVo.createIndex({orderId:"hashed"});
db.GoblinNftOrderVo.createIndex({orderCode:"hashed"});
db.GoblinNftOrderVo.createIndex({skuId:"hashed"});
db.GoblinNftOrderVo.createIndex({userId:"hashed"});
// ================================================== 创建分片
......@@ -102,3 +108,4 @@ sh.shardCollection("test_ln_scene.GoblinOrderLogVo",{"orderId":"hashed"});
sh.shardCollection("test_ln_scene.GoblinOrderSkuVo",{"orderSkuId":"hashed"});
sh.shardCollection("test_ln_scene.GoblinStoreOrderVo",{"orderId":"hashed"});
sh.shardCollection("test_ln_scene.GoblinSelfMarketingVo",{"selfMarketId":"hashed"});
sh.shardCollection("test_ln_scene.GoblinNftOrderVo",{"orderId":"hashed"});
......@@ -51,42 +51,25 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
@Override
public ResponseDto<GoblinNftPayResultVo> checkOrder(GoblinNftOrderPayParam payParam) {
// 基础参数
GoblinNftOrderPayGoodsParam payGoodsParam = payParam.getGoblinNtfOrderPayGoodsParam();
// 判断库存
String skuId = payGoodsParam.getSkuId();
String skuId = payParam.getSkuId();
String uid = CurrentUtil.getCurrentUid();
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
String spuId = skuVo.getSpuId();
int number = 1;
int surplusGeneral = nftOrderUtils.decrSkuStock(skuId, number);
if (surplusGeneral < 0) {
nftOrderUtils.incrSkuStock(skuId, number);
return ResponseDto.failure("库存不足啦~");
}
// 是店铺商品可购买
String storeId = payGoodsParam.getStoreId();
String spuId = payGoodsParam.getSpuId();
GoblinGoodsInfoVo spuVo = goblinRedisUtils.getGoodsInfoVo(spuId);
GoblinGoodsSkuInfoVo skuVo = goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if (!storeId.equals(spuVo.getStoreId()) || !storeId.equals(skuVo.getStoreId())) {
log.info("NFT-storeId错误 相关参数:[storeId:{}, spuId:{}, skuId:{}]", storeId, spuId, skuId);
return ResponseDto.failure("非法参数~");
}
// 3审核通过 3已上架 0未删除 才可购买
if (!skuVo.getStatus().equals("3") || !skuVo.getShelvesStatus().equals("3") || skuVo.getDelFlg().equals("1")) {
return ResponseDto.failure("该商品当前不可购买~");
}
// TODO: jxl 2022/3/23 是否开售
// 数量限购
String uid = CurrentUtil.getCurrentUid();
int limitCount = skuVo.getBuyLimit() == 0 ? Integer.MAX_VALUE : skuVo.getBuyLimit();
String isOutLimt = goblinOrderUtils.judgeOrderLimit(uid, skuId, 1, limitCount);
if (!StringUtils.isEmpty(isOutLimt)) {
goblinRedisUtils.decrSkuCountByUid(uid, skuId, number);
return ResponseDto.failure("已超出限购数量~");
// 判断开售、停售时间
LocalDateTime saleStartTime = skuVo.getSaleStartTime();
LocalDateTime saleStopTime = skuVo.getSaleStopTime();
LocalDateTime nowTime = LocalDateTime.now();
if (nowTime.isBefore(saleStartTime)) {
return ResponseDto.failure("该商品还未开始售卖~");
} else if (null != saleStopTime && nowTime.isAfter(saleStopTime)) {
return ResponseDto.failure("该商品已停售~");
}
// 权限限购
String mobile = StringUtils.defaultString(((String) CurrentUtil.getTokenClaims().get(CurrentUtil.TOKEN_MOBILE)), "");
boolean isVip = nftOrderUtils.isVipMember(uid);
......@@ -94,49 +77,66 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
if (!isAuthBuy) {
return ResponseDto.failure("该商品仅限特定用户购买~");
}
// 判断优惠券
String platVoucherCode = payGoodsParam.getPlatVoucherCode();
String storeVoucherCode = payGoodsParam.getStoreVoucherCode();
// 判断优惠券不能一起使用
String platVoucherCode = payParam.getPlatVoucherCode();
String storeVoucherCode = payParam.getStoreVoucherCode();
if (!StringUtils.isEmpty(platVoucherCode) && !StringUtils.isEmpty(storeVoucherCode)) {
return ResponseDto.failure("平台券与店铺券不可一起使用哦~");
}
// 判断数量限购
int limitCount = skuVo.getBuyLimit();
if (!Objects.equals(0, limitCount)) {
String isOutLimit = goblinOrderUtils.judgeOrderLimit(uid, skuId, number, limitCount);
if (!StringUtils.isEmpty(isOutLimit)) {
goblinRedisUtils.decrSkuCountByUid(uid, skuId, number);
return ResponseDto.failure("您已超出限购数量~");
}
}
// 判断库存
int surplusGeneral = nftOrderUtils.decrSkuStock(skuId, number);
if (surplusGeneral < 0) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
return ResponseDto.failure("库存不足啦~");
}
/**
* 判断优惠券
* 因平台券和店铺券不能同时使用所以不需要相互考虑失败退另一种券的问题,各自处理就好
* 回滚好库存和用户已购买数量
* 无论平台券还是店铺券都只支持代金券1的类型
*/
BigDecimal voucherPrice = BigDecimal.ZERO;
String orderId = IDGenerator.nextSnowId();
String orderCode = IDGenerator.storeCode(orderId);
BigDecimal totalPrice = skuVo.getPrice();
if (isVip) {
if (isVip) {// 会员价
totalPrice = skuVo.getPriceMember();
}
if (!StringUtils.isEmpty(platVoucherCode)) {// 平台券
HashMap<String, Object> hashMap = nftOrderUtils.useCoupon(platVoucherCode, "购买NFT商品[" + orderCode + "]", totalPrice, spuId, uid);
if (hashMap != null) {
voucherPrice = (BigDecimal) hashMap.get("voucher");
Integer typeVoucher = (Integer) hashMap.get("type");
if (typeVoucher.equals(-1)) {
GoblinUseResultVo useResultVo = nftOrderUtils.useCoupon(platVoucherCode, "购买NFT商品[" + orderCode + "]", totalPrice, spuId, uid);
String typeVoucher = useResultVo.getCouType();
if (typeVoucher.equals("-1")) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
return ResponseDto.failure("当前平台券不允许使用~");
} else {
// TODO: jxl 2022/3/24 错误回退
}
voucherPrice = useResultVo.getValue();
}
}
BigDecimal storeVoucherPrice = BigDecimal.ZERO;
if (!StringUtils.isEmpty(storeVoucherCode)) {// 店铺券
GoblinUseResultVo storeCouponVo = nftOrderUtils.useStoreCoupon(storeVoucherCode, "购买NFT商品[" + orderCode + "]", totalPrice, spuId, uid);
String typeVoucher;
if (storeCouponVo != null) {
storeVoucherPrice = storeCouponVo.getValue();
typeVoucher = storeCouponVo.getCouType();
String typeVoucher = storeCouponVo.getCouType();
if (typeVoucher.equals("-1")) {
nftOrderUtils.backSkuCountAndStock(uid, skuId, number);
return ResponseDto.failure("当前店铺券不允许使用~");
} else {
// TODO: jxl 2022/3/24 错误回退
}
storeVoucherPrice = storeCouponVo.getValue();
}
}
// 下单数据
GoblinNftOrder nftOrder = order(payParam, payGoodsParam, uid, orderId, orderCode, totalPrice, voucherPrice, storeVoucherPrice, isVip);
GoblinNftOrder nftOrder = order(payParam, skuVo.getStoreId(), uid, orderId, orderCode, totalPrice, voucherPrice, storeVoucherPrice, isVip);
// 下单唤起支付
GoblinNftPayResultVo nftPayResultVo = payOrder(nftOrder, uid, payParam);
......@@ -144,12 +144,11 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
}
private GoblinNftOrder order(
GoblinNftOrderPayParam payParam, GoblinNftOrderPayGoodsParam payGoodsParam, String uid,
GoblinNftOrderPayParam payParam, String storeId, String uid,
String orderId, String orderCode,
BigDecimal totalPrice, BigDecimal voucherPrice, BigDecimal storeVoucherPrice,
boolean isVip
) {
String storeId = payGoodsParam.getStoreId();
LocalDateTime now = LocalDateTime.now();
Map token = CurrentUtil.getTokenClaims();
......@@ -160,11 +159,12 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
GoblinStoreInfoVo storeInfoVo = goblinRedisUtils.getStoreInfoVo(storeId);
String storeName = storeInfoVo.getStoreName();
//生成订单
// 生成订单
GoblinNftOrder nftOrder = GoblinNftOrder.getNew();
nftOrder.setOrderId(orderId);
nftOrder.setOrderCode(orderCode);
nftOrder.setStoreId(storeId);
nftOrder.setSkuId(payParam.getSkuId());
nftOrder.setStoreName(storeName);
nftOrder.setUserId(uid);
nftOrder.setUserName(StringUtils.defaultString(((String) token.get(CurrentUtil.TOKEN_NICKNAME)), ""));
......@@ -176,14 +176,14 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
nftOrder.setStorePriceCoupon(storeVoucherPrice);
nftOrder.setPriceVoucher(voucherPrice.add(storeVoucherPrice));
nftOrder.setStatus(GoblinStatusConst.NftStatus.ORDER_STATUS_1.getValue());
nftOrder.setUcouponId(payGoodsParam.getPlatVoucherCode());
nftOrder.setStoreCouponId(payGoodsParam.getStoreVoucherCode());
nftOrder.setUcouponId(payParam.getPlatVoucherCode());
nftOrder.setStoreCouponId(payParam.getStoreVoucherCode());
nftOrder.setPayType(payParam.getPayType());
nftOrder.setDeviceFrom(payParam.getDeviceFrom());
nftOrder.setSource(source);
nftOrder.setVersion(version);
nftOrder.setIsMember(isVip ? 1 : 0);
nftOrder.setOrderType(0);
nftOrder.setOrderType(GoblinStatusConst.NftStatus.ORDER_TYPE_1.getValue());
nftOrder.setPayCountdownMinute(5);
nftOrder.setIpAddress(CurrentUtil.getCliIpAddr());
nftOrder.setCreatedAt(now);
......@@ -275,7 +275,7 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
String sqlData = SqlMapping.gets(sqls, sqlDataOrder);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_ORDER_CREATE_PAY.getKey(), sqlData);
log.info(UserPathDto.setData("下单(唤起支付)", nftOrder, NftPayResultVo));
log.info(UserPathDto.setData("NFT下单(唤起支付)", nftOrder, NftPayResultVo));
if (isFree) {// 免费直接回调
GoblinNftOrderPayCallbackParam NftOrderPayCallbackParam = GoblinNftOrderPayCallbackParam.getNew();
NftOrderPayCallbackParam.setCode(payCode);
......
......@@ -59,6 +59,14 @@ public class GoblinNftOrderUtils {
return (int) redisUtil.incr(redisKey, stock);
}
// 回滚用户sku购买个数和库存
public void backSkuCountAndStock(String uid, String skuId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BUY_COUNT.concat(uid + ":skuId:" + skuId);
long decr = redisUtil.decr(redisKey, number);
String redisKey2 = GoblinRedisConst.REAL_STOCK_SKU.concat(skuId);
long incr = redisUtil.incr(redisKey2, number);
}
// 是否是会员
public boolean isVipMember(String uid) {
Integer member = goblinRedisUtils.getMember(uid);
......@@ -117,7 +125,7 @@ public class GoblinNftOrderUtils {
}
/**
* 使用平台优惠券
* 使用平台优惠券 只支持代金券
*
* @param uCouponId 券id
* @param content 消费内容
......@@ -126,9 +134,7 @@ public class GoblinNftOrderUtils {
* @param uid uid
* @return
*/
public HashMap<String, Object> useCoupon(String uCouponId, String content, BigDecimal totalPrice, String spuId, String uid) {
HashMap<String, Object> hashMap = CollectionUtil.mapStringObject();
try {
public GoblinUseResultVo useCoupon(String uCouponId, String content, BigDecimal totalPrice, String spuId, String uid) {
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("uCouponId", uCouponId);
params.add("content", content);
......@@ -148,77 +154,30 @@ public class GoblinNftOrderUtils {
});
CandyUseResultVo candyUseResultVo = useResultVo.getData();
Integer type = candyUseResultVo.getCouType();
List<String> targetList = candyUseResultVo.getTargetIds();
BigDecimal fullValue = candyUseResultVo.getFullValue();
BigDecimal value = candyUseResultVo.getValue();
BigDecimal voucher = BigDecimal.ZERO;
BigDecimal targetPrice = BigDecimal.ZERO;
BigDecimal voucher;
switch (type) {// 券类型[-1-不可用 | 1-代金券|2-满减券|3-兑换券|4-折扣券|101-优先券]
case -1:
voucher = BigDecimal.valueOf(-1);
voucher = BigDecimal.ZERO;
break;
case 1:
if (targetList.size() == 0) {
targetPrice = totalPrice;
} else {
for (String targetId : targetList) {
if (targetId.equals(spuId)) {
targetPrice = totalPrice;
}
}
}
if (targetPrice.compareTo(value) >= 0) {
voucher = voucher.add(value);
} else {
voucher = voucher.add(targetPrice);
if (totalPrice.compareTo(value) >= 0) {
voucher = value;
} else {// 优惠金额大于了总价 优惠金额最大为总价
voucher = totalPrice;
}
break;
case 2:
if (targetList.size() == 0) {
targetPrice = totalPrice;
} else {
for (String targetId : targetList) {
if (targetId.equals(spuId)) {
targetPrice = totalPrice;
}
}
}
if (fullValue.compareTo(targetPrice) <= 0) {
voucher = voucher.add(value);
} else {
goblinOrderUtils.backCoupon(uCouponId, uid);
hashMap.put("type", -1);
hashMap.put("voucher", BigDecimal.ZERO);
return hashMap;
}
break;
case 3:
voucher = voucher.add(totalPrice);
break;
case 4:
if (targetList.size() == 0) {
targetPrice = totalPrice;
} else {
for (String targetId : targetList) {
if (targetId.equals(spuId)) {
targetPrice = totalPrice;
}
}
}
voucher = targetPrice.subtract(targetPrice.multiply(value));
break;
default:
default:// 其他类型如果使用成功了直接退掉 返回不可用
type = -1;
voucher = BigDecimal.ZERO;
goblinOrderUtils.backCoupon(uCouponId, uid);
break;
}
hashMap.put("spuIds", targetList);
hashMap.put("type", type);
hashMap.put("voucher", voucher.setScale(2, BigDecimal.ROUND_HALF_UP));
return hashMap;
} catch (Exception e) {
log.error("用券ERROR:{}", e);
return null;
}
GoblinUseResultVo returnVo = GoblinUseResultVo.getNew();
returnVo.setValue(voucher.setScale(2, BigDecimal.ROUND_HALF_UP));
returnVo.setCouType(String.valueOf(type));
return returnVo;
}
/**
......@@ -232,51 +191,26 @@ public class GoblinNftOrderUtils {
* @return
*/
public GoblinUseResultVo useStoreCoupon(String uCouponId, String content, BigDecimal totalPrice, String spuId, String uid) {
try {
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
GoblinUseResultVo returnVo = GoblinUseResultVo.getNew();
returnVo.setValue(BigDecimal.ZERO);
returnVo.setCouType("-1");
LocalDateTime now = LocalDateTime.now();
List<String> spuIds = CollectionUtil.linkedListString();
for (GoblinUserCouponVo vo : voList) {
if (vo.getUcouponId().equals(uCouponId) && vo.getDuedAt().isAfter(now)) {
//判断券状态 和 触发金额
if ((vo.getState().equals(1))) {
if (vo.getUseScope().equals("0") && vo.getTriggers().compareTo(totalPrice) <= 0) {
if (vo.getType().equals("1")) {//代金券
returnVo.setValue(vo.getValFace());
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("2")) {//折扣
BigDecimal tempPrice = totalPrice.subtract(totalPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP));
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
returnVo.setValue(tempPrice);
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) <= 0) {//满减
returnVo.setValue(vo.getValMinus());
returnVo.setCouType(vo.getType());
}
vo.setState(5);
vo.setUsedFor(content);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now(), vo.getUcouponId()));
if (vo.getUcouponId().equals(uCouponId) && vo.getDuedAt().isAfter(now) && vo.getState().equals(1) && vo.getUseScope().equals("1")) {// 判断可用
List<String> couponSpuIds = goblinRedisUtils.getStoreCouponSpuIds(vo.getStoreCouponId());
if (CollectionUtil.isEmpty(couponSpuIds)) {
break;
} else {
spuIds = goblinRedisUtils.getStoreCouponSpuIds(vo.getStoreCouponId());
if (spuIds == null || spuIds.size() == 0) {
continue;
}
//判断是否在可用商品内
// 判断是否在可用商品内
BigDecimal contentPrice = BigDecimal.ZERO;
for (String item : spuIds) {
for (String item : couponSpuIds) {
if (spuId.equals(item)) {
contentPrice = totalPrice;
}
}
if (vo.getTriggers().compareTo(contentPrice) <= 0) {
if (vo.getTriggers().compareTo(contentPrice) <= 0) {// 订单金额大于等于触发金额可使用
if (vo.getType().equals("1")) {//代金券
if (vo.getValFace().compareTo(contentPrice) > 0) {
returnVo.setValue(contentPrice);
......@@ -284,42 +218,24 @@ public class GoblinNftOrderUtils {
returnVo.setValue(vo.getValFace());
}
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("2")) {//折扣
BigDecimal tempPrice = contentPrice.subtract(contentPrice.multiply(vo.getDiscount()).setScale(2, BigDecimal.ROUND_HALF_UP));
if (tempPrice.compareTo(vo.getDeduction()) > 0) {
tempPrice = vo.getDeduction();
}
returnVo.setValue(tempPrice);
returnVo.setCouType(vo.getType());
} else if (vo.getType().equals("3")) {//满减
if (vo.getValMinus().compareTo(contentPrice) > 0) {
returnVo.setValue(contentPrice);
} else {
returnVo.setValue(vo.getValMinus());
}
returnVo.setCouType(vo.getType());
break;
}
// 更新券信息
vo.setState(5);
vo.setUsedFor(content);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_COUPON.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now(), vo.getUcouponId()));
}
}
}
break;
}
}
// 如果使用了更新redis
if (!returnVo.getCouType().equals("-1")) {
goblinRedisUtils.setUserCouponVos(uid, voList);
}
returnVo.setSpuIds(spuIds);
return returnVo;
} catch (Exception e) {
log.error("店铺券错误:{}", e);
return null;
}
}
//超时支付自动退款
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment