|
@@ -0,0 +1,338 @@
|
|
|
|
+package com.caimei365.order.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.caimei365.order.mapper.AddressMapper;
|
|
|
|
+import com.caimei365.order.mapper.BaseMapper;
|
|
|
|
+import com.caimei365.order.mapper.OrderCommonMapper;
|
|
|
|
+import com.caimei365.order.mapper.ShipMapper;
|
|
|
|
+import com.caimei365.order.model.ResponseJson;
|
|
|
|
+import com.caimei365.order.model.dto.LogisticsDto;
|
|
|
|
+import com.caimei365.order.model.po.LogisticsBatchPo;
|
|
|
|
+import com.caimei365.order.model.po.LogisticsInformationPo;
|
|
|
|
+import com.caimei365.order.model.po.LogisticsRecordPo;
|
|
|
|
+import com.caimei365.order.model.vo.*;
|
|
|
|
+import com.caimei365.order.service.RemoteCallService;
|
|
|
|
+import com.caimei365.order.service.ShipService;
|
|
|
|
+import com.caimei365.order.utils.ImageUtil;
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import static com.alibaba.fastjson.JSON.parseArray;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Description
|
|
|
|
+ *
|
|
|
|
+ * @author : Charles
|
|
|
|
+ * @date : 2021/8/5
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class ShipServiceImpl implements ShipService {
|
|
|
|
+ @Value("${caimei.wwwDomain}")
|
|
|
|
+ private String domain;
|
|
|
|
+ @Resource
|
|
|
|
+ private BaseMapper baseMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private ShipMapper shipMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private AddressMapper addressMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private OrderCommonMapper orderCommonMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private RemoteCallService remoteCallService;
|
|
|
|
+ /**
|
|
|
|
+ * 供应商订单列表
|
|
|
|
+ *
|
|
|
|
+ * @param shopId 供应商Id
|
|
|
|
+ * @param sendOutStatus 发货状态
|
|
|
|
+ * @param payStatus 结算状态
|
|
|
|
+ * @param shopOrderNo 订单编号
|
|
|
|
+ * @param receiver 买家名称(收货人)
|
|
|
|
+ * @param pageNum 页码
|
|
|
|
+ * @param pageSize 每页数量
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<PageInfo<ShopOrderVo>> getShopOrderList(Integer shopId, Integer sendOutStatus, Integer payStatus, String shopOrderNo, String receiver, int pageNum, int pageSize) {
|
|
|
|
+ // 分页请求数据
|
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
|
+ List<ShopOrderVo> shopOrderList = shipMapper.getShopOrderList(shopId, sendOutStatus, payStatus, shopOrderNo, receiver);
|
|
|
|
+ shopOrderList.forEach(shopOrder -> {
|
|
|
|
+ if (null != shopOrder) {
|
|
|
|
+ setShopOrderInfo(shopOrder);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ PageInfo<ShopOrderVo> pageInfo = new PageInfo(shopOrderList);
|
|
|
|
+ return ResponseJson.success(pageInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发货页面子订单数据
|
|
|
|
+ *
|
|
|
|
+ * @param shopOrderId 子订单Id
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<ShopOrderVo> getShopOrderInfo(Integer shopOrderId) {
|
|
|
|
+ ShopOrderVo shopOrder = shipMapper.getShopOrder(shopOrderId);
|
|
|
|
+ if (null != shopOrder) {
|
|
|
|
+ setShopOrderInfo(shopOrder);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success(shopOrder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void setShopOrderInfo(ShopOrderVo shopOrder) {
|
|
|
|
+ // 收货地址
|
|
|
|
+ OrderUserinfoVo userInfo = addressMapper.getOrderUserinfo(shopOrder.getOrderId());
|
|
|
|
+ shopOrder.setUserInfo(userInfo);
|
|
|
|
+ // (收款买家)收款状态:1待收款、2部分收款、3已收款
|
|
|
|
+ Integer receiptStatus = shipMapper.getOrderReceiptStatus(shopOrder.getOrderId());
|
|
|
|
+ //(收款买家)收款状态:1待收款、2部分收款、3已收款
|
|
|
|
+ shopOrder.setReceiptStatus(receiptStatus);
|
|
|
|
+ // 供应商名称
|
|
|
|
+ String shopName = baseMapper.getShopNameById(shopOrder.getShopId());
|
|
|
|
+ shopOrder.setShopName(shopName);
|
|
|
|
+
|
|
|
|
+ if (null != userInfo) {
|
|
|
|
+ String address = userInfo.getProvince() + userInfo.getCity() + userInfo.getTown() + userInfo.getAddress();
|
|
|
|
+ userInfo.setAddress(address);
|
|
|
|
+ }
|
|
|
|
+ List<OrderProductVo> orderProductList = orderCommonMapper.getShopOrderProduct(shopOrder.getShopOrderId());
|
|
|
|
+ orderProductList.forEach(orderProduct -> {
|
|
|
|
+ if (null != orderProduct) {
|
|
|
|
+ orderProduct.setImage(ImageUtil.getImageUrl("product", orderProduct.getImage(), domain));
|
|
|
|
+ //已发货数量
|
|
|
|
+ orderProduct.setShipmentsNum(orderProduct.getNum() + orderProduct.getPresentNum() - orderProduct.getNotOutStore());
|
|
|
|
+ //已退货数量
|
|
|
|
+ Integer returnedNum = orderCommonMapper.countReturnedNum(orderProduct.getShopOrderId(), orderProduct.getProductId());
|
|
|
|
+ returnedNum = null != returnedNum ? returnedNum : 0;
|
|
|
|
+ orderProduct.setReturnedNum(returnedNum);
|
|
|
|
+ //已取消发货数量
|
|
|
|
+ Integer actualCancelNum = orderCommonMapper.countActualCancelNum(orderProduct.getShopOrderId(), orderProduct.getProductId());
|
|
|
|
+ actualCancelNum = null != actualCancelNum ? actualCancelNum : 0;
|
|
|
|
+ orderProduct.setActualCancelNum(actualCancelNum);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ shopOrder.setOrderProductList(orderProductList);
|
|
|
|
+ shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
|
|
|
|
+ shopOrder.setOrderProductList(orderProductList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 物流公司
|
|
|
|
+ *
|
|
|
|
+ * @param value 快递公司代码
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<List<CompanyVo>> getLogisticsCompany(String value) {
|
|
|
|
+ List<CompanyVo> companyList = shipMapper.getLogisticsCompany(value);
|
|
|
|
+ return ResponseJson.success(companyList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发货
|
|
|
|
+ *
|
|
|
|
+ * @param logisticsDto {
|
|
|
|
+ * shopOrderId: 子订单Id,
|
|
|
|
+ * note: 备注信息,
|
|
|
|
+ * image: 图片备注以||隔开,
|
|
|
|
+ * logistics:[ // 物流信息
|
|
|
|
+ * {number:'45646464646',logisticsCompanyName:'顺丰物流',logisticsCompanyCode:'物流英文代码'},
|
|
|
|
+ * {number:'45646464646',logisticsCompanyName:'顺丰物流',logisticsCompanyCode:'物流英文代码'}
|
|
|
|
+ * ],
|
|
|
|
+ * products:[ // 商品信息
|
|
|
|
+ * {orderProductId:订单商品id,num:此次发货数量},
|
|
|
|
+ * {orderProductId:订单商品id,num:此次发货数量}
|
|
|
|
+ * ],
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Integer> addLogistics(LogisticsDto logisticsDto) {
|
|
|
|
+ JSONArray logistics = null;
|
|
|
|
+ JSONArray products = null;
|
|
|
|
+ try {
|
|
|
|
+ logistics = parseArray(logisticsDto.getLogistics());
|
|
|
|
+ products = parseArray(logisticsDto.getProducts());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("发货参数:" + logisticsDto.toString());
|
|
|
|
+ log.error("【发货】>>>发货参数解析异常try-catch:", e);
|
|
|
|
+ return ResponseJson.error("发货参数解析异常!", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String image = logisticsDto.getImage();
|
|
|
|
+ String note = logisticsDto.getNote();
|
|
|
|
+ ShopOrderVo shopOrder = shipMapper.getShopOrder(logisticsDto.getShopOrderId());
|
|
|
|
+ if (null == shopOrder) {
|
|
|
|
+ return ResponseJson.error("订单异常,shopOrderId:" + logisticsDto.getShopOrderId(), null);
|
|
|
|
+ }
|
|
|
|
+ // 本次发货数量
|
|
|
|
+ int shipmentsNum = 0;
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ // 统计物流批次
|
|
|
|
+ int batchCount = shipMapper.countLogisticsBatch(shopOrder.getOrderId());
|
|
|
|
+ // 物流批次
|
|
|
|
+ LogisticsBatchPo logisticsBatch = new LogisticsBatchPo();
|
|
|
|
+ if (batchCount > 0) {
|
|
|
|
+ logisticsBatch.setOutStoreTimes(batchCount + 1);
|
|
|
|
+ } else {
|
|
|
|
+ logisticsBatch.setOutStoreTimes(0);
|
|
|
|
+ }
|
|
|
|
+ logisticsBatch.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
|
+ logisticsBatch.setOrderId(shopOrder.getOrderId());
|
|
|
|
+ logisticsBatch.setStatus("0");
|
|
|
|
+ logisticsBatch.setMailer("1");
|
|
|
|
+ logisticsBatch.setShopId(shopOrder.getShopId());
|
|
|
|
+ logisticsBatch.setUpdateDate(date);
|
|
|
|
+ logisticsBatch.setDeliveryTime(date);
|
|
|
|
+ logisticsBatch.setRemarkImage(image);
|
|
|
|
+ logisticsBatch.setRemark(note);
|
|
|
|
+ // 保存物流批次
|
|
|
|
+ shipMapper.insertLogisticsBatch(logisticsBatch);
|
|
|
|
+
|
|
|
|
+ /* products:[ // 发货商品信息
|
|
|
|
+ * {orderProductId:订单商品id,num:此次发货数量},
|
|
|
|
+ * {orderProductId:订单商品id,num:此次发货数量}]
|
|
|
|
+ */
|
|
|
|
+ for (Object productObj: products) {
|
|
|
|
+ JSONObject productInfo = (JSONObject) productObj;
|
|
|
|
+ Integer orderProductId = (Integer) productInfo.get("orderProductId");
|
|
|
|
+ Integer num = (Integer) productInfo.get("num");
|
|
|
|
+ if (null == num || 0 == num) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("发货数量异常!", null);
|
|
|
|
+ }
|
|
|
|
+ OrderProductVo orderProduct = shipMapper.getOrderProductById(orderProductId);
|
|
|
|
+ if (null == orderProduct || orderProduct.getNotOutStore() < num) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("订单商品异常,orderProductId:" + orderProductId, null);
|
|
|
|
+ }
|
|
|
|
+ LogisticsRecordPo logisticsRecord = new LogisticsRecordPo();
|
|
|
|
+ logisticsRecord.setLogisticsBatchId(logisticsBatch.getId());
|
|
|
|
+ logisticsRecord.setShopOrderId(orderProduct.getShopOrderId());
|
|
|
|
+ logisticsRecord.setOrderId(orderProduct.getOrderId());
|
|
|
|
+ logisticsRecord.setOrderProductId(orderProductId);
|
|
|
|
+ logisticsRecord.setBuyNum((orderProduct.getNum() + orderProduct.getPresentNum()));
|
|
|
|
+ logisticsRecord.setNum(num);
|
|
|
|
+ logisticsRecord.setProductId(orderProduct.getProductId());
|
|
|
|
+ logisticsRecord.setProductName(orderProduct.getName());
|
|
|
|
+ logisticsRecord.setImage(orderProduct.getImage());
|
|
|
|
+ // 保存 发货物流记录
|
|
|
|
+ shipMapper.insertLogisticsRecord(logisticsRecord);
|
|
|
|
+ // 保存订单商品未出库数量
|
|
|
|
+ int notOutStore = orderProduct.getNotOutStore() - num;
|
|
|
|
+ shipMapper.updateNotOutStore(orderProductId, notOutStore);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* logistics:[ // 物流跟踪信息
|
|
|
|
+ * {number:'45646464646',logisticsCompanyName:'顺丰物流',logisticsCompanyCode:'物流英文代码'},
|
|
|
|
+ * {number:'45646464646',logisticsCompanyName:'顺丰物流',logisticsCompanyCode:'物流英文代码'}]
|
|
|
|
+ */
|
|
|
|
+ for (Object logisticObj: logistics) {
|
|
|
|
+ JSONObject logistic = (JSONObject) logisticObj;
|
|
|
|
+ String number = (String) logistic.get("number");
|
|
|
|
+ String logisticsCompanyName = (String) logistic.get("logisticsCompanyName");
|
|
|
|
+ String logisticsCompanyCode = (String) logistic.get("logisticsCompanyCode");
|
|
|
|
+ if (StringUtils.isBlank(number) || StringUtils.isBlank(logisticsCompanyName) || StringUtils.isBlank(logisticsCompanyCode)) {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("物流信息参数异常!", null);
|
|
|
|
+ }
|
|
|
|
+ LogisticsInformationPo logisticsInformation = new LogisticsInformationPo();
|
|
|
|
+ logisticsInformation.setLogisticsBatchId(logisticsBatch.getId());
|
|
|
|
+ logisticsInformation.setType("1");
|
|
|
|
+ logisticsInformation.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
|
+ logisticsInformation.setOrderId(shopOrder.getOrderId());
|
|
|
|
+ logisticsInformation.setNu(number);
|
|
|
|
+ logisticsInformation.setLogisticsCompanyName(logisticsCompanyName);
|
|
|
|
+ logisticsInformation.setLogisticsCompanyCode(logisticsCompanyCode);
|
|
|
|
+ logisticsInformation.setShopId(shopOrder.getShopId());
|
|
|
|
+ logisticsInformation.setUpdateDate(date);
|
|
|
|
+ // 保存 物流跟踪信息
|
|
|
|
+ shipMapper.insertLogisticsInformation(logisticsInformation);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 修改子订单发货状态
|
|
|
|
+ */
|
|
|
|
+ if (null == shopOrder.getOutStoreNum()) {
|
|
|
|
+ shopOrder.setOutStoreNum(shipmentsNum);
|
|
|
|
+ } else {
|
|
|
|
+ shopOrder.setOutStoreNum(shopOrder.getOutStoreNum() + shipmentsNum);
|
|
|
|
+ }
|
|
|
|
+ shopOrder.setOutStoreTimes(logisticsBatch.getOutStoreTimes());
|
|
|
|
+ shopOrder.setPresentNum(shopOrder.getPresentNum() == null ? 0 : shopOrder.getPresentNum());
|
|
|
|
+ int productNum = shopOrder.getPresentNum() + shopOrder.getItemCount();
|
|
|
|
+ if (productNum > shopOrder.getOutStoreNum()) {
|
|
|
|
+ shopOrder.setSendOutStatus(2);
|
|
|
|
+ } else if (productNum == shopOrder.getOutStoreNum()) {
|
|
|
|
+ shopOrder.setSendOutStatus(3);
|
|
|
|
+ } else {
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("发货数量异常!", null);
|
|
|
|
+ }
|
|
|
|
+ shopOrder.setSplitFlag(0);
|
|
|
|
+ shipMapper.updateShopOrderShip(shopOrder.getShopOrderId(), shopOrder.getOutStoreNum(), shopOrder.getOutStoreTimes(), shopOrder.getSendOutStatus());
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 修改主订单发货状态
|
|
|
|
+ */
|
|
|
|
+ OrderVo order = orderCommonMapper.getOrderByOrderId(shopOrder.getOrderId());
|
|
|
|
+ // 主订单发货状态
|
|
|
|
+ Integer sendOutStatus = order.getSendOutStatus();
|
|
|
|
+ // 发货状态:1待发货、2部分发货、3已发货
|
|
|
|
+ List<Integer> allShopSendOutStatus = shipMapper.getAllSendOutStatus(shopOrder.getOrderId());
|
|
|
|
+ String statusSuffix = "";
|
|
|
|
+ if (allShopSendOutStatus.stream().allMatch(s -> 3 == s)) {
|
|
|
|
+ // 所有的子订单都已经完成发货
|
|
|
|
+ statusSuffix = "3";
|
|
|
|
+ order.setSendOutStatus(3);
|
|
|
|
+ } else {
|
|
|
|
+ statusSuffix = "2";
|
|
|
|
+ order.setSendOutStatus(2);
|
|
|
|
+ }
|
|
|
|
+ if (order.getStatus() >= 10) {
|
|
|
|
+ String statusTmp = order.getStatus().toString().charAt(0) + statusSuffix;
|
|
|
|
+ order.setStatus(Integer.valueOf(statusTmp));
|
|
|
|
+ }
|
|
|
|
+ // 修改主订单发货状态
|
|
|
|
+ shipMapper.updateOrderShip(order.getOrderId(), order.getSendOutStatus(), order.getStatus());
|
|
|
|
+ //发货短信推送
|
|
|
|
+ String bindMobile = baseMapper.getBindMobileByUserId(order.getUserId());
|
|
|
|
+ if (StringUtils.isNotBlank(bindMobile) && 0 == order.getRebateFlag()) {
|
|
|
|
+ boolean sendSms = false;
|
|
|
|
+ if (1 == sendOutStatus && 2 == order.getSendOutStatus()){
|
|
|
|
+ String shortLink = remoteCallService.getShortLink(8, 7, domain + "/user/order/detail.html?orderId=" + order.getOrderId());
|
|
|
|
+ String content = "您的订单(订单编号:" + order.getOrderNo() + ")已部分发货。您可关注采美公众号或者访问采美微信小程序和网站查看订单。平台公众号:微信搜索“采美365网”; " +
|
|
|
|
+ "微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
|
|
|
|
+ sendSms = remoteCallService.getSendSms(7, bindMobile, content);
|
|
|
|
+ } else if (3 == order.getSendOutStatus()) {
|
|
|
|
+ String shortLink = remoteCallService.getShortLink(8, 8, domain + "/user/order/detail.html?orderId=" + order.getOrderId());
|
|
|
|
+ String content = "您的订单(订单编号:" + order.getOrderNo() + ")已发货完毕。您可关注采美公众号或者访问采美微信小程序和网站查看订单。平台公众号:微信搜索“采美365网”; " +
|
|
|
|
+ "微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
|
|
|
|
+ sendSms = remoteCallService.getSendSms(8, bindMobile, content);
|
|
|
|
+ }
|
|
|
|
+ if (!sendSms) {
|
|
|
|
+ log.info("发货短信推送失败,orderId>>>>" + order.getOrderId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success(logisticsBatch.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|