feat: 订单

pull/1121/head
梁宇奇 2025-04-11 14:44:57 +08:00
parent de7dde6adb
commit ecaf329b17
18 changed files with 609 additions and 68 deletions

View File

@ -7,14 +7,8 @@ import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.controller.xkt.vo.order.StoreOrderAddReqVO;
import com.ruoyi.web.controller.xkt.vo.order.StoreOrderPayReqVO;
import com.ruoyi.web.controller.xkt.vo.order.StoreOrderPayRespVO;
import com.ruoyi.web.controller.xkt.vo.order.StoreOrderUpdateReqVO;
import com.ruoyi.xkt.dto.order.StoreOrderAddDTO;
import com.ruoyi.xkt.dto.order.StoreOrderAddResult;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderUpdateDTO;
import com.ruoyi.web.controller.xkt.vo.order.*;
import com.ruoyi.xkt.dto.order.*;
import com.ruoyi.xkt.enums.EPayChannel;
import com.ruoyi.xkt.enums.EPayPage;
import com.ruoyi.xkt.manager.PaymentManager;
@ -24,10 +18,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@ -57,7 +48,7 @@ public class StoreOrderController extends XktBaseController {
StoreOrderAddResult result = storeOrderService.createOrder(dto, vo.getBeginPay(),
EPayChannel.of(vo.getPayChannel()), EPayPage.of(vo.getPayFrom()));
//返回信息
StoreOrderPayRespVO respVO = new StoreOrderPayRespVO(result.getOrderInfo().getOrder().getId(),
StoreOrderPayRespVO respVO = new StoreOrderPayRespVO(result.getOrderExt().getOrder().getId(),
result.getPayRtnStr());
return success(respVO);
}
@ -65,11 +56,11 @@ public class StoreOrderController extends XktBaseController {
@PreAuthorize("@ss.hasPermi('system:order:add')")
@Log(title = "订单", businessType = BusinessType.UPDATE)
@ApiOperation("修改订单")
@PostMapping("modify")
public R<Long> modify(@Valid @RequestBody StoreOrderUpdateReqVO vo) {
@PutMapping("edit")
public R<Long> edit(@Valid @RequestBody StoreOrderUpdateReqVO vo) {
StoreOrderUpdateDTO dto = BeanUtil.toBean(vo, StoreOrderUpdateDTO.class);
dto.setOrderUserId(SecurityUtils.getUserId());
StoreOrderInfo result = storeOrderService.modifyOrder(dto);
StoreOrderExt result = storeOrderService.modifyOrder(dto);
return success(result.getOrder().getId());
}
@ -80,13 +71,22 @@ public class StoreOrderController extends XktBaseController {
public R<StoreOrderPayRespVO> pay(@Valid @RequestBody StoreOrderPayReqVO vo) {
PaymentManager paymentManager = getPaymentManager(EPayChannel.of(vo.getPayChannel()));
//订单支付状态->支付中
StoreOrderInfo storeOrderInfo = storeOrderService.preparePayOrder(vo.getStoreOrderId());
StoreOrderExt orderExt = storeOrderService.preparePayOrder(vo.getStoreOrderId());
//调用支付
String rtnStr = paymentManager.payOrder(storeOrderInfo, EPayPage.of(vo.getPayFrom()));
String rtnStr = paymentManager.payOrder(orderExt, EPayPage.of(vo.getPayFrom()));
StoreOrderPayRespVO respVO = new StoreOrderPayRespVO(vo.getStoreOrderId(), rtnStr);
return success(respVO);
}
@PreAuthorize("@ss.hasPermi('system:order:query')")
@ApiOperation(value = "订单详情")
@GetMapping(value = "/{id}")
public R<StoreOrderInfoVO> getInfo(@PathVariable("id") Long id) {
StoreOrderInfoDTO infoDTO = storeOrderService.getInfo(id);
//TODO 非下单人,非所属档口不允许查询
return success(BeanUtil.toBean(infoDTO, StoreOrderInfoVO.class));
}
/**
*
*

View File

@ -0,0 +1,399 @@
package com.ruoyi.web.controller.xkt.vo.order;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @author liangyq
* @date 2025-04-11 13:43
*/
@ApiModel("订单信息")
@Data
public class StoreOrderInfoVO {
/**
* ID
*/
@ApiModelProperty(value = "订单ID")
private Long id;
/**
* ID
*/
@ApiModelProperty(value = "档口ID")
private Long storeId;
/**
* ID
*/
@ApiModelProperty(value = "下单用户ID")
private Long orderUserId;
/**
*
*/
@ApiModelProperty(value = "订单号")
private String orderNo;
/**
* [1: 2:退]
*/
@ApiModelProperty(value = "订单类型[1:销售订单 2:退货订单]")
private Integer orderType;
/**
* 12退[10: 11: 12: 13: 14: 21: 22: 23: 24:]
*/
@ApiModelProperty(value = "订单状态1开头为销售订单状态2开头为退货订单状态[10:已取消 11:待付款 12:待发货 13:已发货 14:已完成 21:售后中 22:售后拒绝 23:平台介入 24:售后完成]")
private Integer orderStatus;
/**
* [1: 2: 3:]
*/
@ApiModelProperty(value = "支付状态[1:初始 2:支付中 3:已支付]")
private Integer payStatus;
/**
*
*/
@ApiModelProperty(value = "订单备注")
private String orderRemark;
/**
*
*/
@ApiModelProperty(value = "商品数量")
private Integer goodsQuantity;
/**
*
*/
@ApiModelProperty(value = "商品金额")
private BigDecimal goodsAmount;
/**
*
*/
@ApiModelProperty(value = "快递费")
private BigDecimal expressFee;
/**
* +
*/
@ApiModelProperty(value = "总金额")
private BigDecimal totalAmount;
/**
* -
*/
@ApiModelProperty(value = "实际总金额")
private BigDecimal realTotalAmount;
/**
* 退ID
*/
@ApiModelProperty(value = "退货原订单ID")
private Long refundOrderId;
/**
* 退
*/
@ApiModelProperty(value = "退货原因")
private Integer refundReasonCode;
/**
* 退
*/
@ApiModelProperty(value = "退货拒绝原因")
private String refundRejectReason;
/**
* ID
*/
@ApiModelProperty(value = "物流ID")
private Long expressId;
/**
* -
*/
@ApiModelProperty(value = "发货人-名称")
private String originContactName;
/**
* -
*/
@ApiModelProperty(value = "发货人-电话")
private String originContactPhoneNumber;
/**
* -
*/
@ApiModelProperty(value = "发货人-省编码")
private String originProvinceCode;
/**
* -
*/
@ApiModelProperty(value = "发货人-市编码")
private String originCityCode;
/**
* -
*/
@ApiModelProperty(value = "发货人-区县编码")
private String originCountyCode;
/**
* -
*/
@ApiModelProperty(value = "发货人-详细地址")
private String originDetailAddress;
/**
* -
*/
@ApiModelProperty(value = "收货人-名称")
private String destinationContactName;
/**
* -
*/
@ApiModelProperty(value = "收货人-电话")
private String destinationContactPhoneNumber;
/**
* -
*/
@ApiModelProperty(value = "收货人-省编码")
private String destinationProvinceCode;
/**
* -
*/
@ApiModelProperty(value = "收货人-市编码")
private String destinationCityCode;
/**
* -
*/
@ApiModelProperty(value = "收货人-区县编码")
private String destinationCountyCode;
/**
* -
*/
@ApiModelProperty(value = "收货人-详细地址")
private String destinationDetailAddress;
/**
* [1: 2:]
*/
@ApiModelProperty(value = "发货方式[1:货其再发 2:有货先发]")
private Integer deliveryType;
/**
*
*/
@ApiModelProperty(value = "最晚发货时间")
private Date deliveryEndTime;
/**
*
*/
@ApiModelProperty(value = "自动完成时间")
private Date autoEndTime;
/**
*
*/
@ApiModelProperty(value = "凭证日期")
private Date voucherDate;
/**
* 0 2
*/
@ApiModelProperty(value = "删除标志0代表存在 2代表删除")
private String delFlag;
/**
*
*/
@ApiModelProperty(value = "创建者")
private String createBy;
/**
*
*/
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
*
*/
@ApiModelProperty(value = "更新者")
private String updateBy;
/**
*
*/
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "快递名")
private String expressName;
@ApiModelProperty(value = "发货人-省名称")
private String originProvinceName;
@ApiModelProperty(value = "发货人-市名称")
private String originCityName;
@ApiModelProperty(value = "发货人-区县名称")
private String originCountyName;
@ApiModelProperty(value = "收货人-省名称")
private String destinationProvinceName;
@ApiModelProperty(value = "收货人-市名称")
private String destinationCityName;
@ApiModelProperty(value = "收货人-区县名称")
private String destinationCountyName;
@ApiModelProperty(value = "订单明细")
private List<Detail> orderDetails;
@ApiModel
@Data
public static class Detail {
/**
* ID
*/
@ApiModelProperty(value = "订单明细ID")
private Long id;
/**
* ID
*/
@ApiModelProperty(value = "订单ID")
private Long storeOrderId;
/**
* ID
*/
@ApiModelProperty(value = "商品颜色尺码ID")
private Long storeProdColorSizeId;
/**
* ID
*/
@ApiModelProperty(value = "商品ID")
private Long storeProdId;
/**
* [10: 11: 12: 13: 14: 21: 22: 23: 24:]
*/
@ApiModelProperty(value = "订单明细状态(同订单状态)[10:已取消 11:待付款 12:待发货 13:已发货 14:已完成 21:售后中 22:售后拒绝 23:平台介入 24:售后完成]")
private Integer detailStatus;
/**
* [1: 2: 3:]
*/
@ApiModelProperty(value = "支付状态[1:初始 2:支付中 3:已支付]")
private Integer payStatus;
/**
* ID
*/
@ApiModelProperty(value = "物流ID")
private Long expressId;
/**
* [1: 2:]
*/
@ApiModelProperty(value = "物流类型[1:平台物流 2:档口物流]")
private Integer expressType;
/**
* [1: 2: 3: 4: 5: 6: 99:]
*/
@ApiModelProperty(value = "物流状态[1:初始 2:下单中 3:已下单 4:取消中 5:已揽件 6:拦截中 99:已结束]")
private Integer expressStatus;
/**
*
*/
@ApiModelProperty(value = "物流请求单号")
private String expressReqNo;
/**
* /使,
*/
@ApiModelProperty(value = "物流运单号(快递单号),档口/用户自己填写时可能存在多个,使用“,”分割")
private String expressWaybillNo;
/**
*
*/
@ApiModelProperty(value = "商品单价")
private BigDecimal goodsPrice;
/**
*
*/
@ApiModelProperty(value = "商品数量")
private Integer goodsQuantity;
/**
* *
*/
@ApiModelProperty(value = "商品金额")
private BigDecimal goodsAmount;
/**
*
*/
@ApiModelProperty(value = "快递费")
private BigDecimal expressFee;
/**
* +
*/
@ApiModelProperty(value = "总金额")
private BigDecimal totalAmount;
/**
* -
*/
@ApiModelProperty(value = "实际总金额")
private BigDecimal realTotalAmount;
/**
* 退ID
*/
@ApiModelProperty(value = "退货原订单明细ID")
private Long refundOrderDetailId;
/**
* 退
*/
@ApiModelProperty(value = "退货原因")
private Integer refundReasonCode;
/**
* 退
*/
@ApiModelProperty(value = "退货拒绝原因")
private String refundRejectReason;
/**
* 0 2
*/
@ApiModelProperty(value = "删除标志0代表存在 2代表删除")
private String delFlag;
/**
*
*/
@ApiModelProperty(value = "创建者")
private String createBy;
/**
*
*/
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
*
*/
@ApiModelProperty(value = "更新者")
private String updateBy;
/**
*
*/
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "档口商品名称")
private String prodName;
@ApiModelProperty(value = "商品货号")
private String prodArtNum;
@ApiModelProperty(value = "商品标题")
private String prodTitle;
@ApiModelProperty(value = "档口颜色ID")
private Long storeColorId;
@ApiModelProperty(value = "颜色名称")
private String colorName;
@ApiModelProperty(value = "商品尺码")
private Integer size;
@ApiModelProperty(value = "档口商品文件")
private List<StoreProdFileVO> fileList;
}
@Data
@ApiModel(value = "档口商品文件")
public static class StoreProdFileVO {
@ApiModelProperty(value = "文件名称")
private String fileName;
@ApiModelProperty(value = "文件路径")
private String fileUrl;
@ApiModelProperty(value = "文件大小")
private BigDecimal fileSize;
@ApiModelProperty(value = "文件类型 1商品主图 2商品主图视频 3下载图片包")
private Integer fileType;
@ApiModelProperty(value = "排序")
private Integer orderNum;
}
}

View File

@ -15,7 +15,7 @@ public class StoreOrderAddResult {
/**
*
*/
private StoreOrderInfo orderInfo;
private StoreOrderExt orderExt;
/**
*
*/

View File

@ -1,9 +1,12 @@
package com.ruoyi.xkt.dto.order;
import com.ruoyi.xkt.dto.storeProductFile.StoreProdFileResDTO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
/**
* @author liangyq
* @date 2025-04-02 22:39
@ -13,4 +16,17 @@ import lombok.ToString;
@ToString(callSuper = true)
public class StoreOrderDetailInfoDTO extends StoreOrderDetailDTO {
private String prodName;
private String prodArtNum;
private String prodTitle;
private Long storeColorId;
private String colorName;
private Integer size;
private List<StoreProdFileResDTO> fileList;
}

View File

@ -15,7 +15,7 @@ import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StoreOrderInfo {
public class StoreOrderExt {
private StoreOrder order;

View File

@ -15,5 +15,19 @@ import java.util.List;
@ToString(callSuper = true)
public class StoreOrderInfoDTO extends StoreOrderDTO {
private List<StoreOrderDetailInfoDTO> detailList;
private String expressName;
private String originProvinceName;
private String originCityName;
private String originCountyName;
private String destinationProvinceName;
private String destinationCityName;
private String destinationCountyName;
private List<StoreOrderDetailInfoDTO> orderDetails;
}

View File

@ -11,7 +11,7 @@ import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class StoreOrderUpdateDTO extends StoreOrderAddDTO{
public class StoreOrderUpdateDTO extends StoreOrderAddDTO {
/**
* ID
*/

View File

@ -1,6 +1,6 @@
package com.ruoyi.xkt.manager;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.EPayChannel;
import com.ruoyi.xkt.enums.EPayPage;
@ -23,6 +23,6 @@ public interface PaymentManager {
* @param payFrom
* @return ///&
*/
String payOrder(StoreOrderInfo order, EPayPage payFrom);
String payOrder(StoreOrderExt order, EPayPage payFrom);
}

View File

@ -8,7 +8,7 @@ import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.xkt.dto.finance.AlipayReqDTO;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.EPayChannel;
import com.ruoyi.xkt.enums.EPayPage;
import com.ruoyi.xkt.enums.EPayStatus;
@ -77,16 +77,16 @@ public class AliPaymentMangerImpl implements PaymentManager {
}
@Override
public String payOrder(StoreOrderInfo orderInfo, EPayPage payFrom) {
Assert.notNull(orderInfo);
public String payOrder(StoreOrderExt orderExt, EPayPage payFrom) {
Assert.notNull(orderExt);
Assert.notNull(payFrom);
if (!EPayStatus.PAYING.getValue().equals(orderInfo.getOrder().getPayStatus())) {
throw new ServiceException("订单[" + orderInfo.getOrder().getOrderNo() + "]支付状态异常");
if (!EPayStatus.PAYING.getValue().equals(orderExt.getOrder().getPayStatus())) {
throw new ServiceException("订单[" + orderExt.getOrder().getOrderNo() + "]支付状态异常");
}
AlipayReqDTO reqDTO = new AlipayReqDTO();
reqDTO.setOutTradeNo(orderInfo.getOrder().getOrderNo());
reqDTO.setTotalAmount(orderInfo.getOrder().getTotalAmount().toPlainString());
reqDTO.setSubject("代发订单" + orderInfo.getOrder().getOrderNo());
reqDTO.setOutTradeNo(orderExt.getOrder().getOrderNo());
reqDTO.setTotalAmount(orderExt.getOrder().getTotalAmount().toPlainString());
reqDTO.setSubject("代发订单" + orderExt.getOrder().getOrderNo());
reqDTO.setProductCode(PAY_PRODUCT_CODE); //这个是固定的
String reqStr = JSON.toJSONString(reqDTO);
AlipayClient alipayClient = new DefaultAlipayClient(gatewayUrl, appId, privateKey, DEFAULT_FORMAT, charset,

View File

@ -3,6 +3,7 @@ package com.ruoyi.xkt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.xkt.domain.StoreColor;
import com.ruoyi.xkt.dto.storeColor.StoreColorDTO;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -12,6 +13,7 @@ import java.util.List;
* @author ruoyi
* @date 2025-03-26
*/
@Repository
public interface StoreColorMapper extends BaseMapper<StoreColor> {
/**
*

View File

@ -6,6 +6,7 @@ import com.ruoyi.xkt.dto.storeProductFile.StoreProdFilePicSpaceResDTO;
import com.ruoyi.xkt.dto.storeProductFile.StoreProdFileResDTO;
import com.ruoyi.xkt.dto.storeProductFile.StoreProdMainPicDTO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -15,6 +16,7 @@ import java.util.List;
* @author ruoyi
* @date 2025-03-26
*/
@Repository
public interface StoreProductFileMapper extends BaseMapper<StoreProductFile> {
/**
*

View File

@ -1,8 +1,13 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.domain.Express;
import com.ruoyi.xkt.domain.ExpressFeeConfig;
import com.ruoyi.xkt.domain.ExpressRegion;
import com.ruoyi.xkt.dto.express.ExpressContactDTO;
import java.util.Collection;
import java.util.List;
/**
* @author liangyq
* @date 2025-04-03 13:35
@ -16,6 +21,14 @@ public interface IExpressService {
*/
void checkExpress(Long expressId);
/**
*
*
* @param expressId
* @return
*/
Express getById(Long expressId);
/**
*
*
@ -34,4 +47,12 @@ public interface IExpressService {
* @return
*/
ExpressContactDTO getStoreContact(Long storeId);
/**
*
*
* @param regionCodes
* @return
*/
List<ExpressRegion> listRegionByCode(Collection<String> regionCodes);
}

View File

@ -1,7 +1,7 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.dto.finance.FinanceBillInfo;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.EPayChannel;
/**
@ -12,10 +12,10 @@ public interface IFinanceBillService {
/**
*
*
* @param orderInfo
* @param orderExt
* @param payId
* @param payChannel
* @return
*/
FinanceBillInfo createCollectionBillAfterOrderPaid(StoreOrderInfo orderInfo, Long payId, EPayChannel payChannel);
FinanceBillInfo createCollectionBillAfterOrderPaid(StoreOrderExt orderExt, Long payId, EPayChannel payChannel);
}

View File

@ -1,10 +1,7 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.domain.StoreOrder;
import com.ruoyi.xkt.dto.order.StoreOrderAddDTO;
import com.ruoyi.xkt.dto.order.StoreOrderAddResult;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderUpdateDTO;
import com.ruoyi.xkt.dto.order.*;
import com.ruoyi.xkt.enums.EPayChannel;
import com.ruoyi.xkt.enums.EPayPage;
@ -33,7 +30,7 @@ public interface IStoreOrderService {
* @param storeOrderUpdateDTO
* @return
*/
StoreOrderInfo modifyOrder(StoreOrderUpdateDTO storeOrderUpdateDTO);
StoreOrderExt modifyOrder(StoreOrderUpdateDTO storeOrderUpdateDTO);
/**
*
@ -43,12 +40,20 @@ public interface IStoreOrderService {
*/
StoreOrder getByOrderNo(String orderNo);
/**
*
*
* @param storeOrderId
* @return
*/
StoreOrderInfoDTO getInfo(Long storeOrderId);
/**
*
*
* @param storeOrderId
*/
StoreOrderInfo preparePayOrder(Long storeOrderId);
StoreOrderExt preparePayOrder(Long storeOrderId);
/**
*
@ -59,5 +64,5 @@ public interface IStoreOrderService {
* @param realTotalAmount
* @return
*/
StoreOrderInfo paySuccess(Long storeOrderId, BigDecimal totalAmount, BigDecimal realTotalAmount);
StoreOrderExt paySuccess(Long storeOrderId, BigDecimal totalAmount, BigDecimal realTotalAmount);
}

View File

@ -3,7 +3,7 @@ package com.ruoyi.xkt.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.xkt.domain.AlipayCallback;
import com.ruoyi.xkt.domain.StoreOrder;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.EPayChannel;
import com.ruoyi.xkt.enums.EProcessStatus;
import com.ruoyi.xkt.mapper.AlipayCallbackMapper;
@ -53,9 +53,9 @@ public class AlipayCallbackServiceImpl implements IAlipayCallbackService {
//更新订单状态
StoreOrder order = storeOrderService.getByOrderNo(info.getOutTradeNo());
Assert.notNull(order);
StoreOrderInfo orderInfo = storeOrderService.paySuccess(order.getId(), info.getTotalAmount(),
StoreOrderExt orderExt = storeOrderService.paySuccess(order.getId(), info.getTotalAmount(),
info.getReceiptAmount());
//创建收款单
financeBillService.createCollectionBillAfterOrderPaid(orderInfo, info.getId(), EPayChannel.ALI_PAY);
financeBillService.createCollectionBillAfterOrderPaid(orderExt, info.getId(), EPayChannel.ALI_PAY);
}
}

View File

@ -1,23 +1,24 @@
package com.ruoyi.xkt.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.xkt.domain.Express;
import com.ruoyi.xkt.domain.ExpressFeeConfig;
import com.ruoyi.xkt.domain.ExpressRegion;
import com.ruoyi.xkt.domain.Store;
import com.ruoyi.xkt.dto.express.ExpressContactDTO;
import com.ruoyi.xkt.mapper.ExpressFeeConfigMapper;
import com.ruoyi.xkt.mapper.ExpressMapper;
import com.ruoyi.xkt.mapper.StoreMapper;
import com.ruoyi.xkt.mapper.StoreOrderExpressTrackMapper;
import com.ruoyi.xkt.mapper.*;
import com.ruoyi.xkt.service.IExpressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -42,6 +43,8 @@ public class ExpressServiceImpl implements IExpressService {
@Autowired
private StoreOrderExpressTrackMapper storeOrderExpressTrackMapper;
@Autowired
private ExpressRegionMapper expressRegionMapper;
@Autowired
private StoreMapper storeMapper;
@Override
@ -52,6 +55,11 @@ public class ExpressServiceImpl implements IExpressService {
Assert.isTrue(express.getSystemDeliverAccess(), "快递不可用");
}
@Override
public Express getById(Long expressId) {
return expressMapper.selectById(expressId);
}
@Override
public ExpressFeeConfig getExpressFeeConfig(Long expressId, String provinceCode, String cityCode,
String countyCode) {
@ -60,8 +68,8 @@ public class ExpressServiceImpl implements IExpressService {
Assert.notEmpty(cityCode);
Assert.notEmpty(countyCode);
Map<String, ExpressFeeConfig> map = expressFeeConfigMapper.selectList(Wrappers.lambdaQuery(ExpressFeeConfig.class)
.eq(ExpressFeeConfig::getExpressId, expressId)
.in(ExpressFeeConfig::getRegionCode, Arrays.asList(provinceCode, cityCode, countyCode)))
.eq(ExpressFeeConfig::getExpressId, expressId)
.in(ExpressFeeConfig::getRegionCode, Arrays.asList(provinceCode, cityCode, countyCode)))
.stream()
//过滤掉已被删除的配置
.filter(BeanValidators::exists)
@ -98,4 +106,13 @@ public class ExpressServiceImpl implements IExpressService {
expressContactDTO.setContactPhoneNumber(store.getContactPhone());
return expressContactDTO;
}
@Override
public List<ExpressRegion> listRegionByCode(Collection<String> regionCodes) {
if (CollUtil.isEmpty(regionCodes)) {
return ListUtil.empty();
}
return expressRegionMapper.selectList(Wrappers.lambdaQuery(ExpressRegion.class)
.in(ExpressRegion::getRegionCode, regionCodes));
}
}

View File

@ -7,7 +7,7 @@ import com.ruoyi.xkt.domain.FinanceBillDetail;
import com.ruoyi.xkt.domain.StoreOrderDetail;
import com.ruoyi.xkt.dto.finance.FinanceBillInfo;
import com.ruoyi.xkt.dto.finance.TransInfo;
import com.ruoyi.xkt.dto.order.StoreOrderInfo;
import com.ruoyi.xkt.dto.order.StoreOrderExt;
import com.ruoyi.xkt.enums.*;
import com.ruoyi.xkt.mapper.FinanceBillDetailMapper;
import com.ruoyi.xkt.mapper.FinanceBillMapper;
@ -41,9 +41,9 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
@Transactional
@Override
public FinanceBillInfo createCollectionBillAfterOrderPaid(StoreOrderInfo orderInfo, Long payId,
public FinanceBillInfo createCollectionBillAfterOrderPaid(StoreOrderExt orderExt, Long payId,
EPayChannel payChannel) {
Assert.notNull(orderInfo);
Assert.notNull(orderExt);
Assert.notNull(payId);
Assert.notNull(payChannel);
//获取平台内部账户并加锁
@ -55,19 +55,19 @@ public class FinanceBillServiceImpl implements IFinanceBillService {
bill.setSrcType(EFinBillSrcType.STORE_ORDER_PAID.getValue());
bill.setSrcId(payId);
bill.setRelType(EFinBillRelType.STORE_ORDER.getValue());
bill.setRelId(orderInfo.getOrder().getId());
bill.setRelId(orderExt.getOrder().getId());
//支付渠道+回调ID构成业务唯一键防止重复创建收款单
String businessUniqueKey = payChannel.getPrefix() + payId;
bill.setBusinessUniqueKey(businessUniqueKey);
bill.setInputInternalAccountId(Constants.PLATFORM_INTERNAL_ACCOUNT_ID);
bill.setInputExternalAccountId(payChannel.getPlatformExternalAccountId());
bill.setBusinessAmount(orderInfo.getOrder().getTotalAmount());
bill.setTransAmount(orderInfo.getOrder().getRealTotalAmount());
bill.setBusinessAmount(orderExt.getOrder().getTotalAmount());
bill.setTransAmount(orderExt.getOrder().getRealTotalAmount());
bill.setVersion(0L);
bill.setDelFlag(Constants.UNDELETED);
financeBillMapper.insert(bill);
List<FinanceBillDetail> billDetails = new ArrayList<>(orderInfo.getOrderDetails().size());
for (StoreOrderDetail orderDetail : orderInfo.getOrderDetails()) {
List<FinanceBillDetail> billDetails = new ArrayList<>(orderExt.getOrderDetails().size());
for (StoreOrderDetail orderDetail : orderExt.getOrderDetails()) {
FinanceBillDetail billDetail = new FinanceBillDetail();
billDetail.setFinanceBillId(bill.getId());
billDetail.setRelType(EFinBillDetailRelType.STORE_ORDER_DETAIL.getValue());

View File

@ -1,5 +1,6 @@
package com.ruoyi.xkt.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -47,6 +49,10 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
@Autowired
private StoreProductColorPriceMapper storeProductColorPriceMapper;
@Autowired
private StoreColorMapper storeColorMapper;
@Autowired
private StoreProductFileMapper storeProductFileMapper;
@Autowired
private IExpressService expressService;
@Autowired
private IOperationRecordService operationRecordService;
@ -165,19 +171,19 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
//操作记录
addOperationRecords(orderId, EOrderAction.INSERT, orderDetailIdList, EOrderAction.INSERT, orderUserId,
new Date());
StoreOrderInfo orderInfo = new StoreOrderInfo(order, orderDetailList);
StoreOrderExt orderExt = new StoreOrderExt(order, orderDetailList);
String rtnStr = null;
if (beginPay) {
//发起支付
PaymentManager paymentManager = getPaymentManager(payChannel);
rtnStr = paymentManager.payOrder(orderInfo, payPage);
rtnStr = paymentManager.payOrder(orderExt, payPage);
}
return new StoreOrderAddResult(orderInfo, rtnStr);
return new StoreOrderAddResult(orderExt, rtnStr);
}
@Transactional
@Override
public StoreOrderInfo modifyOrder(StoreOrderUpdateDTO storeOrderUpdateDTO) {
public StoreOrderExt modifyOrder(StoreOrderUpdateDTO storeOrderUpdateDTO) {
//原订单
StoreOrder order = storeOrderMapper.selectById(storeOrderUpdateDTO.getId());
if (!BeanValidators.exists(order)) {
@ -291,7 +297,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
//操作记录
addOperationRecords(orderId, EOrderAction.UPDATE, orderDetailIdList, EOrderAction.INSERT, orderUserId,
new Date());
return new StoreOrderInfo(order, orderDetailList);
return new StoreOrderExt(order, orderDetailList);
}
@Override
@ -301,9 +307,68 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
.eq(StoreOrder::getOrderNo, orderNo));
}
@Override
public StoreOrderInfoDTO getInfo(Long storeOrderId) {
StoreOrder order = storeOrderMapper.selectById(storeOrderId);
if (order == null) {
return null;
}
List<StoreOrderDetail> details = storeOrderDetailMapper.selectList(Wrappers.lambdaQuery(StoreOrderDetail.class)
.eq(StoreOrderDetail::getStoreOrderId, storeOrderId)
.eq(SimpleEntity::getDelFlag, Constants.UNDELETED));
StoreOrderInfoDTO orderInfo = BeanUtil.toBean(order, StoreOrderInfoDTO.class);
List<StoreOrderDetailInfoDTO> detailInfos = BeanUtil.copyToList(details,
StoreOrderDetailInfoDTO.class);
orderInfo.setOrderDetails(detailInfos);
//物流信息
Express express = expressService.getById(order.getExpressId());
orderInfo.setExpressName(Optional.ofNullable(express).map(Express::getExpressName).orElse(null));
Map<String, String> regionNameMap = expressService.listRegionByCode(Arrays
.asList(order.getDestinationProvinceCode(), order.getDestinationCityCode(),
order.getDestinationCountyCode(), order.getOriginProvinceCode(),
order.getOriginCityCode(), order.getOriginCountyCode()))
.stream()
.collect(Collectors.toMap(ExpressRegion::getRegionCode, ExpressRegion::getRegionName));
orderInfo.setDestinationProvinceName(regionNameMap.get(orderInfo.getDestinationProvinceCode()));
orderInfo.setDestinationCityName(regionNameMap.get(orderInfo.getDestinationCityCode()));
orderInfo.setDestinationCountyName(regionNameMap.get(orderInfo.getDestinationCountyCode()));
orderInfo.setOriginProvinceName(regionNameMap.get(orderInfo.getOriginProvinceCode()));
orderInfo.setOriginCityName(regionNameMap.get(orderInfo.getOriginCityCode()));
orderInfo.setOriginCountyName(regionNameMap.get(orderInfo.getOriginCountyCode()));
//商品信息
Set<Long> spcsIds = detailInfos.stream().map(StoreOrderDetailDTO::getStoreProdColorSizeId)
.collect(Collectors.toSet());
List<StoreProductColorSize> spcsList = storeProductColorSizeMapper.selectByIds(spcsIds);
Map<Long, StoreProductColorSize> spcsMap = spcsList.stream()
.collect(Collectors.toMap(StoreProductColorSize::getId, Function.identity()));
Set<Long> scIds = spcsList.stream().map(StoreProductColorSize::getStoreColorId).collect(Collectors.toSet());
Map<Long, StoreColor> scMap = storeColorMapper.selectByIds(scIds).stream()
.collect(Collectors.toMap(StoreColor::getId, Function.identity()));
Set<Long> pIds = spcsList.stream().map(StoreProductColorSize::getStoreProdId).collect(Collectors.toSet());
Map<Long, StoreProduct> storeProductMap = storeProductMapper.selectByIds(pIds).stream()
.collect(Collectors.toMap(StoreProduct::getId, Function.identity()));
for (StoreOrderDetailInfoDTO detailInfo : detailInfos) {
StoreProductColorSize spcs = spcsMap.get(detailInfo.getStoreProdColorSizeId());
if (spcs != null) {
detailInfo.setSize(spcs.getSize());
detailInfo.setStoreColorId(spcs.getStoreColorId());
detailInfo.setColorName(Optional.ofNullable(scMap.get(spcs.getStoreColorId()))
.map(StoreColor::getColorName).orElse(null));
StoreProduct sp = storeProductMap.get(spcs.getStoreProdId());
if (sp != null) {
detailInfo.setProdName(sp.getProdName());
detailInfo.setProdArtNum(sp.getProdArtNum());
detailInfo.setProdTitle(sp.getProdTitle());
}
detailInfo.setFileList(storeProductFileMapper.selectListByStoreProdId(spcs.getStoreProdId()));
}
}
return orderInfo;
}
@Transactional
@Override
public StoreOrderInfo preparePayOrder(Long storeOrderId) {
public StoreOrderExt preparePayOrder(Long storeOrderId) {
Assert.notNull(storeOrderId);
StoreOrder order = storeOrderMapper.selectById(storeOrderId);
Assert.isTrue(EOrderType.SALES_ORDER.getValue().equals(order.getOrderType()),
@ -327,12 +392,12 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG);
}
}
return new StoreOrderInfo(order, orderDetails);
return new StoreOrderExt(order, orderDetails);
}
@Transactional
@Override
public StoreOrderInfo paySuccess(Long storeOrderId, BigDecimal totalAmount, BigDecimal realTotalAmount) {
public StoreOrderExt paySuccess(Long storeOrderId, BigDecimal totalAmount, BigDecimal realTotalAmount) {
Assert.notNull(storeOrderId);
StoreOrder order = storeOrderMapper.selectById(storeOrderId);
Assert.isTrue(EOrderType.SALES_ORDER.getValue().equals(order.getOrderType()),
@ -379,7 +444,7 @@ public class StoreOrderServiceImpl implements IStoreOrderService {
//操作记录
addOperationRecords(storeOrderId, EOrderAction.PAY, orderDetailIdList, EOrderAction.PAY, null,
new Date());
return new StoreOrderInfo(order, orderDetails);
return new StoreOrderExt(order, orderDetails);
}
private void checkPreparePayStatus(Integer payStatus) {