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

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

order 增加超时支付自动退款逻辑[商铺]

parent 705a177b
......@@ -729,7 +729,8 @@ public class GoblinOrderServiceImpl implements IGoblinOrderService {
GoblinStoreOrder storeOrder = GoblinStoreOrder.getNew();
if (orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_5.getValue() && syncOrderParam.getStatus().equals(1)) {
log.error("订单号为 {} 的订单超时支付", syncOrderParam.getOrderCode());
// todo hujiachen 操作超时支付
// 商铺退款逻辑
orderUtils.refundOrderSku(orderId);
// orderVo.setStatus(GoblinStatusConst.OrderStatus.ORDER_STATUS_61.getValue());
// redisUtils.setGoblinOrder(orderVo.getOrderId(),orderVo);
} else if ((orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_6.getValue() || orderVo.getStatus() == GoblinStatusConst.Status.ORDER_STATUS_7.getValue()) && syncOrderParam.getStatus().equals(1)) {
......
......@@ -61,16 +61,12 @@ public class GoblinMongoUtils {
// SPU信息
public GoblinGoodsInfoVo getGoodsInfoVo(String spuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0").and("shelvesStatus").is("3")),
// return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId).and("delFlg").is("0")),
return mongoTemplate.findOne(Query.query(Criteria.where("spuId").is(spuId)),
GoblinGoodsInfoVo.class, GoblinGoodsInfoVo.class.getSimpleName());
}
// SKU信息
public GoblinGoodsSkuInfoVo getGoodsSkuInfoVo(String skuId) {
// return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0").and("shelvesStatus").is("3")),
// return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId).and("delFlg").is("0")),
return mongoTemplate.findOne(Query.query(Criteria.where("skuId").is(skuId)),
GoblinGoodsSkuInfoVo.class, GoblinGoodsSkuInfoVo.class.getSimpleName());
}
......@@ -139,4 +135,9 @@ public class GoblinMongoUtils {
);
}
//添加 订单退款数据
public GoblinBackOrderVo insertGoblinBackOrderVo(GoblinBackOrderVo vo) {
return mongoTemplate.insert(vo, GoblinBackOrderVo.class.getSimpleName());
}
}
......@@ -2,10 +2,7 @@ package com.liquidnet.service.order.utils;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.CurrentUtil;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.adam.dto.vo.AdamRscPolymer01Vo;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping;
......@@ -13,9 +10,13 @@ import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.candy.param.BackCouponParam;
import com.liquidnet.service.candy.vo.CandyCouponVo;
import com.liquidnet.service.candy.vo.CandyUseResultVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUseResultVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUserCouponVo;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinBackOrder;
import com.liquidnet.service.goblin.entity.GoblinBackOrderLog;
import com.liquidnet.service.goblin.entity.GoblinOrderOperationLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -38,6 +39,11 @@ public class GoblinOrderUtils {
private String candyUrl;
@Value("${liquidnet.service.stone.url}")
private String stoneUrl;
@Value("${liquidnet.service.order.url-pay.goblinRefundUrl}")
private String synUrl;
@Value("${liquidnet.service.dragon.urls.refundApply}")
private String refundApply;
@Autowired
QueueUtils queueUtils;
@Autowired
......@@ -275,8 +281,8 @@ public class GoblinOrderUtils {
redisUtils.setUserCouponVos(uid, voList);
}
return returnVo;
}catch (Exception e){
log.error("店铺券错误:{}",e);
} catch (Exception e) {
log.error("店铺券错误:{}", e);
return null;
}
}
......@@ -309,4 +315,125 @@ public class GoblinOrderUtils {
public Integer getMember(String uid) {
return redisUtils.getMember(uid);
}
//超时支付自动退款
public Boolean refundOrderSku(String orderId) {
String uid = CurrentUtil.getCurrentUid();
LocalDateTime now = LocalDateTime.now();
String nowStr = DateUtil.getNowTime();
List<GoblinBackOrderSkuVo> orderSkuVoList = ObjectUtil.goblinBackOrderSkuVoArrayList();
GoblinStoreOrderVo orderVo = redisUtils.getGoblinOrder(orderId);
BigDecimal refundPrice = BigDecimal.ZERO;
for (String orderSkuIdItem : orderVo.getOrderSkuVoIds()) {
GoblinOrderSkuVo orderSkuVo = redisUtils.getGoblinOrderSkuVo(orderSkuIdItem);
GoblinBackOrderSkuVo backOrderSkuVo = GoblinBackOrderSkuVo.getNew();
backOrderSkuVo.setOrderSkuId(orderSkuIdItem);
backOrderSkuVo.setSpuId(orderSkuVo.getSpuId());
backOrderSkuVo.setSpuName(orderSkuVo.getSpuName());
backOrderSkuVo.setSkuId(orderSkuVo.getSkuId());
backOrderSkuVo.setSkuName(orderSkuVo.getSkuName());
backOrderSkuVo.setRefundPrice(orderSkuVo.getSkuPriceActual());
backOrderSkuVo.setSkuSpecs(orderSkuVo.getSkuSpecs());
backOrderSkuVo.setCreatedAt(nowStr);
backOrderSkuVo.setSkuPic(orderSkuVo.getSkuImage());
orderSkuVoList.add(backOrderSkuVo);
refundPrice = refundPrice.add(orderSkuVo.getSkuPriceActual().subtract(orderSkuVo.getPriceRefund()));
}
//记录退款单
String refundCode = IDGenerator.storeRefundCode(orderVo.getMasterOrderCode());
GoblinBackOrder goblinBackOrder = GoblinBackOrder.getNew();
goblinBackOrder.setBackOrderId(IDGenerator.nextTimeId2());
goblinBackOrder.setBackCode(refundCode);
goblinBackOrder.setOrderId(orderVo.getOrderId());
goblinBackOrder.setOrderCode(orderVo.getOrderCode());
goblinBackOrder.setStoreId(orderVo.getStoreId());
goblinBackOrder.setUserId(orderVo.getUserId());
// goblinBackOrder.setSkuIdNums(orderSkuId);
goblinBackOrder.setType(GoblinStatusConst.Type.BACK_TYPE_1.getValue());
goblinBackOrder.setReason(GoblinStatusConst.Type.BACK_REASON_TYPE_8.getDesc());
goblinBackOrder.setDescribes("超时支付自动退款");
goblinBackOrder.setRealBackPrice(refundPrice);
goblinBackOrder.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_0.getValue());
goblinBackOrder.setAuditAt(now);
goblinBackOrder.setCreatedAt(now);
GoblinBackOrderVo backOrderVo = GoblinBackOrderVo.getNew();
BeanUtils.copyProperties(goblinBackOrder, backOrderVo);
backOrderVo.setCreatedAt(nowStr);
backOrderVo.setBackOrderSkuVos(orderSkuVoList);
//添加日志
GoblinBackOrderLog backOrderLog = initBackLog(goblinBackOrder.getBackOrderId(), uid, now);
backOrderLog.setStatus(GoblinStatusConst.Status.ORDER_LOG_STATUS_22.getValue());
backOrderLog.setOperationType(GoblinStatusConst.Type.OPERATION_TYPE_2.getValue());
backOrderLog.setMessage("商户发起[自动退款]:orderId=[" + orderId + "],refundPrice=[" + refundPrice + "],[refundCode=" + refundCode + "]");
//调用退款
String returnString = initRefund(orderVo, refundPrice, refundCode);
HashMap hashMapResult = JsonUtils.fromJson(returnString, HashMap.class);
Boolean success = (Boolean) hashMapResult.get("success");
String message = (String) hashMapResult.get("message");
if (!success) {
if (!(backOrderVo.getStatus() == GoblinStatusConst.Status.ORDER_BACK_STATUS_8.getValue() || backOrderVo.getStatus() == GoblinStatusConst.Status.ORDER_BACK_STATUS_2.getValue())) {
backOrderVo.setStatus(GoblinStatusConst.Status.ORDER_BACK_STATUS_10.getValue());
backOrderVo.setErrorReason(backOrderVo.getErrorReason() + ",失败原因:" + message);
log.error("REFUND DATA = " + returnString);
}
}
//redis
redisUtils.setBackOrderVo(backOrderVo.getBackOrderId(), backOrderVo);
redisUtils.addBackOrderByOrderId(orderVo.getOrderId(), backOrderVo.getBackOrderId());
//mongo
goblinMongoUtils.insertGoblinBackOrderVo(backOrderVo);
//添加退款
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.backOrder",
goblinBackOrder.getBackOrderId(), goblinBackOrder.getBackCode(), goblinBackOrder.getOrderId(),
goblinBackOrder.getOrderCode(), goblinBackOrder.getStoreId(), goblinBackOrder.getUserId(),
goblinBackOrder.getSkuIdNums(), goblinBackOrder.getType(), goblinBackOrder.getReason(),
goblinBackOrder.getDescribes(), goblinBackOrder.getRealBackPrice(), goblinBackOrder.getStatus(),
goblinBackOrder.getCreatedAt(), goblinBackOrder.getAuditAt(), goblinBackOrder.getErrorReason()
)
);
//添加日志
queueUtils.sendMsgByRedis(
MQConst.GoblinQueue.GOBLIN_STORE_ORDER_OPERA.getKey(),
SqlMapping.get("goblin_order.store.refundLog",
backOrderLog.getBackOrderLogId(), backOrderLog.getBackOrderId(), backOrderLog.getOperationType(),
backOrderLog.getMessage(), backOrderLog.getOperationName(), backOrderLog.getStatus(), now
)
);
if(success){
return true;
}else{
log.error("退款失败:" + message);
return false;
}
}
private GoblinBackOrderLog initBackLog(String orderId, String uid, LocalDateTime now) {
GoblinBackOrderLog log = GoblinBackOrderLog.getNew();
log.setBackOrderId(orderId);
log.setOperationName(uid);
log.setBackOrderLogId(IDGenerator.nextTimeId2());
log.setCreatedAt(now);
return log;
}
private String initRefund(GoblinStoreOrderVo orderVo, BigDecimal price, String refundCode) {
MultiValueMap<String, String> params = CollectionUtil.linkedMultiValueMapStringString();
params.add("code", orderVo.getPayCode());
params.add("notifyUrl", synUrl);
params.add("orderCode", orderVo.getMasterOrderCode());
params.add("orderRefundCode", refundCode);
params.add("paymentId", orderVo.getPaymentId());
params.add("paymentType", orderVo.getPaymentType());
params.add("price", String.valueOf(price));
params.add("priceTotal", String.valueOf(orderVo.getPriceActual()));
params.add("reason", "超时支付");
MultiValueMap<String, String> headers = CollectionUtil.linkedMultiValueMapStringString();
headers.add("Accept", "application/json;charset=UTF-8");
String returnString = HttpUtil.post(refundApply, params, headers);
log.debug("REFUND DATA = " + returnString);
return returnString;
}
}
......@@ -371,4 +371,23 @@ public class GoblinRedisUtils {
return (Integer) obj;
}
}
// 添加 订单id下的退款订单id
public void addBackOrderByOrderId(String orderId, String backOrderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BACK_ORDER_ID.concat(orderId);
List<String> list = getBackOrderByOrderId(orderId);
list.add(backOrderId);
redisUtil.set(redisKey, list);
}
// 获取 订单id下的退款订单id
public List<String> getBackOrderByOrderId(String orderId) {
String redisKey = GoblinRedisConst.REDIS_GOBLIN_BACK_ORDER_ID.concat(orderId);
Object obj = redisUtil.get(redisKey);
if (obj == null) {
return CollectionUtil.arrayListString();
} else {
return (List<String>) obj;
}
}
}
package com.liquidnet.service.order.utils;
import com.liquidnet.service.adam.dto.vo.AdamEntersVo;
import com.liquidnet.service.goblin.dto.vo.GoblinMailVo;
import com.liquidnet.service.goblin.dto.vo.GoblinOrderSkuVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreOrderVo;
import com.liquidnet.service.goblin.dto.vo.GoblinUserCouponVo;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.GoblinOrderSku;
import com.liquidnet.service.goblin.param.BackCouponParam;
import com.liquidnet.service.goblin.param.GoblinOrderSqlParam;
......@@ -51,10 +48,16 @@ public class ObjectUtil {
private static final ArrayList<GoblinOrderSkuVo> goblinOrderSkuVoArrayList = new ArrayList<>();
private static final ArrayList<WriteModel<Document>> writeModelDocumentArrayList = new ArrayList<>();
private static final ArrayList<GoblinUserCouponVo> goblinUserCouponVo = new ArrayList<>();
private static final ArrayList<GoblinBackOrderSkuVo> goblinBackOrderSkuVoArrayList = new ArrayList<>();
public static Object[] objectsArray;
public static final Integer[] integerArray2 = new Integer[2];
public static ArrayList<GoblinBackOrderSkuVo> goblinBackOrderSkuVoArrayList() {
return (ArrayList<GoblinBackOrderSkuVo>) goblinBackOrderSkuVoArrayList.clone();
}
public static ArrayList<GoblinOrderSqlParam> getGoblinOrderSqlParamArrayListList() {
return (ArrayList<GoblinOrderSqlParam>) goblinOrderSqlParamArrayList.clone();
}
......
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