1
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package com.ruoyi.web.controller.publicapi;
|
||||
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.annotation.RateLimiter;
|
||||
import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.enums.LimitType;
|
||||
import com.ruoyi.jarvis.domain.OrderRows;
|
||||
import com.ruoyi.jarvis.domain.dto.PromoterOrderInfoVO;
|
||||
import com.ruoyi.jarvis.enums.ValidCodeConverter;
|
||||
import com.ruoyi.jarvis.service.IOrderRowsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 京东开放接口(免登录,路径统一 /open/jd/)
|
||||
*/
|
||||
@Anonymous
|
||||
@RestController
|
||||
@RequestMapping("/open/jd")
|
||||
public class PublicPromoterOrderController {
|
||||
|
||||
private static final String DEFAULT_SHOP_LOGO = "https://www.jd.com/favicon.ico";
|
||||
private static final SimpleDateFormat DATE_FMT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Autowired
|
||||
private IOrderRowsService orderRowsService;
|
||||
|
||||
/**
|
||||
* 跟团订单查询(兼容 jiadiantemai 接口格式)
|
||||
*/
|
||||
@GetMapping("/queryTkOrder")
|
||||
@RateLimiter(key = CacheConstants.RATE_LIMIT_KEY, time = 60, count = 30, limitType = LimitType.IP)
|
||||
public Map<String, Object> queryTkOrder(
|
||||
@RequestParam String orderId,
|
||||
@RequestParam(required = false) String t) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
String trimmedOrderId = orderId != null ? orderId.trim() : "";
|
||||
if (trimmedOrderId.isEmpty()) {
|
||||
result.put("code", 200);
|
||||
result.put("count", 0);
|
||||
result.put("msg", "请输入订单编号");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<OrderRows> rows = orderRowsService.selectOrderRowsByOrderNo(trimmedOrderId);
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
result.put("code", 200);
|
||||
result.put("count", 0);
|
||||
result.put("msg", "未查找到对应订单信息~");
|
||||
return result;
|
||||
}
|
||||
|
||||
String promoterTag = t != null ? t.trim() : "";
|
||||
List<PromoterOrderInfoVO> orderInfoList = new ArrayList<>();
|
||||
ValidCodeConverter validCodeConverter = new ValidCodeConverter();
|
||||
for (OrderRows row : rows) {
|
||||
if (!promoterTag.isEmpty() && !matchesPromoterTag(row, promoterTag)) {
|
||||
continue;
|
||||
}
|
||||
orderInfoList.add(toPromoterOrderInfo(row, validCodeConverter));
|
||||
}
|
||||
|
||||
if (orderInfoList.isEmpty()) {
|
||||
result.put("code", 200);
|
||||
result.put("count", 0);
|
||||
result.put("msg", "未查找到对应订单信息~");
|
||||
return result;
|
||||
}
|
||||
|
||||
result.put("code", 200);
|
||||
result.put("orderInfoList", orderInfoList);
|
||||
result.put("msg", "查询成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean matchesPromoterTag(OrderRows row, String promoterTag) {
|
||||
if (promoterTag.equals(row.getUnionTag()) || promoterTag.equals(row.getSubUnionId())) {
|
||||
return true;
|
||||
}
|
||||
if (row.getUnionId() != null && promoterTag.equals(String.valueOf(row.getUnionId()))) {
|
||||
return true;
|
||||
}
|
||||
return row.getPid() != null && row.getPid().contains(promoterTag);
|
||||
}
|
||||
|
||||
private PromoterOrderInfoVO toPromoterOrderInfo(OrderRows row, ValidCodeConverter validCodeConverter) {
|
||||
PromoterOrderInfoVO vo = new PromoterOrderInfoVO();
|
||||
vo.setShopName(row.getUnionAlias() != null && !row.getUnionAlias().isEmpty()
|
||||
? row.getUnionAlias() : "京东商城");
|
||||
vo.setShopLogo(DEFAULT_SHOP_LOGO);
|
||||
vo.setOrderSource("京东");
|
||||
vo.setTraceTypeStr(row.getTraceType() != null && row.getTraceType() == 2 ? "同店" : "跨店");
|
||||
if (row.getParentId() != null && row.getParentId() > 0) {
|
||||
vo.setParentId(String.valueOf(row.getParentId()));
|
||||
}
|
||||
if (row.getOrderId() != null) {
|
||||
vo.setOrderId(String.valueOf(row.getOrderId()));
|
||||
}
|
||||
vo.setValidCodeMsg(validCodeConverter.getCodeDescription(row.getValidCode()));
|
||||
if (row.getSkuId() != null) {
|
||||
vo.setSkuImageUrl("https://img14.360buyimg.com/n1/s240x240_" + row.getSkuId() + ".jpg");
|
||||
}
|
||||
vo.setSkuName(row.getSkuName());
|
||||
vo.setItemId(row.getItemId());
|
||||
vo.setSkuNum(row.getSkuNum() != null ? row.getSkuNum() : 1);
|
||||
vo.setCosPrice(formatPrice(row));
|
||||
vo.setOrderTime(formatDate(row.getOrderTime()));
|
||||
vo.setFinishTime(formatDate(row.getFinishTime()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
private String formatPrice(OrderRows row) {
|
||||
Double price = row.getActualCosPrice();
|
||||
if (price == null || price <= 0) {
|
||||
price = row.getEstimateCosPrice();
|
||||
}
|
||||
if (price == null) {
|
||||
return "0.00";
|
||||
}
|
||||
return String.format("%.2f", price);
|
||||
}
|
||||
|
||||
private String formatDate(java.util.Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
synchronized (DATE_FMT) {
|
||||
return DATE_FMT.format(date);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,8 @@ public class SecurityConfig
|
||||
requests.antMatchers("/login", "/register", "/captchaImage").permitAll()
|
||||
// 公开接口,允许匿名访问
|
||||
.antMatchers("/public/**").permitAll()
|
||||
// 开放页面接口(京东等),允许匿名访问
|
||||
.antMatchers("/open/**").permitAll()
|
||||
// 腾讯文档OAuth回调接口,允许匿名访问
|
||||
.antMatchers("/jarvis/tendoc/oauth/callback").permitAll()
|
||||
// 腾讯文档OAuth回调接口(备用路径),允许匿名访问
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.ruoyi.jarvis.domain.dto;
|
||||
|
||||
/**
|
||||
* 跟团查询页订单信息
|
||||
*/
|
||||
public class PromoterOrderInfoVO {
|
||||
|
||||
private String shopName;
|
||||
private String shopLogo;
|
||||
private String orderSource;
|
||||
private String traceTypeStr;
|
||||
private String parentId;
|
||||
private String orderId;
|
||||
private String validCodeMsg;
|
||||
private String skuImageUrl;
|
||||
private String skuName;
|
||||
private String itemId;
|
||||
private Integer skuNum;
|
||||
private String cosPrice;
|
||||
private String orderTime;
|
||||
private String finishTime;
|
||||
|
||||
public String getShopName() {
|
||||
return shopName;
|
||||
}
|
||||
|
||||
public void setShopName(String shopName) {
|
||||
this.shopName = shopName;
|
||||
}
|
||||
|
||||
public String getShopLogo() {
|
||||
return shopLogo;
|
||||
}
|
||||
|
||||
public void setShopLogo(String shopLogo) {
|
||||
this.shopLogo = shopLogo;
|
||||
}
|
||||
|
||||
public String getOrderSource() {
|
||||
return orderSource;
|
||||
}
|
||||
|
||||
public void setOrderSource(String orderSource) {
|
||||
this.orderSource = orderSource;
|
||||
}
|
||||
|
||||
public String getTraceTypeStr() {
|
||||
return traceTypeStr;
|
||||
}
|
||||
|
||||
public void setTraceTypeStr(String traceTypeStr) {
|
||||
this.traceTypeStr = traceTypeStr;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(String orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getValidCodeMsg() {
|
||||
return validCodeMsg;
|
||||
}
|
||||
|
||||
public void setValidCodeMsg(String validCodeMsg) {
|
||||
this.validCodeMsg = validCodeMsg;
|
||||
}
|
||||
|
||||
public String getSkuImageUrl() {
|
||||
return skuImageUrl;
|
||||
}
|
||||
|
||||
public void setSkuImageUrl(String skuImageUrl) {
|
||||
this.skuImageUrl = skuImageUrl;
|
||||
}
|
||||
|
||||
public String getSkuName() {
|
||||
return skuName;
|
||||
}
|
||||
|
||||
public void setSkuName(String skuName) {
|
||||
this.skuName = skuName;
|
||||
}
|
||||
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public void setItemId(String itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public Integer getSkuNum() {
|
||||
return skuNum;
|
||||
}
|
||||
|
||||
public void setSkuNum(Integer skuNum) {
|
||||
this.skuNum = skuNum;
|
||||
}
|
||||
|
||||
public String getCosPrice() {
|
||||
return cosPrice;
|
||||
}
|
||||
|
||||
public void setCosPrice(String cosPrice) {
|
||||
this.cosPrice = cosPrice;
|
||||
}
|
||||
|
||||
public String getOrderTime() {
|
||||
return orderTime;
|
||||
}
|
||||
|
||||
public void setOrderTime(String orderTime) {
|
||||
this.orderTime = orderTime;
|
||||
}
|
||||
|
||||
public String getFinishTime() {
|
||||
return finishTime;
|
||||
}
|
||||
|
||||
public void setFinishTime(String finishTime) {
|
||||
this.finishTime = finishTime;
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,9 @@ public interface OrderRowsMapper
|
||||
* @return 订单列表
|
||||
*/
|
||||
public List<OrderRows> selectOrderRowsByGiftCouponKey(@Param("giftCouponKey") String giftCouponKey);
|
||||
|
||||
/**
|
||||
* 根据订单号查询(匹配子单号或父单号)
|
||||
*/
|
||||
public List<OrderRows> selectOrderRowsByOrderNo(@Param("orderNo") String orderNo);
|
||||
}
|
||||
|
||||
@@ -72,4 +72,9 @@ public interface IOrderRowsService
|
||||
public int deleteOrderRowsById(String id);
|
||||
|
||||
public OrderRows selectOrderRowsByOrderId(String orderId);
|
||||
|
||||
/**
|
||||
* 根据订单号查询(匹配子单号或父单号)
|
||||
*/
|
||||
public List<OrderRows> selectOrderRowsByOrderNo(String orderNo);
|
||||
}
|
||||
|
||||
@@ -112,4 +112,9 @@ public class OrderRowsServiceImpl implements IOrderRowsService
|
||||
public OrderRows selectOrderRowsByOrderId(String orderId) {
|
||||
return orderRowsMapper.selectOrderRowsByOrderId(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderRows> selectOrderRowsByOrderNo(String orderNo) {
|
||||
return orderRowsMapper.selectOrderRowsByOrderNo(orderNo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,6 +398,12 @@
|
||||
where order_id = #{orderId}
|
||||
</select>
|
||||
|
||||
<select id="selectOrderRowsByOrderNo" parameterType="String" resultMap="OrderRowsResult">
|
||||
<include refid="selectOrderRowsVo"/>
|
||||
where order_id = #{orderNo} or parent_id = #{orderNo}
|
||||
order by order_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectOrderRowsByGiftCouponKey" parameterType="String" resultMap="OrderRowsResult">
|
||||
<include refid="selectOrderRowsVo"/>
|
||||
where gift_coupon_key = #{giftCouponKey}
|
||||
|
||||
Reference in New Issue
Block a user