|
|
@@ -3,11 +3,16 @@ package com.fs.hisStore.service.impl;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
+import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -41,8 +46,10 @@ import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.service.IFsUserWxService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.utils.HttpUtil;
|
|
|
+import com.fs.hisStore.config.StoreConfig;
|
|
|
import com.fs.hisStore.enums.SysConfigEnum;
|
|
|
import com.fs.hisStore.param.*;
|
|
|
+import com.fs.hisStore.vo.FsStorePaymentUsetVo;
|
|
|
import com.fs.huifuPay.domain.HuiFuCreateOrder;
|
|
|
import com.fs.huifuPay.domain.HuifuCreateOrderResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
|
|
|
@@ -53,6 +60,7 @@ import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.utils.TwelveDigitSnowflake;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
import com.fs.hisStore.domain.FsUserScrm;
|
|
|
import com.fs.hisStore.service.IFsUserScrmService;
|
|
|
@@ -71,6 +79,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -91,6 +100,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
* @date 2022-06-20
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
{
|
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
@@ -949,4 +959,87 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
|
|
|
return R.error(result.getResp_desc());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R oneClickShipping() {
|
|
|
+ try {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ //获取商城配置
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+ //验证是否开启微信发货
|
|
|
+ if (config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
|
|
|
+ //获取支付信息
|
|
|
+ List<FsStorePaymentUsetVo> paymentList = fsStorePaymentMapper.getPaymentUsetInfoList();
|
|
|
+ if (paymentList.isEmpty()) {
|
|
|
+ return R.ok("操作成功,暂无同步订单信息!");
|
|
|
+ }
|
|
|
+ String uploadTime = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"))
|
|
|
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
|
+ Map<String, List<FsStorePaymentUsetVo>> paymentUsetVoMap = paymentList.stream().collect(Collectors.groupingBy(FsStorePaymentUsetVo::getAppId));
|
|
|
+ for (Map.Entry<String, List<FsStorePaymentUsetVo>> entry : paymentUsetVoMap.entrySet()) {
|
|
|
+ List<String> successList = new ArrayList<>();
|
|
|
+ String appId = entry.getKey();
|
|
|
+ List<FsStorePaymentUsetVo> userPayments = entry.getValue();
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
+ if (!userPayments.isEmpty()) {
|
|
|
+ for (FsStorePaymentUsetVo v : userPayments) {
|
|
|
+ // 上传物流信息到微信
|
|
|
+ if (uploadShippingInfoToWechat(wxService, v, uploadTime)) {
|
|
|
+ successList.add(v.getBankTransactionId());
|
|
|
+ }else {
|
|
|
+ successList.add(v.getBankTransactionId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量更新数据
|
|
|
+ if (!successList.isEmpty()) {
|
|
|
+ fsStorePaymentMapper.batchUpadte(successList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return R.ok(builder.toString().equals("") ? "操作成功!" : builder.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导入发货单快递信息失败", e);
|
|
|
+ return R.error("导入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean uploadShippingInfoToWechat(WxMaService wxService,
|
|
|
+ FsStorePaymentUsetVo dto,
|
|
|
+ String uploadTime) {
|
|
|
+ try {
|
|
|
+ WxMaOrderShippingInfoUploadRequest request = new WxMaOrderShippingInfoUploadRequest();
|
|
|
+ OrderKeyBean orderKeyBean = new OrderKeyBean();
|
|
|
+ orderKeyBean.setOrderNumberType(2);
|
|
|
+ orderKeyBean.setTransactionId(dto.getBankTransactionId());//交易订单号ID
|
|
|
+ request.setOrderKey(orderKeyBean);
|
|
|
+ request.setDeliveryMode(1);
|
|
|
+ request.setLogisticsType(4);
|
|
|
+ List<ShippingListBean> shippingList = new ArrayList<>();
|
|
|
+ ShippingListBean shippingListBean = new ShippingListBean();
|
|
|
+ //默认物品信息
|
|
|
+ shippingListBean.setTrackingNo(String.valueOf(new TwelveDigitSnowflake(1).nextId()));
|
|
|
+ shippingListBean.setExpressCompany("FS");
|
|
|
+ shippingListBean.setItemDesc("默认商品");
|
|
|
+ ContactBean contactBean = new ContactBean();
|
|
|
+ contactBean.setReceiverContact(dto.getPhone());
|
|
|
+ shippingListBean.setContact(contactBean);
|
|
|
+
|
|
|
+ shippingList.add(shippingListBean);
|
|
|
+ request.setShippingList(shippingList);
|
|
|
+ request.setUploadTime(uploadTime);
|
|
|
+ // 设置支付者信息
|
|
|
+ PayerBean payerBean = new PayerBean();
|
|
|
+ payerBean.setOpenid(dto.getOpenId());
|
|
|
+ request.setPayer(payerBean);
|
|
|
+ // 上传物流信息
|
|
|
+ return wxService.getWxMaOrderShippingService().upload(request).getErrCode() == 0;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传物流信息到微信失败,订单号: {}", dto.getBankTransactionId(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|