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

Commit 5e2577af authored by jiangxiulong's avatar jiangxiulong

兑换

parent 42e6df85
...@@ -258,6 +258,11 @@ public class GoblinRedisConst { ...@@ -258,6 +258,11 @@ public class GoblinRedisConst {
*/ */
public static final String NFT_EX_CODE = PREFIX.concat("nft:ex:code:"); public static final String NFT_EX_CODE = PREFIX.concat("nft:ex:code:");
/**
* 用户sku兑换数量 activityId、skuId、userId
*/
public static final String REDIS_GOBLIN_EX_BUY_COUNT = PREFIX.concat("nft:ex:buy:");
/** /**
......
...@@ -199,6 +199,7 @@ public class GoblinStatusConst { ...@@ -199,6 +199,7 @@ public class GoblinStatusConst {
ORDER_TYPE_1(1, "购买订单"), ORDER_TYPE_1(1, "购买订单"),
ORDER_TYPE_2(2, "兑换订单"), ORDER_TYPE_2(2, "兑换订单"),
ORDER_TYPE_3(3, "演出赠送订单"), ORDER_TYPE_3(3, "演出赠送订单"),
ORDER_TYPE_4(4, "空头订单"),
; ;
......
...@@ -41,5 +41,15 @@ public class GoblinNftOrderPayParam { ...@@ -41,5 +41,15 @@ public class GoblinNftOrderPayParam {
@ApiModelProperty(position = 17, value = "returnUrl 之前h5需要 app不需要再说") @ApiModelProperty(position = 17, value = "returnUrl 之前h5需要 app不需要再说")
private String returnUrl; private String returnUrl;
private static final GoblinNftOrderPayParam obj = new GoblinNftOrderPayParam();
public static GoblinNftOrderPayParam getNew() {
try {
return (GoblinNftOrderPayParam) obj.clone();
} catch (CloneNotSupportedException e) {
return new GoblinNftOrderPayParam();
}
}
} }
...@@ -26,5 +26,5 @@ public interface IGoblinNftOrderService { ...@@ -26,5 +26,5 @@ public interface IGoblinNftOrderService {
String refundSyncOrder(GoblinNftOrderRefundCallbackParam refundCallbackParam); String refundSyncOrder(GoblinNftOrderRefundCallbackParam refundCallbackParam);
ResponseDto<Boolean> exchange(String code, String uid); ResponseDto<Boolean> exchange(String code, String uid, String deviceFrom, int orderType);
} }
package com.liquidnet.service.order.controller; package com.liquidnet.service.order.controller;
import com.liquidnet.commons.lang.constant.LnsRegex;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.codec.vo.EncryptedReq; import com.liquidnet.service.base.codec.vo.EncryptedReq;
import com.liquidnet.service.goblin.dto.vo.GoblinNftPayResultVo; import com.liquidnet.service.goblin.dto.vo.GoblinNftPayResultVo;
...@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
@Api(tags = "NFT-支付相关") @Api(tags = "NFT-支付相关")
@RestController @RestController
...@@ -74,11 +76,13 @@ public class GoblinNftOrderController { ...@@ -74,11 +76,13 @@ public class GoblinNftOrderController {
@ApiOperation("兑换") @ApiOperation("兑换")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(type = "from", required = true, dataType = "String", name = "code", value = "兑换码", example = "1"), @ApiImplicitParam(type = "from", required = true, dataType = "String", name = "code", value = "兑换码", example = "1"),
@ApiImplicitParam(type = "from", required = true, dataType = "String", name = "deviceFrom", value = "支付终端", example = "app", allowableValues = "app,wap,js,applet"),
}) })
public ResponseDto<Boolean> exchange( public ResponseDto<Boolean> exchange(
@RequestParam("code") @NotBlank(message = "兑换码不能为空") String code @RequestParam("code") @NotBlank(message = "兑换码不能为空") String code,
@RequestParam("deviceFrom") @NotBlank(message = "支付终端不能为空") @Pattern(regexp = LnsRegex.Valid.TRIPLE_PF_FOR_PAY_TERMINAL, message = "支付终端类型无效") String deviceFrom
) { ) {
return iGoblinNftOrderService.exchange(code, null); return iGoblinNftOrderService.exchange(code, null, deviceFrom, 2);
} }
} }
package com.liquidnet.service.order.controller.inner; package com.liquidnet.service.order.controller.inner;
import com.liquidnet.commons.lang.constant.LnsRegex;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.service.IGoblinNftOrderService; import com.liquidnet.service.goblin.service.IGoblinNftOrderService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
@Api(tags = "NFT-支付相关") @Api(tags = "NFT-支付相关")
@RestController @RestController
...@@ -29,12 +31,15 @@ public class GoblinInnerNftController { ...@@ -29,12 +31,15 @@ public class GoblinInnerNftController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(type = "from", required = true, dataType = "String", name = "code", value = "兑换码", example = "1"), @ApiImplicitParam(type = "from", required = true, dataType = "String", name = "code", value = "兑换码", example = "1"),
@ApiImplicitParam(type = "from", required = true, dataType = "String", name = "userId", value = "用户ID", example = "1"), @ApiImplicitParam(type = "from", required = true, dataType = "String", name = "userId", value = "用户ID", example = "1"),
@ApiImplicitParam(type = "from", required = true, dataType = "String", name = "deviceFrom", value = "支付终端", example = "app", allowableValues = "app,wap,js,applet"),
}) })
public ResponseDto<Boolean> exchange( public ResponseDto<Boolean> exchange(
@RequestParam("code") @NotBlank(message = "兑换码不能为空") String code, @RequestParam("code") @NotBlank(message = "兑换码不能为空") String code,
@RequestParam("userId") @NotBlank(message = "用户ID不能为空") String userId @RequestParam("userId") @NotBlank(message = "用户ID不能为空") String userId,
@RequestParam("deviceFrom") @NotBlank(message = "支付终端不能为空") @Pattern(regexp = LnsRegex.Valid.TRIPLE_PF_FOR_PAY_TERMINAL, message = "支付终端类型无效") String deviceFrom
) { ) {
return iGoblinNftOrderService.exchange(code, userId); return iGoblinNftOrderService.exchange(code, userId, deviceFrom, 4);
} }
} }
...@@ -184,7 +184,8 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService { ...@@ -184,7 +184,8 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
}*/ }*/
// 下单数据 // 下单数据
GoblinNftOrder nftOrder = order(payParam, skuVo.getStoreId(), uid, spuId, number, orderId, orderCode, totalPrice, voucherPrice, storeVoucherPrice, boxSkuId); int orderType1 = GoblinStatusConst.NftStatus.ORDER_TYPE_1.getValue();
GoblinNftOrder nftOrder = order(payParam, skuVo.getStoreId(), uid, spuId, number, orderId, orderCode, totalPrice, voucherPrice, storeVoucherPrice, boxSkuId, orderType1);
if (null == nftOrder) { if (null == nftOrder) {
nftOrderUtils.backSkuCountAndStock(uid, stockSkuId, skuId, number); nftOrderUtils.backSkuCountAndStock(uid, stockSkuId, skuId, number);
return ResponseDto.failure("下单失败~"); return ResponseDto.failure("下单失败~");
...@@ -303,7 +304,8 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService { ...@@ -303,7 +304,8 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
private GoblinNftOrder order( private GoblinNftOrder order(
GoblinNftOrderPayParam payParam, String storeId, String uid, String spuId, int number, GoblinNftOrderPayParam payParam, String storeId, String uid, String spuId, int number,
String orderId, String orderCode, String orderId, String orderCode,
BigDecimal totalPrice, BigDecimal voucherPrice, BigDecimal storeVoucherPrice, String boxSkuId BigDecimal totalPrice, BigDecimal voucherPrice, BigDecimal storeVoucherPrice, String boxSkuId,
int orderType
) { ) {
try { try {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
...@@ -343,7 +345,7 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService { ...@@ -343,7 +345,7 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
nftOrder.setRedEnvelopeCode(""); nftOrder.setRedEnvelopeCode("");
nftOrder.setStatus(GoblinStatusConst.NftStatus.ORDER_STATUS_1.getValue()); nftOrder.setStatus(GoblinStatusConst.NftStatus.ORDER_STATUS_1.getValue());
nftOrder.setSource(source); nftOrder.setSource(source);
nftOrder.setOrderType(GoblinStatusConst.NftStatus.ORDER_TYPE_1.getValue()); nftOrder.setOrderType(orderType);
nftOrder.setPayType(payParam.getPayType()); nftOrder.setPayType(payParam.getPayType());
nftOrder.setDeviceFrom(payParam.getDeviceFrom()); nftOrder.setDeviceFrom(payParam.getDeviceFrom());
nftOrder.setVersion(version); nftOrder.setVersion(version);
...@@ -456,9 +458,6 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService { ...@@ -456,9 +458,6 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
// mongo // mongo
goblinMongoUtils.setGoblinNftOrderVo(orderVo); goblinMongoUtils.setGoblinNftOrderVo(orderVo);
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlDataOrder);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_NFT_ORDER.getKey(), sqlData);
log.info(UserPathDto.setData("NFT下单(唤起支付)", nftOrder, NftPayResultVo)); log.info(UserPathDto.setData("NFT下单(唤起支付)", nftOrder, NftPayResultVo));
if (isFree) {// 免费直接回调 if (isFree) {// 免费直接回调
...@@ -749,15 +748,88 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService { ...@@ -749,15 +748,88 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
} }
@Override @Override
public ResponseDto<Boolean> exchange(String code, String uid) { public ResponseDto<Boolean> exchange(String code, String uid, String deviceFrom, int orderType) {
// 验证 1code是否存在 2是否在生效日期内 3是否未兑换的状态 4兑换限购 if (null == uid) {
// 使用 uid = CurrentUtil.getCurrentUid();
// 下单 }
boolean isLock = nftOrderUtils.setNftOrderExLock(code); boolean isLock = nftOrderUtils.setNftOrderExLock(code);
if (!isLock) { if (!isLock) {
return ResponseDto.failure("处理未完成,请稍等~"); return ResponseDto.failure("处理未完成,请稍等~");
} else { } else {
try { try {
// 验证 1code是否存在 2是否未兑换的状态 3是否在生效日期内 4兑换限购
GoblinNftExCodeVo goblinNftExCodeVo = nftOrderUtils.getGoblinNftExCodeVo(code);
if (null == goblinNftExCodeVo || goblinNftExCodeVo.getState() != 1) {
return ResponseDto.failure("兑换码不正确或已失效");
}
LocalDateTime nowTime = LocalDateTime.now();
if (nowTime.isBefore(goblinNftExCodeVo.getExStartTime()) || nowTime.isAfter(goblinNftExCodeVo.getExStopTime())) {
return ResponseDto.failure("当前时间不允许兑换时间内");
}
int buyCount = nftOrderUtils.incrExCountByUid(uid, goblinNftExCodeVo.getSkuId(), goblinNftExCodeVo.getActivityId(), 1);
if (null != goblinNftExCodeVo.getExLimit() && goblinNftExCodeVo.getExLimit() > 0) {
if (buyCount > goblinNftExCodeVo.getExLimit()) {
nftOrderUtils.decrExCountByUid(uid, goblinNftExCodeVo.getSkuId(), goblinNftExCodeVo.getActivityId(), 1);
return ResponseDto.failure("您已超出兑换限制数量~");
}
}
// 使用
goblinNftExCodeVo.setState(2);
goblinNftExCodeVo.setRedeemUid(uid);
goblinNftExCodeVo.setRedeemAt(nowTime);
goblinNftExCodeVo.setUpdatedAt(nowTime);
nftOrderUtils.setGoblinNftExCodeVo(goblinNftExCodeVo);
LinkedList<String> sqls = CollectionUtil.linkedListString();
sqls.add(SqlMapping.get("goblin_nft_ex_code.update"));
LinkedList<Object[]> sqlDataCode = CollectionUtil.linkedListObjectArr();
sqlDataCode.add(new Object[]{
2, uid, nowTime, nowTime, goblinNftExCodeVo.getCodeId()
});
// 下单
GoblinNftOrderPayParam payParam = GoblinNftOrderPayParam.getNew();
payParam.setPayType("");
payParam.setSkuId(goblinNftExCodeVo.getSkuId());
payParam.setDeviceFrom(deviceFrom);
String orderId = IDGenerator.nextSnowId();
String orderCode = IDGenerator.storeCode(orderId);
BigDecimal totalPrice = BigDecimal.ZERO;
GoblinNftOrder nftOrder = order(payParam, goblinNftExCodeVo.getStoreId(), uid, goblinNftExCodeVo.getSpuId(), 1, orderId, orderCode, totalPrice, totalPrice, totalPrice, goblinNftExCodeVo.getBoxSkuId(), orderType);
if (null == nftOrder) {
return ResponseDto.failure("兑换失败~");
}
// redis 订单详情
GoblinNftOrderVo orderVo = GoblinNftOrderVo.getNew().copy(nftOrder);
orderVo.setCreatedAt(nftOrder.getCreatedAt());
orderVo.setPaymentType("");
orderVo.setPaymentId("");
nftOrder.setPayCode("EXCODE");
nftOrder.setPayType("EXCODE");
orderVo.setPayTime(nowTime);
orderVo.setStatus(GoblinStatusConst.NftStatus.ORDER_STATUS_2.getValue());
nftOrderUtils.setNftOrder(orderVo);
nftOrderUtils.setNftOrderIdOfCode(nftOrder.getOrderCode(), nftOrder.getOrderId());
// mongo
goblinMongoUtils.setGoblinNftOrderVo(orderVo);
// 执行sql
sqls.add(SqlMapping.get("goblin_nft_order.insert"));
LinkedList<Object[]> sqlDataOrder = CollectionUtil.linkedListObjectArr();
sqlDataOrder.add(new Object[]{
nftOrder.getOrderId(), nftOrder.getSpuId(), nftOrder.getSkuId(), nftOrder.getBoxSkuId(),
nftOrder.getNum(), nftOrder.getStoreId(), nftOrder.getStoreName(), nftOrder.getOrderCode(), nftOrder.getUserId(), nftOrder.getUserName(), nftOrder.getUserMobile(), nftOrder.getPriceTotal(), nftOrder.getPriceCoupon(),
nftOrder.getStorePriceCoupon(), nftOrder.getPriceRedEnvelope(), nftOrder.getPriceVoucher(), nftOrder.getPriceActual(), nftOrder.getUcouponId(), nftOrder.getStoreCouponId(), nftOrder.getRedEnvelopeCode(), nftOrder.getStatus(), nftOrder.getSource(),
nftOrder.getOrderType(), orderVo.getPayType(), nftOrder.getDeviceFrom(), nftOrder.getVersion(), nftOrder.getPayCountdownMinute(), nftOrder.getIpAddress(), nftOrder.getCreatedAt(), orderVo.getPayCode()
});
String sqlData = SqlMapping.gets(sqls, sqlDataCode, sqlDataOrder);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.GOBLIN_NFT_ORDER.getKey(), sqlData);
// 加积分
goblinOrderUtils.integral(uid, orderVo.getPriceActual(), "购买数字藏品", 1);
// 生产藏品列表
this.generateUserArtwork(orderVo);
// 增加销量
goblinRedisUtils.incrSkuSaleCount(orderVo.getSpuId(), orderVo.getSkuId(), orderVo.getNum());
// 写入用户订单列表 因取消的订单不展示 所以放在这里
nftOrderUtils.addNftOrderList(uid, orderVo.getOrderId());
return ResponseDto.success(); return ResponseDto.success();
} catch (Exception e) { } catch (Exception e) {
log.error("NFT兑换异常 e:{}", e); log.error("NFT兑换异常 e:{}", e);
......
...@@ -151,6 +151,32 @@ public class GoblinNftOrderUtils { ...@@ -151,6 +151,32 @@ public class GoblinNftOrderUtils {
redisUtil.uLock(redisKey); redisUtil.uLock(redisKey);
} }
/**
* 兑换码
*/
public GoblinNftExCodeVo getGoblinNftExCodeVo(String code) {
String redisKey = GoblinRedisConst.NFT_EX_CODE.concat(code);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinNftExCodeVo) obj;
}
}
public void setGoblinNftExCodeVo(GoblinNftExCodeVo codeVo) {
String redisKey = GoblinRedisConst.NFT_EX_CODE.concat(codeVo.getCode());
redisUtil.set(redisKey, codeVo);
}
public int incrExCountByUid(String uid, String skuId, String activityId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_EX_BUY_COUNT.concat(activityId+':').concat(skuId+':').concat(uid);
return (int) redisUtil.incr(redisKey, number);
}
public int decrExCountByUid(String uid, String skuId, String activityId, int number) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_EX_BUY_COUNT.concat(activityId+':').concat(skuId+':').concat(uid);
return (int) redisUtil.decr(redisKey, number);
}
/** /**
* 使用平台优惠券 只支持代金券 * 使用平台优惠券 只支持代金券
* *
......
...@@ -48,8 +48,9 @@ goblin_order.store.backOrder=INSERT INTO goblin_back_order (`back_order_id`,`bac ...@@ -48,8 +48,9 @@ goblin_order.store.backOrder=INSERT INTO goblin_back_order (`back_order_id`,`bac
#-------- NFT ------- #-------- NFT -------
goblin_nft_order.insert=INSERT INTO goblin_nft_order (`order_id`,`spu_id`,`sku_id`,`box_sku_id`,`num`,`store_id`,`store_name`,`order_code`,`user_id`,`user_name`,`user_mobile`,`price_total`,`price_coupon`,`store_price_coupon`,`price_red_envelope`,`price_voucher`,`price_actual`,`ucoupon_id`,`store_coupon_id`,`red_envelope_code`,`status`,`source`,`order_type`,`pay_type`,`device_from`,`version`,`pay_countdown_minute`,`ip_address`,`created_at`,`pay_code`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) goblin_nft_order.insert=INSERT INTO goblin_nft_order (`order_id`,`spu_id`,`sku_id`,`box_sku_id`,`num`,`store_id`,`store_name`,`order_code`,`user_id`,`user_name`,`user_mobile`,`price_total`,`price_coupon`,`store_price_coupon`,`price_red_envelope`,`price_voucher`,`price_actual`,`ucoupon_id`,`store_coupon_id`,`red_envelope_code`,`status`,`source`,`order_type`,`pay_type`,`device_from`,`version`,`pay_countdown_minute`,`ip_address`,`created_at`,`pay_code`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
goblin_nft_order.update.pay=UPDATE goblin_nft_order SET payment_type = ?, payment_id=?, pay_code = ?, pay_time = ?, status = ?, updated_at = ? WHERE order_id = ? and (updated_at <= ? or created_at = ? or updated_at is null) goblin_nft_order.update.pay=UPDATE goblin_nft_order SET payment_type = ?, payment_id = ?, pay_code = ?, pay_time = ?, status = ?, updated_at = ? WHERE order_id = ? and (updated_at <= ? or created_at = ? or updated_at is null)
goblin_nft_order.update.refund=UPDATE goblin_nft_order SET status = ?, updated_at = ? WHERE order_id = ? and (updated_at <= ? or created_at = ? or updated_at is null) goblin_nft_order.update.refund=UPDATE goblin_nft_order SET status = ?, updated_at = ? WHERE order_id = ? and (updated_at <= ? or created_at = ? or updated_at is null)
goblin_nft_order_refund.insert=INSERT INTO goblin_nft_order_refund (`order_refund_id`,`refund_code`,`order_id`,`order_code`,`store_id`,`user_id`,`price`,`status`,`error_reason`,`created_at`) VALUES (?,?,?,?,?,?,?,?,?,?) goblin_nft_order_refund.insert=INSERT INTO goblin_nft_order_refund (`order_refund_id`,`refund_code`,`order_id`,`order_code`,`store_id`,`user_id`,`price`,`status`,`error_reason`,`created_at`) VALUES (?,?,?,?,?,?,?,?,?,?)
goblin_nft_order_refund.refund=UPDATE goblin_nft_order_refund SET status = ?, refund_at = ?, updated_at = ? WHERE order_refund_id = ? and (updated_at <= ? or created_at = ? or updated_at is null) goblin_nft_order_refund.refund=UPDATE goblin_nft_order_refund SET status = ?, refund_at = ?, updated_at = ? WHERE order_refund_id = ? and (updated_at <= ? or created_at = ? or updated_at is null)
goblin_user_digital_artwork.insert=INSERT INTO goblin_user_digital_artwork (artwork_id, sku_id, uid, order_id, source, state, created_at)VALUES(?,?,?,?,?,?,?) goblin_user_digital_artwork.insert=INSERT INTO goblin_user_digital_artwork (artwork_id, sku_id, uid, order_id, source, state, created_at)VALUES(?,?,?,?,?,?,?)
\ No newline at end of file goblin_nft_ex_code.update=UPDATE goblin_nft_ex_code SET state = ?, redeem_uid = ?, redeem_at = ?, updated_at = ? WHERE code_id = ?
\ No newline at end of file
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