parent
6a48c6b345
commit
f75f07107d
|
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
/**
|
||||
* 店铺会员相关
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
|
|
@ -24,6 +25,7 @@ public class UShopUserController {
|
|||
/**
|
||||
* 获取当前店铺会员信息
|
||||
* 请求头必须携带shopId, 不携带则会失败
|
||||
*
|
||||
* @return 店铺会员信息
|
||||
*/
|
||||
@GetMapping
|
||||
|
|
@ -33,6 +35,7 @@ public class UShopUserController {
|
|||
|
||||
/**
|
||||
* 获取当前用户所有店铺会员信息
|
||||
*
|
||||
* @return 店铺会员信息列表
|
||||
*/
|
||||
@GetMapping("/vipCard")
|
||||
|
|
@ -42,11 +45,12 @@ public class UShopUserController {
|
|||
|
||||
/**
|
||||
* 获取动态会员码
|
||||
*
|
||||
* @return 店铺会员信息列表
|
||||
*/
|
||||
@GetMapping("/code")
|
||||
public CzgResult<String> code() {
|
||||
return CzgResult.success(shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId()));
|
||||
return shopUserService.getCode(StpKit.USER.getLoginIdAsLong(), StpKit.USER.getShopId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.czg.controller;
|
|||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.ServletUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
|
@ -26,6 +27,22 @@ public class OrderPayController {
|
|||
@Resource
|
||||
private PayService payService;
|
||||
|
||||
|
||||
/**
|
||||
* 会员支付
|
||||
* payType 必填
|
||||
* <p>
|
||||
* scanCode(收银机使用) 会员码支付 authCode 必填
|
||||
* userPay(收银机使用) 选择用户支付 userId必填
|
||||
* <p>
|
||||
* accountPay(小程序使用) 密码支付 用户密码pwd 必填
|
||||
*/
|
||||
@PostMapping("vipPay")
|
||||
public CzgResult<Object> vipPayOrder(@Validated @RequestBody OrderPayParamDTO payParam) {
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付类型不可为空");
|
||||
return payService.vipPayOrder(payParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* h5支付
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.czg.controller;
|
||||
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.ServletUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
|
@ -29,10 +29,11 @@ public class VipPayController {
|
|||
|
||||
/**
|
||||
* 现金充值
|
||||
* 如果shop_info的 is_member_in_pwd=1 则pwd必填 店铺操作密码
|
||||
*/
|
||||
@PostMapping("cashPayVip")
|
||||
public CzgResult<Object> cashPayVip(@Validated @RequestBody VipPayParamDTO payParam) {
|
||||
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
|
||||
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
return payService.cashPayVip(payParam);
|
||||
}
|
||||
|
|
@ -44,7 +45,7 @@ public class VipPayController {
|
|||
*/
|
||||
@PostMapping("jsPayVip")
|
||||
public CzgResult<Map<String, Object>> jsPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
|
||||
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
|
||||
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
return payService.jsPayVip(ServletUtil.getClientIPByHeader(request), payParam);
|
||||
}
|
||||
|
|
@ -56,7 +57,7 @@ public class VipPayController {
|
|||
*/
|
||||
@PostMapping("ltPayVip")
|
||||
public CzgResult<Map<String, Object>> ltPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
|
||||
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
|
||||
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
return payService.ltPayVip(ServletUtil.getClientIPByHeader(request), payParam);
|
||||
}
|
||||
|
|
@ -66,7 +67,7 @@ public class VipPayController {
|
|||
*/
|
||||
@PostMapping("scanPayVip")
|
||||
public CzgResult<Map<String, Object>> scanPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
|
||||
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
|
||||
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
return payService.scanPayVip(ServletUtil.getClientIPByHeader(request), payParam);
|
||||
}
|
||||
|
|
@ -77,7 +78,7 @@ public class VipPayController {
|
|||
*/
|
||||
@PostMapping("microPayVip")
|
||||
public CzgResult<Map<String, Object>> microPayVip(@Validated @RequestBody VipPayParamDTO payParam) {
|
||||
payParam.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
|
||||
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
|
||||
return payService.microPayVip(payParam);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import lombok.NoArgsConstructor;
|
|||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
|
|
@ -100,14 +99,12 @@ public class ShopCouponDTO implements Serializable {
|
|||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
@JSONField(format = "HH:mm:ss")
|
||||
private Time useStartTime;
|
||||
private String useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
@JSONField(format = "HH:mm:ss")
|
||||
private Time useEndTime;
|
||||
private String useEndTime;
|
||||
|
||||
/**
|
||||
* 1-满减 2-商品
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class ShopUserMoneyEditDTO {
|
|||
private Integer type;
|
||||
/**
|
||||
* 关联id,
|
||||
* 霸王餐时 订单id
|
||||
* 订单支付/订单退款/霸王餐时 订单id
|
||||
* 支付/退款 tb_order_payment.id
|
||||
*/
|
||||
private Long relationId;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import lombok.NoArgsConstructor;
|
|||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
|
|
@ -100,14 +99,14 @@ public class ShopCoupon implements Serializable {
|
|||
private String useTimeType;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
* 可用开始时间 00:00
|
||||
*/
|
||||
private Time useStartTime;
|
||||
private String useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
* 可用结束时间 23:59
|
||||
*/
|
||||
private Time useEndTime;
|
||||
private String useEndTime;
|
||||
|
||||
/**
|
||||
* 1-满减 2-商品
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class ShopUserFlow implements Serializable {
|
|||
|
||||
/**
|
||||
* 关联id,
|
||||
* 霸王餐时 订单id
|
||||
* 订单支付/订单退款/霸王餐时 订单id
|
||||
* 支付/退款 tb_order_payment.id
|
||||
*/
|
||||
private Long relationId;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.czg.account.service;
|
|||
|
||||
import com.czg.account.dto.shopuser.*;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
|
|
@ -33,5 +34,5 @@ public interface ShopUserService extends IService<ShopUser> {
|
|||
*/
|
||||
Page<ShopUserVipCardDTO> vipCard(long userInfoId);
|
||||
|
||||
String getCode(long userInfoId, long shopId);
|
||||
CzgResult<String> getCode(long userInfoId, long shopId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,8 +183,10 @@ public class OrderInfoDTO implements Serializable {
|
|||
|
||||
/**
|
||||
* 支付订单号
|
||||
* tb_order_payment.id
|
||||
* tb_shop_user_flow.id
|
||||
*/
|
||||
private String payOrderNo;
|
||||
private Long payOrderId;
|
||||
|
||||
/**
|
||||
* 交易日期
|
||||
|
|
|
|||
|
|
@ -186,7 +186,11 @@ public class OrderInfo implements Serializable {
|
|||
|
||||
/**
|
||||
* 支付订单号
|
||||
* tb_order_payment.id
|
||||
* tb_shop_user_flow.id
|
||||
*/
|
||||
private Long payOrderId;
|
||||
|
||||
private String payOrderNo;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,15 +2,19 @@ package com.czg.service.account.service.impl;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.CoordinateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoAddDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoByCodeDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoEditDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.account.entity.MerchantRegister;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopTable;
|
||||
import com.czg.account.entity.SysUser;
|
||||
import com.czg.account.service.MerchantRegisterService;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopTableService;
|
||||
import com.czg.account.service.SysUserService;
|
||||
import com.czg.enums.StatusEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.exception.CzgException;
|
||||
|
|
@ -22,16 +26,15 @@ import com.mybatisflex.core.paginate.Page;
|
|||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Service
|
||||
@DubboService
|
||||
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.czg.account.service.ShopUserService;
|
|||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.mapper.ShopUserMapper;
|
||||
|
|
@ -23,6 +24,7 @@ import com.mybatisflex.core.query.QueryWrapper;
|
|||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
|
|
@ -73,6 +75,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long updateMoney(Long shopId, ShopUserMoneyEditDTO shopUserEditDTO) {
|
||||
shopUserEditDTO.setMoney(shopUserEditDTO.getMoney().setScale(2, RoundingMode.DOWN));
|
||||
ShopUser userInfo = getUserInfo(shopId, shopUserEditDTO.getId());
|
||||
|
|
@ -121,12 +124,13 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean add(Long shopId, ShopUserAddDTO shopUserAddDTO) {
|
||||
UserInfo userInfo = userInfoService.queryChain().eq(UserInfo::getPhone, shopUserAddDTO.getPhone()).one();
|
||||
if (userInfo == null) {
|
||||
userInfo = BeanUtil.copyProperties(shopUserAddDTO, UserInfo.class);
|
||||
userInfoService.save(userInfo);
|
||||
}else {
|
||||
} else {
|
||||
throw new ApiNotPrintException("此用户已存在");
|
||||
}
|
||||
|
||||
|
|
@ -143,12 +147,15 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getCode(long userInfoId, long shopId) {
|
||||
public CzgResult<String> getCode(long userInfoId, long shopId) {
|
||||
ShopUser shopUser = queryChain().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, userInfoId).one();
|
||||
AssertUtil.isNull(shopUser, "会员信息不存在");
|
||||
if (shopUser.getIsVip().equals(0)) {
|
||||
return CzgResult.failure("加入会员后使用");
|
||||
}
|
||||
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
|
||||
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getId() + ":" + dynamicCode, 1, 180);
|
||||
return dynamicCode;
|
||||
redisService.set(STR."\{RedisCst.SHOP_USER_DYNAMIC_CODE}\{shopUser.getShopId()}:\{dynamicCode}", shopUser.getId(), 180);
|
||||
return CzgResult.success(dynamicCode);
|
||||
}
|
||||
|
||||
public String generatePaymentCode(String shopId, String platformNumber) {
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import com.czg.account.dto.user.userinfo.UserInfoAssetsSummaryDTO;
|
||||
import com.czg.account.dto.user.userinfo.UserInfoDTO;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.service.account.mapper.ShopUserMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.service.account.mapper.UserInfoMapper;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
|
|
@ -19,7 +18,7 @@ import org.springframework.stereotype.Service;
|
|||
* @author Administrator
|
||||
* @since 2025-02-11
|
||||
*/
|
||||
@Service
|
||||
@DubboService
|
||||
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService{
|
||||
@Resource
|
||||
private ShopUserMapper shopUserMapper;
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ public class OrderPayParamDTO {
|
|||
private Long shopId;
|
||||
@NotNull(message = "订单不能为空")
|
||||
private Long orderId;
|
||||
private Long shopUserId;
|
||||
private String buyerRemark;
|
||||
private String returnUrl;
|
||||
private String payType;
|
||||
private String openId;
|
||||
private String authCode;
|
||||
private String pwd;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ public class VipPayParamDTO {
|
|||
@NotNull(message = "店铺不能为空")
|
||||
private Long shopId;
|
||||
private Long shopUserId;
|
||||
private Long userId;
|
||||
@NotNull(message = "充值金额不为空")
|
||||
private BigDecimal amount;
|
||||
|
||||
|
|
@ -29,4 +28,5 @@ public class VipPayParamDTO {
|
|||
private String payType;
|
||||
private String openId;
|
||||
private String authCode;
|
||||
private String pwd;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ import java.util.Map;
|
|||
* @author ww
|
||||
*/
|
||||
public interface PayService {
|
||||
/**
|
||||
* 会员支付
|
||||
*/
|
||||
CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam);
|
||||
/**
|
||||
* h5支付
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
|||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.entity.notify.CzgPayNotifyDTO;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
|
|
@ -50,6 +51,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
|
|
@ -105,10 +108,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
.set(OrderInfo::getPayAmount, new BigDecimal(czgCallBackDto.getAmount() / 100L))
|
||||
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
|
||||
.set(OrderInfo::getPaidTime, DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()))
|
||||
.set(OrderInfo::getPayOrderNo, czgCallBackDto.getMchOrderNo())
|
||||
.set(OrderInfo::getPayOrderId, payment.getId())
|
||||
.where(OrderInfo::getId).eq(payment.getSourceId())
|
||||
.update();
|
||||
//发送打票信息
|
||||
rabbitPublisher.sendOrderPrintMsg(payment.getSourceId().toString());
|
||||
} else if ("memberIn".equals(payment.getPayType())) {
|
||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||
if (shopUser == null) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopMerchant;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopActivateService;
|
||||
import com.czg.account.service.ShopMerchantService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.*;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
|
|
@ -18,13 +21,16 @@ import com.czg.order.service.OrderInfoService;
|
|||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.CzgPayService;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.enums.PayEnums;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.system.enums.SysParamCodeEnum;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.MD5Util;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.NonNull;
|
||||
|
|
@ -33,6 +39,8 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -50,24 +58,98 @@ public class PayServiceImpl implements PayService {
|
|||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private ShopActivateService shopActivateService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
private CzgPayService czgPayService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
return CzgResult.failure("该订单已不可支付");
|
||||
}
|
||||
if (!"afterPay".equals(orderInfo.getPayMode())
|
||||
&& orderInfo.getCreateTime().isAfter(LocalDateTimeUtil.offset(LocalDateTime.now(), -15, ChronoUnit.SECONDS))) {
|
||||
return CzgResult.failure("订单十五分钟内有效,当前已超时,请重新下单。");
|
||||
}
|
||||
|
||||
ShopUser shopUser = new ShopUser();
|
||||
if ("scanCode".equals(payParam.getPayType())) {
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "会员码不能为空");
|
||||
Object o = redisService.get(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getShopId() + ":" + payParam.getAuthCode());
|
||||
AssertUtil.isNull(o, "会员码已失效");
|
||||
shopUser = shopUserService.getById(o.toString());
|
||||
} else {
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
if ("userPay".equals(payParam.getPayType()) && shopInfo.getIsMemberInPwd() == 1) {
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试");
|
||||
shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
} else if ("accountPay".equals(payParam.getPayType())) {
|
||||
AssertUtil.isBlank(payParam.getPwd(), "支付密码不能为空");
|
||||
shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "会员不存在");
|
||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||
AssertUtil.isNull(userInfo, "用户信息不存在");
|
||||
if (!userInfo.getPayPwd().equals(MD5Util.md5AsHex(payParam.getPwd()))) {
|
||||
return CzgResult.failure("支付密码错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
AssertUtil.isNull(shopUser, "会员不存在");
|
||||
if (!shopUser.getShopId().equals(orderInfo.getShopId())) {
|
||||
return CzgResult.failure("违规操作,请确认店铺后重试");
|
||||
}
|
||||
if (shopUser.getAmount().compareTo(orderInfo.getOrderAmount()) < 0) {
|
||||
return CzgResult.failure("会员余额不足");
|
||||
}
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
|
||||
.id(orderInfo.getId())
|
||||
.money(orderInfo.getOrderAmount())
|
||||
.type(0)
|
||||
.bizEnum(ShopUserFlowBizEnum.ORDER_PAY)
|
||||
.relationId(orderInfo.getId())
|
||||
.build();
|
||||
//更新会员余额 并生成流水
|
||||
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
orderInfoService.updateChain()
|
||||
.set(OrderInfo::getPayAmount, orderInfo.getOrderAmount())
|
||||
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
|
||||
.set(OrderInfo::getPaidTime, LocalDateTime.now())
|
||||
.set(OrderInfo::getPayType, "vip-pay")
|
||||
.set(OrderInfo::getPayOrderId, flowId)
|
||||
.where(OrderInfo::getId).eq(orderInfo.getId())
|
||||
.update();
|
||||
//发送打票信息
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString());
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY.getValue(), payOrderNo);
|
||||
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
|
||||
"order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY.getValue(), paymentId);
|
||||
return h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
|
@ -81,8 +163,9 @@ public class PayServiceImpl implements PayService {
|
|||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), payOrderNo);
|
||||
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
|
||||
"order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), paymentId);
|
||||
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
|
@ -93,8 +176,9 @@ public class PayServiceImpl implements PayService {
|
|||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), payOrderNo);
|
||||
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
|
||||
"order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI.getValue() : PayEnums.WECHAT_MINI.getValue(), paymentId);
|
||||
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
|
@ -105,8 +189,9 @@ public class PayServiceImpl implements PayService {
|
|||
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
|
||||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN.getValue(), payOrderNo);
|
||||
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
|
||||
"order", payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN.getValue(), paymentId);
|
||||
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
|
@ -118,8 +203,9 @@ public class PayServiceImpl implements PayService {
|
|||
AssertUtil.isNull(orderInfo, "订单不存在");
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
||||
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(), "order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN.getValue(), payOrderNo);
|
||||
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
|
||||
"order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN.getValue(), paymentId);
|
||||
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
|
@ -127,9 +213,16 @@ public class PayServiceImpl implements PayService {
|
|||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> cashPayVip(VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
||||
.eq(ShopUser::getUserId, payParam.getUserId()).one();
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
if (shopInfo.getIsMemberInPwd().equals(1)) {
|
||||
AssertUtil.isBlank(shopInfo.getOperationPwd(), "请设置操作密码后使用");
|
||||
if (!shopInfo.getOperationPwd().equals(MD5Util.md5AsHex(payParam.getPwd()))) {
|
||||
return CzgResult.failure("支付密码错误");
|
||||
}
|
||||
}
|
||||
if (shopUser.getIsVip().equals(0)) {
|
||||
shopUserService.updateChain()
|
||||
.set(ShopUser::getIsVip, 1)
|
||||
|
|
@ -153,8 +246,7 @@ public class PayServiceImpl implements PayService {
|
|||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
||||
.eq(ShopUser::getUserId, payParam.getUserId()).one();
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
|
|
@ -167,8 +259,7 @@ public class PayServiceImpl implements PayService {
|
|||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
||||
.eq(ShopUser::getUserId, payParam.getUserId()).one();
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
|
|
@ -181,8 +272,7 @@ public class PayServiceImpl implements PayService {
|
|||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
||||
.eq(ShopUser::getUserId, payParam.getUserId()).one();
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
|
||||
|
|
@ -193,10 +283,9 @@ public class PayServiceImpl implements PayService {
|
|||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
|
||||
.eq(ShopUser::getUserId, payParam.getUserId()).one();
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, payParam.getAuthCode(), payParam.getAmount()));
|
||||
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
|
||||
|
|
@ -228,13 +317,14 @@ public class PayServiceImpl implements PayService {
|
|||
}
|
||||
|
||||
|
||||
private void initOrderPayment(OrderPayment payment) {
|
||||
private Long initOrderPayment(OrderPayment payment) {
|
||||
paymentService.save(payment);
|
||||
return payment.getId();
|
||||
}
|
||||
|
||||
private void upOrderPayInfo(@NonNull Long orderId, @NotBlank String payType, @NotBlank String payOrderNo) {
|
||||
private void upOrderPayInfo(@NonNull Long orderId, @NotBlank String payType, @NotBlank Long paymentId) {
|
||||
orderInfoService.updateChain()
|
||||
.set(OrderInfo::getPayOrderNo, payOrderNo)
|
||||
.set(OrderInfo::getPayOrderId, paymentId)
|
||||
.set(OrderInfo::getPayType, payType)
|
||||
.where(OrderInfo::getId).eq(orderId)
|
||||
.update();
|
||||
|
|
|
|||
Loading…
Reference in New Issue