拼团 订单

This commit is contained in:
2025-12-16 18:06:04 +08:00
parent 48f368c1b1
commit 01ca38079b
38 changed files with 1485 additions and 116 deletions

View File

@@ -0,0 +1,70 @@
package com.czg.controller.admin;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.log.annotation.OperationLog;
import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.service.GbOrderService;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 拼团商品
*
* @author ww
*/
@RestController
@RequestMapping("/admin/gbOrder")
public class GbOrderController {
@Resource
private GbOrderService orderService;
/**
* 拼团商品:订单列表
*/
@GetMapping("page")
@SaAdminCheckPermission(parentName = "拼团商品", value = "ware:order:list", name = "拼团商品-订单列表")
public CzgResult<Page<GbOrderDetailVO>> getGbOrderPage(GbOrderQueryParam param) {
if (param.getShopId() == null) {
param.setShopId(StpKit.USER.getShopId());
}
Page<GbOrderDetailVO> page = orderService.getGbOrderPage(param);
return CzgResult.success(page);
}
/**
* 拼团商品:核销
*
* @param verifyCode 核销码
*/
@PostMapping("checkout")
@OperationLog("拼团商品-核销")
@SaAdminCheckPermission(parentName = "拼团商品", value = "ware:order:checkout", name = "拼团商品-核销")
public CzgResult<Boolean> checkout(@RequestBody String verifyCode) {
return CzgResult.success(orderService.checkout(verifyCode, StpKit.USER.getShopId()));
}
/**
* 退单/同意退单
*/
@PostMapping("/agreeRefund")
public CzgResult<Boolean> agreeRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(orderService.agreeRefund(param, StpKit.USER.getShopId()));
}
/**
* 驳回退单
*/
@PostMapping("/rejectRefund")
public CzgResult<Boolean> rejectRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(orderService.cancelRefund(param, null, StpKit.USER.getShopId()));
}
}

View File

@@ -6,7 +6,7 @@ import com.czg.log.annotation.OperationLog;
import com.czg.market.dto.MkPointsGoodsRecordDTO; import com.czg.market.dto.MkPointsGoodsRecordDTO;
import com.czg.market.dto.MkPointsGoodsRecordQueryDTO; import com.czg.market.dto.MkPointsGoodsRecordQueryDTO;
import com.czg.market.service.MkPointsGoodsRecordService; import com.czg.market.service.MkPointsGoodsRecordService;
import com.czg.order.dto.PointGoodsRefundDTO; import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.service.PointsGoodPayService; import com.czg.order.service.PointsGoodPayService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@@ -68,7 +68,7 @@ public class PointsGoodsRecordController {
* 退单/同意退单 * 退单/同意退单
*/ */
@PostMapping("/agreeRefund") @PostMapping("/agreeRefund")
public CzgResult<Boolean> agreeRefund(@RequestBody @Validated PointGoodsRefundDTO param) { public CzgResult<Boolean> agreeRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(goodPayService.agreeRefund(param, StpKit.USER.getShopId())); return CzgResult.success(goodPayService.agreeRefund(param, StpKit.USER.getShopId()));
} }
@@ -76,7 +76,7 @@ public class PointsGoodsRecordController {
* 驳回退单 * 驳回退单
*/ */
@PostMapping("/rejectRefund") @PostMapping("/rejectRefund")
public CzgResult<Boolean> rejectRefund(@RequestBody @Validated PointGoodsRefundDTO param) { public CzgResult<Boolean> rejectRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(goodPayService.cancelRefund(param, null, StpKit.USER.getShopId())); return CzgResult.success(goodPayService.cancelRefund(param, null, StpKit.USER.getShopId()));
} }

View File

@@ -0,0 +1,121 @@
package com.czg.controller.user;
import com.czg.market.dto.GbWareQueryParamDTO;
import com.czg.market.entity.GbWare;
import com.czg.market.entity.MkPointsGoodsRecord;
import com.czg.market.service.GbWareService;
import com.czg.market.service.MkPointsGoodsRecordService;
import com.czg.market.service.MkPointsGoodsService;
import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.dto.GroupJoinDTO;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.service.GbOrderService;
import com.czg.order.service.PointsGoodPayService;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.order.vo.GbWareVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.ServletUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 用户拼团
*
* @author ww
*/
@RestController
@RequestMapping("/user/gbOrder")
public class UGbOrderController {
@Resource
private GbOrderService orderService;
@Resource
private GbWareService wareService;
/**
* 商品列表
*/
@GetMapping("/ware/page")
public CzgResult<Page<GbWare>> getPointsGoodsSettingPage(@RequestParam(defaultValue = "1", required = false) Integer page,
@RequestParam(defaultValue = "10", required = false) Integer size,
@RequestParam(required = false) String wareName,
@RequestParam(required = false) Integer groupPeopleNum,
Long shopId) {
GbWareQueryParamDTO param = new GbWareQueryParamDTO();
param.setPage(page);
param.setSize(size);
param.setOnlineStatus(1);
param.setWareName(wareName);
param.setGroupPeopleNum(groupPeopleNum);
Page<GbWare> data = wareService.getGbWarePage(param, shopId);
return CzgResult.success(data);
}
/**
* 拼团订单详情
*/
@GetMapping("/ware/detail")
public CzgResult<GbWareVO> getWareDetail(@RequestParam Long shopId, @RequestParam Long wareId) {
return CzgResult.success(orderService.getWareDetail(shopId, wareId));
}
/**
* 我的拼团记录
*/
@GetMapping("/record/page")
public CzgResult<Page<GbOrderDetailVO>> getGoodsRecordPage(@RequestParam GbOrderQueryParam param) {
param.setUserId(StpKit.USER.getLoginIdAsLong());
Page<GbOrderDetailVO> pages = orderService.getGbOrderPage(param);
return CzgResult.success(pages);
}
/**
* 拼团订单详情
*/
@GetMapping("/record/detail")
public CzgResult<GbOrderDetailVO> getGoodsRecordDetail(@RequestParam Long shopId, @RequestParam Long detailId) {
return CzgResult.success(orderService.getGoodsRecordDetail(shopId, detailId));
}
/**
* 生成订单
* 小程序支付
* payType 必填 支付方式aliPay 支付宝wechatPay 微信
* openId 必填
*/
@PostMapping("/exchange")
public CzgResult<Map<String, Object>> exchange(HttpServletRequest request, @Validated @RequestBody GroupJoinDTO param) {
param.setUserId(StpKit.USER.getLoginIdAsLong());
param.setIp(ServletUtil.getClientIP(request));
return orderService.groupJoin(param);
}
/**
* 申请退单
*/
@PostMapping("/applyRefund")
public CzgResult<Boolean> applyRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(orderService.applyRefund(param, StpKit.USER.getLoginIdAsLong()));
}
/**
* 取消退单
*/
@PostMapping("/cancelRefund")
public CzgResult<Boolean> cancelRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(orderService.cancelRefund(param, StpKit.USER.getLoginIdAsLong(), null));
}
}

View File

@@ -3,8 +3,8 @@ package com.czg.controller.user;
import com.czg.market.entity.MkPointsGoodsRecord; import com.czg.market.entity.MkPointsGoodsRecord;
import com.czg.market.service.MkPointsGoodsRecordService; import com.czg.market.service.MkPointsGoodsRecordService;
import com.czg.market.service.MkPointsGoodsService; import com.czg.market.service.MkPointsGoodsService;
import com.czg.order.dto.PointGoodsExchangeDTO; import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.PointGoodsRefundDTO; import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.service.PointsGoodPayService; import com.czg.order.service.PointsGoodPayService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@@ -58,16 +58,17 @@ public class UPointGoodsController {
* openId 必填 * openId 必填
*/ */
@PostMapping("/exchange") @PostMapping("/exchange")
public CzgResult<Map<String, Object>> exchange(HttpServletRequest request, @Validated @RequestBody PointGoodsExchangeDTO param) { public CzgResult<Map<String, Object>> exchange(HttpServletRequest request, @Validated @RequestBody LtPayOtherDTO param) {
param.setUserId(StpKit.USER.getLoginIdAsLong()); param.setUserId(StpKit.USER.getLoginIdAsLong());
return goodPayService.exchange(ServletUtil.getClientIP(request), param); param.setIp(ServletUtil.getClientIP(request));
return goodPayService.exchange(param);
} }
/** /**
* 申请退单 * 申请退单
*/ */
@PostMapping("/applyRefund") @PostMapping("/applyRefund")
public CzgResult<Boolean> applyRefund(@RequestBody @Validated PointGoodsRefundDTO param) { public CzgResult<Boolean> applyRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(goodPayService.applyRefund(param, StpKit.USER.getLoginIdAsLong())); return CzgResult.success(goodPayService.applyRefund(param, StpKit.USER.getLoginIdAsLong()));
} }
@@ -75,7 +76,7 @@ public class UPointGoodsController {
* 取消退单 * 取消退单
*/ */
@PostMapping("/cancelRefund") @PostMapping("/cancelRefund")
public CzgResult<Boolean> cancelRefund(@RequestBody @Validated PointGoodsRefundDTO param) { public CzgResult<Boolean> cancelRefund(@RequestBody @Validated CommonRefundDTO param) {
return CzgResult.success(goodPayService.cancelRefund(param, StpKit.USER.getLoginIdAsLong(), null)); return CzgResult.success(goodPayService.cancelRefund(param, StpKit.USER.getLoginIdAsLong(), null));
} }

View File

@@ -2,14 +2,17 @@ package com.czg.task;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.czg.enums.OrderNoPrefixEnum;
import com.czg.market.service.OrderInfoService; import com.czg.market.service.OrderInfoService;
import com.czg.order.entity.CashierCart; import com.czg.order.entity.CashierCart;
import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment; import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.order.service.CashierCartService; import com.czg.order.service.CashierCartService;
import com.czg.order.service.OrderPaymentService; import com.czg.order.service.OrderPaymentService;
import com.czg.service.order.enums.OrderStatusEnums; import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.service.PayService; import com.czg.service.order.service.PayService;
import com.czg.utils.CzgRandomUtils;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -66,10 +69,10 @@ public class OTimeTask {
List<OrderPayment> list = orderPaymentService.list(QueryWrapper.create() List<OrderPayment> list = orderPaymentService.list(QueryWrapper.create()
.gt(OrderPayment::getUpdateTime, thirdDayAgo) .gt(OrderPayment::getUpdateTime, thirdDayAgo)
.lt(OrderPayment::getUpdateTime, tenMinutesAgo) .lt(OrderPayment::getUpdateTime, tenMinutesAgo)
.eq(OrderPayment::getPayType, "refund") .eq(OrderPayment::getPayType, PaymentPayTypeEnum.REFUND.getValue())
.ne(OrderPayment::getPayStatus, "success")); .ne(OrderPayment::getPayStatus, "success"));
for (OrderPayment payment : list) { for (OrderPayment payment : list) {
String refPayOrderNo = "REP" + IdUtil.getSnowflakeNextId(); String refPayOrderNo = CzgRandomUtils.snowflake(OrderNoPrefixEnum.REP);
payService.unifyRefund(payment, refPayOrderNo); payService.unifyRefund(payment, refPayOrderNo);
} }
} }

