|
|
@@ -17,8 +17,6 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.api.param.OrderListParam;
|
|
|
import com.fs.api.vo.OrderListVO;
|
|
|
import com.fs.api.vo.ProductListVO;
|
|
|
@@ -37,7 +35,6 @@ import com.fs.common.utils.IpUtil;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.ip.IpUtils;
|
|
|
-import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyDept;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
@@ -5591,7 +5588,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
- public R queryReceiptType() {
|
|
|
+ public R queryReceiptType(Long orderId) {
|
|
|
//获取商城配置
|
|
|
String json = configService.selectConfigByKey("store.config");
|
|
|
StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
@@ -5599,6 +5596,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (config != null && config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
|
|
|
receiptType = config.getIsWeChatShipping();
|
|
|
}
|
|
|
+ if (orderId != null) {
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
|
|
|
+ if (order != null && Objects.equals(order.getStatus(), OrderInfoEnum.STATUS_2.getValue())) {
|
|
|
+ order.setStatus(OrderInfoEnum.STATUS_3.getValue());
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(order);
|
|
|
+ }
|
|
|
+ }
|
|
|
return R.ok().put("data", receiptType);
|
|
|
}
|
|
|
|
|
|
@@ -5611,50 +5615,92 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
logger.info("进入微信结算订单定时任务--------------->{}", "start");
|
|
|
if (config != null && config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
|
|
|
- // 获取未结算订单
|
|
|
+ // 订单主数据来自 fs_store_order_scrm;bank_transaction_id、paymentAppId 来自联表的 fs_store_payment_scrm
|
|
|
List<FsStoreOrderScrm> orderScrmList = fsStoreOrderMapper.getUnsettledOrder();
|
|
|
|
|
|
- String payConfig = configService.selectConfigByKey("store.pay");
|
|
|
- JSONObject js = JSON.parseObject(payConfig);
|
|
|
- String appId = js.getString("appId");
|
|
|
-
|
|
|
- if (ObjectUtil.isNotNull(appId) && !appId.isEmpty()) {
|
|
|
- final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
-
|
|
|
- if (!orderScrmList.isEmpty()) {
|
|
|
- for (FsStoreOrderScrm order : orderScrmList) {
|
|
|
- WxMaOrderShippingInfoGetRequest request = new WxMaOrderShippingInfoGetRequest();
|
|
|
- request.setTransactionId(order.getBankTransactionId());
|
|
|
- WxMaOrderShippingInfoGetResponse response;
|
|
|
+ if (!orderScrmList.isEmpty()) {
|
|
|
+ for (FsStoreOrderScrm order : orderScrmList) {
|
|
|
+ String wxAppId = StrUtil.trim(order.getPaymentAppId());
|
|
|
+ if (StrUtil.isBlank(wxAppId)) {
|
|
|
+ logger.warn("refreshOrderSettlementStatus 跳过订单 id={},支付记录未关联小程序 app_id",
|
|
|
+ order.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ WxMaService wxService;
|
|
|
+ try {
|
|
|
+ wxService = WxMaConfiguration.getMaService(wxAppId);
|
|
|
+ } catch (IllegalArgumentException ex) {
|
|
|
+ logger.warn("refreshOrderSettlementStatus 跳过订单 id={} appId={}:{}", order.getId(), wxAppId,
|
|
|
+ ex.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- response = wxService.getWxMaOrderShippingService().get(request);
|
|
|
+ WxMaOrderShippingInfoGetRequest request = new WxMaOrderShippingInfoGetRequest();
|
|
|
+ request.setTransactionId(order.getBankTransactionId());
|
|
|
+ WxMaOrderShippingInfoGetResponse response;
|
|
|
|
|
|
- if (response.getErrCode().equals(0)) {
|
|
|
- // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款
|
|
|
- if (response.getOrder().getOrderState().equals(3) || response.getOrder().getOrderState().equals(4)) {
|
|
|
- if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
|
|
|
- this.finishOrder(order.getId());
|
|
|
- }
|
|
|
+ try {
|
|
|
+ response = wxService.getWxMaOrderShippingService().get(request);
|
|
|
+
|
|
|
+ if (response != null && Objects.equals(response.getErrCode(), 0)) {
|
|
|
+ // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款
|
|
|
+ if (response.getOrder() != null
|
|
|
+ && (Objects.equals(response.getOrder().getOrderState(), 3)
|
|
|
+ || Objects.equals(response.getOrder().getOrderState(), 4))) {
|
|
|
+ if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
|
|
|
+ this.finishOrder(order.getId());
|
|
|
}
|
|
|
- logger.info("请求信息------------------------》{}", response);
|
|
|
}
|
|
|
+ logger.info("refreshOrderSettlementStatus orderId={} appId={} 微信发货查询----------》{}", order.getId(),
|
|
|
+ wxAppId, response);
|
|
|
+ } else if (response != null && isWxShippingGetFinishLocally(response.getErrCode())) {
|
|
|
+ // 无法再依赖微信查询订单状态时本地办结:50002 账号受限;10060001 支付单不存在;40125 等凭证异常
|
|
|
+ logger.warn(
|
|
|
+ "refreshOrderSettlementStatus 微信 errCode={},发货查询不可用,本地办结 orderId={} appId={} errMsg={}",
|
|
|
+ response.getErrCode(), order.getId(), wxAppId, response.getErrMsg());
|
|
|
+ if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
|
|
|
+ this.finishOrder(order.getId());
|
|
|
+ }
|
|
|
+ } else if (response != null) {
|
|
|
+ logger.info("refreshOrderSettlementStatus orderId={} appId={} errCode={} errMsg={}",
|
|
|
+ order.getId(), wxAppId, response.getErrCode(), response.getErrMsg());
|
|
|
+ }
|
|
|
|
|
|
- } catch (WxErrorException e) {
|
|
|
- logger.info("异常信息------------------------》{}", e.getMessage());
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ Integer wxErr = e.getError() != null ? e.getError().getErrorCode() : null;
|
|
|
+ if (isWxShippingGetFinishLocally(wxErr)) {
|
|
|
+ logger.warn("refreshOrderSettlementStatus 微信接口 errCode={},发货查询不可用,本地办结 orderId={} appId={}",
|
|
|
+ wxErr, order.getId(), wxAppId);
|
|
|
+ if (order.getStatus() == OrderInfoEnum.STATUS_2.getValue()) {
|
|
|
+ this.finishOrder(order.getId());
|
|
|
+ }
|
|
|
continue;
|
|
|
}
|
|
|
+ logger.info("refreshOrderSettlementStatus orderId={} appId={} 异常----------》{}", order.getId(),
|
|
|
+ wxAppId, e.getMessage());
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.getStackTrace();
|
|
|
+ logger.error("refreshOrderSettlementStatus 执行异常", e);
|
|
|
} finally {
|
|
|
logger.info("进入微信结算订单定时任务--------------->{}", "end");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询小程序发货信息时若微信返回下列错误,无法依赖接口同步状态,本地直接将待收货订单办结:<br>
|
|
|
+ * 50002 user limited(小程序/账号受限);10060001 支付单不存在;40125 常见为无效 appsecret 等凭证问题。
|
|
|
+ */
|
|
|
+ private static boolean isWxShippingGetFinishLocally(Integer errCode) {
|
|
|
+ if (errCode == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return errCode == 50002 || errCode == 10060001 || errCode == 40125;
|
|
|
+ }
|
|
|
+
|
|
|
private static final DateTimeFormatter CST_FORMATTER = DateTimeFormatter
|
|
|
.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
|
|
|
.withZone(ZoneId.of("Asia/Shanghai"));
|