|
|
@@ -1,6 +1,8 @@
|
|
|
package com.fs.hisStore.service.impl;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
+import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
|
|
|
+import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetResponse;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.hutool.core.net.URLDecoder;
|
|
|
@@ -46,6 +48,7 @@ import com.fs.core.config.WxMaConfiguration;
|
|
|
import com.fs.core.config.WxPayProperties;
|
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
|
import com.fs.course.dto.FsOrderDeliveryNoteDTO;
|
|
|
+import com.fs.course.dto.OrderOpenIdTransDTO;
|
|
|
import com.fs.erp.domain.*;
|
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.dto.df.*;
|
|
|
@@ -102,6 +105,12 @@ import com.fs.hisStore.enums.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
+import com.fs.wx.order.domain.FsWxExpressTask;
|
|
|
+import com.fs.wx.order.dto.*;
|
|
|
+import com.fs.wx.order.mapper.FsWxExpressTaskMapper;
|
|
|
+import com.fs.wx.order.service.ExpressToWxHolder;
|
|
|
+import com.fs.wx.order.service.ExpressToWxService;
|
|
|
+import com.fs.wx.order.service.ShippingService;
|
|
|
import com.fs.ybPay.domain.OrderResult;
|
|
|
import com.fs.ybPay.domain.RefundResult;
|
|
|
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
@@ -112,6 +121,7 @@ import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
|
|
|
import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.google.common.base.Joiner;
|
|
|
import lombok.Synchronized;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
@@ -141,6 +151,7 @@ import java.sql.Timestamp;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.OffsetDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
@@ -360,6 +371,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
|
|
|
@Autowired
|
|
|
private FsStoreOrderDfMapper fsStoreOrderDfMapper;
|
|
|
+ @Autowired
|
|
|
+ private ShippingService shippingService;
|
|
|
+ @Autowired
|
|
|
+ private FsWxExpressTaskMapper fsWxExpressTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreCartScrmService fsStoreCartScrmService;
|
|
|
|
|
|
@PostConstruct
|
|
|
public void initErpServiceMap() {
|
|
|
@@ -371,6 +389,82 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
erpServiceMap.put(5, jSTOrderService); // 聚水潭
|
|
|
erpServiceMap.put(6, k9OrderService); // K9
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public void syncExpressToWx() {
|
|
|
+ List<FsWxExpressTask> fsWxExpressTasks = fsWxExpressTaskMapper.selectPendingData();
|
|
|
+ if (CollectionUtils.isEmpty(fsWxExpressTasks)) {
|
|
|
+ logger.info("当前没有待同步的数据!已取消");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (FsWxExpressTask fsWxExpressTask : fsWxExpressTasks) {
|
|
|
+
|
|
|
+ try{
|
|
|
+ UploadShippingInfoRequest request = new UploadShippingInfoRequest();
|
|
|
+
|
|
|
+ OrderKey orderKey = new OrderKey();
|
|
|
+ orderKey.setOrderNumberType(2);
|
|
|
+
|
|
|
+
|
|
|
+ FsUserScrm fsUser = userService.selectFsUserByUserId(fsWxExpressTask.getUserId());
|
|
|
+
|
|
|
+ // 目前支持商城订单和直播订单
|
|
|
+ ExpressToWxService service = ExpressToWxHolder.findBest(fsWxExpressTask.getType(),fsWxExpressTask.getOrderCode());
|
|
|
+ Asserts.notNull(service,"订单类型不被支持!");
|
|
|
+
|
|
|
+
|
|
|
+ orderKey.setTransactionId(service.getTransactionId());
|
|
|
+
|
|
|
+
|
|
|
+ String userPhone = service.getUserPhone();
|
|
|
+ String orderGoodsInfo = service.getOrderGoodsInfo();
|
|
|
+
|
|
|
+
|
|
|
+ Payer payer = new Payer();
|
|
|
+ if(StringUtils.isNotBlank(fsUser.getMaOpenId())){
|
|
|
+ payer.setOpenid(fsUser.getMaOpenId());
|
|
|
+ }
|
|
|
+ request.setPayer(payer);
|
|
|
+ request.setOrderKey(orderKey);
|
|
|
+
|
|
|
+ request.setLogisticsType(1);
|
|
|
+ request.setDeliveryMode(1);
|
|
|
+
|
|
|
+ request.setShippingList(Collections.singletonList(ShippingItem.builder()
|
|
|
+ .itemDesc(orderGoodsInfo)
|
|
|
+ .expressCompany(service.getExpressCompany())
|
|
|
+ .trackingNo(service.getExpressNo())
|
|
|
+ .contact(Contact.builder().consignorContact(userPhone).build())
|
|
|
+ .build()));
|
|
|
+
|
|
|
+ OffsetDateTime now = OffsetDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
+ String formattedTimestamp = now.format(formatter);
|
|
|
+ request.setUploadTime(formattedTimestamp);
|
|
|
+
|
|
|
+
|
|
|
+ request.setAppid(fsWxExpressTask.getAppid());
|
|
|
+ WeChatApiResponse response = shippingService.uploadShippingInfo(request);
|
|
|
+ if(ObjectUtil.equal(response.getErrcode(),0)){
|
|
|
+ fsWxExpressTask.setStatus(2);
|
|
|
+ } else {
|
|
|
+ fsWxExpressTask.setRetryCount(fsWxExpressTask.getRetryCount() +1);
|
|
|
+ fsWxExpressTask.setStatus(3);
|
|
|
+ fsWxExpressTask.setData(JSON.toJSONString(request));
|
|
|
+ fsWxExpressTask.setRequestBody(JSON.toJSONString(request));
|
|
|
+ fsWxExpressTask.setResponseBody(JSON.toJSONString(response));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.info("该单 {} 推送到物流失败!",fsWxExpressTask);
|
|
|
+ fsWxExpressTask.setRetryCount(fsWxExpressTask.getRetryCount() +1);
|
|
|
+ fsWxExpressTask.setStatus(3);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fsWxExpressTaskMapper.batchUpdate(fsWxExpressTasks);
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* 查询订单
|
|
|
*
|
|
|
@@ -905,7 +999,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
//使用了积分扣积分
|
|
|
if (dto.getUsedIntegral() > 0) {
|
|
|
- this.decIntegral(userId, dto.getUsedIntegral(), dto.getDeductionPrice().doubleValue(), storeOrder.getId().toString());
|
|
|
+ this.decIntegral(userId, dto.getUsedIntegral(), dto.getDeductionPrice(), storeOrder.getId().toString());
|
|
|
}
|
|
|
//减库存加销量
|
|
|
this.deStockIncSale(carts);
|
|
|
@@ -1109,11 +1203,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
/**
|
|
|
* 积分抵扣
|
|
|
*/
|
|
|
- private void decIntegral(Long uid, double usedIntegral, double deductionPrice, String busId) {
|
|
|
+ private void decIntegral(Long uid, double usedIntegral, BigDecimal deductionPrice, String busId) {
|
|
|
userService.decIntegral(uid, usedIntegral);
|
|
|
FsUserScrm user = userService.selectFsUserById(uid);
|
|
|
//积分记录
|
|
|
- billService.addBill(uid, BillDetailEnum.CATEGORY_2.getValue(), 0, BillDetailEnum.TYPE_1.getDesc(), usedIntegral, user.getIntegral().doubleValue(),
|
|
|
+ billService.addBill(uid, BillDetailEnum.CATEGORY_2.getValue(), 0, BillDetailEnum.TYPE_1.getDesc(), new BigDecimal(usedIntegral) ,new BigDecimal(user.getIntegral()),
|
|
|
"购买商品使用" + usedIntegral + "积分抵扣" + deductionPrice + "元", busId, 0l);
|
|
|
|
|
|
}
|
|
|
@@ -1266,7 +1360,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
OrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
//订阅物流回调
|
|
|
String lastFourNumber = "";
|
|
|
- if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue()) || order.getDeliverySn().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -1283,6 +1377,20 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
.templateType(TemplateListenEnum.TYPE_2.getValue())
|
|
|
.build();
|
|
|
publisher.publishEvent(new TemplateEvent(this, templateBean));
|
|
|
+
|
|
|
+ List<FsStorePaymentScrm> fsStorePayments = fsStorePaymentMapper.selectFsStorePaymentByOrderId(order.getId());
|
|
|
+ FsStorePaymentScrm fsStorePayment = fsStorePayments.get(0);
|
|
|
+ FsWxExpressTask fsWxExpressTask = new FsWxExpressTask();
|
|
|
+ fsWxExpressTask.setUserId(order.getUserId());
|
|
|
+ fsWxExpressTask.setStatus(0);
|
|
|
+ fsWxExpressTask.setRetryCount(0);
|
|
|
+ fsWxExpressTask.setCreateTime(LocalDateTime.now());
|
|
|
+ fsWxExpressTask.setUpdateTime(LocalDateTime.now());
|
|
|
+ fsWxExpressTask.setOrderCode(order.getOrderCode());
|
|
|
+ fsWxExpressTask.setExpressCompany(express.getCode());
|
|
|
+ fsWxExpressTask.setExpressNo(deliveryId);
|
|
|
+ fsWxExpressTask.setAppid(fsStorePayment.getAppId());
|
|
|
+ fsWxExpressTaskMapper.insert(fsWxExpressTask);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1301,7 +1409,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
OrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
//订阅物流回调
|
|
|
String lastFourNumber = "";
|
|
|
- if (express.getCode().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (express.getCode().equals(ShipperCodeEnum.SF.getValue()) || express.getCode().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -1360,7 +1468,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
public R getExpress(FsStoreOrderScrm order) {
|
|
|
//顺丰轨迹查询处理
|
|
|
String lastFourNumber = "";
|
|
|
- if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue()) || order.getDeliverySn().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -1450,14 +1558,24 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
public R confirmPackageOrder(long uid, FsStoreConfirmPackageIdOrderParam param) {
|
|
|
FsUserAddressScrm address = userAddressMapper.selectFsUserAddressByDefaultAddress(uid);
|
|
|
FsStoreProductPackageScrm storeProductPackage = productPackageService.selectFsStoreProductPackageById(param.getPackageId());
|
|
|
- String uuid = IdUtil.randomUUID();
|
|
|
- BigDecimal totalMoney = storeProductPackage.getPayMoney();
|
|
|
+ // 由于套餐制单前面有生成oderkey,并且要取修改的价格,所以这里判断,如果有传就用传的orderkey,如果没有就生成(代表走的是直接购买)
|
|
|
+ String uuid;
|
|
|
+ BigDecimal totalMoney;
|
|
|
+ if(StringUtils.isEmpty(param.getCreateOrderKey())){
|
|
|
+ //直接购买
|
|
|
+ uuid = IdUtil.randomUUID();
|
|
|
+ totalMoney = storeProductPackage.getPayMoney();
|
|
|
+ } else {
|
|
|
+ // 套餐制单
|
|
|
+ uuid = param.getCreateOrderKey();
|
|
|
+ totalMoney = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
+ }
|
|
|
+
|
|
|
if (param.getCouponUserId() != null) {
|
|
|
FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
if (couponUser != null && couponUser.getStatus() == 0) {
|
|
|
if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) == -1) {
|
|
|
- //
|
|
|
- totalMoney = totalMoney.subtract(couponUser.getCouponPrice());
|
|
|
+ totalMoney = totalMoney != null ? totalMoney.subtract(couponUser.getCouponPrice()) : BigDecimal.ZERO.subtract(couponUser.getCouponPrice());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1493,29 +1611,37 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
List<StorePackageProductDTO> goodsList = JSONUtil.toList(jsonArray, StorePackageProductDTO.class);
|
|
|
//检测库存
|
|
|
Integer totalNum = 0;
|
|
|
- List<FsStoreCartQueryVO> carts = new ArrayList<>();
|
|
|
- for (StorePackageProductDTO goods : goodsList) {
|
|
|
- FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
|
|
|
- if (attrValue != null && attrValue.getProductId() != null) {
|
|
|
- FsStoreProductScrm product = storeProductService.selectFsStoreProductById(attrValue.getProductId());
|
|
|
- if (product != null) {
|
|
|
- totalNum += goods.getCount();
|
|
|
- FsStoreCartQueryVO vo = new FsStoreCartQueryVO();
|
|
|
- vo.setProductId(attrValue.getProductId());
|
|
|
- vo.setProductAttrValueId(goods.getId());
|
|
|
- vo.setCartNum(goods.getCount());
|
|
|
- vo.setProductName(product.getProductName());
|
|
|
- vo.setProductAttrName(attrValue.getSku());
|
|
|
- vo.setProductImage(product.getImage());
|
|
|
- vo.setBarCode(attrValue.getBarCode());
|
|
|
- vo.setGroupBarCode(attrValue.getGroupBarCode());
|
|
|
- vo.setPrice(product.getPrice());
|
|
|
- vo.setProductType(product.getProductType());
|
|
|
- carts.add(vo);
|
|
|
+ List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ String joinCartIds = null;
|
|
|
+ if(carts == null || carts.isEmpty()){
|
|
|
+ carts = new ArrayList<>();
|
|
|
+ for (StorePackageProductDTO goods : goodsList) {
|
|
|
+ FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
|
|
|
+ if (attrValue != null && attrValue.getProductId() != null) {
|
|
|
+ FsStoreProductScrm product = storeProductService.selectFsStoreProductById(attrValue.getProductId());
|
|
|
+ if (product != null) {
|
|
|
+ totalNum += goods.getCount();
|
|
|
+ FsStoreCartQueryVO vo = new FsStoreCartQueryVO();
|
|
|
+ vo.setProductId(attrValue.getProductId());
|
|
|
+ vo.setProductAttrValueId(goods.getId());
|
|
|
+ vo.setCartNum(goods.getCount());
|
|
|
+ vo.setProductName(product.getProductName());
|
|
|
+ vo.setProductAttrName(attrValue.getSku());
|
|
|
+ vo.setProductImage(product.getImage());
|
|
|
+ vo.setBarCode(attrValue.getBarCode());
|
|
|
+ vo.setGroupBarCode(attrValue.getGroupBarCode());
|
|
|
+ vo.setPrice(product.getPrice());
|
|
|
+ vo.setProductType(product.getProductType());
|
|
|
+ carts.add(vo);
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
+ cartService.checkProductStock(attrValue.getProductId(), attrValue.getId());
|
|
|
}
|
|
|
- cartService.checkProductStock(attrValue.getProductId(), attrValue.getId());
|
|
|
+ } else {
|
|
|
+ // 如果cartIds不为空,则表示是套餐制单购买,非套餐制单是没有购物车信息的。
|
|
|
+ List<Long> cartIds = carts.stream().map(FsStoreCartQueryVO::getId).collect(Collectors.toList());
|
|
|
+ joinCartIds = Joiner.on(",").join(cartIds);
|
|
|
}
|
|
|
//生成分布式唯一值
|
|
|
String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
@@ -1524,6 +1650,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
//组合数据
|
|
|
CompanyUser user = companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
+ storeOrder.setCartId(joinCartIds);
|
|
|
//修改默认仓库
|
|
|
|
|
|
storeOrder.setStoreHouseCode("CK01");
|
|
|
@@ -1532,7 +1659,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
storeOrder.setCompanyId(user.getCompanyId());
|
|
|
storeOrder.setDeptId(user.getDeptId());
|
|
|
}
|
|
|
- BigDecimal totalMoney = storeProductPackage.getPayMoney();
|
|
|
+ BigDecimal totalMoney;
|
|
|
+ if(param.getIsPackage() != null && param.getIsPackage() == 1){
|
|
|
+ totalMoney = redisCache.getCacheObject("createOrderMoney:" + param.getOrderKey());
|
|
|
+ } else {
|
|
|
+ totalMoney = storeProductPackage.getPayMoney();
|
|
|
+ }
|
|
|
+
|
|
|
//优惠券处理
|
|
|
if (param.getCouponUserId() != null) {
|
|
|
FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
@@ -1597,6 +1730,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
//减库存加销量
|
|
|
this.deStockIncSale(carts);
|
|
|
//保存购物车商品信息
|
|
|
+ List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
|
|
|
for (FsStoreCartQueryVO vo : carts) {
|
|
|
FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
|
|
|
fsStoreCartDTO.setProductId(vo.getProductId());
|
|
|
@@ -1624,7 +1758,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
item.setIsPrescribe(1);
|
|
|
}
|
|
|
fsStoreOrderItemMapper.insertFsStoreOrderItem(item);
|
|
|
+ listOrderItem.add(item);
|
|
|
+ }
|
|
|
+ if (!listOrderItem.isEmpty()) {
|
|
|
+ storeOrder.setItemJson(JSONUtil.toJsonStr(listOrderItem));
|
|
|
}
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
+
|
|
|
//删除缓存
|
|
|
redisCache.deleteObject("orderKey:" + param.getOrderKey());
|
|
|
//添加记录
|
|
|
@@ -1867,6 +2007,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public R createOmsOrder(Long orderId) throws ParseException {
|
|
|
FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
|
|
|
FsSysConfig erpConfig = configUtil.generateStructConfigByKey(SysConfigEnum.HIS_CONFIG.getKey(), FsSysConfig.class);
|
|
|
@@ -2266,7 +2407,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
if (payment.getAppId() != null) {
|
|
|
FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
- huifuId = fsHfpayConfig.getHuifuId();
|
|
|
+ if (fsHfpayConfig == null){
|
|
|
+ huifuId = fsPayConfig.getHuifuId();
|
|
|
+ }else {
|
|
|
+ huifuId = fsHfpayConfig.getHuifuId();
|
|
|
+ }
|
|
|
} else {
|
|
|
if (("益善缘".equals(cloudHostProper.getCompanyName()))) {
|
|
|
|
|
|
@@ -2378,7 +2523,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
public R syncExpress(FsStoreOrderExpressEditParam param) {
|
|
|
FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(param.getOrderId());
|
|
|
String lastFourNumber = "";
|
|
|
- if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue()) || order.getDeliverySn().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -2489,7 +2634,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount,Integer payType) {
|
|
|
+ public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount,Integer payType, Integer isPackage) {
|
|
|
//货到付款自定义金额
|
|
|
if (payAmount == null) {
|
|
|
String configJson = configService.selectConfigByKey("store.config");
|
|
|
@@ -2513,8 +2658,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
|
List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
|
|
|
BigDecimal totalMoney = BigDecimal.ZERO;
|
|
|
- for (FsStoreCartQueryVO vo : carts) {
|
|
|
- totalMoney = totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
+ if(isPackage == 0){
|
|
|
+ for (FsStoreCartQueryVO vo : carts) {
|
|
|
+ totalMoney = totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //套餐制单
|
|
|
+ totalMoney = carts.get(0).getPrice();
|
|
|
}
|
|
|
if (money.compareTo(totalMoney) == 1) {
|
|
|
throw new CustomException("价格不能大于商品总价", 501);
|
|
|
@@ -2782,8 +2932,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
userService.updateFsUser(user);
|
|
|
//增加流水
|
|
|
billService.addBill(user.getUserId(), BillDetailEnum.CATEGORY_2.getValue(), 1, BillDetailEnum.TYPE_5.getDesc(),
|
|
|
- order.getUseIntegral().doubleValue(),
|
|
|
- newIntegral.doubleValue(),
|
|
|
+ order.getUseIntegral(),
|
|
|
+ newIntegral,
|
|
|
"购买商品失败,回退积分" + order.getUseIntegral(), order.getId().toString(), 0l);
|
|
|
//更新订单回退积分
|
|
|
FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
@@ -2821,9 +2971,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
BigDecimal payIntegral = this.getOrderSumPrice(cartInfo, "payIntegral");//获取订单需要的积分
|
|
|
|
|
|
//如果设置满包邮0 表示全局包邮,如果设置大于0表示满这价格包邮,否则走运费模板算法
|
|
|
- if (storeFreePostage.compareTo(BigDecimal.ZERO) != 0 && totalPrice.compareTo(storeFreePostage) <= 0) {
|
|
|
- storePostage = this.handlePostage(cartInfo, userAddress);
|
|
|
- }
|
|
|
+ storePostage = this.handlePostage(cartInfo, userAddress);
|
|
|
+
|
|
|
|
|
|
FsStoreOrderPriceDTO priceGroupDTO = new FsStoreOrderPriceDTO();
|
|
|
priceGroupDTO.setStorePostage(storePostage);
|
|
|
@@ -2897,10 +3046,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
TemplateDTO templateDTO = TemplateDTO.builder()
|
|
|
.number(num)
|
|
|
.price(price)
|
|
|
- .first(shippingTemplatesRegion.getFirst().doubleValue())
|
|
|
- .firstPrice(shippingTemplatesRegion.getFirstPrice())
|
|
|
- .continues(shippingTemplatesRegion.getContinues().doubleValue())
|
|
|
- .continuePrice(shippingTemplatesRegion.getContinuePrice())
|
|
|
+ .first(ObjectUtil.isNotEmpty(shippingTemplatesRegion)?shippingTemplatesRegion.getFirst().doubleValue():0.0)
|
|
|
+ .firstPrice(ObjectUtil.isNotEmpty(shippingTemplatesRegion)?shippingTemplatesRegion.getFirstPrice():new BigDecimal(0.0))
|
|
|
+ .continues(ObjectUtil.isNotEmpty(shippingTemplatesRegion)?shippingTemplatesRegion.getContinues().doubleValue():0.0)
|
|
|
+ .continuePrice(ObjectUtil.isNotEmpty(shippingTemplatesRegion)?shippingTemplatesRegion.getContinuePrice():new BigDecimal(0.0))
|
|
|
.tempId(tempId)
|
|
|
.cityId(cityId)
|
|
|
.build();
|
|
|
@@ -3070,7 +3219,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if ((!dto.isSuccess() && dto.getReason().equals("三天无轨迹")) || (!dto.isSuccess() && dto.getReason().equals("七天内无轨迹变化"))) {
|
|
|
//订阅物流回调
|
|
|
String lastFourNumber = "";
|
|
|
- if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (order.getDeliverySn().equals(ShipperCodeEnum.SF.getValue()) || order.getDeliverySn().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -3426,7 +3575,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
FsStoreScrm store = fsStoreMapper.selectFsStoreByStoreId(o.getStoreId());
|
|
|
int i = fsStoreOrderMapper.updateFsStoreOrderByOrderCode(fsStoreOrder);
|
|
|
String lastFourNumber = "";
|
|
|
- if (fsStoreOrder.getDeliveryCode().equals(com.fs.his.enums.ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (fsStoreOrder.getDeliveryCode().equals(com.fs.his.enums.ShipperCodeEnum.SF.getValue()) || fsStoreOrder.getDeliveryCode().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
if (store.getSendPhone() != null) {
|
|
|
lastFourNumber = store.getSendPhone();
|
|
|
} else {
|
|
|
@@ -3526,7 +3675,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
fsStoreOrderLogsMapper.insertFsStoreOrderLogs(Logs);
|
|
|
|
|
|
String lastFourNumber = "";
|
|
|
- if (order.getDeliveryCode().equals(com.fs.his.enums.ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (order.getDeliveryCode().equals(com.fs.his.enums.ShipperCodeEnum.SF.getValue()) || order.getDeliveryCode().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -3854,7 +4003,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderByOrderCode(dto.getOrderNumber());
|
|
|
//订阅物流回调
|
|
|
String lastFourNumber = "";
|
|
|
- if (dto.getDeliverySn().equals(ShipperCodeEnum.SF.getValue())) {
|
|
|
+ if (dto.getDeliverySn().equals(ShipperCodeEnum.SF.getValue()) || order.getDeliverySn().equals(ShipperCodeEnum.ZTO.getValue())) {
|
|
|
lastFourNumber = order.getUserPhone();
|
|
|
if (lastFourNumber.length() == 11) {
|
|
|
lastFourNumber = StrUtil.sub(lastFourNumber, lastFourNumber.length(), -4);
|
|
|
@@ -3944,6 +4093,17 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (amount != null){
|
|
|
payMoney=amount;
|
|
|
}
|
|
|
+ //运费
|
|
|
+ BigDecimal payPostage = order.getPayPostage();
|
|
|
+ if (payPostage == null || payPostage.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
+ payPostage = storeConfig.getPayPostage();
|
|
|
+ if (payPostage == null){
|
|
|
+ payPostage = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ order.setPayPrice(order.getPayPrice().add(payPostage));
|
|
|
+ }
|
|
|
+ order.setPayPostage(payPostage);
|
|
|
+ payMoney = payMoney.add(payPostage);
|
|
|
order.setPayMoney(payMoney);
|
|
|
order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
}
|
|
|
@@ -3968,6 +4128,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
storePayment.setUserId(user.getUserId());
|
|
|
storePayment.setBusinessOrderId(order.getId().toString());
|
|
|
storePayment.setOrderId(order.getId());
|
|
|
+ storePayment.setAppId(fsPayConfig.getAppId() == null ? "" : fsPayConfig.getAppId());
|
|
|
fsStorePaymentMapper.insertFsStorePayment(storePayment);
|
|
|
|
|
|
if (fsPayConfig.getType().equals("hf")){
|
|
|
@@ -4063,6 +4224,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
user.setStatus(1);
|
|
|
user.setMaOpenId(session.getOpenid());
|
|
|
user.setUnionId(session.getUnionid());
|
|
|
+ user.setAppId(properties.getConfigs().get(0).getAppid());
|
|
|
user.setIsWeixinAuth(0);
|
|
|
user.setLastIp(ip);
|
|
|
user.setCreateTime(new Date());
|
|
|
@@ -4181,6 +4343,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
user.setStatus(1);
|
|
|
user.setMaOpenId(session.getOpenid());
|
|
|
user.setUnionId(session.getUnionid());
|
|
|
+ user.setAppId(properties.getConfigs().get(0).getAppid());
|
|
|
user.setIsWeixinAuth(0);
|
|
|
user.setLastIp(ip);
|
|
|
user.setCreateTime(new Date());
|
|
|
@@ -4440,6 +4603,17 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (amount != null){
|
|
|
payMoney=amount;
|
|
|
}
|
|
|
+ //运费
|
|
|
+ BigDecimal payPostage = order.getPayPostage();
|
|
|
+ if (payPostage == null || payPostage.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
+ payPostage = storeConfig.getPayPostage();
|
|
|
+ if (payPostage == null){
|
|
|
+ payPostage = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ order.setPayPrice(order.getPayPrice().add(payPostage));
|
|
|
+ }
|
|
|
+ order.setPayPostage(payPostage);
|
|
|
+ payMoney = payMoney.add(payPostage);
|
|
|
order.setPayMoney(payMoney);
|
|
|
order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
}
|
|
|
@@ -4710,6 +4884,308 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<FsStoreOrderDeliveryNoteExportVO> getDeliveryNote(FsStoreOrderParam param) {
|
|
|
+ return fsStoreOrderMapper.getDeliveryNote(param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R importDeliveryNoteExpress(List<FsOrderDeliveryNoteDTO> dtoList, String appId) {
|
|
|
+ try {
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ //获取商城配置
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+
|
|
|
+ List<FsOrderDeliveryNoteDTO> successList = new ArrayList<>(dtoList.size());
|
|
|
+ //提前获取所有必要数据
|
|
|
+ Map<String, String> expressDeliveryMap = buildExpressDeliveryMap();
|
|
|
+ //提取所有有效订单号
|
|
|
+ List<String> orderCodeList = new ArrayList<>(dtoList.size());
|
|
|
+ for (int i = 0; i < dtoList.size(); i++) {
|
|
|
+ FsOrderDeliveryNoteDTO dto = dtoList.get(i);
|
|
|
+ if (StringUtils.isEmpty(dto.getOrderNumber())) {
|
|
|
+ builder.append("数据第").append(i + 2).append("行系统订单为空!").append(System.lineSeparator());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(dto.getLogisticsCompany())) {
|
|
|
+ builder.append("数据第").append(i + 2).append("行物流公司为空!").append(System.lineSeparator());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(dto.getDeliveryId())) {
|
|
|
+ builder.append("数据第").append(i + 2).append("行快递单号为空!").append(System.lineSeparator());
|
|
|
+ } else {
|
|
|
+ //处理订单ID信息
|
|
|
+ String originalOrderNumber = dto.getOrderNumber();
|
|
|
+ String processedOrderNumber = extractNumbers(originalOrderNumber);
|
|
|
+ dto.setOrderNumber(processedOrderNumber);
|
|
|
+ orderCodeList.add(dto.getOrderNumber());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量查询订单信息
|
|
|
+ if (orderCodeList.isEmpty()) {
|
|
|
+ return R.ok(builder.toString());
|
|
|
+ }
|
|
|
+ List<FsStoreOrderCodeOpenIdVo> orderCodeOpenIdVoList = fsStoreOrderMapper.selectOrderCodeOpenIdInOrderCode(orderCodeList);
|
|
|
+ Map<String, OrderOpenIdTransDTO> orderMap = new HashMap<>(orderCodeOpenIdVoList.size());
|
|
|
+ Map<String, List<FsStoreOrderCodeOpenIdVo>> orderDetailsMap = new HashMap<>(orderCodeOpenIdVoList.size());
|
|
|
+
|
|
|
+ for (FsStoreOrderCodeOpenIdVo vo : orderCodeOpenIdVoList) {
|
|
|
+ orderMap.computeIfAbsent(vo.getId(), k -> {
|
|
|
+ OrderOpenIdTransDTO dto = new OrderOpenIdTransDTO();
|
|
|
+ dto.setOpenId(vo.getOpenId());
|
|
|
+ dto.setTransactionId(vo.getOutTransId());
|
|
|
+ return dto;
|
|
|
+ });
|
|
|
+
|
|
|
+ orderDetailsMap
|
|
|
+ .computeIfAbsent(vo.getId(), k -> new ArrayList<>())
|
|
|
+ .add(vo);
|
|
|
+ }
|
|
|
+ final WxMaService wxService = WxMaConfiguration.getMaService(appId);
|
|
|
+ String uploadTime = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"))
|
|
|
+ .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
|
|
+
|
|
|
+ for (int i = 0; i < dtoList.size(); i++) {
|
|
|
+ FsOrderDeliveryNoteDTO dto = dtoList.get(i);
|
|
|
+ int rowNum = i + 2;
|
|
|
+ if (StringUtils.isEmpty(dto.getOrderNumber())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(dto.getDeliveryId())) {
|
|
|
+ builder.append("数据第").append(rowNum).append("行快递单号为空!")
|
|
|
+ .append(System.lineSeparator());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(dto.getLogisticsCompany())) {
|
|
|
+ builder.append("数据第").append(rowNum).append("行快递公司编号为空!")
|
|
|
+ .append(System.lineSeparator());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+// if (dto.getDeliveryStatus() == null) {
|
|
|
+// dto.setDeliveryStatus(0);
|
|
|
+// }
|
|
|
+// if (ObjectUtil.isNotNull(dto.getDeliveryTime())) {
|
|
|
+// dto.setDeliveryTime(parseCstToDateOnlyString(dto.getDeliveryTime()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (ObjectUtil.isNotNull(dto.getDeliveryPayTime()) &&
|
|
|
+// !dto.getDeliveryPayTime().isEmpty()) {
|
|
|
+// dto.setDeliveryPayTime(parseCstToDateOnlyString(dto.getDeliveryPayTime()));
|
|
|
+// }
|
|
|
+ // 验证快递公司
|
|
|
+ String deliverySn = expressDeliveryMap.get(dto.getLogisticsCompany());
|
|
|
+ if (deliverySn == null) {
|
|
|
+ builder.append("数据第").append(rowNum).append("行订单号为")
|
|
|
+ .append(dto.getOrderNumber()).append("物流公司名称异常")
|
|
|
+ .append(System.lineSeparator());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ dto.setDeliverySn(deliverySn);
|
|
|
+
|
|
|
+ // 检查订单是否存在
|
|
|
+ String orderNumber = dto.getOrderNumber();
|
|
|
+ OrderOpenIdTransDTO orderInfo = orderMap.get(orderNumber);
|
|
|
+ if (orderInfo == null) {
|
|
|
+ builder.append("数据第").append(rowNum).append("行订单号")
|
|
|
+ .append(orderNumber).append("不存在").append(System.lineSeparator());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //验证是否开启微信发货
|
|
|
+ if (config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
|
|
|
+ // 上传物流信息到微信
|
|
|
+ List<FsStoreOrderCodeOpenIdVo> orderDetails = orderDetailsMap.get(orderNumber);
|
|
|
+ if (uploadShippingInfoToWechat(wxService, orderInfo, orderDetails, dto, uploadTime)) {
|
|
|
+ successList.add(dto);
|
|
|
+ } else {
|
|
|
+ builder.append("数据第").append(rowNum).append("行订单号为")
|
|
|
+ .append(orderNumber).append("上传微信失败").append(System.lineSeparator());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ successList.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量更新数据
|
|
|
+ if (!successList.isEmpty()) {
|
|
|
+ batchUpdateDeliveryNotes(successList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(builder.toString().equals("") ? "操作成功!" : builder.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导入发货单快递信息失败", e);
|
|
|
+ return R.error("导入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public void refreshOrderSettlementStatus() {
|
|
|
+ try {
|
|
|
+ // 判断是否对接微信发货
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+ logger.info("进入微信结算订单定时任务--------------->{}", "start");
|
|
|
+ if (config != null && config.getIsWeChatShipping() != null && config.getIsWeChatShipping()) {
|
|
|
+ // 获取未结算订单
|
|
|
+ List<FsStoreOrderScrm> orderScrmList = fsStoreOrderMapper.getUnsettledOrder();
|
|
|
+
|
|
|
+// String payConfig = configService.selectConfigByKey("store.pay");
|
|
|
+ String payConfig = configService.selectConfigByKey("his.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;
|
|
|
+
|
|
|
+ try {
|
|
|
+ response = wxService.getWxMaOrderShippingService().get(request);
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("请求信息------------------------》{}", response);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ logger.info("异常信息------------------------》{}", e.getMessage());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getStackTrace();
|
|
|
+ } finally {
|
|
|
+ logger.info("进入微信结算订单定时任务--------------->{}", "end");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void batchUpdateDeliveryNotes(List<FsOrderDeliveryNoteDTO> list) {
|
|
|
+ int batchSize = 500;
|
|
|
+ int total = list.size();
|
|
|
+ int batches = (total + batchSize - 1) / batchSize;
|
|
|
+ for (int i = 0; i < batches; i++) {
|
|
|
+ int start = i * batchSize;
|
|
|
+ int end = Math.min(start + batchSize, total);
|
|
|
+ List<FsOrderDeliveryNoteDTO> subList = list.subList(start, end);
|
|
|
+ fsStoreOrderMapper.batchUpdateInOrderCode(subList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean uploadShippingInfoToWechat(WxMaService wxService,
|
|
|
+ OrderOpenIdTransDTO orderInfo,
|
|
|
+ List<FsStoreOrderCodeOpenIdVo> orderDetails,
|
|
|
+ FsOrderDeliveryNoteDTO dto,
|
|
|
+ String uploadTime) {
|
|
|
+ try {
|
|
|
+ WxMaOrderShippingInfoUploadRequest request = new WxMaOrderShippingInfoUploadRequest();
|
|
|
+ OrderKeyBean orderKeyBean = new OrderKeyBean();
|
|
|
+ orderKeyBean.setOrderNumberType(2);
|
|
|
+ orderKeyBean.setTransactionId(orderInfo.getTransactionId());
|
|
|
+ request.setOrderKey(orderKeyBean);
|
|
|
+ request.setDeliveryMode(1);
|
|
|
+ request.setLogisticsType(1);
|
|
|
+ List<ShippingListBean> shippingList = new ArrayList<>(orderDetails.size());
|
|
|
+ ShippingListBean shippingListBean = null;
|
|
|
+ for (FsStoreOrderCodeOpenIdVo detail : orderDetails) {
|
|
|
+ if (shippingListBean == null) {
|
|
|
+ shippingListBean = new ShippingListBean();
|
|
|
+ shippingListBean.setTrackingNo(dto.getDeliveryId());
|
|
|
+ shippingListBean.setExpressCompany(dto.getDeliverySn());
|
|
|
+ JSONObject js = JSON.parseObject(detail.getJsonInfo());
|
|
|
+ shippingListBean.setItemDesc(js.getString("productName"));
|
|
|
+ ContactBean contactBean = new ContactBean();
|
|
|
+ contactBean.setReceiverContact(detail.getPhone());
|
|
|
+ shippingListBean.setContact(contactBean);
|
|
|
+ } else {
|
|
|
+ //拼接
|
|
|
+// JSONObject js = JSON.parseObject(detail.getJsonInfo());
|
|
|
+// shippingListBean.setItemDesc(shippingListBean.getItemDesc()+"-"+js.getString("productName"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ shippingList.add(shippingListBean);
|
|
|
+ request.setShippingList(shippingList);
|
|
|
+ request.setUploadTime(uploadTime);
|
|
|
+ // 设置支付者信息
|
|
|
+ PayerBean payerBean = new PayerBean();
|
|
|
+ payerBean.setOpenid(orderInfo.getOpenId());
|
|
|
+ request.setPayer(payerBean);
|
|
|
+
|
|
|
+ // 上传物流信息
|
|
|
+ return wxService.getWxMaOrderShippingService().upload(request).getErrCode() == 0;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传物流信息到微信失败,订单号: {}", dto.getOrderNumber(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R createPackageSalesOrder(CompanyUser companyUser, String packageId, Integer orderType, Integer orderMedium) {
|
|
|
+ FsStoreProductPackageScrm storeProductPackage = productPackageService.selectFsStoreProductPackageById(Long.parseLong(packageId));
|
|
|
+ if(storeProductPackage == null){
|
|
|
+ return R.error("商品套餐不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 由于套餐包制单前端页面没有走购物车,因为为了保证后续可以使用之前商品制单的改价接口、创建订单接口、支付等接口,
|
|
|
+ * 也为了保持结构一致,因此这里手动添加购物车
|
|
|
+ */
|
|
|
+ // 获取套餐包的商品信息,然后添加购物车
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(storeProductPackage.getProducts());
|
|
|
+ List<StorePackageProductDTO> goodsList = JSONUtil.toList(jsonArray, StorePackageProductDTO.class);
|
|
|
+ String cartIds = "";
|
|
|
+ for (StorePackageProductDTO goods : goodsList) {
|
|
|
+ FsStoreCartParam fsStoreCartParam = new FsStoreCartParam();
|
|
|
+ FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
|
|
|
+ if (attrValue != null && attrValue.getProductId() != null) {
|
|
|
+ fsStoreCartParam.setProductId(attrValue.getProductId());
|
|
|
+ fsStoreCartParam.setCartNum(goods.getCount());
|
|
|
+ fsStoreCartParam.setIsBuy(1);
|
|
|
+ fsStoreCartParam.setAttrValueId(goods.getId());
|
|
|
+ R r = fsStoreCartScrmService.addCart(companyUser.getUserId(), fsStoreCartParam);
|
|
|
+ Object id = r.get("id");
|
|
|
+ if(id != null){
|
|
|
+ cartIds += id + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FsStoreCartQueryVO> carts = cartMapper.selectFsStoreCartListByIds(cartIds);
|
|
|
+ String uuid = IdUtil.randomUUID();
|
|
|
+ redisCache.setCacheObject("createOrderKey:" + uuid, companyUser.getCompanyId() + "-" + companyUser.getUserId(), 24, TimeUnit.HOURS);
|
|
|
+
|
|
|
+ // 这里的carts是购物车信息,价格取的套餐包价格
|
|
|
+ for (FsStoreCartQueryVO vo : carts) {
|
|
|
+ vo.setPrice(storeProductPackage.getPayMoney());
|
|
|
+ }
|
|
|
+ redisCache.setCacheObject("orderCarts:" + uuid, carts, 24, TimeUnit.HOURS);
|
|
|
+ if (orderType != null || orderMedium != null) {
|
|
|
+ FsStoreOrderScrm fsStoreOrder = new FsStoreOrderScrm();
|
|
|
+ fsStoreOrder.setOrderMedium(orderMedium);
|
|
|
+ fsStoreOrder.setOrderType(orderType);
|
|
|
+ redisCache.setCacheObject("orderInfo:" + uuid, fsStoreOrder, 24, TimeUnit.HOURS);
|
|
|
+ }
|
|
|
+
|
|
|
+ redisCache.setCacheObject("createOrderMoney:" + uuid, storeProductPackage.getPayMoney(), 24, TimeUnit.HOURS);
|
|
|
+ // 根据前端要求,为了前端方便取值,所以返回的参数key与商品制单的接口保持一致
|
|
|
+ return R.ok().put("orderKey", uuid);
|
|
|
+ }
|
|
|
+
|
|
|
private static final DateTimeFormatter CST_FORMATTER = DateTimeFormatter
|
|
|
.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
|
|
|
.withZone(ZoneId.of("Asia/Shanghai"));
|
|
|
@@ -4746,9 +5222,23 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
map.put("ZTO", "中通");
|
|
|
map.put("JD", "京东");
|
|
|
map.put("DBL", "德邦");
|
|
|
+ map.put("YTO", "圆通");
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ //高性能截取订单ID
|
|
|
+ private static String extractNumbers(String str) {
|
|
|
+ if (str == null || str.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ int start = 0;
|
|
|
+ int len = str.length();
|
|
|
+ while (start < len && !Character.isDigit(str.charAt(start))) {
|
|
|
+ start++;
|
|
|
+ }
|
|
|
+ return start < len ? str.substring(start) : "";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public FsStoreOrderAmountScrmStatsVo selectFsStoreOrderAmountScrmStats(FsStoreOrderAmountScrmStatsQueryDto queryDto) {
|