feat: 1.美团团购券相关接口

This commit is contained in:
张松
2024-11-26 15:26:07 +08:00
parent 94285f68d0
commit 2d65fc817c
25 changed files with 784 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -196,6 +196,7 @@ public class PayController {
return result;
}
/**
* 会员支付
*

View File

@@ -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));
}
}

View File

@@ -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");
}

View File

@@ -51,5 +51,6 @@ public class TbOrderDetail implements Serializable {
private static final long serialVersionUID = 1L;
private Integer isMember;
private Integer isThirdCoupon;
}

View File

@@ -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();
}
}

View File

@@ -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<Integer> cartId;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<TbThirdPartyCouponRecord> {
}

View File

@@ -0,0 +1,11 @@
package com.chaozhanggui.system.cashierservice.resp;
import lombok.Data;
@Data
public class PhpCommonResp<T> {
private String code;
private String msg;
private long time;
private T data;
}

View File

@@ -53,5 +53,13 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
* @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<TbCashierCart> selectByIds(Integer shopId, Integer orderId, List<Integer> ids, TableConstant.OrderInfo.Status... statuses);
}

View File

@@ -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<TbOrderDetail> {
* @param totalAmount 总价格
*/
boolean updatePriceByCartId(Integer cartId, BigDecimal saleAmount, BigDecimal totalAmount);
boolean updateFieldByCartId(SFunction<TbOrderDetail, ?> field, Object val, List<Integer> cartIds);
}

View File

@@ -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<TbCashierCart> 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;
}
}

View File

@@ -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<TbThirdPartyCouponRecord> {
}

View File

@@ -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<String, Object> getActivateCoupon(Integer shopId, String code);
Map<String, Object> checkCoupon(CheckCouponDTO checkCouponDTO);
Map<String, Object> revokeCoupon(CheckCouponDTO checkCouponDTO);
Map<String, Object> getState(Integer shopId);
}

View File

@@ -100,5 +100,17 @@ public class MpCashierCartServiceImpl extends ServiceImpl<MPCashierCartMapper, T
}
return getOne(queryWrapper);
}
@Override
public List<TbCashierCart> selectByIds(Integer shopId, Integer orderId, List<Integer> ids, TableConstant.OrderInfo.Status... statuses) {
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.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);
}
}

View File

@@ -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<MPOrderDetailMapper, T
.set(TbOrderDetail::getPrice, saleAmount)
.set(TbOrderDetail::getPriceAmount, totalAmount));
}
@Override
public boolean updateFieldByCartId(SFunction<TbOrderDetail, ?> field, Object val, List<Integer> cartIds) {
LambdaUpdateWrapper<TbOrderDetail> query = new LambdaUpdateWrapper<TbOrderDetail>()
.set(field, val);
if (!cartIds.isEmpty()) {
query.in(TbOrderDetail::getCartId, cartIds);
}
return update(query);
}
}

View File

@@ -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<TbThirdPartyCouponRecordMapper, TbThirdPartyCouponRecord>
implements TbThirdPartyCouponRecordService{
}

View File

@@ -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> 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<Object> entity;
if (data != null) {
Map<String, Object> map = BeanUtil.beanToMap(data);
map.put("title", shopInfo.getShopName());
entity = new HttpEntity<>(map, headers);
} else {
entity = new HttpEntity<>(new HashMap<String, Object>(){{
put("title", shopInfo.getShopName());
}},headers);
}
// 发起请求
ResponseEntity<PhpCommonResp> 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<String, Object> getActivateCoupon(Integer shopId, String code) {
return exec("/meituan/fulfilmentcertificateprepare", shopId, new HashMap<String, Object>(){{
put("code", code);
}});
}
@Override
public Map<String, Object> checkCoupon(CheckCouponDTO checkCouponDTO) {
return exec("/meituan/certificateprepare", checkCouponDTO.getShopId(), checkCouponDTO);
}
@Override
public Map<String, Object> revokeCoupon(CheckCouponDTO checkCouponDTO) {
return exec("/meituan/fulfilmentcertificatecancel", checkCouponDTO.getShopId(), checkCouponDTO);
}
@Override
public Map<String, Object> getState(Integer shopId) {
return exec("/meituan/searchstorestatus", shopId, null);
}
}

View File

@@ -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

View File

@@ -0,0 +1,26 @@
<?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.chaozhanggui.system.cashierservice.mapper.TbThirdPartyCouponRecordMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbThirdPartyCouponRecord">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="orderId" column="order_id" jdbcType="INTEGER"/>
<result property="state" column="state" jdbcType="TINYINT"/>
<result property="plat" column="plat" jdbcType="VARCHAR"/>
<result property="code" column="code" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="checkTime" column="check_time" jdbcType="TIMESTAMP"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="num" column="num" jdbcType="INTEGER"/>
<result property="cartIdList" column="cart_id_list" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id,order_id,state,
plat,code,create_time,
check_time,shop_id,num,
cart_id_list
</sql>
</mapper>