|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
@@ -23,8 +24,10 @@ import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.domain.FsUserAddress;
|
|
|
import com.fs.his.dto.ComputeGuCoinOrderMoneyDTO;
|
|
|
import com.fs.his.dto.ErpRemarkDTO;
|
|
|
+import com.fs.his.dto.ExpressInfoDTO;
|
|
|
import com.fs.his.enums.BusinessTypeEnum;
|
|
|
import com.fs.his.enums.PaymentMethodEnum;
|
|
|
+import com.fs.his.enums.ShipperCodeEnum;
|
|
|
import com.fs.his.mapper.FsGuCoinGoodsMapper;
|
|
|
import com.fs.his.mapper.FsGuCoinOrderMapper;
|
|
|
import com.fs.his.mapper.FsUserAddressMapper;
|
|
|
@@ -47,6 +50,8 @@ import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.his.vo.FsGuCoinCartVO;
|
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.course.domain.FsUserCompanyUser;
|
|
|
+import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -93,6 +98,8 @@ public class FsGuCoinOrderServiceImpl implements IFsGuCoinOrderService
|
|
|
@Autowired
|
|
|
private QwUserMapper qwUserMapper;
|
|
|
@Autowired
|
|
|
+ private FsUserCompanyUserMapper fsUserCompanyUserMapper;
|
|
|
+ @Autowired
|
|
|
private IFsUserGuCoinLogsService fsUserGuCoinLogsService;
|
|
|
@Autowired
|
|
|
private IFsStorePaymentService storePaymentService;
|
|
|
@@ -322,13 +329,16 @@ public class FsGuCoinOrderServiceImpl implements IFsGuCoinOrderService
|
|
|
order.setPayTime(new Date());
|
|
|
}
|
|
|
|
|
|
- // 关联销售信息
|
|
|
- Long companyUserId = param.getCompanyUserId();
|
|
|
- if (companyUserId != null) {
|
|
|
- order.setCompanyUserId(companyUserId);
|
|
|
- CompanyUser companyUser = companyUserMapper.selectCompanyUserByCompanyUserId(companyUserId);
|
|
|
- if (ObjectUtil.isNotEmpty(companyUser)) {
|
|
|
- order.setCompanyId(companyUser.getCompanyId());
|
|
|
+ // 关联销售信息(根据userId从fs_user_company_user查询,不从前端获取)
|
|
|
+ FsUserCompanyUser companyUserRel = fsUserCompanyUserMapper.selectOne(new LambdaQueryWrapper<FsUserCompanyUser>()
|
|
|
+ .eq(FsUserCompanyUser::getUserId, user.getUserId())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (companyUserRel != null) {
|
|
|
+ if (companyUserRel.getCompanyUserId() != null) {
|
|
|
+ order.setCompanyUserId(companyUserRel.getCompanyUserId());
|
|
|
+ }
|
|
|
+ if (companyUserRel.getCompanyId() != null) {
|
|
|
+ order.setCompanyId(companyUserRel.getCompanyId());
|
|
|
}
|
|
|
}
|
|
|
// 关联企微信息
|
|
|
@@ -479,17 +489,29 @@ public class FsGuCoinOrderServiceImpl implements IFsGuCoinOrderService
|
|
|
order.setPayTime(new Date());
|
|
|
}
|
|
|
|
|
|
- // 关联企微信息(购物车下单无销售关联)
|
|
|
+ // 关联销售信息(根据userId从fs_user_company_user查询,不从前端获取)
|
|
|
+ FsUserCompanyUser companyUserRel = fsUserCompanyUserMapper.selectOne(new LambdaQueryWrapper<FsUserCompanyUser>()
|
|
|
+ .eq(FsUserCompanyUser::getUserId, user.getUserId())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (companyUserRel != null) {
|
|
|
+ if (companyUserRel.getCompanyUserId() != null) {
|
|
|
+ order.setCompanyUserId(companyUserRel.getCompanyUserId());
|
|
|
+ }
|
|
|
+ if (companyUserRel.getCompanyId() != null) {
|
|
|
+ order.setCompanyId(companyUserRel.getCompanyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 关联企微信息
|
|
|
if (ObjectUtil.isNotNull(user.getQwUserId())) {
|
|
|
QwUser qwUser = qwUserMapper.selectOne(new LambdaQueryWrapper<QwUser>()
|
|
|
.select(QwUser::getId, QwUser::getCompanyId, QwUser::getCompanyUserId)
|
|
|
.eq(QwUser::getId, user.getQwUserId()));
|
|
|
if (ObjectUtil.isNotNull(qwUser)) {
|
|
|
order.setQwUserId(qwUser.getId());
|
|
|
- if (qwUser.getCompanyId() != null) {
|
|
|
+ if (order.getCompanyId() == null && qwUser.getCompanyId() != null) {
|
|
|
order.setCompanyId(qwUser.getCompanyId());
|
|
|
}
|
|
|
- if (qwUser.getCompanyUserId() != null) {
|
|
|
+ if (order.getCompanyUserId() == null && qwUser.getCompanyUserId() != null) {
|
|
|
order.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
}
|
|
|
}
|
|
|
@@ -964,4 +986,72 @@ public class FsGuCoinOrderServiceImpl implements IFsGuCoinOrderService
|
|
|
log.error("谷币订单订阅快递鸟失败 orderCode: {}", orderCode, e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExpressInfoDTO getExpress(Long orderId) {
|
|
|
+ FsGuCoinOrder order = fsGuCoinOrderMapper.selectFsGuCoinOrderByOrderId(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ throw new RuntimeException("谷币订单不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(order.getDeliverySn())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String lastFourNumber = getExpressLastFourNumber(order);
|
|
|
+ ExpressInfoDTO expressInfoDTO = expressService.getExpressInfo(order.getOrderCode(), order.getDeliveryCode(), order.getDeliverySn(), lastFourNumber);
|
|
|
+ if (expressInfoDTO != null
|
|
|
+ && "0".equals(expressInfoDTO.getStateEx())
|
|
|
+ && "0".equals(expressInfoDTO.getState())) {
|
|
|
+ expressInfoDTO = expressService.getExpressInfo(order.getOrderCode(), order.getDeliveryCode(), order.getDeliverySn(), getDefaultExpressLastFourNumber(order));
|
|
|
+ }
|
|
|
+ return expressInfoDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R syncExpress(Long orderId) {
|
|
|
+ FsGuCoinOrder order = fsGuCoinOrderMapper.selectFsGuCoinOrderByOrderId(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ return R.error("谷币订单不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(order.getDeliverySn())) {
|
|
|
+ return R.error("快递单号为空");
|
|
|
+ }
|
|
|
+ ExpressInfoDTO dto = getExpress(orderId);
|
|
|
+ log.info("谷币订单快递鸟查询dto:{}", JSONUtil.toJsonStr(dto));
|
|
|
+ if (dto == null) {
|
|
|
+ return R.error("未查询到物流信息");
|
|
|
+ }
|
|
|
+ if (!dto.isSuccess()) {
|
|
|
+ return R.error(dto.getReason());
|
|
|
+ }
|
|
|
+ FsGuCoinOrder update = new FsGuCoinOrder();
|
|
|
+ update.setOrderId(order.getOrderId());
|
|
|
+ update.setDeliveryStatus(Integer.parseInt(dto.getState()));
|
|
|
+ update.setDeliveryType(dto.getStateEx());
|
|
|
+ update.setDeliveryUpdateTime(DateUtils.getNowDate());
|
|
|
+ fsGuCoinOrderMapper.updateFsGuCoinOrder(update);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getExpressLastFourNumber(FsGuCoinOrder order) {
|
|
|
+ if (!ShipperCodeEnum.SF.getValue().equals(order.getDeliveryCode()) || StringUtils.isBlank(order.getUserPhone())) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String phone = order.getUserPhone();
|
|
|
+ if (phone.length() > 11) {
|
|
|
+ phone = decryptPhone(phone);
|
|
|
+ }
|
|
|
+ if (phone.length() >= 4) {
|
|
|
+ return StrUtil.sub(phone, phone.length(), -4);
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDefaultExpressLastFourNumber(FsGuCoinOrder order) {
|
|
|
+ if (!ShipperCodeEnum.SF.getValue().equals(order.getDeliveryCode())) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String phone = "19331276912";
|
|
|
+ return StrUtil.sub(phone, phone.length(), -4);
|
|
|
+ }
|
|
|
}
|