Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai
2025-02-19 11:48:36 +08:00
33 changed files with 599 additions and 135 deletions

View File

@@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopTableCode;
/**
* 映射层。
*
* @author zs
* @since 2025-02-19
*/
public interface ShopTableCodeMapper extends BaseMapper<ShopTableCode> {
}

View File

@@ -1,18 +0,0 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.service.ShopAreaService;
import com.czg.service.account.mapper.ShopAreaMapper;
import org.springframework.stereotype.Service;
/**
* 店铺区域 服务层实现。
*
* @author zs
* @since 2025-02-18
*/
@Service
public class ShopAreaServiceImpl extends ServiceImpl<ShopAreaMapper, ShopTableArea> implements ShopAreaService{
}

View File

@@ -7,14 +7,8 @@ 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.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.account.entity.*;
import com.czg.account.service.*;
import com.czg.enums.StatusEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
@@ -42,6 +36,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
private MerchantRegisterService merchantRegisterService;
@Resource
private ShopTableService shopTableService;
@Resource
private ShopUserService shopUserService;
private ShopInfo getShopInfo(Long shopId) {
ShopInfo shopInfo = getById(shopId);
@@ -152,6 +148,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
// 计算距离,单位:米
distance = GeoUtil.getDistance(Long.parseLong(shopInfo.getLat()), Long.parseLong(shopInfo.getLng()), Long.parseLong(lat), Long.parseLong(lng));
}
return new ShopInfoByCodeDTO(distance, shopInfo, shopTable);
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, shopInfo.getId()).eq(ShopUser::getUserId, StpKit.USER.getLoginIdAsLong()).one();
return new ShopInfoByCodeDTO(distance, shopInfo, shopTable, shopUser != null && shopUser.getIsVip() != null && shopUser.getIsVip() == 1);
}
}

View File

