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

Commit b91d3235 authored by 胡佳晨's avatar 胡佳晨

订单 券相关逻辑 提交 未实现

parent 31b2caf1
-- 退款配置添加 --
ALTER TABLE kylin_performance_status ADD is_refund_poundage tinyint DEFAULT 0 COMMENT '是否有手续费';
ALTER TABLE kylin_performance_status ADD is_refund_voucher tinyint DEFAULT 0 COMMENT '是否退优惠券';
ALTER TABLE kylin_performance_status ADD is_refund_express tinyint DEFAULT 0 COMMENT '是否手续费';
-- 订单相关券逻辑添加 --
drop TABLE if exists `kylin_order_vouchers`;
CREATE TABLE `kylin_order_vouchers`
(
`mid` int NOT NULL AUTO_INCREMENT,
`order_voucher_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'order_voucher_id',
`order_id` varchar(255) NOT NULL DEFAULT '' COMMENT '订单id',
`voucher_code` varchar(255) NOT NULL DEFAULT '' COMMENT '券code',
`voucher_type` tinyint NOT NULL DEFAULT '' COMMENT '券类别',
`voucher_price` decimal(8, 2) NOT NULL DEFAULT 0.0 COMMENT '券的优惠金额',
`created_at` datetime(3) NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime(3) NULL DEFAULT NULL COMMENT '修改时间',
KEY `kylin_order_vouchers_order_voucher_id_index` (`order_voucher_id`),
KEY `kylin_order_vouchers_order_id_index` (`order_id`),
KEY `kylin_order_vouchers_voucher_type_index` (`voucher_type`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '订单券 关联表';
\ No newline at end of file
......@@ -61,4 +61,11 @@ public class PayOrderParam {
private String showUrl;
@ApiModelProperty(value = "returnUrl")
private String returnUrl;
@ApiModelProperty(value = "优惠券类型")
private String voucherType;
@ApiModelProperty(value = "优惠券码")
private String voucherCode;
@ApiModelProperty(value = "会员提前券码")
private String advanceCode;
}
ALTER TABLE kylin_performance_status ADD is_refund_poundage tinyint DEFAULT 0 COMMENT '是否有手续费';
ALTER TABLE kylin_performance_status ADD is_refund_voucher tinyint DEFAULT 0 COMMENT '是否退优惠券';
ALTER TABLE kylin_performance_status ADD is_refund_express tinyint DEFAULT 0 COMMENT '是否手续费';
\ No newline at end of file
......@@ -92,15 +92,15 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
@Override
public ResponseDto<PayInnerResultVo> checkCanOrder(PayOrderParam payOrderParam) {
Long currentTime;
boolean isDownGeneral = false;
boolean isPay = true;
List<AdamEntersVo> entersVoList = ObjectUtil.cloneArrayListObject();
String uid = CurrentUtil.getCurrentUid();
if (payOrderParam.getVoucherType() != null && payOrderParam.getVoucherType().equals("exchange")) {
isPay = false;
}
try {
currentTime = System.currentTimeMillis();
KylinPerformanceVo performanceData = dataUtils.getPerformanceVo(payOrderParam.getPerformanceId());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 获取演出详情 -> time:" + currentTime + "毫秒");
KylinTicketTimesVo ticketTimesData = null;
KylinTicketVo ticketData = null;
for (int x = 0; x < performanceData.getTicketTimeList().size(); x++) {
......@@ -138,10 +138,7 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
String timeStart = ticketData.getTimeStart(); // 普通开售时间
String timeEnd = ticketData.getTimeEnd(); // 购票停售时间
String timeExpressEnd = ticketData.getTimeEndExpress(); // 快递停售时间
currentTime = System.currentTimeMillis();
boolean isMember = orderUtils.isMember(uid);//feignAdamBaseClient.isMember(uid).getData();//获取是否是会员
currentTime = System.currentTimeMillis() - currentTime;
log.debug("fegin 会员 -> time:" + (currentTime) + "毫秒");
int memberType; //会员状态 不需要判断会员 1判断会员逻辑 2会员专属
if (ticketData.getIsExclusive() == 1) {
memberType = 2;
......@@ -209,17 +206,12 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
// 判断库存
currentTime = System.currentTimeMillis();
int surplusGeneral = dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), -payOrderParam.getNumber());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 获取库存 -> time:" + (currentTime) + "毫秒");
int surplusGeneral = orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), -payOrderParam.getNumber());
log.debug("TAG_REDIS 正常 剩余库存 -> count:" + surplusGeneral);
if (surplusGeneral < 0) {//库存回滚
currentTime = System.currentTimeMillis();
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 修改库存 售罄 -> time:" + (currentTime) + "毫秒");
orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), payOrderParam.getNumber());
log.debug("TAG_REDIS 售罄 回滚库存1 -> count:" + payOrderParam.getNumber());
return ResponseDto.failure(ErrorMapping.get("20016"));//没抢到
} else {
......@@ -228,63 +220,48 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
//学生票 判断
entersVoList = ObjectUtil.cloneArrayListObject();
if (isTrueName == 1) {
currentTime = System.currentTimeMillis();
for (String enterId : payOrderParam.getEnterIdList()) {
AdamEntersVo adamEnters = orderUtils.getEnters(uid, enterId);//feignAdamBaseClient.queryEnters(enterId, uid).getData();
entersVoList.add(adamEnters);
if (isStudent == 1) {
int age = IDCard.getAgeByIdCard(adamEnters.getIdCard());
if (age > 25) {
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), payOrderParam.getNumber());
log.debug("TAG_REDIS 学生票 回滚库存2 -> count:" + payOrderParam.getNumber());
return ResponseDto.failure(ErrorMapping.get("20017"));//年龄超了
}
}
}
currentTime = System.currentTimeMillis() - currentTime;
log.debug("获取 feign 入场人 -> time:" + (currentTime) + "毫秒");
}
//限购判断 如果实名 则身份证维度限购 如果不实名则数量限购
if (entersVoList.size() > 0) {
currentTime = System.currentTimeMillis();
for (int i = 0; i < entersVoList.size(); i++) {
String res1 = orderUtils.judgeOrderLimit(performanceData.getType(), uid, entersVoList.get(i).getIdCard(), payOrderParam.getPerformanceId(), payOrderParam.getTicketId(), performanceLimit, performanceMemberLimit, ticketLimit, ticketMemberLimit, 1, 1, memberType, isTrueName);
log.debug("redis 判断库存 -> time:" + (currentTime) + "毫秒");
if (!res1.equals("")) {
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), payOrderParam.getNumber());
log.debug("TAG_REDIS 限购 回滚库存3 -> count:" + payOrderParam.getNumber());
return ResponseDto.failure(res1);//乱七八糟异常
}
}
currentTime = System.currentTimeMillis() - currentTime;
} else {
log.debug("redis 判断库存 -> time:" + (currentTime) + "毫秒");
currentTime = System.currentTimeMillis();
String res1 = orderUtils.judgeOrderLimit(performanceData.getType(), uid, "", payOrderParam.getPerformanceId(), payOrderParam.getTicketId(), performanceLimit, performanceMemberLimit, ticketLimit, ticketMemberLimit, payOrderParam.getNumber(), payOrderParam.getNumber(), memberType, isTrueName);
currentTime = System.currentTimeMillis() - currentTime;
if (!res1.equals("")) {
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), payOrderParam.getNumber());
log.debug("TAG_REDIS 限购 回滚库存3 -> count:" + payOrderParam.getNumber());
return ResponseDto.failure(res1);//乱七八糟异常
}
currentTime = System.currentTimeMillis() - currentTime;
}
ResponseDto<PayInnerResultVo> resultData = order(payOrderParam, uid, isMember, isTrueName, performanceData, ticketData, entersVoList, isStudent, ticketTimesData, currentTime);
ResponseDto<PayInnerResultVo> resultData = order(payOrderParam, uid, isMember, isTrueName, performanceData, ticketData, entersVoList, isStudent);
isDownGeneral = false;
return resultData;
}
} catch (Exception e) {
log.error("Kylin Order Pay Error = ", e);
if (isDownGeneral) {
currentTime = System.currentTimeMillis();
dataUtils.changeSurplusGeneral(payOrderParam.getTicketId(), payOrderParam.getNumber());
orderUtils.changeSurplus(isPay, payOrderParam.getTicketId(), payOrderParam.getNumber());
log.debug("TAG_REDIS 异常 回滚库存4 -> count:" + payOrderParam.getNumber());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 修改库存 异常 -> time:" + (currentTime) + "毫秒");
for (AdamEntersVo enters : entersVoList) {
dataUtils.changeBuyInfo(uid, enters.getIdCard(), payOrderParam.getPerformanceId(), payOrderParam.getTicketId(), -1);
}
......@@ -298,7 +275,7 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
}
}
private ResponseDto<PayInnerResultVo> order(PayOrderParam payOrderParam, String uid, boolean isMember, int isTrueName, KylinPerformanceVo performanceData, KylinTicketVo ticketData, List<AdamEntersVo> entersVoList, Integer isStudent, KylinTicketTimesVo ticketTimesData, Long currentTime) {
private ResponseDto<PayInnerResultVo> order(PayOrderParam payOrderParam, String uid, boolean isMember, int isTrueName, KylinPerformanceVo performanceData, KylinTicketVo ticketData, List<AdamEntersVo> entersVoList, Integer isStudent) {
LinkedList<String> sqls = ObjectUtil.cloneLinkedListStr();
String headerCliSource = CurrentUtil.getHeaderCliSource(), headerCliVersion = CurrentUtil.getHeaderCliVersion();
String source = headerCliSource == null ? "" : headerCliSource;
......@@ -321,13 +298,20 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTickets.setNumber(payOrderParam.getNumber());
orderTickets.setPrice(ticketData.getPrice());
orderTickets.setPriceMember(ticketData.getMemberPrice());
//TODO 券的使用逻辑
orderTickets.setPriceVoucher(BigDecimal.valueOf(0.0));
if (payOrderParam.getVoucherType() != null) {
orderTickets.setCouponType(payOrderParam.getVoucherType().equalsIgnoreCase("exchange") ? "exchange" : "no");
} else {
orderTickets.setCouponType("no");
}
if (isMember) {
orderTickets.setPriceTotal(ticketData.getMemberPrice().multiply(BigDecimal.valueOf(payOrderParam.getNumber())).add(payOrderParam.getIsExpress() == 1 ? ticketData.getPriceExpress() : BigDecimal.valueOf(0)));
} else {
orderTickets.setPriceTotal(ticketData.getPrice().multiply(BigDecimal.valueOf(payOrderParam.getNumber())).add(payOrderParam.getIsExpress() == 1 ? ticketData.getPriceExpress() : BigDecimal.valueOf(0)));
}
orderTickets.setPriceActual(orderTickets.getPriceTotal());
orderTickets.setPriceVoucher(BigDecimal.valueOf(0.0));
orderTickets.setPriceActual(orderTickets.getPriceTotal().subtract(orderTickets.getPriceVoucher()));
orderTickets.setPriceExpress(payOrderParam.getIsExpress() == 1 ? ticketData.getPriceExpress() : BigDecimal.valueOf(0));
orderTickets.setPriceRefund(BigDecimal.valueOf(0.0));
orderTickets.setRefundNumber(0);
......@@ -335,7 +319,6 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTickets.setPaymentType(null);
orderTickets.setTimePay(null);
if (payOrderParam.getIsExpress() == 1) {
currentTime = System.currentTimeMillis();
AdamAddressesVo addressesVo = orderUtils.getAddress(uid, payOrderParam.getAddressId());//feignAdamBaseClient.queryAddresses(payOrderParam.getAddressId(), uid).getData();
orderTickets.setExpressContacts(addressesVo.getName());
orderTickets.setExpressAddress(addressesVo.getProvince() + addressesVo.getCity() + addressesVo.getCounty() + addressesVo.getAddress());
......@@ -344,8 +327,6 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTickets.setProvince(addressesVo.getProvince());
orderTickets.setCounty(addressesVo.getCounty());
orderTickets.setGetTicketType("express");
currentTime = System.currentTimeMillis() - currentTime;
log.debug("feign 获取入场人 -> time:" + (currentTime) + "毫秒");
} else {
orderTickets.setExpressContacts("");
orderTickets.setExpressAddress("");
......@@ -355,7 +336,6 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTickets.setCounty("");
orderTickets.setGetTicketType("electronic");
}
orderTickets.setCouponType("no");
orderTickets.setGetTicketDescribe("");
orderTickets.setPayCountdownMinute(performanceData.getPayCountdownMinute());
orderTickets.setCreatedAt(now);
......@@ -435,14 +415,8 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTicketEntitiesVo.setCreatedAt(orderTicketEntities.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
orderTicketEntitiesVo.setUpdatedAt(null);
orderTicketEntitiesVo.setChangeDate(orderTicketEntities.getCreatedAt());
currentTime = System.currentTimeMillis();
mongoTemplate.insert(orderTicketEntitiesVo, KylinOrderTicketEntitiesVo.class.getSimpleName());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("mongo 添加入场人 -> time:" + (currentTime) + "毫秒");
currentTime = System.currentTimeMillis();
dataUtils.changeBuyInfo(orderTicketEntitiesVo.getUserId(), orderTicketEntitiesVo.getEnterIdCode(), orderTicketEntitiesVo.getPerformanceId(), orderTicketEntitiesVo.getTicketId(), 1);
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 修改 限购 -> time:" + (currentTime) + "毫秒");
}
} else {
for (int i = 0; i < payOrderParam.getNumber(); i++) {
......@@ -477,22 +451,16 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTicketEntitiesVo.setCreatedAt(orderTicketEntities.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
orderTicketEntitiesVo.setUpdatedAt(null);
orderTicketEntitiesVo.setChangeDate(orderTicketEntities.getCreatedAt());
currentTime = System.currentTimeMillis();
mongoTemplate.insert(orderTicketEntitiesVo, KylinOrderTicketEntitiesVo.class.getSimpleName());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("mongo 添加入场人 -> time:" + (currentTime) + "毫秒");
currentTime = System.currentTimeMillis();
dataUtils.changeBuyInfo(orderTicketEntitiesVo.getUserId(), orderTicketEntitiesVo.getEnterIdCode(), orderTicketEntitiesVo.getPerformanceId(), orderTicketEntitiesVo.getTicketId(), 1);
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 修改限购 -> time:" + (currentTime) + "毫秒");
}
}
//是否免费
boolean isFree=false;
boolean isFree = false;
PayResultVo payResultVo;
if(orderTickets.getPriceActual().compareTo(BigDecimal.valueOf(0))>0){
if (orderTickets.getPriceActual().compareTo(BigDecimal.valueOf(0)) > 0) {
// 调用支付
String time1 = DateUtil.format(DateUtil.Formatter.yyyyMMddHHmmss.parse(ticketData.getUseStart()), DateUtil.Formatter.MM_dd_zh);
String time2 = DateUtil.format(DateUtil.Formatter.yyyyMMddHHmmss.parse(ticketData.getUseEnd()), DateUtil.Formatter.MM_dd_zh);
......@@ -516,10 +484,7 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
httpData.add("showUrl", payOrderParam.getShowUrl() + orderTicketId);
httpData.add("returnUrl", payOrderParam.getReturnUrl() + orderTicketId);
}
currentTime = System.currentTimeMillis();
String returnData = HttpUtil.post(payUrl, httpData);
currentTime = System.currentTimeMillis() - currentTime;
log.info("调用 DRAGON 支付 -> time:" + (currentTime) + "毫秒");
log.info("调用 DRAGON 结果 = " + returnData);
payResultVo = JsonUtils.fromJson(returnData, PayResultVo.class);
payResultVo.getData().setOrderId(orderTicketId);
......@@ -529,8 +494,8 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
payResultVo.getData().setShowUrl(payOrderParam.getShowUrl() + orderTicketId);
payResultVo.getData().setReturnUrl(payOrderParam.getReturnUrl() + orderTicketId);
}
}else{
isFree=true;
} else {
isFree = true;
orderTickets.setPayType("FREE");
orderTickets.setPayCode("FREE_PAY_CODE");
payResultVo = PayResultVo.getNew();
......@@ -555,28 +520,19 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderTicketVo.setOverdueAt(orderTickets.getCreatedAt().plusMinutes(performanceData.getPayCountdownMinute()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
orderTicketVo.setCreatedAt(orderTickets.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
orderTicketVo.setChangeDate(orderTickets.getCreatedAt());
currentTime = System.currentTimeMillis();
mongoTemplate.insert(orderTicketVo, KylinOrderTicketVo.class.getSimpleName());
currentTime = System.currentTimeMillis() - currentTime;
log.debug("mongo 添加 订单 -> time:" + (currentTime) + "毫秒");
currentTime = System.currentTimeMillis();
orderUtils.resetOrderListVo(uid, 1, orderTicketVo.getOrderTicketsId(), orderTicketVo);
currentTime = System.currentTimeMillis() - currentTime;
log.debug("redis 修改订单列表 -> time:" + (currentTime) + "毫秒");
// 执行sql
String sqlData = SqlMapping.gets(sqls, sqlsDataB, sqlsDataC, sqlsDataD, sqlsDataA);
currentTime = System.currentTimeMillis();
queueUtils.sendMsgByRedis(MQConst.KylinQueue.SQL_ORDER_CREATE.getKey(),
sqlData);
currentTime = System.currentTimeMillis() - currentTime;
log.debug("MQ 发送 -> time:" + (currentTime) + "毫秒");
log.info(UserPathDto.setData("下单(唤起支付)", payOrderParam, payResultVo.getData()));
if(isFree){
if (isFree) {
SyncOrderParam syncOrderParam = SyncOrderParam.getNew();
syncOrderParam.setOrderCode(orderTickets.getOrderCode());
syncOrderParam.setPaymentAt(DateUtil.format(LocalDateTime.now(),DateUtil.Formatter.yyyyMMddHHmmss));
syncOrderParam.setPaymentAt(DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyyMMddHHmmss));
syncOrderParam.setCode(orderTickets.getPayCode());
syncOrderParam.setPrice(orderTickets.getPrice());
syncOrderParam.setPaymentId("FREE_PAYMENT_ID");
......@@ -584,7 +540,7 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
syncOrderParam.setStatus(1);
syncOrder(syncOrderParam);
return ResponseDto.success(payResultVo.getData());
}else {
} else {
return ResponseDto.success(payResultVo.getData());
}
}
......@@ -768,7 +724,7 @@ public class KylinOrderTicketsServiceImpl implements IKylinOrderTicketsOrderServ
orderRefundsCallbackService.refundApply(orderTicketData.getOrderTicketsId(), syncOrderParam.getPaymentId(), syncOrderParam.getPaymentType());
} else if ((orderTicketData.getStatus() == 3 || orderTicketData.getStatus() == 4) && syncOrderParam.getStatus().equals(1)) {
log.error("订单号为 {} 的订单正在退款 或者已退款", syncOrderParam.getOrderCode());
} else if(syncOrderParam.getStatus().equals(1)){
} else if (syncOrderParam.getStatus().equals(1)) {
log.error("订单号为 {} 的订单正常流程", syncOrderParam.getOrderCode());
orderTickets.setOrderTicketsId(orderTicketData.getOrderTicketsId());
orderTickets.setPaymentType(syncOrderParam.getPaymentType());
......
......@@ -47,6 +47,21 @@ public class DataUtils {
}
}
/**
* 修改兑换库存 并 返回修改后的数量
*
* @param ticketId 票id
* @param surplusGeneral 普通库存
* @return 普通剩余库存
*/
public int changeSurplusExchange(String ticketId, int surplusGeneral) {
if (surplusGeneral > 0) {
return (int) redisUtil.incr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId + ":" + KylinRedisConst.SURPLUS_EXCHANGE, surplusGeneral);
} else {
return (int) redisUtil.decr(KylinRedisConst.PERFORMANCES_INVENTORY + ticketId + ":" + KylinRedisConst.SURPLUS_EXCHANGE, Math.abs(surplusGeneral));
}
}
public void setOrderList(String userId, List<KylinOrderListVo> vo) {
redisUtil.set(KylinRedisConst.ORDER_LIST + userId, vo);
......
......@@ -118,6 +118,18 @@ public class OrderUtils {
return "";
}
//判断 操作 普通库存还是兑换库存
public int changeSurplus(boolean isPay ,String ticketId,int number){
int surplusGeneral;
if(isPay) {
surplusGeneral = dataUtils.changeSurplusGeneral(ticketId, number);
}else{
surplusGeneral = dataUtils.changeSurplusExchange(ticketId, number);
}
return surplusGeneral;
}
public boolean isMember(String uid) {
// String resultData = HttpUtil.get("/adam/member/check/depth?uid=" + uid, null);
// AdamUserMemberVo vo = JsonUtils.fromJson(resultData, AdamUserMemberVo.class);
......
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