View File

@@ -22,7 +22,12 @@ public class GbWareQueryParamDTO extends TimeQueryParam {
/** /**
* 上架状态0下架 1上架 * 上架状态0下架 1上架
*/ */
private Boolean onlineStatus; private Integer onlineStatus;
/**
* 成团人数 最小为1
*/
private Integer groupPeopleNum;
public String getWareName() { public String getWareName() {
return CzgStrUtils.getStrOrNull(wareName); return CzgStrUtils.getStrOrNull(wareName);

View File

@@ -3,18 +3,16 @@ package com.czg.order.dto;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal;
/** /**
* 积分商品退款 * 积分商品退款
* *
* @author ww * @author ww
*/ */
@Data @Data
public class PointGoodsRefundDTO { public class CommonRefundDTO {
/** /**
* 积分商品id * 记录 id
*/ */
@NotNull(message = "记录不能为空") @NotNull(message = "记录不能为空")
private Long recordId; private Long recordId;

View File

@@ -0,0 +1,79 @@
package com.czg.order.dto;
import com.czg.BaseQueryParam;
import com.czg.utils.CzgStrUtils;
import lombok.Data;
/**
* 拼团订单查询参数
*
* @author ww
*/
@Data
public class GbOrderQueryParam extends BaseQueryParam {
private Long shopId;
/**
* 订单状态:待支付/待核销/待成团/已核销/退款中/已退款
*/
private String status;
/**
* 下单 开始时间 yyyy-MM-dd HH:mm:ss
*/
private String orderStartTime;
/**
* 下单 结束时间 yyyy-MM-dd HH:mm:ss
*/
private String orderEndTime;
/**
* 核销 开始时间 yyyy-MM-dd HH:mm:ss
*/
private String verifyStartTime;
/**
* 核销 开始时间 yyyy-MM-dd HH:mm:ss
*/
private String verifyEndTime;
private String phone;
private Long userId;
/**
* 订单号(唯一)
*/
private String orderNo;
/**
* 团单号(关联拼团订单表)
*/
private String groupOrderNo;
public String getOrderStartTime() {
return CzgStrUtils.getStrOrNull(orderStartTime);
}
public String getOrderEndTime() {
return CzgStrUtils.getStrOrNull(orderEndTime);
}
public String getVerifyStartTime() {
return CzgStrUtils.getStrOrNull(verifyStartTime);
}
public String getVerifyEndTime() {
return CzgStrUtils.getStrOrNull(verifyEndTime);
}
public String getOrderNo() {
return CzgStrUtils.getStrOrNull(orderNo);
}
public String getGroupOrderNo() {
return CzgStrUtils.getStrOrNull(groupOrderNo);
}
}

View File

@@ -0,0 +1,16 @@
package com.czg.order.dto;
import lombok.Data;
/**
* 拼团参与 DTO
*
* @author ww
*/
@Data
public class GroupJoinDTO extends LtPayOtherDTO{
/**
* 团单号 为空时 开新团
*/
private String groupOrderNo;
}

View File

@@ -0,0 +1,67 @@
package com.czg.order.dto;
import com.czg.utils.AssertUtil;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
/**
* 小程序支付 其它类型
* payType 必填 支付方式aliPay 支付宝wechatPay 微信
* openId 必填
* @author ww
*/
@Data
public class LtPayOtherDTO {
/**
* 积分商品id/团购商品id
*/
@NotNull(message = "需要购买的商品不能为空")
private Long paramId;
/**
* 店铺Id
*/
@NotNull(message = "未指定店铺")
private Long shopId;
/**
* 兑换数量
*/
@NotNull(message = "兑换数量不能为空")
private int number;
/**
* 支付方式 支付方式aliPay 支付宝wechatPay 微信
*/
private String payType;
/**
* 用户openId
*/
private String openId;
/**
* 用户Id 对应 用户表 userID
*/
private Long userId;
/**
* 用户IP 后端填充
*/
private String ip;
/**
* 兑换价格 后端自己计算填充
*/
private BigDecimal price;
/**
* 对应的记录Id 支付回调向该内容进行回填
* 积分商品为 mk_points_goods_record 主键id
* 团购商品为 gb_order_detail 主键id
*/
private Long recordId;
public void checkPayInfo(){
AssertUtil.isBlank(payType, "支付方式不能为空");
AssertUtil.isBlank(openId, "openId 不能为空");
AssertUtil.isNull(userId, "用户Id 不能为空");
}
}

View File

@@ -11,34 +11,10 @@ import java.math.BigDecimal;
* @author ww * @author ww
*/ */
@Data @Data
public class PointGoodsExchangeDTO { public class PointGoodsExchangeDTO extends LtPayOtherDTO{
/** /**
* 积分商品id * 积分商品id
*/ */
@NotNull(message = "积分商品不能为空") @NotNull(message = "积分商品不能为空")
private Long pointsGoodsId; private Long pointsGoodsId;
/**
* 店铺Id
*/
@NotNull(message = "未指定店铺")
private Long shopId;
/**
* 兑换数量
*/
@NotNull(message = "兑换数量不能为空")
private int number;
/**
* 兑换价格
*/
private BigDecimal price;
/**
* 支付方式 支付方式aliPay 支付宝wechatPay 微信
*/
private String payType;
/**
* 用户openId
*/
private String openId;
private Long userId;
} }

View File

@@ -0,0 +1,108 @@
package com.czg.order.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 拼团订单表 实体类。
*
* @author ww
* @since 2025-12-16
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("gb_order")
public class GbOrder implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 店铺ID
*/
private Long shopId;
/**
* 团单号(唯一)
*/
private String groupOrderNo;
/**
* 商品ID关联gb_ware表
*/
private Long wareId;
/**
* 商品信息
(商品名称,商品描述,商品图片,商品详情图片)
*/
private String wareJson;
/**
* 商品原价
*/
private BigDecimal wareOriginalPrice;
/**
* 商品拼团价
*/
private BigDecimal wareGroupPrice;
/**
* 要求成团人数
*/
private Integer groupPeopleNum;
/**
* 现有人数初始为1即开团人
*/
private Integer currentPeopleNum;
/**
* 拼团结束时间(超时未成团则失败)
*/
private LocalDateTime groupEndTime;
/**
* 创建时间/成团时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* ing 进行中 success 成功 fail 失败
*/
private String status;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 取消原因(默认空,取消拼团时填充)如:商家下架
*/
private String cancelReason;
}

View File

@@ -0,0 +1,120 @@
package com.czg.order.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 拼团订单详情表 实体类。
*
* @author ww
* @since 2025-12-16
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("gb_order_detail")
public class GbOrderDetail implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 店铺ID
*/
private Long shopId;
/**
* 商品ID
*/
private Long wareId;
/**
* 团单号(关联拼团订单表)
*/
private String groupOrderNo;
/**
* 用户ID下单用户
*/
private Long userId;
/**
* 订单号(唯一)
*/
private String orderNo;
/**
* 支付单号
*/
private Long payOrderId;
/**
* 支付金额(单位:元)
*/
private BigDecimal payAmount;
/**
* 支付时间未支付则为NULL
*/
private LocalDateTime payTime;
/**
* 订单状态:待支付/待核销/待成团/已核销/退款中/已退款
*/
private String status;
/**
* 核销码(唯一,核销时使用)
*/
private String verifyCode;
/**
* 核销时间未核销则为NULL
*/
private LocalDateTime verifyTime;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 退款时间/取消时间
*/
private LocalDateTime cancelTime;
/**
* 取消原因(默认空,取消/退款时填充)
*/
private String cancelReason;
/**
* 删除标记 0-未删 1-已删
*/
private Integer isDel;
}

View File

@@ -59,6 +59,7 @@ public class OrderPayment implements Serializable {
/** /**
* 支付方式order,refund, memberIn,memberRefund, free * 支付方式order,refund, memberIn,memberRefund, free
* {@link com.czg.order.enums.PaymentPayTypeEnum}
*/ */
private String payType; private String payType;

View File

@@ -0,0 +1,35 @@
package com.czg.order.enums;
import lombok.Getter;
/**
* 支付类型枚举
* tb_order_payment
*
* @author ww
*/
@Getter
public enum PaymentPayTypeEnum {
ORDER("order", "订单支付"),
FREE("free", "霸王餐"),
MEMBER_IN("memberIn", "会员充值"),
MEMBER_PAY("memberPay", "会员购买开通"),
DISTRIBUTION("distribution", "分销员购买开通"),
DISTRIBUTION_RECHARGE("distributionRecharge", "商家运营余额充值"),
POINT("point", "积分商品购买"),
WARE("ware", "拼团商品"),
REFUND("refund", "订单退款"),
MEMBER_REFUND("memberRefund", "会员充值的退款"),
;
private final String value;
private final String msg;
PaymentPayTypeEnum(String value, String msg) {
this.value = value;
this.msg = msg;
}
}

View File

@@ -0,0 +1,14 @@
package com.czg.order.service;
import com.mybatisflex.core.service.IService;
import com.czg.order.entity.GbOrderDetail;
/**
* 拼团订单详情表 服务层。
*
* @author ww
* @since 2025-12-16
*/
public interface GbOrderDetailService extends IService<GbOrderDetail> {
}

View File

@@ -0,0 +1,50 @@
package com.czg.order.service;
import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.dto.GroupJoinDTO;
import com.czg.order.entity.GbOrder;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.order.vo.GbWareVO;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import java.util.Map;
/**
* 拼团订单表 服务层。
*
* @author ww
* @since 2025-12-16
*/
public interface GbOrderService extends IService<GbOrder> {
//列表 详细列表 detail的
Page<GbOrderDetailVO> getGbOrderPage(GbOrderQueryParam param);
//拼团订单详情
GbOrderDetailVO getGoodsRecordDetail(Long shopId, Long detailId);
//商品详情
GbWareVO getWareDetail(Long shopId, Long wareId);
//成团/参团 支付
CzgResult<Map<String, Object>> groupJoin(GroupJoinDTO param);
//核销
boolean checkout(String verifyCode, Long shopId);
//支付回调 处理成团人数, 如果没团则创团
void payCallBack(Long recordId, Long payOrderId);
//用户申请退款
boolean applyRefund(CommonRefundDTO param, Long userId);
//取消退款
boolean cancelRefund(CommonRefundDTO param, Long userId, Long shopId);
//退款 同意退款/任务过期 自动退款
boolean agreeRefund(CommonRefundDTO param, Long shopId);
}

View File

@@ -1,7 +1,7 @@
package com.czg.order.service; package com.czg.order.service;
import com.czg.order.dto.PointGoodsExchangeDTO; import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.PointGoodsRefundDTO; import com.czg.order.dto.LtPayOtherDTO;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import java.util.Map; import java.util.Map;
@@ -14,16 +14,16 @@ import java.util.Map;
public interface PointsGoodPayService { public interface PointsGoodPayService {
//积分商品兑换 //积分商品兑换
CzgResult<Map<String, Object>> exchange(String ip, PointGoodsExchangeDTO param); CzgResult<Map<String, Object>> exchange(LtPayOtherDTO param);
//用户申请退款 //用户申请退款
boolean applyRefund(PointGoodsRefundDTO param, Long userId); boolean applyRefund(CommonRefundDTO param, Long userId);
//取消退款 //取消退款
boolean cancelRefund(PointGoodsRefundDTO param, Long userId, Long shopId); boolean cancelRefund(CommonRefundDTO param, Long userId, Long shopId);
//同意退款 //同意退款
boolean agreeRefund(PointGoodsRefundDTO param, Long shopId); boolean agreeRefund(CommonRefundDTO param, Long shopId);
//支付回调 进行兑换内容发放 //支付回调 进行兑换内容发放
void payCallBack(Long recordId, Long payOrderId); void payCallBack(Long recordId, Long payOrderId);

View File

@@ -0,0 +1,41 @@
package com.czg.order.vo;
import com.czg.order.entity.GbOrderDetail;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* 拼团订单详情VO
*
* @author ww
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class GbOrderDetailVO extends GbOrderDetail {
/**
* 商品信息
*/
private String wareJson;
/**
* 店铺名称
*/
private String shopName;
/**
* 店铺地址
*/
private String shopAddress;
/**
* 用户名称
*/
private String userName;
/**
* 用户手机号
*/
private String userPhone;
private List<GbOrderUserVO> users;
}

View File

@@ -0,0 +1,19 @@
package com.czg.order.vo;
import lombok.Data;
@Data
public class GbOrderUserVO {
/**
* 用户头像
*/
private String userAvatar;
/**
* 用户手机号
*/
private String userPhone;
/**
* 用户名称
*/
private String userName;
}

View File

@@ -0,0 +1,40 @@
package com.czg.order.vo;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author ww
*/
@Data
public class GbWareOrderVO {
/**
* 用户头像
*/
private String avatar;
/**
* 用户昵称
*/
private String nickName;
/**
* 团单id
*/
private Long groupOrderId;
/**
* 团单编号
*/
private String groupOrderNo;
/**
* 现有人数初始为1即开团人
*/
private Integer currentPeopleNum;
/**
* 拼团结束时间(超时未成团则失败)
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime groupEndTime;
}

View File

@@ -0,0 +1,27 @@
package com.czg.order.vo;
import com.czg.market.entity.GbWare;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* @author ww
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class GbWareVO extends GbWare {
/**
* 可核销门店 店铺名称
*/
private String shopName;
/**
* 可核销门店 店铺地址
*/
private String shopAddress;
/**
* 正在进行的 拼团单
*/
private List<GbWareOrderVO> gbOrderList;
}

View File

@@ -0,0 +1,33 @@
package com.czg.enums;
import lombok.Getter;
/**
* 订单号前缀枚举
*
* @author ww
*/
@Getter
public enum OrderNoPrefixEnum {
//RE 是固定退款前缀 具体功能 往后拼标识
// 积分 point P 标识
// 拼团 group buy GB 或者 G 标识
// 预约 Booking BK 标识
BK("BK", "预约"),
DH("DH", "积分商品兑换单号"),
REP("REP", "积分商品退款"),
GB("GB", "拼团-团单号"),
GBO("GBO", "拼团-订单号"),
REG("REG", "拼团-退单"),
;
private final String value;
private final String msg;
OrderNoPrefixEnum(String value, String msg) {
this.value = value;
this.msg = msg;
}
}

View File

@@ -1,6 +1,8 @@
package com.czg.utils; package com.czg.utils;
import cn.hutool.core.lang.id.NanoId; import cn.hutool.core.lang.id.NanoId;
import cn.hutool.core.util.IdUtil;
import com.czg.enums.OrderNoPrefixEnum;
/** /**
* @author ww * @author ww
@@ -31,6 +33,7 @@ public class CzgRandomUtils {
return NanoId.randomNanoId(null, DEFAULT_ALPHABET, DEFAULT_SIZE); return NanoId.randomNanoId(null, DEFAULT_ALPHABET, DEFAULT_SIZE);
} }
/** /**
* 随机生成指定长度的字符串 * 随机生成指定长度的字符串
* *
@@ -42,15 +45,40 @@ public class CzgRandomUtils {
} }
public static String randomNumber(int length) { /**
* 随机生成指定长度的数字 不带前缀
*
* @param length 订单号长度
* @param isFirstNoZero 是否第一个字符不能为0
* @return 订单号
*/
public static String randomNumber(int length, boolean isFirstNoZero) {
if (isFirstNoZero) {
return NanoId.randomNanoId(null, BASE_NUMBER_NO_ZERO, 1) + NanoId.randomNanoId(null, BASE_NUMBER, length - 1);
}
return NanoId.randomNanoId(null, BASE_NUMBER, length); return NanoId.randomNanoId(null, BASE_NUMBER, length);
} }
public static String randomNumFirstNoZero(int length) { /**
return NanoId.randomNanoId(null, BASE_NUMBER_NO_ZERO, 1) + NanoId.randomNanoId(null, BASE_NUMBER, length - 1); * 随机生成指定长度的数字
*
* @param prefixEnum 订单号前缀枚举
* @param length 订单号长度
* @param isFirstNoZero 是否第一个字符不能为0
* @return 订单号
*/
public static String randomNumber(OrderNoPrefixEnum prefixEnum, int length, boolean isFirstNoZero) {
if (isFirstNoZero) {
return prefixEnum.getValue() + NanoId.randomNanoId(null, BASE_NUMBER_NO_ZERO, 1) + NanoId.randomNanoId(null, BASE_NUMBER, length - 1);
}
return prefixEnum.getValue() + NanoId.randomNanoId(null, BASE_NUMBER, length);
} }
public static void main(String[] args) { public static String snowflake(OrderNoPrefixEnum prefixEnum) {
System.out.println(CzgRandomUtils.randomNumFirstNoZero(20)); return prefixEnum.getValue() + IdUtil.getSnowflakeNextId();
}
public static String snowflake() {
return IdUtil.getSnowflakeNextId() + "";
} }
} }

View File

@@ -8,9 +8,11 @@ import com.czg.account.entity.BkOrderTable;
import com.czg.account.service.BkOrderService; import com.czg.account.service.BkOrderService;
import com.czg.account.vo.BkTableVO; import com.czg.account.vo.BkTableVO;
import com.czg.account.vo.BookingOrderStatisticsVO; import com.czg.account.vo.BookingOrderStatisticsVO;
import com.czg.enums.OrderNoPrefixEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.service.account.mapper.BkOrderMapper; import com.czg.service.account.mapper.BkOrderMapper;
import com.czg.service.account.mapper.BkOrderTableMapper; import com.czg.service.account.mapper.BkOrderTableMapper;
import com.czg.utils.CzgRandomUtils;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@@ -64,7 +66,7 @@ public class BkOrderServiceImpl extends ServiceImpl<BkOrderMapper, BkOrder> impl
tableMapper.deleteByQuery(QueryWrapper.create().eq(BkOrderTable::getBookOrderId, bkOrderEntity.getId())); tableMapper.deleteByQuery(QueryWrapper.create().eq(BkOrderTable::getBookOrderId, bkOrderEntity.getId()));
tableMapper.customInsertBatch(shopId, bkOrderEntity.getId(), bkOrder.getBookingTables()); tableMapper.customInsertBatch(shopId, bkOrderEntity.getId(), bkOrder.getBookingTables());
} else { } else {
bkOrderEntity.setBookingOrderNo("BK" + IdUtil.getSnowflakeNextId()); bkOrderEntity.setBookingOrderNo(CzgRandomUtils.randomNumber(OrderNoPrefixEnum.BK, 12, false));
} }
bkOrderEntity.setStatus("待到店"); bkOrderEntity.setStatus("待到店");

View File

@@ -1,6 +1,7 @@
package com.czg.service.market.service.impl; package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.service.ShopInfoService; import com.czg.account.service.ShopInfoService;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.market.dto.GbWareDTO; import com.czg.market.dto.GbWareDTO;
@@ -32,20 +33,20 @@ public class GbWareServiceImpl extends ServiceImpl<GbWareMapper, GbWare> impleme
public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) { public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) {
Long mainShopId = shopInfoService.getMainIdByShopId(shopId); Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq(GbWare::getShopId, mainShopId) queryWrapper.eq(GbWare::getIsDel, 0)
.eq(GbWare::getIsDel, 0)
.eq(GbWare::getOnlineStatus, param.getOnlineStatus()) .eq(GbWare::getOnlineStatus, param.getOnlineStatus())
.like(GbWare::getWareName, CzgStrUtils.getStrOrNull(param.getWareName())) .eq(GbWare::getGroupPeopleNum, param.getGroupPeopleNum())
.between(GbWare::getCreateTime, param.getStartTime(), param.getEndTime()) .like(GbWare::getWareName, param.getWareName())
.orderBy(GbWare::getCreateTime).desc(); .orderBy(GbWare::getCreateTime).asc();
if (StrUtil.isNotBlank(param.getStartTime()) || StrUtil.isNotBlank(param.getEndTime())) {
queryWrapper.between(GbWare::getCreateTime, param.getStartTime(), param.getEndTime());
}
queryWrapper.and(q -> { queryWrapper.and(q -> {
q.eq(GbWare::getUseShopType, "all").or(q1 -> { q.eq(GbWare::getShopId, shopId).or(q1 -> {
q1.eq(GbWare::getUseShopType, "only").eq(GbWare::getShopId, shopId); q1.eq(GbWare::getUseShopType, "all").eq(GbWare::getShopId, mainShopId);
}).or(q2 -> { }).or(q2 -> {
q2.eq(GbWare::getUseShopType, "custom").and(q3 -> { q2.eq(GbWare::getUseShopType, "custom").and("FIND_IN_SET( " + shopId + ", use_shops ) > 0");
q3.eq(GbWare::getShopId, shopId).or("FIND_IN_SET( " + shopId + ", use_shops ) > 0");
});
}); });
}); });
return page(Page.of(param.getPage(), param.getSize()), queryWrapper); return page(Page.of(param.getPage(), param.getSize()), queryWrapper);

View File

@@ -49,20 +49,17 @@ public class MkLimitTimeDiscountServiceImpl extends ServiceImpl<MkLimitTimeDisco
public Page<MkLimitTimeDiscountDTO> getLimitTimeDiscountPage(TimeQueryParam param, Long shopId) { public Page<MkLimitTimeDiscountDTO> getLimitTimeDiscountPage(TimeQueryParam param, Long shopId) {
Long mainShopId = shopInfoService.getMainIdByShopId(shopId); Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq(MkLimitTimeDiscount::getShopId, mainShopId) queryWrapper.eq(MkLimitTimeDiscount::getIsDel, 0)
.eq(MkLimitTimeDiscount::getIsDel, 0)
.lt(MkLimitTimeDiscount::getValidStartTime, CzgStrUtils.getStrOrNull(param.getStartTime())) .lt(MkLimitTimeDiscount::getValidStartTime, CzgStrUtils.getStrOrNull(param.getStartTime()))
.le(MkLimitTimeDiscount::getValidEndTime, CzgStrUtils.getStrOrNull(param.getEndTime())) .le(MkLimitTimeDiscount::getValidEndTime, CzgStrUtils.getStrOrNull(param.getEndTime()))
.orderBy(MkLimitTimeDiscount::getSort).desc() .orderBy(MkLimitTimeDiscount::getSort).desc()
.orderBy(MkLimitTimeDiscount::getUpdateTime).desc(); .orderBy(MkLimitTimeDiscount::getUpdateTime).desc();
queryWrapper.and(q -> { queryWrapper.and(q -> {
q.eq(MkLimitTimeDiscount::getUseShopType, "all").or(q1 -> { q.eq(MkLimitTimeDiscount::getShopId, shopId).or(q1 -> {
q1.eq(MkLimitTimeDiscount::getUseShopType, "only").eq(MkLimitTimeDiscount::getShopId, shopId); q1.eq(MkLimitTimeDiscount::getUseShopType, "all").eq(MkLimitTimeDiscount::getShopId, mainShopId);
}).or(q2 -> { }).or(q2 -> {
q2.eq(MkLimitTimeDiscount::getUseShopType, "custom").and(q3 -> { q2.eq(MkLimitTimeDiscount::getUseShopType, "custom").and("FIND_IN_SET( " + shopId + ", use_shops ) > 0");
q3.eq(MkLimitTimeDiscount::getShopId, shopId).or("FIND_IN_SET( " + shopId + ", use_shops ) > 0");
});
}); });
}); });
Page<MkLimitTimeDiscountDTO> page = pageAs(PageUtil.buildPage(), queryWrapper, MkLimitTimeDiscountDTO.class); Page<MkLimitTimeDiscountDTO> page = pageAs(PageUtil.buildPage(), queryWrapper, MkLimitTimeDiscountDTO.class);

View File

@@ -0,0 +1,14 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.GbOrderDetail;
/**
* 拼团订单详情表 映射层。
*
* @author ww
* @since 2025-12-16
*/
public interface GbOrderDetailMapper extends BaseMapper<GbOrderDetail> {
}

View File

@@ -0,0 +1,25 @@
package com.czg.service.order.mapper;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.order.vo.GbOrderUserVO;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.GbOrder;
import java.util.List;
/**
* 拼团订单表 映射层。
*
* @author ww
* @since 2025-12-16
*/
public interface GbOrderMapper extends BaseMapper<GbOrder> {
List<GbOrderDetailVO> getGbOrderPage(GbOrderQueryParam param, Long shopId, Long mainShopId);
GbOrderDetailVO getGbOrderDetail(Long shopId, Long detailId);
List<GbOrderUserVO> getGbOrderDetailUsers(Long mainShopId, Long shopId, String groupOrderNo);
}

View File

@@ -2,9 +2,11 @@ package com.czg.service.order.service;
import com.czg.entity.resp.CzgBaseResp; import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp; import com.czg.entity.resp.CzgRefundResp;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.dto.OrderInfoRefundDTO; import com.czg.order.dto.OrderInfoRefundDTO;
import com.czg.order.dto.PointGoodsExchangeDTO; import com.czg.order.dto.PointGoodsExchangeDTO;
import com.czg.order.entity.OrderPayment; import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.service.order.dto.*; import com.czg.service.order.dto.*;
import lombok.NonNull; import lombok.NonNull;
@@ -104,9 +106,15 @@ public interface PayService {
CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long userId); CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long userId);
//-----------------------------------------------------------------积分商品 付款 ---------------------------------------------------------- //-----------------------------------------------------------------积分商品/拼团 付款 ----------------------------------------------------------
CzgResult<Map<String, Object>> ltPayPointsGoods(String ip, PointGoodsExchangeDTO param, Long recordId); /**
*
* @param param 支付参数
* @param payType 暂时只有 POINT 积分 和 WARE 拼团商品
* @param detail 操作描述 如 积分商品购买 / 拼团商品购买
*/
CzgResult<Map<String, Object>> ltPayOther(LtPayOtherDTO param, PaymentPayTypeEnum payType, String detail);
//-----------------------------------------------------------------退款----------------------------------------------------------------- //-----------------------------------------------------------------退款-----------------------------------------------------------------
@@ -130,7 +138,7 @@ public interface PayService {
/** /**
* 统一退款接口 * 统一退款接口
* *
* @param refPayOrderNo 自定义退单号 * @param refPayOrderNo 自定义退单号 {@link com.czg.enums.OrderNoPrefixEnum} + 雪花Id
*/ */
void unifyRefund(Long shopId, Long sourceId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount); void unifyRefund(Long shopId, Long sourceId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);

View File

@@ -70,7 +70,9 @@ public class DistributionPayServiceImpl implements DistributionPayService {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId); ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(isRecharge ? payParam.getShopId() : shopUserInfo.getId()) OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(isRecharge ? payParam.getShopId() : shopUserInfo.getId())
.setPayType(isRecharge ? "distributionRecharge" : "distribution").setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(isRecharge ? payParam.getAmount() : detail.getPayAmount()); .setPayType(isRecharge ? "distributionRecharge" : "distribution")
.setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId())
.setAmount(isRecharge ? payParam.getAmount() : detail.getPayAmount());
orderPaymentService.save(orderPayment); orderPaymentService.save(orderPayment);
InitInfo initInfo = new InitInfo().setConfig(detail); InitInfo initInfo = new InitInfo().setConfig(detail);

View File

@@ -0,0 +1,18 @@
package com.czg.service.order.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.order.entity.GbOrderDetail;
import com.czg.order.service.GbOrderDetailService;
import com.czg.service.order.mapper.GbOrderDetailMapper;
import org.springframework.stereotype.Service;
/**
* 拼团订单详情表 服务层实现。
*
* @author ww
* @since 2025-12-16
*/
@Service
public class GbOrderDetailServiceImpl extends ServiceImpl<GbOrderDetailMapper, GbOrderDetail> implements GbOrderDetailService{
}

View File

@@ -0,0 +1,362 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.enums.OrderNoPrefixEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException;
import com.czg.market.entity.GbWare;
import com.czg.market.entity.MkPointsGoodsRecord;
import com.czg.market.service.GbWareService;
import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.GbOrderQueryParam;
import com.czg.order.dto.GroupJoinDTO;
import com.czg.order.entity.GbOrder;
import com.czg.order.entity.GbOrderDetail;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.order.service.GbOrderDetailService;
import com.czg.order.service.GbOrderService;
import com.czg.order.vo.GbOrderDetailVO;
import com.czg.order.vo.GbOrderUserVO;
import com.czg.order.vo.GbWareOrderVO;
import com.czg.order.vo.GbWareVO;
import com.czg.resp.CzgResult;
import com.czg.service.order.mapper.GbOrderMapper;
import com.czg.service.order.service.PayService;
import com.czg.utils.AssertUtil;
import com.czg.utils.CzgRandomUtils;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 拼团订单表 服务层实现。
*
* @author ww
* @since 2025-12-16
*/
@Slf4j
@Service
public class GbOrderServiceImpl extends ServiceImpl<GbOrderMapper, GbOrder> implements GbOrderService {
@Resource
private GbWareService wareService;
@Resource
private GbOrderDetailService detailService;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
private ShopUserService shopUserService;
@Resource
@Lazy
private PayService payService;
@Override
public Page<GbOrderDetailVO> getGbOrderPage(GbOrderQueryParam param) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(param.getShopId());
PageHelper.startPage(param.getPage(), param.getSize());
List<GbOrderDetailVO> result = mapper.getGbOrderPage(param, param.getShopId(), mainIdByShopId);
return PageUtil.convert(new PageInfo<>(result));
}
@Override
public GbOrderDetailVO getGoodsRecordDetail(Long shopId, Long detailId) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId);
GbOrderDetailVO gbOrderDetail = mapper.getGbOrderDetail(shopId, detailId);
AssertUtil.isNull(gbOrderDetail, "记录不存在");
List<GbOrderUserVO> users = mapper.getGbOrderDetailUsers(mainIdByShopId, shopId, gbOrderDetail.getGroupOrderNo());
gbOrderDetail.setUsers(users);
return gbOrderDetail;
}
@Override
public GbWareVO getWareDetail(Long shopId, Long wareId) {
GbWareVO ware = wareService.getOneAs(query().eq(GbWare::getId, wareId), GbWareVO.class);
AssertUtil.isNull(ware, "商品不存在");
if (ware.getIsDel() || ware.getOnlineStatus() == 0) {
throw new CzgException("商品已下架");
}
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo != null) {
ware.setShopName(shopInfo.getShopName());
ware.setShopAddress(shopInfo.getAddress());
}
List<GbWareOrderVO> orderIng = listAs(query().eq(GbOrder::getId, wareId)
.eq(GbOrder::getShopId, shopId)
.eq(GbOrder::getStatus, "ing")
, GbWareOrderVO.class);
orderIng.forEach(ing -> {
QueryWrapper queryWrapper = QueryWrapper.create();
queryWrapper.eq(GbOrderDetail::getIsDel, 0)
.and(q -> {
q.eq(GbOrderDetail::getStatus, "待成团").or(GbOrderDetail::getStatus).eq("退款中");
})
.orderBy(GbOrderDetail::getPayTime);
queryWrapper.eq(GbOrderDetail::getGroupOrderNo, ing.getGroupOrderNo());
GbOrderDetail detail = detailService.getOne(queryWrapper);
if (detail != null) {
ShopUser userInfo = shopUserService.getUserInfo(detail.getShopId(), detail.getUserId());
if (userInfo != null) {
ing.setAvatar(userInfo.getHeadImg());
ing.setNickName(userInfo.getNickName());
}
}
});
ware.setGbOrderList(orderIng);
return ware;
}
@Override
public CzgResult<Map<String, Object>> groupJoin(GroupJoinDTO param) {
GbWare ware = wareService.getById(param.getParamId());
if (ware == null) {
throw new CzgException("拼团失败,商品不存在");
}
if (ware.getOnlineStatus() == 0) {
throw new CzgException("拼团失败,商品已下架");
}
if (ware.getLimitBuyNum() > param.getNumber()) {
throw new CzgException("拼团失败,该商品每人限购" + ware.getLimitBuyNum() + "");
}
if (StrUtil.isNotBlank(param.getGroupOrderNo())) {
GbOrder order = getOne(query().eq(GbOrder::getGroupOrderNo, param.getGroupOrderNo())
.eq(GbOrder::getShopId, param.getShopId()));
if (order == null || !"ing".equals(order.getStatus())) {
throw new CzgException("拼团失败,该拼团单不存在或已结束");
}
}
param.setPrice(ware.getGroupPrice().multiply(BigDecimal.valueOf(param.getNumber())));
GbOrderDetail record = new GbOrderDetail();
record.setShopId(param.getShopId());
record.setUserId(param.getUserId());
record.setWareId(param.getParamId());
record.setCreateTime(LocalDateTime.now());
record.setPayAmount(param.getPrice());
record.setStatus("待支付");
record.setOrderNo(CzgRandomUtils.randomNumber(OrderNoPrefixEnum.GBO, 12, false));
record.setIsDel(YesNoEnum.YES.value());
detailService.save(record);
CzgResult<Map<String, Object>> result = CzgResult.success();
CzgResult<Map<String, Object>> mapCzgResult = payService.ltPayOther(param, PaymentPayTypeEnum.WARE, "拼团商品购买");
if (200 != mapCzgResult.getCode()) {
return mapCzgResult;
}
Map<String, Object> resultMap = new HashMap<>(2);
resultMap.put("payInfo", mapCzgResult.getData());
resultMap.put("record", record);
result.setData(resultMap);
return result;
}
@Override
public boolean checkout(String verifyCode, Long shopId) {
GbOrderDetail record = detailService.getOne(query()
.eq(GbOrderDetail::getIsDel, YesNoEnum.NO.value())
.eq(GbOrderDetail::getVerifyCode, verifyCode)
.eq(GbOrderDetail::getShopId, shopId));
if (record == null) {
throw new CzgException("核销失败,核销码不存在");
}
if (!"待核销".equals(record.getStatus()) && !"退款中".equals(record.getStatus())) {
throw new CzgException("核销失败,该商品不可核销");
}
boolean success = exists(query().eq(GbOrder::getGroupOrderNo, record.getGroupOrderNo())
.eq(GbOrder::getShopId, shopId)
.eq(GbOrder::getStatus, "success"));
if (!success) {
throw new CzgException("核销失败,请拼团成功后核销");
}
GbOrderDetail upRecord = new GbOrderDetail();
upRecord.setVerifyTime(LocalDateTime.now());
upRecord.setStatus("已完成");
return detailService.update(upRecord, query().eq(GbOrderDetail::getId, record.getId()));
}
@Transactional
@Override
public void payCallBack(Long recordId, Long payOrderId) {
GbOrderDetail record = detailService.getById(recordId);
if (record == null) {
log.error("积分兑换商品发放失败,记录不存在");
return;
}
record.setIsDel(YesNoEnum.NO.value());
record.setPayOrderId(payOrderId);
record.setPayTime(LocalDateTime.now());
record.setVerifyCode(CzgRandomUtils.randomNumber(12, true));
if (StrUtil.isBlank(record.getGroupOrderNo())) {
GbWare ware = wareService.getById(record.getWareId());
if (ware == null || ware.getOnlineStatus() == 0 || ware.getIsDel()) {
CommonRefundDTO refundDTO = new CommonRefundDTO();
refundDTO.setRecordId(recordId);
refundDTO.setOrderNo(record.getOrderNo());
refundDTO.setReason("商品已下架 自动退款。");
agreeRefund(refundDTO, record.getShopId());
return;
}
GbOrder order = new GbOrder();
order.setShopId(record.getShopId());
String groupOrderNo = CzgRandomUtils.randomNumber(OrderNoPrefixEnum.GBO, 12, false);
order.setGroupOrderNo(groupOrderNo);
order.setWareId(record.getWareId());
//(商品名称,商品描述,商品图片,商品详情图片)
JSONObject wareJson = new JSONObject();
wareJson.put("wareName", ware.getWareName());
wareJson.put("wareImgs", ware.getWareImgs());
wareJson.put("wareDetail", ware.getWareDetail());
wareJson.put("wareCommentImgs", ware.getWareCommentImgs());
order.setWareJson(wareJson.toJSONString());
order.setWareGroupPrice(ware.getGroupPrice());
order.setWareOriginalPrice(ware.getOriginalPrice());
order.setGroupPeopleNum(ware.getGroupPeopleNum());
order.setCurrentPeopleNum(1);
order.setGroupEndTime(LocalDateTime.now().plusHours(ware.getGroupTimeoutHour()));
order.setCreateTime(LocalDateTime.now());
order.setStatus("ing");
if (ware.getGroupPeopleNum() == 1) {
order.setStatus("success");
}
save(order);
record.setGroupOrderNo(order.getGroupOrderNo());
if ("success".equals(order.getStatus())) {
record.setStatus("待核销");
}
} else {
GbOrder order = getOne(query().eq(GbOrder::getGroupOrderNo, record.getGroupOrderNo())
.eq(GbOrder::getShopId, record.getShopId()));
order.setCurrentPeopleNum(order.getCurrentPeopleNum() + 1);
if (order.getCurrentPeopleNum().equals(order.getGroupPeopleNum())) {
record.setStatus("待核销");
order.setStatus("success");
order.setGroupEndTime(LocalDateTime.now());
GbOrderDetail upRecord = new GbOrderDetail();
upRecord.setStatus("待核销");
detailService.update(upRecord, query()
.eq(GbOrderDetail::getGroupOrderNo, order.getGroupOrderNo())
.eq(GbOrderDetail::getShopId, order.getShopId())
.eq(GbOrderDetail::getIsDel, YesNoEnum.NO.value())
.eq(GbOrderDetail::getStatus, "待成团")
);
}
updateById(order);
}
detailService.updateById(record);
}
@Override
public boolean applyRefund(CommonRefundDTO param, Long userId) {
GbOrderDetail record = detailService.getOne(query()
.eq(GbOrderDetail::getIsDel, YesNoEnum.NO.value())
.eq(GbOrderDetail::getId, param.getRecordId())
.eq(GbOrderDetail::getUserId, userId));
AssertUtil.isNull(record, "记录不存在");
if (!"待成团".equals(record.getStatus()) && !"待核销".equals(record.getStatus())) {
throw new CzgException("申请失败,该商品不可申请退款");
}
if ("待成团".equals(record.getStatus())) {
return refundAmount(record, "");
}
GbOrderDetail upRecord = new GbOrderDetail();
record.setStatus("退款中");
record.setCancelReason(param.getReason());
record.setCancelTime(LocalDateTime.now());
return detailService.update(upRecord, QueryWrapper.create()
.eq(GbOrderDetail::getId, param.getRecordId())
.eq(GbOrderDetail::getOrderNo, param.getOrderNo())
.eq(GbOrderDetail::getUserId, userId)
.eq(GbOrderDetail::getShopId, record.getShopId())
);
}
@Override
public boolean cancelRefund(CommonRefundDTO param, Long userId, Long shopId) {
GbOrderDetail record = detailService.getOne(query()
.eq(GbOrderDetail::getId, param.getRecordId())
.eq(GbOrderDetail::getIsDel, YesNoEnum.NO.value())
.eq(GbOrderDetail::getUserId, userId));
AssertUtil.isNull(record, "取消失败,订单不存在");
if (!"待退款".equals(record.getStatus())) {
throw new CzgException("取消失败,订单不处于退款中");
}
boolean success = exists(query().eq(GbOrder::getGroupOrderNo, record.getGroupOrderNo())
.eq(GbOrder::getShopId, shopId)
.eq(GbOrder::getStatus, "success"));
GbOrderDetail upRecord = new GbOrderDetail();
if (success) {
upRecord.setStatus("待核销");
} else {
upRecord.setStatus("待成团");
}
if (record.getVerifyTime() != null) {
upRecord.setStatus("已核销");
}
upRecord.setCancelReason(param.getReason());
upRecord.setCancelTime(LocalDateTime.now());
return detailService.update(upRecord, QueryWrapper.create()
.eq(GbOrderDetail::getId, param.getRecordId())
.eq(GbOrderDetail::getOrderNo, param.getOrderNo())
.eq(GbOrderDetail::getUserId, userId)
.eq(GbOrderDetail::getShopId, shopId)
);
}
@Transactional
@Override
public boolean agreeRefund(CommonRefundDTO param, Long shopId) {
GbOrderDetail record = detailService.getOne(QueryWrapper.create()
.eq(GbOrderDetail::getIsDel, YesNoEnum.NO.value())
.eq(GbOrderDetail::getId, param.getRecordId())
.eq(GbOrderDetail::getShopId, shopId));
AssertUtil.isNull(record, "退款失败,订单不存在");
//待支付/待核销/待成团/已核销/退款中/已退款
if (!"待核销".equals(record.getStatus()) && !"待成团".equals(record.getStatus()) && !"退款中".equals(record.getStatus())) {
throw new CzgException("退款失败,订单不处于待退款");
}
return refundAmount(record, param.getReason());
}
private boolean refundAmount(GbOrderDetail record, String reason) {
//退钱
String refPayOrderNo = CzgRandomUtils.snowflake(OrderNoPrefixEnum.REP);
payService.unifyRefund(record.getShopId(), record.getId(), record.getPayOrderId(), refPayOrderNo,
StrUtil.isBlankIfStr(reason) ? "拼团退款" : reason, record.getPayAmount());
//回退 人数
GbOrder gbOrder = getOne(query().eq(GbOrder::getGroupOrderNo, record.getGroupOrderNo()).eq(GbOrder::getShopId, record.getShopId()));
if (gbOrder != null) {
GbOrder upOrder = new GbOrder();
upOrder.setCurrentPeopleNum(gbOrder.getCurrentPeopleNum() - 1);
if (upOrder.getCurrentPeopleNum() == 0) {
upOrder.setStatus("fail");
upOrder.setGroupEndTime(LocalDateTime.now());
}
updateById(upOrder);
}
GbOrderDetail upRecord = new GbOrderDetail();
upRecord.setStatus("已退款");
return detailService.update(upRecord, query().eq(GbOrderDetail::getId, record.getId()));
}
}

