diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java index 4fa575f..d55aa34 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java @@ -32,6 +32,18 @@ public interface TableConstant { } } + class ThirdPartyCoupon { + @Getter + public enum Plat { + MEI_TUAN("meituan"); + private final String value; + + Plat(String value) { + this.value = value; + } + } + } + class OrderInfo { @Getter public enum Status { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 5fe8f00..25ed4c4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -49,6 +49,14 @@ public class OrderController { public Result addTemporaryDishes(@Valid @RequestBody AddTemporaryDishesDTO temporaryDishesDTO) { return Result.success(CodeEnum.SUCCESS, orderService.addTemporaryDishes(temporaryDishesDTO)); } + /** + * 美团核销 + */ + @PostMapping("checkCoupon") + public Result checkCoupon(@Validated @RequestBody ThirdCouponCheckDTO checkDTO) { + return Result.success(CodeEnum.SUCCESS, orderService.checkCoupon(checkDTO)); + } + @PutMapping("/updatePrice") public Result updatePrice(@Valid @RequestBody UpdatePriceDTO updatePriceDTO) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 1d4dfa6..d7ece6c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -196,6 +196,7 @@ public class PayController { return result; } + /** * 会员支付 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ThirdPartyCouponController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ThirdPartyCouponController.java new file mode 100644 index 0000000..d4ccc79 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ThirdPartyCouponController.java @@ -0,0 +1,78 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon.CheckCouponDTO; +import com.chaozhanggui.system.cashierservice.service.ThirdPartyCouponService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * 三方团购券 + */ +@RestController +@RequestMapping("/thirdPartyCoupon") +public class ThirdPartyCouponController { + + private final ThirdPartyCouponService thirdPartyCouponService; + + public ThirdPartyCouponController(ThirdPartyCouponService thirdPartyCouponService) { + this.thirdPartyCouponService = thirdPartyCouponService; + } + + /** + * 获取绑定状态 + * @return 绑定状态 + */ + @GetMapping("/state") + public Result getState(@RequestParam Integer shopId) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.getState(shopId)); + } + + /** + * 获取美团绑定链接 + * @return 美团绑定链接 + */ + @GetMapping("bindUrl") + public Result getBindUrl(@RequestParam Integer shopId) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.getBindUrl(shopId)); + } + + /** + * 解绑美团商家 + * @return 美团解绑链接 + */ + @GetMapping("unBindUrl") + public Result getUnBindUrl(@RequestParam Integer shopId) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.getUnBindUrl(shopId)); + } + + /** + * 获取门店客核销券 + * @return 所有券 + */ + @GetMapping("list") + public Result getActivateCoupon(@RequestParam Integer shopId, @RequestParam String code) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.getActivateCoupon(shopId, code)); + } + + /** + * 核销券 + */ + @PostMapping + public Result checkCoupon(@RequestBody CheckCouponDTO checkCouponDTO) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.checkCoupon(checkCouponDTO)); + } + + /** + * 撤销券核销 + */ + @DeleteMapping("revoke") + public Result revokeCoupon(@RequestBody CheckCouponDTO checkCouponDTO) { + return Result.success(CodeEnum.SUCCESS, thirdPartyCouponService.revokeCoupon(checkCouponDTO)); + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java index 9847dae..708d764 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java @@ -85,6 +85,7 @@ public class TbCashierCart implements Serializable { private String discountSaleNote; private Boolean isPrint; private String useCouponInfo; + private int isThirdCoupon; public void copy(TbCashierCart source) { BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); @@ -94,6 +95,10 @@ public class TbCashierCart implements Serializable { * 根据是否会员充值价格 */ public void resetTotalAmount() { + if (isThirdCoupon == 1) { + totalAmount = BigDecimal.ZERO; + return; + } if ("false".equals(isPack)) { packFee = BigDecimal.ZERO; } @@ -115,6 +120,10 @@ public class TbCashierCart implements Serializable { * 根据是否会员充值价格 */ public void resetTotalAmount(BigDecimal discountRadio) { + if (isThirdCoupon == 1) { + totalAmount = BigDecimal.ZERO; + return; + } if (discountRadio == null) { discountRadio = BigDecimal.ONE; } @@ -124,10 +133,15 @@ public class TbCashierCart implements Serializable { if ("true".equals(isGift)) { totalAmount = packFee; } else { + discountSaleAmount = discountSaleAmount == null ? BigDecimal.ZERO : discountSaleAmount; + BigDecimal subtract; if (isMember != null && isMember == 1 && memberPrice != null && memberPrice.compareTo(BigDecimal.ZERO) > 0) { - totalAmount = totalNumber.multiply(memberPrice).add(packFee).multiply(discountRadio); + subtract = memberPrice.subtract(discountSaleAmount); + totalAmount = totalNumber.multiply(subtract).add(packFee).multiply(discountRadio).setScale(2, RoundingMode.HALF_UP); } else { - totalAmount = totalNumber.multiply(discountSaleAmount != null ? discountSaleAmount : salePrice).add(packFee).multiply(discountRadio); + subtract = salePrice.subtract(discountSaleAmount); + totalAmount = totalNumber.multiply(subtract) + .add(packFee).multiply(discountRadio).setScale(2, RoundingMode.HALF_UP); } } } @@ -137,6 +151,9 @@ public class TbCashierCart implements Serializable { * */ public BigDecimal getTotalAmountByNum(BigDecimal num, BigDecimal discountRadio) { + if (isThirdCoupon == 1) { + return BigDecimal.ZERO; + } if (discountRadio == null) { discountRadio = new BigDecimal("1"); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java index f88a117..59cd315 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java @@ -51,5 +51,6 @@ public class TbOrderDetail implements Serializable { private static final long serialVersionUID = 1L; private Integer isMember; + private Integer isThirdCoupon; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbThirdPartyCouponRecord.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbThirdPartyCouponRecord.java new file mode 100644 index 0000000..4332600 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbThirdPartyCouponRecord.java @@ -0,0 +1,271 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.util.Date; + +/** + * + * @TableName tb_third_party_coupon_record + */ +@TableName(value ="tb_third_party_coupon_record") +public class TbThirdPartyCouponRecord implements Serializable { + /** + * + */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** + * 订单id + */ + private Integer orderId; + + /** + * 核销状态 1 成功 + */ + private Integer state; + + /** + * 平台 meituan + */ + private String plat; + + /** + * 券码 + */ + private String code; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 核销时间 + */ + private Date checkTime; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 使用数量 + */ + private Integer num; + + /** + * 抵扣的购物车id + */ + private String cartIdList; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + /** + * + */ + public Integer getId() { + return id; + } + + /** + * + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * 订单id + */ + public Integer getOrderId() { + return orderId; + } + + /** + * 订单id + */ + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + /** + * 核销状态 1 成功 + */ + public Integer getState() { + return state; + } + + /** + * 核销状态 1 成功 + */ + public void setState(Integer state) { + this.state = state; + } + + /** + * 平台 meituan + */ + public String getPlat() { + return plat; + } + + /** + * 平台 meituan + */ + public void setPlat(String plat) { + this.plat = plat; + } + + /** + * 券码 + */ + public String getCode() { + return code; + } + + /** + * 券码 + */ + public void setCode(String code) { + this.code = code; + } + + /** + * 创建时间 + */ + public Date getCreateTime() { + return createTime; + } + + /** + * 创建时间 + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + /** + * 核销时间 + */ + public Date getCheckTime() { + return checkTime; + } + + /** + * 核销时间 + */ + public void setCheckTime(Date checkTime) { + this.checkTime = checkTime; + } + + /** + * 店铺id + */ + public Integer getShopId() { + return shopId; + } + + /** + * 店铺id + */ + public void setShopId(Integer shopId) { + this.shopId = shopId; + } + + /** + * 使用数量 + */ + public Integer getNum() { + return num; + } + + /** + * 使用数量 + */ + public void setNum(Integer num) { + this.num = num; + } + + /** + * 抵扣的购物车id + */ + public String getCartIdList() { + return cartIdList; + } + + /** + * 抵扣的购物车id + */ + public void setCartIdList(String cartIdList) { + this.cartIdList = cartIdList; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbThirdPartyCouponRecord other = (TbThirdPartyCouponRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getPlat() == null ? other.getPlat() == null : this.getPlat().equals(other.getPlat())) + && (this.getCode() == null ? other.getCode() == null : this.getCode().equals(other.getCode())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getCheckTime() == null ? other.getCheckTime() == null : this.getCheckTime().equals(other.getCheckTime())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getNum() == null ? other.getNum() == null : this.getNum().equals(other.getNum())) + && (this.getCartIdList() == null ? other.getCartIdList() == null : this.getCartIdList().equals(other.getCartIdList())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getPlat() == null) ? 0 : getPlat().hashCode()); + result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getCheckTime() == null) ? 0 : getCheckTime().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getNum() == null) ? 0 : getNum().hashCode()); + result = prime * result + ((getCartIdList() == null) ? 0 : getCartIdList().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", orderId=").append(orderId); + sb.append(", state=").append(state); + sb.append(", plat=").append(plat); + sb.append(", code=").append(code); + sb.append(", createTime=").append(createTime); + sb.append(", checkTime=").append(checkTime); + sb.append(", shopId=").append(shopId); + sb.append(", num=").append(num); + sb.append(", cartIdList=").append(cartIdList); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ThirdCouponCheckDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ThirdCouponCheckDTO.java new file mode 100644 index 0000000..76b2180 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ThirdCouponCheckDTO.java @@ -0,0 +1,25 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +public class ThirdCouponCheckDTO { + private String type = "meituan"; + @NotNull + private Integer shopId; + @NotBlank + private String code; + @Min(1) + private Integer num; + @NotNull + private Integer orderId; + // 核销的对应商品 + @NotEmpty + private List cartId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/BaseQueryDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/BaseQueryDTO.java new file mode 100644 index 0000000..81abd43 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/BaseQueryDTO.java @@ -0,0 +1,11 @@ +package com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class BaseQueryDTO { + @NotNull + private Integer shopId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/CheckCouponDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/CheckCouponDTO.java new file mode 100644 index 0000000..32e0e47 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/CheckCouponDTO.java @@ -0,0 +1,20 @@ +package com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@EqualsAndHashCode(callSuper = true) +@Data +public class CheckCouponDTO extends BaseQueryDTO { + @NotBlank + private String couponCode; + @NotNull + @Min(1) + private Integer num; + @NotBlank + private String title; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/GetActivateCouponDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/GetActivateCouponDTO.java new file mode 100644 index 0000000..d601b82 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/GetActivateCouponDTO.java @@ -0,0 +1,13 @@ +package com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; + +@EqualsAndHashCode(callSuper = true) +@Data +public class GetActivateCouponDTO extends BaseQueryDTO{ + @NotBlank + private String code; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/RevokeCouponDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/RevokeCouponDTO.java new file mode 100644 index 0000000..e5fdea3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/thirdcoupon/RevokeCouponDTO.java @@ -0,0 +1,13 @@ +package com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; + +@EqualsAndHashCode(callSuper = true) +@Data +public class RevokeCouponDTO extends BaseQueryDTO{ + @NotBlank + private String couponCode; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbThirdPartyCouponRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbThirdPartyCouponRecordMapper.java new file mode 100644 index 0000000..1666b89 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbThirdPartyCouponRecordMapper.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.mapper; + +import com.chaozhanggui.system.cashierservice.entity.TbThirdPartyCouponRecord; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_third_party_coupon_record】的数据库操作Mapper +* @createDate 2024-11-26 15:06:35 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbThirdPartyCouponRecord +*/ +public interface TbThirdPartyCouponRecordMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/resp/PhpCommonResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/resp/PhpCommonResp.java new file mode 100644 index 0000000..b6a5a04 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/resp/PhpCommonResp.java @@ -0,0 +1,11 @@ +package com.chaozhanggui.system.cashierservice.resp; + +import lombok.Data; + +@Data +public class PhpCommonResp { + private String code; + private String msg; + private long time; + private T data; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java index ba29a06..683107b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java @@ -53,5 +53,13 @@ public interface MpCashierCartService extends IService { * @param statuses 状态 */ TbCashierCart selectByShopIdAndId(Integer shopId, Integer cartId, TableConstant.OrderInfo.Status... statuses); + /** + * 根据id查询购物车数据 + * @param shopId 店铺id + * @param orderId 订单id + * @param ids 购物车id + * @param statuses 状态 + */ + List selectByIds(Integer shopId, Integer orderId, List ids, TableConstant.OrderInfo.Status... statuses); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpOrderDetailService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpOrderDetailService.java index 92bf032..7a0113a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpOrderDetailService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpOrderDetailService.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.service; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.service.IService; import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; @@ -45,5 +46,8 @@ public interface MpOrderDetailService extends IService { * @param totalAmount 总价格 */ boolean updatePriceByCartId(Integer cartId, BigDecimal saleAmount, BigDecimal totalAmount); + + + boolean updateFieldByCartId(SFunction field, Object val, List cartIds); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 951c8bc..1ecb37c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -17,6 +17,7 @@ import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.dto.*; +import com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon.CheckCouponDTO; import com.chaozhanggui.system.cashierservice.entity.po.CartPo; import com.chaozhanggui.system.cashierservice.entity.po.OrderPo; import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo; @@ -128,10 +129,13 @@ public class OrderService { @Resource private MPOrderDetailMapper mpOrderDetailMapper; + private final TbThirdPartyCouponRecordService thirdPartyCouponRecordService; + private final ThirdPartyCouponService thirdPartyCouponService; + public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, MpOrderInfoService mpOrderInfoService, MpShopTableService mpShopTableService, - TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) { + TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService, TbThirdPartyCouponRecordService thirdPartyCouponRecordService, ThirdPartyCouponService thirdPartyCouponService) { this.wxAccountUtil = wxAccountUtil; this.mpCashierCartMapper = mpCashierCartMapper; this.shopOpenIdMapper = shopOpenIdMapper; @@ -140,6 +144,8 @@ public class OrderService { this.mpShopTableService = mpShopTableService; this.tbCashierCartMapper = tbCashierCartMapper; this.mpCashierCartService = mpCashierCartService; + this.thirdPartyCouponRecordService = thirdPartyCouponRecordService; + this.thirdPartyCouponService = thirdPartyCouponService; } /** @@ -2099,7 +2105,6 @@ public class OrderService { tbCashierCart.setNote(temporaryDishesDTO.getNote()); tbCashierCart.setPlatformType(OrderPlatformTypeEnum.PC.getValue()); tbCashierCart.setIsMember(shopEatTypeInfoDTO.isMemberPrice() && temporaryDishesDTO.getVipUserId() != null ? 1 : 0); - tbCashierCart.setIsTemporary(1); tbCashierCart.setUnit(temporaryDishesDTO.getUnit()); tbCashierCart.setIsMember(temporaryDishesDTO.getVipUserId() == null ? 0 : 1); tbCashierCart.setNote(temporaryDishesDTO.getNote()); @@ -2152,4 +2157,49 @@ public class OrderService { } return cashierCart; } + + public Object checkCoupon(ThirdCouponCheckDTO checkDTO) { + TbOrderInfo orderInfo = mpOrderInfoService.getById(checkDTO.getOrderId()); + if (orderInfo == null) { + throw new MsgException("订单信息不存在"); + } + + if (!TableConstant.OrderInfo.Status.UNPAID.equalsVals(orderInfo.getStatus())) { + throw new MsgException("订单不为待支付状态"); + } + + List cashierCarts = mpCashierCartService.selectByIds(checkDTO.getShopId(), checkDTO.getOrderId(), checkDTO.getCartId()); + if (cashierCarts.size() != checkDTO.getCartId().size()) { + throw new MsgException("含有不存在购物车"); + } + + CheckCouponDTO dto = new CheckCouponDTO(); + dto.setShopId(checkDTO.getShopId()); + dto.setCouponCode(checkDTO.getCode()); + dto.setNum(checkDTO.getNum()); + thirdPartyCouponService.checkCoupon(dto); + + BigDecimal incrAmount = BigDecimal.ZERO; + for (TbCashierCart item : cashierCarts) { + item.setIsThirdCoupon(1); + incrAmount = incrAmount.add(item.getTotalAmount()); + } + mpCashierCartService.updateBatchById(cashierCarts); + mpOrderDetailService.updateFieldByCartId(TbOrderDetail::getIsThirdCoupon, 1, checkDTO.getCartId()); + mpOrderInfoService.incrAmount(orderInfo.getId(), incrAmount.negate()); + + TbThirdPartyCouponRecord record = new TbThirdPartyCouponRecord(); + record.setOrderId(orderInfo.getId()); + record.setCode(checkDTO.getCode()); + record.setNum(1); + record.setState(1); + record.setPlat(TableConstant.ThirdPartyCoupon.Plat.MEI_TUAN.getValue()); + record.setCreateTime(DateUtil.date()); + record.setCheckTime(DateUtil.date()); + record.setShopId(checkDTO.getShopId()); + record.setCartIdList(JSONObject.toJSONString(checkDTO.getCartId())); + thirdPartyCouponRecordService.save(record); + return true; + + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbThirdPartyCouponRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbThirdPartyCouponRecordService.java new file mode 100644 index 0000000..b9b67f8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbThirdPartyCouponRecordService.java @@ -0,0 +1,13 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.TbThirdPartyCouponRecord; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_third_party_coupon_record】的数据库操作Service +* @createDate 2024-11-26 15:06:35 +*/ +public interface TbThirdPartyCouponRecordService extends IService { + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ThirdPartyCouponService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ThirdPartyCouponService.java new file mode 100644 index 0000000..b77f44d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ThirdPartyCouponService.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.service; + + +import com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon.CheckCouponDTO; + +import java.util.Map; + +public interface ThirdPartyCouponService { + + String getBindUrl(Integer shopId); + + String getUnBindUrl(Integer shopId); + + Map getActivateCoupon(Integer shopId, String code); + + Map checkCoupon(CheckCouponDTO checkCouponDTO); + + Map revokeCoupon(CheckCouponDTO checkCouponDTO); + + Map getState(Integer shopId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java index 012b05e..dc5d153 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java @@ -100,5 +100,17 @@ public class MpCashierCartServiceImpl extends ServiceImpl selectByIds(Integer shopId, Integer orderId, List ids, TableConstant.OrderInfo.Status... statuses) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, shopId) + .eq(TbCashierCart::getOrderId, orderId) + .in(TbCashierCart::getId, ids); + if (statuses.length != 0) { + queryWrapper.in(TbCashierCart::getStatus, CollUtil.newArrayList(statuses)); + } + return list(queryWrapper); + } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpOrderDetailServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpOrderDetailServiceImpl.java index 6eef90b..7476e39 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpOrderDetailServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpOrderDetailServiceImpl.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant; import com.chaozhanggui.system.cashierservice.dao.TbOrderDetailMapper; @@ -59,5 +60,15 @@ public class MpOrderDetailServiceImpl extends ServiceImpl field, Object val, List cartIds) { + LambdaUpdateWrapper query = new LambdaUpdateWrapper() + .set(field, val); + if (!cartIds.isEmpty()) { + query.in(TbOrderDetail::getCartId, cartIds); + } + return update(query); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbThirdPartyCouponRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbThirdPartyCouponRecordServiceImpl.java new file mode 100644 index 0000000..40700aa --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbThirdPartyCouponRecordServiceImpl.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.chaozhanggui.system.cashierservice.entity.TbThirdPartyCouponRecord; +import com.chaozhanggui.system.cashierservice.service.TbThirdPartyCouponRecordService; +import com.chaozhanggui.system.cashierservice.mapper.TbThirdPartyCouponRecordMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_third_party_coupon_record】的数据库操作Service实现 +* @createDate 2024-11-26 15:06:35 +*/ +@Service +public class TbThirdPartyCouponRecordServiceImpl extends ServiceImpl + implements TbThirdPartyCouponRecordService{ + +} + + + + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/ThirdPartyCouponServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/ThirdPartyCouponServiceImpl.java new file mode 100644 index 0000000..47bfdf6 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/ThirdPartyCouponServiceImpl.java @@ -0,0 +1,110 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; +import com.chaozhanggui.system.cashierservice.entity.dto.thirdcoupon.CheckCouponDTO; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.mybatis.MpShopInfoMapper; +import com.chaozhanggui.system.cashierservice.resp.PhpCommonResp; +import com.chaozhanggui.system.cashierservice.service.ThirdPartyCouponService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +@Service +public class ThirdPartyCouponServiceImpl implements ThirdPartyCouponService { + + private final MpShopInfoMapper mpShopInfoMapper; + @Value("${phpServer}") + private String phpServerUrl; + + public ThirdPartyCouponServiceImpl(RestTemplate restTemplate, MpShopInfoMapper mpShopInfoMapper) { + this.restTemplate = restTemplate; + this.mpShopInfoMapper = mpShopInfoMapper; + } + private final RestTemplate restTemplate; + + private T exec(String url, Integer shopId, Object data) { + // 获取店铺信息 + TbShopInfo shopInfo = mpShopInfoMapper.selectById(shopId); + if (shopInfo == null) { + throw new MsgException("店铺信息不存在"); + } + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.set("account", shopId.toString()); + + // 构造请求实体,根据 data 是否为空设置请求体 + HttpEntity entity; + if (data != null) { + Map map = BeanUtil.beanToMap(data); + map.put("title", shopInfo.getShopName()); + entity = new HttpEntity<>(map, headers); + } else { + entity = new HttpEntity<>(new HashMap(){{ + put("title", shopInfo.getShopName()); + }},headers); + } + + // 发起请求 + ResponseEntity response = restTemplate.exchange( + phpServerUrl + url, + HttpMethod.POST, // 使用 POST 请求发送 body 数据 + entity, + PhpCommonResp.class + ); + + // 处理响应 + PhpCommonResp resp = response.getBody(); + if (resp == null) { + throw new MsgException("请求php服务器失败"); + } + if (!"1".equals(resp.getCode())) { + throw new MsgException(resp.getMsg()); + } + + // 返回数据 + return (T) resp.getData(); + } + + + @Override + public String getBindUrl(Integer shopId) { + return exec("/meituan/getuisdkurl", shopId, null); + } + + @Override + public String getUnBindUrl(Integer shopId) { + return exec("/meituan/getuisdkuniurl", shopId, null); + } + + @Override + public Map getActivateCoupon(Integer shopId, String code) { + return exec("/meituan/fulfilmentcertificateprepare", shopId, new HashMap(){{ + put("code", code); + }}); + } + + @Override + public Map checkCoupon(CheckCouponDTO checkCouponDTO) { + return exec("/meituan/certificateprepare", checkCouponDTO.getShopId(), checkCouponDTO); + } + + @Override + public Map revokeCoupon(CheckCouponDTO checkCouponDTO) { + return exec("/meituan/fulfilmentcertificatecancel", checkCouponDTO.getShopId(), checkCouponDTO); + } + + @Override + public Map getState(Integer shopId) { + return exec("/meituan/searchstorestatus", shopId, null); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3df3b0c..3a5fa0c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -39,6 +39,7 @@ logging: # file-name-pattern: log/%d{yyyy-MM}/cashier-client.%d{yyyy-MM-dd}.%i.log.gz + gateway: url: https://gateway.api.sxczgkj.cn/gate-service/ @@ -72,3 +73,6 @@ mybatis-plus: db-config: id-type: auto + +# php服务器地址 +phpServer: https://czgdoumei.sxczgkj.com/index.php/api diff --git a/src/main/resources/mapper/TbThirdPartyCouponRecordMapper.xml b/src/main/resources/mapper/TbThirdPartyCouponRecordMapper.xml new file mode 100644 index 0000000..444cbd9 --- /dev/null +++ b/src/main/resources/mapper/TbThirdPartyCouponRecordMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + id,order_id,state, + plat,code,create_time, + check_time,shop_id,num, + cart_id_list + +