@@ -19,6 +19,7 @@ import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +42,7 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
private ShopStaffPermissionService shopStaffPermissionService;
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean add(ShopStaffAddDTO shopStaffAddDTO) {
SysUser sysUser = sysUserService.addUser(shopStaffAddDTO.getName(), StpKit.USER.getLoginIdAsString() + "@" +shopStaffAddDTO.getAccountName(),
shopStaffAddDTO.getAccountPwd(), shopStaffAddDTO.getPhone(), shopStaffAddDTO.getRoleId());
@@ -50,7 +52,9 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
save(shopStaff);
// 权限添加
addPermission(shopStaff, shopStaffAddDTO.getShopPermissionIds());
if (shopStaffAddDTO.getShopPermissionIds() != null && !shopStaffAddDTO.getShopPermissionIds().isEmpty()) {
addPermission(shopStaff, shopStaffAddDTO.getShopPermissionIds());
}
return true;
}
@@ -66,7 +70,7 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
BeanUtil.copyProperties(shopStaffEditDTO, shopStaff);
updateById(shopStaff);
if (!shopStaffEditDTO.getShopPermissionIds().isEmpty()) {
if (shopStaffEditDTO.getShopPermissionIds() != null && !shopStaffEditDTO.getShopPermissionIds().isEmpty()) {
shopStaffPermissionService.updateChain().eq(ShopStaffPermission::getStaffId, shopStaff.getId())
.eq(ShopStaffPermission::getShopId, StpKit.USER.getShopId()).eq(ShopStaffPermission::getUserId, shopStaff.getId()).remove();
// 权限添加

View File

@@ -0,0 +1,54 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.area.ShopAreaAddDTO;
import com.czg.account.dto.area.ShopAreaEditDTO;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.service.ShopTableAreaService;
import com.czg.service.account.mapper.ShopAreaMapper;
import org.springframework.stereotype.Service;
/**
* 店铺区域 服务层实现。
*
* @author zs
* @since 2025-02-18
*/
@Service
public class ShopTableAreaServiceImpl extends ServiceImpl<ShopAreaMapper, ShopTableArea> implements ShopTableAreaService {
@Override
public Page<ShopTableArea> pageInfo(Long shopId, String name) {
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopTableArea::getShopId, shopId);
if (StrUtil.isNotBlank(name)) {
queryWrapper.like(ShopTableArea::getName, name);
}
return page(PageUtil.buildPage(), queryWrapper);
}
@Override
public boolean edit(Long shopId, ShopAreaEditDTO shopAreaEditDTO) {
ShopTableArea tableArea = queryChain().eq(ShopTableArea::getShopId, shopId).eq(ShopTableArea::getId, shopAreaEditDTO.getId()).one();
if (tableArea == null) {
throw new ApiNotPrintException("区域不存在");
}
BeanUtil.copyProperties(shopAreaEditDTO, tableArea);
return updateById(tableArea);
}
@Override
public Boolean add(ShopAreaAddDTO shopAreaAddDTO) {
ShopTableArea shopTableArea = BeanUtil.copyProperties(shopAreaAddDTO, ShopTableArea.class);
shopTableArea.setShopId(StpKit.USER.getShopId());
return save(shopTableArea);
}
}

View File

@@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopTableCode;
import com.czg.account.service.ShopTableCodeService;
import com.czg.service.account.mapper.ShopTableCodeMapper;
import org.springframework.stereotype.Service;
/**
* 服务层实现。
*
* @author zs
* @since 2025-02-19
*/
@Service
public class ShopTableCodeServiceImpl extends ServiceImpl<ShopTableCodeMapper, ShopTableCode> implements ShopTableCodeService{
}

View File

@@ -1,12 +1,16 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.czg.account.dto.table.ShopTableAddDTO;
import com.czg.account.dto.table.ShopTableBindDTO;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.service.ShopAreaService;
import com.czg.account.entity.ShopTableCode;
import com.czg.account.service.ShopTableAreaService;
import com.czg.account.service.ShopTableCodeService;
import com.czg.enums.ShopTableStatusEnum;
import com.czg.exception.ApiNotPrintException;
import com.mybatisflex.core.paginate.Page;
@@ -24,6 +28,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -36,7 +42,9 @@ import java.util.zip.ZipOutputStream;
@Service
public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable> implements ShopTableService{
@Resource
private ShopAreaService shopAreaService;
private ShopTableAreaService shopAreaService;
@Resource
private ShopTableCodeService shopTableCodeService;
@Override
public Boolean add(Long shopId, ShopTableAddDTO shopTableAddDTO) {
@@ -81,27 +89,24 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
}
// 获取可用 id
List<Integer> idList = queryChain().isNull(ShopTable::getTableCode)
.select("id").orderBy(ShopTable::getId, false)
.page(new Page<>(1, num)).getRecords().stream()
.map(ShopTable::getId).toList();
List<ShopTableCode> records = shopTableCodeService.queryChain().orderBy(ShopTableCode::getId, false).page(new Page<>(1, 1)).getRecords();
Map<String, Long> codeMap = shopTableCodeService.queryChain().eq(ShopTableCode::getShopId, shopId).select(ShopTableCode::getTableCode, ShopTableCode::getId)
.list().stream().collect(Collectors.toMap(ShopTableCode::getTableCode, ShopTableCode::getId));
long maxId = idList.isEmpty() ? 1 : idList.getLast();
long maxId = records.isEmpty() ? 0 : records.getFirst().getId();
// 设置 ZIP 响应头
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=shop_qrcodes_" + shopId + ".zip");
ArrayList<ShopTableCode> codeList = new ArrayList<>();
// 使用 ZipOutputStream 将二维码写入 zip
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
for (int i = 0; i < num; i++) {
String tableCode = shopId.toString();
if (i > idList.size() - 1) {
tableCode = tableCode + ++maxId;
} else {
tableCode = tableCode + idList.get(i);
}
tableCode = tableCode + RandomUtil.randomNumbers(8);
String tableCode = generateCode(1, shopId, ++maxId, codeMap);
codeMap.put(tableCode, maxId);
codeList.add(new ShopTableCode().setShopId(shopId).setTableCode(tableCode));
// 生成二维码
BufferedImage qrImage = QrCodeUtil.generate(tableCode, 300, 300);
@@ -117,5 +122,48 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
zipOut.closeEntry();
}
}
shopTableCodeService.saveBatch(codeList);
}
private String generateCode(Integer count, Long shopId, Long id, Map<String, Long> map) {
if (count > 100) {
throw new ApiNotPrintException("桌码生成失败");
}
String tableCode = "40" + shopId % 10 + id % 10 + RandomUtil.randomNumbers(7);
if (map.containsKey(tableCode)) {
generateCode(++count, shopId, id + 1, map);
}
return tableCode;
}
@Override
public Boolean bind(Long shopId, ShopTableBindDTO shopTableBindDTO) {
if (!StrUtil.startWith(shopTableBindDTO.getTableCode(), "40")) {
throw new ApiNotPrintException("错误码");
}
ShopTableCode tableCode = shopTableCodeService.queryChain().eq(ShopTableCode::getTableCode, shopTableBindDTO.getTableCode())
.eq(ShopTableCode::getShopId, shopId).one();
if (tableCode == null) {
throw new ApiNotPrintException("错误码");
}
if (tableCode.getState() == 1) {
throw new ApiNotPrintException("此桌码已绑定,请勿重复绑定");
}
ShopTable shopTable = queryChain().eq(ShopTable::getShopId, shopId).eq(ShopTable::getId, shopTableBindDTO.getId()).one();
if (shopTable == null) {
throw new ApiNotPrintException("台桌不存在");
}
tableCode.setBindTime(DateUtil.date().toLocalDateTime());
tableCode.setState(1);
shopTableCodeService.updateById(tableCode);
shopTable.setTableCode(tableCode.getTableCode());
return updateById(shopTable);
}
}