View File

@@ -19,6 +19,7 @@ import com.czg.constant.MarketConstants;
import com.czg.constant.TableValueConstant; import com.czg.constant.TableValueConstant;
import com.czg.entity.notify.CzgPayNotifyDTO; import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.notify.CzgRefundNotifyDTO; import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.enums.ShopTableStatusEnum; import com.czg.enums.ShopTableStatusEnum;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
@@ -48,9 +49,7 @@ import com.czg.service.RedisService;
import com.czg.service.order.enums.OrderStatusEnums; import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.mapper.OrderInfoCustomMapper; import com.czg.service.order.mapper.OrderInfoCustomMapper;
import com.czg.service.order.print.PrinterHandler; import com.czg.service.order.print.PrinterHandler;
import com.czg.utils.AssertUtil; import com.czg.utils.*;
import com.czg.utils.CzgStrUtils;
import com.czg.utils.FunUtils;
import com.czg.utils.PageUtil; import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
@@ -60,7 +59,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronization;
@@ -128,6 +126,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
@Resource @Resource
private PointsGoodPayService goodPayService; private PointsGoodPayService goodPayService;
@Resource @Resource
private GbOrderService gbOrderService;
@Resource
private ShopCouponService couponService; private ShopCouponService couponService;
@Resource @Resource
private MkShopCouponRecordService couponRecordService; private MkShopCouponRecordService couponRecordService;
@@ -1046,7 +1046,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
payment.setPayStatus("fail"); payment.setPayStatus("fail");
if ("TRADE_SUCCESS".equals(czgCallBackDto.getState())) { if ("TRADE_SUCCESS".equals(czgCallBackDto.getState())) {
payment.setPayStatus("success"); payment.setPayStatus("success");
if ("order".equals(payment.getPayType())) { if (PaymentPayTypeEnum.ORDER.getValue().equals(payment.getPayType())) {
OrderInfo orderInfo = orderInfoService.getById(payment.getSourceId()); OrderInfo orderInfo = orderInfoService.getById(payment.getSourceId());
if (orderInfo == null) { if (orderInfo == null) {
log.error("订单支付回调失败,订单不存在,支付记录Id,{}", payment.getId()); log.error("订单支付回调失败,订单不存在,支付记录Id,{}", payment.getId());
@@ -1058,8 +1058,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId()); distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
// 分销奖励 // 分销奖励
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order"); distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) { } else if (PaymentPayTypeEnum.MEMBER_IN.getValue().equals(payment.getPayType()) || PaymentPayTypeEnum.FREE.getValue().equals(payment.getPayType())) {
boolean isFree = "free".equals(payment.getPayType()); boolean isFree = PaymentPayTypeEnum.FREE.getValue().equals(payment.getPayType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId()); ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo = null; OrderInfo orderInfo = null;
if (shopUser == null) { if (shopUser == null) {
@@ -1159,7 +1159,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// if (orderInfo != null) { // if (orderInfo != null) {
// distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge"); // distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge");
// } // }
} else if ("memberPay".equals(payment.getPayType())) { } else if (PaymentPayTypeEnum.MEMBER_PAY.getValue().equals(payment.getPayType())) {
//购买会员 //购买会员
ShopUser shopUser = shopUserService.getById(payment.getSourceId()); ShopUser shopUser = shopUserService.getById(payment.getSourceId());
memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId()); memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId());
@@ -1167,10 +1167,12 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId()); // memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId());
// 分销员开通 // 分销员开通
} else if ("distribution".equals(payment.getPayType())) { } else if (PaymentPayTypeEnum.DISTRIBUTION.getValue().equals(payment.getPayType())) {
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId()); distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
} else if ("point".equals(payment.getPayType())) { } else if (PaymentPayTypeEnum.POINT.getValue().equals(payment.getPayType())) {
goodPayService.payCallBack(payment.getSourceId(), payment.getId()); goodPayService.payCallBack(payment.getSourceId(), payment.getId());
} else if (PaymentPayTypeEnum.WARE.getValue().equals(payment.getPayType())) {
gbOrderService.payCallBack(payment.getSourceId(), payment.getId());
} }
} }
paymentService.updateById(payment); paymentService.updateById(payment);
@@ -1409,7 +1411,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
throw new CzgException("生成订单失败,订单已结束,请重新下单"); throw new CzgException("生成订单失败,订单已结束,请重新下单");
} }
} else { } else {
orderInfo.setOrderNo(param.getPlatformType() + IdUtil.getSnowflakeNextId()); orderInfo.setOrderNo(param.getPlatformType() + CzgRandomUtils.snowflake());
orderInfo.setShopId(param.getShopId()); orderInfo.setShopId(param.getShopId());
if (table != null) { if (table != null) {
orderInfo.setTableCode(table.getTableCode()); orderInfo.setTableCode(table.getTableCode());

View File

@@ -26,12 +26,14 @@ import com.czg.market.entity.MkShopRechargeDetail;
import com.czg.market.service.*; import com.czg.market.service.*;
import com.czg.market.vo.MkShopRechargeVO; import com.czg.market.vo.MkShopRechargeVO;
import com.czg.order.dto.CheckOrderPay; import com.czg.order.dto.CheckOrderPay;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.dto.OrderInfoRefundDTO; import com.czg.order.dto.OrderInfoRefundDTO;
import com.czg.order.dto.PointGoodsExchangeDTO; import com.czg.order.dto.PointGoodsExchangeDTO;
import com.czg.order.entity.OrderDetail; import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo; import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment; import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums; import com.czg.order.enums.PayEnums;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.order.service.CreditBuyerOrderService; import com.czg.order.service.CreditBuyerOrderService;
import com.czg.order.service.OrderDetailService; import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoCustomService; import com.czg.order.service.OrderInfoCustomService;
@@ -50,6 +52,7 @@ import com.czg.service.order.service.PayService;
import com.czg.system.enums.SysParamCodeEnum; import com.czg.system.enums.SysParamCodeEnum;
import com.czg.system.service.SysParamsService; import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.utils.CzgRandomUtils;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
@@ -279,7 +282,7 @@ public class PayServiceImpl implements PayService {
log.info("充值金额小于订单金额,充值金额:{} 订单金额:{}", rechargeDetail.getAmount(), orderInfo.getOrderAmount()); log.info("充值金额小于订单金额,充值金额:{} 订单金额:{}", rechargeDetail.getAmount(), orderInfo.getOrderAmount());
return CzgResult.failure("支付失败 充值金额必须大雨订单金额"); return CzgResult.failure("支付失败 充值金额必须大雨订单金额");
} }
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo,
"", rechargeDetail.getAmount(), rechargeDetail.getId())); "", rechargeDetail.getAmount(), rechargeDetail.getId()));
upOrderPayInfo(orderInfo.getId(), PayEnums.VIP_PAY, paymentId, upOrderPayInfo(orderInfo.getId(), PayEnums.VIP_PAY, paymentId,
@@ -292,7 +295,7 @@ public class PayServiceImpl implements PayService {
@Transactional(noRollbackFor = PaySuccessException.class) @Transactional(noRollbackFor = PaySuccessException.class)
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) { public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount())); "order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId, upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId,
@@ -308,7 +311,7 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount())); "order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId, upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
@@ -332,7 +335,7 @@ public class PayServiceImpl implements PayService {
} else { } else {
orderInfo = orderInfoService.getById(payParam.getCheckOrderPay().getOrderId()); orderInfo = orderInfoService.getById(payParam.getCheckOrderPay().getOrderId());
} }
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount())); "order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId, upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
@@ -347,7 +350,7 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay()); OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount())); "order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId, upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
@@ -370,7 +373,7 @@ public class PayServiceImpl implements PayService {
Long mainShopId = shopInfoService.getMainIdByShopId(payParam.getShopId()); Long mainShopId = shopInfoService.getMainIdByShopId(payParam.getShopId());
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount()); BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount());
payParam.setAmount(amount); payParam.setAmount(amount);
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount())); "order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN, paymentId, upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN, paymentId,
@@ -397,7 +400,7 @@ public class PayServiceImpl implements PayService {
payParam.setAmount(amount); payParam.setAmount(amount);
} }
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(), Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount())); "order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
CzgResult<Map<String, Object>> mapCzgResult = microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(), CzgResult<Map<String, Object>> mapCzgResult = microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
@@ -446,7 +449,7 @@ public class PayServiceImpl implements PayService {
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在"); AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo, initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId())); "", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(), return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@@ -466,7 +469,7 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberPay", payOrderNo, initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberPay", payOrderNo,
"", memberOrder.getAmount(), memberOrder.getId())); "", memberOrder.getAmount(), memberOrder.getId()));
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, memberOrder.getAmount().multiply(MONEY_RATE).longValue(), return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, memberOrder.getAmount().multiply(MONEY_RATE).longValue(),
@@ -493,7 +496,7 @@ public class PayServiceImpl implements PayService {
payParam.setAmount(amount); payParam.setAmount(amount);
} }
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo, initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId())); "", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(), return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@@ -515,7 +518,7 @@ public class PayServiceImpl implements PayService {
UserInfo userInfo = userInfoService.getById(shopUser.getUserId()); UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, rechargeDTO.getShopId(), shopUser.getUserId(), rechargeDTO.getRechargeDetailId(), rechargeDTO.getAmount()); BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, rechargeDTO.getShopId(), shopUser.getUserId(), rechargeDTO.getRechargeDetailId(), rechargeDTO.getAmount());
String payOrderNo = rechargeDTO.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = rechargeDTO.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(rechargeDTO.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo, initOrderPayment(new OrderPayment(rechargeDTO.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
"", amount, isFree ? rechargeDTO.getOrderId() : rechargeDTO.getRechargeDetailId())); "", amount, isFree ? rechargeDTO.getOrderId() : rechargeDTO.getRechargeDetailId()));
return ltPay(rechargeDTO.getShopId(), rechargeDTO.getPayType(), new CzgLtPayReq(payOrderNo, amount.multiply(MONEY_RATE).longValue(), return ltPay(rechargeDTO.getShopId(), rechargeDTO.getPayType(), new CzgLtPayReq(payOrderNo, amount.multiply(MONEY_RATE).longValue(),
@@ -529,7 +532,7 @@ public class PayServiceImpl implements PayService {
boolean isFree = checkPayVip(payParam); boolean isFree = checkPayVip(payParam);
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId()); ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在"); AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo, initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId())); "", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(), return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@@ -543,7 +546,7 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空"); AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId()); ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在"); AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId(); String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo, initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
payParam.getAuthCode(), payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId())); payParam.getAuthCode(), payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
CzgResult<Map<String, Object>> mapCzgResult = microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(), CzgResult<Map<String, Object>> mapCzgResult = microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@@ -555,14 +558,14 @@ public class PayServiceImpl implements PayService {
@Override @Override
@Transactional @Transactional
public CzgResult<Map<String, Object>> ltPayPointsGoods(String ip, PointGoodsExchangeDTO param, Long mkPointsGoodsRecordId) { public CzgResult<Map<String, Object>> ltPayOther(LtPayOtherDTO param, PaymentPayTypeEnum payType, String detail) {
AssertUtil.isBlank(param.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(param.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(param.getPayType(), "支付方式不能为空"); AssertUtil.isBlank(param.getPayType(), "支付方式不能为空");
String payOrderNo = "DH" + IdUtil.getSnowflakeNextId(); String payOrderNo = "DH" + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(param.getShopId(), mkPointsGoodsRecordId, "point", payOrderNo, initOrderPayment(new OrderPayment(param.getShopId(), param.getRecordId(), payType.getValue(), payOrderNo,
"", param.getPrice(), null)); "", param.getPrice(), null));
return ltPay(param.getShopId(), param.getPayType(), new CzgLtPayReq(payOrderNo, param.getPrice().multiply(MONEY_RATE).longValue(), return ltPay(param.getShopId(), param.getPayType(), new CzgLtPayReq(payOrderNo, param.getPrice().multiply(MONEY_RATE).longValue(),
param.getPayType(), "积分商品购买", param.getOpenId(), ip, "", "", "")); param.getPayType(), detail, param.getOpenId(), param.getIp(), "", "", ""));
} }
@Override @Override

View File

@@ -1,11 +1,11 @@
package com.czg.service.order.service.impl; package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService; import com.czg.account.service.ShopUserService;
import com.czg.enums.OrderNoPrefixEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.market.dto.MkShopCouponGiftDTO; import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.entity.MkPointsGoods; import com.czg.market.entity.MkPointsGoods;
@@ -14,8 +14,9 @@ import com.czg.market.entity.MkPointsUser;
import com.czg.market.entity.ShopCoupon; import com.czg.market.entity.ShopCoupon;
import com.czg.market.enums.PointsConstant; import com.czg.market.enums.PointsConstant;
import com.czg.market.service.*; import com.czg.market.service.*;
import com.czg.order.dto.PointGoodsExchangeDTO; import com.czg.order.dto.CommonRefundDTO;
import com.czg.order.dto.PointGoodsRefundDTO; import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.enums.PaymentPayTypeEnum;
import com.czg.order.service.PointsGoodPayService; import com.czg.order.service.PointsGoodPayService;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.service.order.service.PayService; import com.czg.service.order.service.PayService;
@@ -56,8 +57,8 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
@Override @Override
@Transactional @Transactional
public CzgResult<Map<String, Object>> exchange(String ip, PointGoodsExchangeDTO param) { public CzgResult<Map<String, Object>> exchange(LtPayOtherDTO param) {
MkPointsGoods goods = goodsService.getById(param.getPointsGoodsId()); MkPointsGoods goods = goodsService.getById(param.getParamId());
if (goods == null) { if (goods == null) {
throw new CzgException("兑换失败,商品不存在"); throw new CzgException("兑换失败,商品不存在");
} }
@@ -68,7 +69,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
throw new CzgException("兑换失败,商品库存不足"); throw new CzgException("兑换失败,商品库存不足");
} }
Integer boughtCount = goodsRecordService.getOneAs(QueryWrapper.create().select("sum(number)") Integer boughtCount = goodsRecordService.getOneAs(QueryWrapper.create().select("sum(number)")
.eq(MkPointsGoodsRecord::getPointsGoodsId, param.getPointsGoodsId()) .eq(MkPointsGoodsRecord::getPointsGoodsId, param.getParamId())
.ne(MkPointsGoodsRecord::getStatus, "已退款") .ne(MkPointsGoodsRecord::getStatus, "已退款")
.eq(MkPointsGoodsRecord::getUserId, param.getUserId()), Integer.class); .eq(MkPointsGoodsRecord::getUserId, param.getUserId()), Integer.class);
if (goods.getLimitQuota() != null && goods.getLimitQuota() > 0 && boughtCount != null && boughtCount >= goods.getLimitQuota()) { if (goods.getLimitQuota() != null && goods.getLimitQuota() > 0 && boughtCount != null && boughtCount >= goods.getLimitQuota()) {
@@ -87,9 +88,9 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
} }
MkPointsGoodsRecord record = new MkPointsGoodsRecord(); MkPointsGoodsRecord record = new MkPointsGoodsRecord();
record.setOrderNo("DH" + CzgRandomUtils.randomNumFirstNoZero(20)); record.setOrderNo(CzgRandomUtils.randomNumber(OrderNoPrefixEnum.DH, 20, true));
record.setShopId(param.getShopId()); record.setShopId(param.getShopId());
record.setPointsGoodsId(param.getPointsGoodsId()); record.setPointsGoodsId(param.getParamId());
record.setPointsGoodsName(goods.getGoodsName()); record.setPointsGoodsName(goods.getGoodsName());
record.setGoodsImageUrl(goods.getGoodsImageUrl()); record.setGoodsImageUrl(goods.getGoodsImageUrl());
record.setGoodsCategory(goods.getGoodsCategory()); record.setGoodsCategory(goods.getGoodsCategory());
@@ -101,12 +102,14 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
record.setExtraPaymentAmount(goods.getExtraPrice() != null ? goods.getExtraPrice().multiply(new BigDecimal(param.getNumber())) : BigDecimal.ZERO); record.setExtraPaymentAmount(goods.getExtraPrice() != null ? goods.getExtraPrice().multiply(new BigDecimal(param.getNumber())) : BigDecimal.ZERO);
record.setCreateTime(LocalDateTime.now()); record.setCreateTime(LocalDateTime.now());
if (goods.getExtraPrice() != null && goods.getExtraPrice().compareTo(BigDecimal.ZERO) > 0) { if (goods.getExtraPrice() != null && goods.getExtraPrice().compareTo(BigDecimal.ZERO) > 0) {
param.checkPayInfo();
param.setPrice(record.getExtraPaymentAmount()); param.setPrice(record.getExtraPaymentAmount());
record.setStatus("待支付"); record.setStatus("待支付");
record.setIsDel(1); record.setIsDel(1);
goodsRecordService.save(record); goodsRecordService.save(record);
param.setRecordId(record.getId());
CzgResult<Map<String, Object>> result = CzgResult.success(); CzgResult<Map<String, Object>> result = CzgResult.success();
CzgResult<Map<String, Object>> mapCzgResult = payService.ltPayPointsGoods(ip, param, record.getId()); CzgResult<Map<String, Object>> mapCzgResult = payService.ltPayOther(param, PaymentPayTypeEnum.POINT, "积分商品购买");
if (200 != mapCzgResult.getCode()) { if (200 != mapCzgResult.getCode()) {
return mapCzgResult; return mapCzgResult;
} }
@@ -123,7 +126,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
} }
@Override @Override
public boolean applyRefund(PointGoodsRefundDTO param, Long userId) { public boolean applyRefund(CommonRefundDTO param, Long userId) {
MkPointsGoodsRecord record = new MkPointsGoodsRecord(); MkPointsGoodsRecord record = new MkPointsGoodsRecord();
record.setStatus("退款中"); record.setStatus("退款中");
record.setCancelOrRefundReason(param.getReason()); record.setCancelOrRefundReason(param.getReason());
@@ -137,7 +140,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
} }
@Override @Override
public boolean cancelRefund(PointGoodsRefundDTO param, Long userId, Long shopId) { public boolean cancelRefund(CommonRefundDTO param, Long userId, Long shopId) {
MkPointsGoodsRecord record1 = goodsRecordService.getById(param.getRecordId()); MkPointsGoodsRecord record1 = goodsRecordService.getById(param.getRecordId());
if (record1 == null) { if (record1 == null) {
throw new CzgException("取消失败,订单不存在"); throw new CzgException("取消失败,订单不存在");
@@ -164,13 +167,17 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
@Override @Override
@Transactional @Transactional
public boolean agreeRefund(PointGoodsRefundDTO param, Long shopId) { public boolean agreeRefund(CommonRefundDTO param, Long shopId) {
MkPointsGoodsRecord record = goodsRecordService.getOne(QueryWrapper.create() MkPointsGoodsRecord record = goodsRecordService.getOne(QueryWrapper.create()
.eq(MkPointsGoodsRecord::getId, param.getRecordId()) .eq(MkPointsGoodsRecord::getId, param.getRecordId())
.eq(MkPointsGoodsRecord::getShopId, shopId)); .eq(MkPointsGoodsRecord::getShopId, shopId)
.eq(MkPointsGoodsRecord::getIsDel, 0));
if (record == null) { if (record == null) {
throw new CzgException("操作失败,记录不存在"); throw new CzgException("操作失败,记录不存在");
} }
if (!"待核销".equals(record.getStatus()) && !"退款中".equals(record.getStatus())) {
throw new CzgException("退款失败,订单不处于待退款");
}
//退积分 //退积分
if (record.getSpendPoints() != null && record.getSpendPoints() > 0) { if (record.getSpendPoints() != null && record.getSpendPoints() > 0) {
//回增积分 //回增积分
@@ -179,7 +186,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
} }
//退钱 //退钱
if (record.getExtraPaymentAmount() != null && record.getExtraPaymentAmount().compareTo(BigDecimal.ZERO) > 0) { if (record.getExtraPaymentAmount() != null && record.getExtraPaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
String refPayOrderNo = "REP" + IdUtil.getSnowflakeNextId(); String refPayOrderNo = CzgRandomUtils.snowflake(OrderNoPrefixEnum.REP);
payService.unifyRefund(shopId, record.getId(), record.getPayOrderId(), refPayOrderNo, payService.unifyRefund(shopId, record.getId(), record.getPayOrderId(), refPayOrderNo,
StrUtil.isBlankIfStr(param.getReason()) ? "积分商品退款" : param.getReason(), record.getExtraPaymentAmount()); StrUtil.isBlankIfStr(param.getReason()) ? "积分商品退款" : param.getReason(), record.getExtraPaymentAmount());
} }
@@ -238,7 +245,7 @@ public class PointsGoodPayServiceImpl implements PointsGoodPayService {
return record; return record;
} else { } else {
record.setStatus("待核销"); record.setStatus("待核销");
record.setCouponCode(CzgRandomUtils.randomNumFirstNoZero(12)); record.setCouponCode(CzgRandomUtils.randomNumber(12, true));
goodsRecordService.saveOrUpdate(record); goodsRecordService.saveOrUpdate(record);
goodsService.upNumberById(goods.getId(), goods.getQuantity() - record.getNumber(), goods.getTotalExchangeCount() + record.getNumber()); goodsService.upNumberById(goods.getId(), goods.getQuantity() - record.getNumber(), goods.getTotalExchangeCount() + record.getNumber());
//扣除积分 //扣除积分

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.order.mapper.GbOrderDetailMapper">
</mapper>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.order.mapper.GbOrderMapper">
<select id="getGbOrderPage" resultType="com.czg.order.vo.GbOrderDetailVO">
SELECT
detail.* ,`order`.ware_json as wareJson,`user`.nick_name as userName,
`user`.phone as userPhone,shop.shop_name as shopName,shop.address as shopAddress
FROM
`gb_order_detail` detail
LEFT JOIN gb_order `order` on detail.group_order_no = `order`.group_order_no and `order`.shop_id = #{shopId}
left join tb_shop_user `user` on `user`.main_shop_id = #{mainShopId} and `user`.user_id = detail.user_id
LEFT JOIN tb_shop_info shop on detail.shop_id = shop.id
WHERE
detail.shop_id = #{shopId}
and detail.is_del = 0
<if test="param.orderNo != null">
and detail.order_no = #{param.orderNo}
</if>
<if test="param.groupOrderNo != null">
AND detail.group_order_no = #{param.groupOrderNo}
</if>
<if test="param.status != null">
<if test="param.status == '退款'">
AND (detail.STATUS = '退款中' or detail.STATUS = '已退款')
</if>
<if test="param.status != '退款'">
AND detail.STATUS = #{param.status}
</if>
</if>
<if test="param.userId != null">
AND detail.user_id = #{param.userId}
</if>
<if test="param.orderStartTime != null and param.orderEndTime != null ">
and detail.pay_time BETWEEN #{param.orderStartTime} and #{param.orderEndTime}
</if>
<if test="param.verifyStartTime != null and param.verifyEndTime != null ">
and detail.verify_time BETWEEN #{param.verifyStartTime} and #{param.verifyEndTime}
</if>
order by detail.create_time desc
</select>
<select id="getGbOrderDetail" resultType="com.czg.order.vo.GbOrderDetailVO">
SELECT
detail.* ,`order`.ware_json as wareJson,`user`.nick_name as userName,
`user`.phone as userPhone,shop.shop_name as shopName,shop.address as shopAddress
FROM
`gb_order_detail` detail
LEFT JOIN gb_order `order` on detail.group_order_no = `order`.group_order_no and `order`.shop_id = #{shopId}
left join tb_shop_user `user` on `user`.main_shop_id = #{mainShopId} and `user`.user_id = detail.user_id
LEFT JOIN tb_shop_info shop on detail.shop_id = shop.id
WHERE
detail.shop_id = #{shopId} and detail.id=#{id}
order by detail.create_time desc
</select>
<select id="getGbOrderDetailUsers" resultType="com.czg.order.vo.GbOrderUserVO">
select `user`.nick_name as userName, `user`.phone as userPhone, `user`.head_img as userAvatar
from gb_order_detail detail
left join tb_shop_user `user`
on `user`.main_shop_id = #{mainShopId} and `user`.user_id = detail.user_id
where detail.shop_id = #{shopId}
and detail.group_order_no = #{groupOrderNo}
and (detail.status = '待成团' or detail.status = '待核销' or detail.status = '退款中')
order by detail.pay_time
limit 10
</select>
</mapper>