View File

@@ -154,7 +154,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
return CzgResult.failure("加入会员后使用");
}
String dynamicCode = generatePaymentCode(String.valueOf(shopId), String.valueOf(userInfoId));
redisService.set(STR."\{RedisCst.SHOP_USER_DYNAMIC_CODE}\{shopUser.getShopId()}:\{dynamicCode}", shopUser.getId(), 180);
redisService.set(RedisCst.SHOP_USER_DYNAMIC_CODE + shopUser.getShopId() + ":" + dynamicCode, shopUser.getId(), 180);
return CzgResult.success(dynamicCode);
}

View File

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

View File

@@ -28,7 +28,7 @@ public class Main {
// String packageName = "product";
// String packageName = "order";
String tableName = "tb_shop_area";
String tableName = "tb_shop_table_code";
String author = "zs";
//是否生成DTO实体 默认生成
boolean isGenerateDto = true;

View File

@@ -20,6 +20,9 @@ public class VipPayParamDTO {
private BigDecimal amount;
private String buyerRemark;
/**
* 跳转地址
*/
private String returnUrl;
/**
* 平台类型 pc 收银机客户端 wechat 微信小程序 alipay 支付宝小程序 admin-pc PC管理端 admin-app APP管理端
@@ -27,6 +30,9 @@ public class VipPayParamDTO {
private String platformType;
private String payType;
private String openId;
/**
* 扫码支付 扫描码
*/
private String authCode;
private String pwd;
}

View File

@@ -1,28 +0,0 @@
package com.czg.service.order.enums;
import lombok.Getter;
/**
* @author ww
*/
@Getter
public enum PayEnums {
MAIN_SCAN("main_scan", "主扫"),
BACK_SCAN("back_scan", "被扫"),
WECHAT_MINI("wechat_mini", "微信小程序"),
ALIPAY_MINI("alipay_mini", "支付宝小程序"),
VIP_PAY("vip_pay", "会员支付"),
CASH_PAY("cash_pay", "现金支付"),
H5_PAY("h5_pay", "h5支付");
private final String value;
private final String msg;
PayEnums(String value, String msg) {
this.value = value;
this.msg = msg;
}
}

View File

@@ -16,6 +16,10 @@ import java.util.Map;
* @author ww
*/
public interface PayService {
/**
* 现金支付
*/
CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam);
/**
* 会员支付
*/

View File

@@ -1,6 +1,7 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
@@ -14,6 +15,7 @@ import com.czg.order.dto.OrderInfoQueryDTO;
import com.czg.order.entity.OrderDetail;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
@@ -25,6 +27,7 @@ import com.czg.utils.CzgStrUtils;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
@@ -34,6 +37,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -104,15 +108,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if ("TRADE_SUCCESS".equals(czgCallBackDto.getState())) {
if ("order".equals(payment.getPayType())) {
updateChain()
.set(OrderInfo::getPayAmount, new BigDecimal(czgCallBackDto.getAmount() / 100L))
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
.set(OrderInfo::getPaidTime, DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()))
.set(OrderInfo::getPayOrderId, payment.getId())
.where(OrderInfo::getId).eq(payment.getSourceId())
.update();
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(payment.getSourceId().toString());
upOrderInfo(payment.getSourceId(), new BigDecimal(czgCallBackDto.getAmount() / 100L),
DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()), payment.getId(), null);
} else if ("memberIn".equals(payment.getPayType())) {
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
if (shopUser == null) {
@@ -152,4 +149,33 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
public void refundCallBackOrder() {
}
/**
* 更新订单信息 (支付成功后调用)
*
* @param payAmount 注意是分 还是元
* @param payTime 支付时间
* @param payOrderId 支付订单号
* 现金支付为空
* 会员支付为tb_shop_user_flow.id
* 其它支付为 tb_order_payment.id
*/
@Override
public void upOrderInfo(Long orderId, BigDecimal payAmount, LocalDateTime payTime, Long payOrderId, PayEnums payType) {
UpdateChain<OrderInfo> updateChain = updateChain()
.set(OrderInfo::getPayAmount, payAmount)
.set(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())
.set(OrderInfo::getPaidTime, payTime)
.where(OrderInfo::getId).eq(orderId);
if (payOrderId != null) {
updateChain.set(OrderInfo::getPayOrderId, payOrderId);
}
if (ObjectUtil.isNotNull(payType)) {
updateChain.set(OrderInfo::getPayType, payType.getValue());
}
updateChain.update();
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(orderId.toString());
}
}

View File

@@ -17,6 +17,7 @@ import com.czg.entity.resp.*;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.resp.CzgResult;
@@ -24,8 +25,6 @@ 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;
@@ -76,19 +75,32 @@ public class PayServiceImpl implements PayService {
private final BigDecimal MONEY_RATE = new BigDecimal("100");
@Override
@Transactional
public CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
private OrderInfo checkPay(Long orderId) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
AssertUtil.isNull(orderInfo, "订单不存在");
if (!"unpaid".equals(orderInfo.getStatus())) {
return CzgResult.failure("该订单已不可支付");
throw new ValidateException("该订单已不可支付");
}
if (!"afterPay".equals(orderInfo.getPayMode())
&& orderInfo.getCreateTime().isAfter(LocalDateTimeUtil.offset(LocalDateTime.now(), -15, ChronoUnit.SECONDS))) {
return CzgResult.failure("订单十五分钟内有效,当前已超时,请重新下单。");
throw new ValidateException("订单十五分钟内有效,当前已超时,请重新下单。");
}
return orderInfo;
}
@Override
@Transactional
public CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = checkPay(payParam.getOrderId());
orderInfoService.upOrderInfo(orderInfo.getId(), orderInfo.getOrderAmount(),
LocalDateTime.now(), null, PayEnums.CASH_PAY);
return CzgResult.success();
}
@Override
@Transactional
public CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = checkPay(payParam.getOrderId());
ShopUser shopUser = new ShopUser();
if ("scanCode".equals(payParam.getPayType())) {
AssertUtil.isBlank(payParam.getAuthCode(), "会员码不能为空");
@@ -128,28 +140,19 @@ public class PayServiceImpl implements PayService {
.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());
orderInfoService.upOrderInfo(orderInfo.getId(), orderInfo.getOrderAmount(),
LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
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, "订单不存在");
OrderInfo orderInfo = checkPay(payParam.getOrderId());
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
"order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY.getValue(), paymentId);
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId);
return h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@@ -158,14 +161,13 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
OrderInfo orderInfo = checkPay(payParam.getOrderId());
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
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);
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId);
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@@ -173,12 +175,13 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
OrderInfo orderInfo = checkPay(payParam.getOrderId());
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
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);
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId);
return ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@@ -186,12 +189,12 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
OrderInfo orderInfo = checkPay(payParam.getOrderId());
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
"order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN.getValue(), paymentId);
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN, paymentId);
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@@ -199,13 +202,12 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
OrderInfo orderInfo = checkPay(payParam.getOrderId());
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), payParam.getOrderId(),
"order", payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN.getValue(), paymentId);
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId);
return microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
}
@@ -322,10 +324,10 @@ public class PayServiceImpl implements PayService {
return payment.getId();
}
private void upOrderPayInfo(@NonNull Long orderId, @NotBlank String payType, @NotBlank Long paymentId) {
private void upOrderPayInfo(@NonNull Long orderId, @NonNull PayEnums payType, @NotBlank Long paymentId) {
orderInfoService.updateChain()
.set(OrderInfo::getPayOrderId, paymentId)
.set(OrderInfo::getPayType, payType)
.set(OrderInfo::getPayType, payType.getValue())
.where(OrderInfo::getId).eq(orderId)
.update();
}