Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai 2025-02-19 19:48:43 +08:00
commit 6312eff400
25 changed files with 582 additions and 46 deletions

View File

@ -33,7 +33,7 @@ public class MerchantRegisterController {
* @return 激活码列表 * @return 激活码列表
*/ */
@SaAdminCheckRole("管理员") @SaAdminCheckRole("管理员")
@SaAdminCheckPermission("merchantRegister:list") @SaAdminCheckPermission(value = "merchantRegister:list", name = "激活码列表")
@GetMapping @GetMapping
public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, String startTime, String endTime) { public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, String startTime, String endTime) {
return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime)); return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime));

View File

@ -0,0 +1,51 @@
package com.czg.controller.admin;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.extend.ShopExtendDTO;
import com.czg.account.entity.ShopExtend;
import com.czg.account.service.ShopExtendService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 店铺拓展配置/装修
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopExtend")
public class ShopExtendController {
@Resource
private ShopExtendService shopExtendService;
/**
* 获取当前店铺拓展参数
* @param autoKey key名称
* @return 参数列表
*/
@SaAdminCheckPermission(value = "shopExtend:list", name = "店铺拓展参数列表")
@GetMapping
public CzgResult<List<ShopExtend>> list(String autoKey) {
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopExtend::getShopId, StpKit.USER.getShopId());
if (StrUtil.isNotBlank(autoKey)) {
queryWrapper.eq(ShopExtend::getAutoKey, autoKey);
}
return CzgResult.success(shopExtendService.list(queryWrapper));
}
/**
* 店铺拓展参数修改
* @return 是否成功
*/
@SaAdminCheckPermission(value = "shopExtend:edit", name = "店铺拓展参数修改")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopExtendDTO shopExtendDTO) {
return CzgResult.success(shopExtendService.edit(StpKit.USER.getShopId(), shopExtendDTO));
}
}

View File

@ -28,9 +28,18 @@ public class NotifyController {
@RequestMapping("/payCallBack") @RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){ public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){
JSONObject czg = CzgPayUtils.getCzg(respParams); JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "回调数据为空"); AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg); log.info("支付回调数据为:{}", czg);
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg); orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
return SUCCESS; return SUCCESS;
} }
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams){
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "退款回调数据为空");
log.info("退款回调数据为:{}", czg);
orderInfoService.refundCallBackOrder(czg.getString("mchOrderNo"), czg);
return SUCCESS;
}
} }

View File

@ -2,6 +2,7 @@ package com.czg.controller;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.service.order.dto.VipPayParamDTO; import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import com.czg.service.order.service.PayService; import com.czg.service.order.service.PayService;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.utils.ServletUtil; import com.czg.utils.ServletUtil;
@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Map; import java.util.Map;
/** /**
@ -68,7 +70,7 @@ public class VipPayController {
@PostMapping("/scanPayVip") @PostMapping("/scanPayVip")
public CzgResult<Map<String, Object>> scanPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) { public CzgResult<Map<String, Object>> scanPayVip(HttpServletRequest request, @Validated @RequestBody VipPayParamDTO payParam) {
AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id"); AssertUtil.isNull(payParam.getShopUserId(), "充值失败 未指定店铺用户Id");
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType")); payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(request, "platformType"));
return payService.scanPayVip(ServletUtil.getClientIPByHeader(request), payParam); return payService.scanPayVip(ServletUtil.getClientIPByHeader(request), payParam);
} }
@ -82,4 +84,34 @@ public class VipPayController {
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType")); payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(ServletUtil.getRequest(), "platformType"));
return payService.microPayVip(payParam); return payService.microPayVip(payParam);
} }
/**
* 退款前置
* 最大退款金额 充值金额 inAmount
*/
@PostMapping("/refundVipBefore")
public CzgResult<Map<String, BigDecimal>> refundVipBefore(@Validated @RequestBody VipRefundDTO payParam) {
return payService.refundVipBefore(payParam);
}
/**
* cashRefund 是否是现金退款
* 会员退款(先调用 退款前置接口 refundVipBefore)
* 最大退款金额为 充值金额 inAmount
* 理论可退最大金额为
* 用户余额-赠送金额 >充值金额 则可退充值金额
* 实际可退最大金额为 充值金额
* 如果实际 大于 理论 需要勾选 outOfRange 超额退款 为true 默认为false
*/
@PostMapping("/refundVip")
public CzgResult<Object> refundVip(HttpServletRequest request, @Validated @RequestBody VipRefundDTO payParam) {
AssertUtil.isNull(payParam.getRefAmount(), "退款金额不能为空");
if (payParam.getRefAmount().compareTo(BigDecimal.ZERO) <= 0) {
return CzgResult.failure("退款金额必须大于0");
} else if (payParam.getRefAmount().compareTo(new BigDecimal("10001")) > 0) {
return CzgResult.failure("退款金额过大");
}
payParam.setPlatformType(ServletUtil.getHeaderIgnoreCase(request, "platformType"));
return payService.refundVip(payParam);
}
} }

View File

@ -28,6 +28,8 @@ public @interface SaAdminCheckPermission {
@AliasFor(annotation = SaCheckPermission.class) @AliasFor(annotation = SaCheckPermission.class)
String [] value() default {}; String [] value() default {};
String name() default "";
/** /**
* 验证模式AND | OR默认AND * 验证模式AND | OR默认AND
* @return 验证模式 * @return 验证模式

View File

@ -0,0 +1,42 @@
package com.czg.account.dto.extend;
import com.alibaba.fastjson2.annotation.JSONField;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 店铺扩展信息 实体类
*
* @author zs
* @since 2025-02-19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopExtendDTO {
/**
* 自增id
*/
@NotNull
private String autokey;
/**
*
*/
@NotEmpty
private String value;
}

View File

@ -1,16 +1,19 @@
package com.czg.account.dto.flow; package com.czg.account.dto.flow;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/** /**
* 用户余额流水 实体类 * 用户余额流水 实体类
* *
@ -26,27 +29,56 @@ public class ShopUserFlowDTO implements Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id; private Long id;
private Long userId; private Long userId;
private Long shopId; private Long shopId;
/**
* 充值金额
*/
private BigDecimal amount; private BigDecimal amount;
/**
* 当前余额
*/
private BigDecimal balance; private BigDecimal balance;
/**
* 已退款金额
*/
private BigDecimal refundAmount;
/** /**
* 类型cashIn 会员充值awardIn 充值奖励wechatIn 微信小程序充值alipayIn 支付宝小程序充值orderPay 订单消费orderRefund 订单退款rechargeRefund 充值退款 adminOp 管理员手动增减 * 类型
* cashIn 现金充值
* wechatIn 微信小程序充值
* alipayIn 支付宝小程序充值
* awardIn 充值奖励
* rechargeRefund 充值退款
* <p>
* orderPay 订单消费
* orderRefund 订单退款
* <p>
* adminIn 管理员充值
* adminOut管理员消费
*/ */
private String bizCode; private String bizCode;
/**
* 备注
*/
private String remark;
/** /**
* 加减号 * 关联id
* 订单支付/订单退款/霸王餐时 订单id
* 支付/退款 tb_order_payment.id
*/ */
private String type; private Long relationId;
/**
private String remark; * 充值记录id 当前表的id
* 退款使用
*/
private Long rechargeId;
/** /**
* 关联订单编号支付单号退款单号 * 关联订单编号支付单号退款单号

View File

@ -31,6 +31,11 @@ public class ShopUserMoneyEditDTO {
* 支付/退款 tb_order_payment.id * 支付/退款 tb_order_payment.id
*/ */
private Long relationId; private Long relationId;
/**
* 充值记录id 当前表的id
* 退款使用
*/
private Long rechargeId;
/** /**
* 浮动金额 * 浮动金额
*/ */

View File

@ -0,0 +1,78 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺扩展信息 实体类
*
* @author zs
* @since 2025-02-19
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_extend")
public class ShopExtend implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增id
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 商户Id
*/
private Integer shopId;
/**
* img:图片text:文本
*/
private String type;
/**
* 描述
*/
private String name;
/**
* 自定义key
*/
private String autoKey;
/**
*
*/
private String value;
/**
* 更新时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
private String detail;
}

View File

@ -127,4 +127,11 @@ public class ShopUser implements Serializable {
@Column(onInsertValue = "now()", onUpdateValue = "now()") @Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime; private LocalDateTime updateTime;
public BigDecimal getAmount() {
if (amount == null) {
return BigDecimal.ZERO;
}
return amount;
}
} }

View File

@ -4,6 +4,7 @@ import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -37,36 +38,67 @@ public class ShopUserFlow implements Serializable {
private Long userId; private Long userId;
private Long shopId; private Long shopId;
/**
* 充值金额
*/
private BigDecimal amount; private BigDecimal amount;
/**
* 当前余额
*/
private BigDecimal balance; private BigDecimal balance;
/**
* 已退款金额
*/
private BigDecimal refundAmount;
/** /**
* 类型cashIn 会员充值awardIn 充值奖励wechatIn 微信小程序充值alipayIn 支付宝小程序充值orderPay 订单消费orderRefund 订单退款rechargeRefund 充值退款 adminOp 管理员手动增减 * 类型
* cashIn 现金充值
* wechatIn 微信小程序充值
* alipayIn 支付宝小程序充值
* awardIn 充值奖励
* rechargeRefund 充值退款
* <p>
* orderPay 订单消费
* orderRefund 订单退款
* <p>
* adminIn 管理员充值
* adminOut管理员消费
*/ */
private String bizCode; private String bizCode;
/** /**
* 加减号 * 备注
*/ */
private String type;
private String remark; private String remark;
/**
* 是否可退款
*/
private Integer isCanRefund;
/** /**
* 关联id * 关联id
* 订单支付/订单退款/霸王餐时 订单id * 订单支付/订单退款/霸王餐时 订单id
* 支付/退款 tb_order_payment.id * 支付/退款 tb_order_payment.id
*/ */
private Long relationId; private Long relationId;
/**
* 充值记录id 当前表的id
* 退款使用
*/
private Long rechargeId;
@Column(onInsertValue = "now()") @Column(onInsertValue = "now()")
private LocalDateTime createTime; private LocalDateTime createTime;
public BigDecimal getAmount() {
if (amount == null) {
return BigDecimal.ZERO;
}
return amount;
}
public BigDecimal getRefundAmount() {
if (refundAmount == null) {
return BigDecimal.ZERO;
}
return refundAmount;
}
} }

View File

@ -0,0 +1,17 @@
package com.czg.account.service;
import com.czg.account.dto.extend.ShopExtendDTO;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopExtend;
/**
* 店铺扩展信息 服务层
*
* @author zs
* @since 2025-02-19
*/
public interface ShopExtendService extends IService<ShopExtend> {
Boolean edit(Long shopId, ShopExtendDTO shopExtendDTO);
}

View File

@ -1,7 +1,7 @@
package com.czg.account.service; package com.czg.account.service;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopUserFlow; import com.czg.account.entity.ShopUserFlow;
import com.mybatisflex.core.service.IService;
/** /**
* 用户余额流水 服务层 * 用户余额流水 服务层

View File

@ -7,6 +7,8 @@ import com.czg.order.enums.PayEnums;
import com.czg.order.vo.OrderInfoVo; import com.czg.order.vo.OrderInfoVo;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import jakarta.validation.constraints.NotBlank;
import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -21,9 +23,9 @@ public interface OrderInfoService extends IService<OrderInfo> {
Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param); Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param);
void payCallBackOrder(String orderNo, JSONObject resultJson); void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
void refundCallBackOrder(); void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
void upOrderInfo(Long orderId, BigDecimal payAmount, LocalDateTime payTime, Long payOrderId, PayEnums payType); void upOrderInfo(Long orderId, BigDecimal payAmount, LocalDateTime payTime, Long payOrderId, PayEnums payType);
} }

View File

@ -1,6 +1,7 @@
package com.czg; package com.czg;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.Row;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -41,12 +42,15 @@ public class LoadingRole implements CommandLineRunner {
Method valueMethod = annotationClass.getMethod("value"); Method valueMethod = annotationClass.getMethod("value");
String[] permissions = (String[]) valueMethod.invoke(annotation); String[] permissions = (String[]) valueMethod.invoke(annotation);
Method nameMethod = annotationClass.getMethod("name");
String permissionName = (String) nameMethod.invoke(annotation);
for (String s : permissions) { for (String s : permissions) {
String sql = "select * from sys_menu where permission=?"; String sql = "select * from sys_menu where permission=?";
Row menu1 = Db.selectOneBySql(sql, s); Row menu1 = Db.selectOneBySql(sql, s);
if (menu1 != null) { if (menu1 != null) {
Long menuId = menu1.getLong("menu_id"); Long menuId = menu1.getLong("menu_id");
String name = menu1.getString("name"); String title = menu1.getString("title");
String permission = menu1.getString("permission"); String permission = menu1.getString("permission");
String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?"; String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?";
List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L); List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L);
@ -54,14 +58,20 @@ public class LoadingRole implements CommandLineRunner {
if (count1.isEmpty()) { if (count1.isEmpty()) {
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);"; sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
Db.insertBySql(sql, menu1, 1L); Db.insertBySql(sql, menu1, 1L);
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", name, permission); log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", title, permission);
}
if (StrUtil.isNotBlank(permissionName) && !title.equals(permissionName)) {
sql = "update sys_menu set title=? where menu_id=?";
Db.updateBySql(sql, permissionName, menuId);
log.info("接口菜单修改成功, 旧名称: {}, 新菜单名称: {}", title, permissionName);
} }
continue; continue;
} }
sql = "INSERT INTO `czg_cashier`.`sys_menu` ( `sub_count`, `type`, `title`, `name`, `component`, `menu_sort`, `icon`, `path`, `i_frame`, `cache`, `hidden`, `permission`, `create_by`, `update_by`, `create_time`, `update_time`, `active_menu`, `is_shop`) VALUES " + sql = "INSERT INTO `czg_cashier`.`sys_menu` ( `sub_count`, `type`, `title`, `name`, `component`, `menu_sort`, `icon`, `path`, `i_frame`, `cache`, `hidden`, `permission`, `create_by`, `update_by`, `create_time`, `update_time`, `active_menu`, `is_shop`) VALUES " +
"(0, 2, ?, NULL, '', 2, '', '', b'0', b'0', b'0', ?, NULL, NULL, ?, NULL, NULL, 0);"; "(0, 2, ?, NULL, '', 2, '', '', b'0', b'0', b'0', ?, NULL, NULL, ?, NULL, NULL, 0);";
Db.insertBySql(sql, s, s, DateUtil.date()); Db.insertBySql(sql, StrUtil.isNotBlank(permissionName) ? permissionName : s, s, DateUtil.date());
sql = "select * from sys_menu where permission=?"; sql = "select * from sys_menu where permission=?";
Row info = Db.selectOneBySql(sql, s); Row info = Db.selectOneBySql(sql, s);
Long menuId = info.getLong("menu_id"); Long menuId = info.getLong("menu_id");

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopExtend;
/**
* 店铺扩展信息 映射层
*
* @author zs
* @since 2025-02-19
*/
public interface ShopExtendMapper extends BaseMapper<ShopExtend> {
}

View File

@ -0,0 +1,33 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.account.dto.extend.ShopExtendDTO;
import com.czg.exception.ApiNotPrintException;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopExtend;
import com.czg.account.service.ShopExtendService;
import com.czg.service.account.mapper.ShopExtendMapper;
import org.springframework.stereotype.Service;
/**
* 店铺扩展信息 服务层实现
*
* @author zs
* @since 2025-02-19
*/
@Service
public class ShopExtendServiceImpl extends ServiceImpl<ShopExtendMapper, ShopExtend> implements ShopExtendService{
@Override
public Boolean edit(Long shopId, ShopExtendDTO shopExtendDTO) {
ShopExtend shopExtend = queryChain().eq(ShopExtend::getShopId, shopId).eq(ShopExtend::getAutoKey, shopExtendDTO.getAutokey()).one();
if (shopExtend == null) {
throw new ApiNotPrintException("key有误");
}
BeanUtil.copyProperties(shopExtendDTO, shopExtend);
shopExtend.setAutoKey(null);
return update(shopExtend, new QueryWrapper().eq(ShopExtend::getShopId, shopId).eq(ShopExtend::getAutoKey, shopExtendDTO.getAutokey()));
}
}

View File

@ -1,11 +1,10 @@
package com.czg.service.account.service.impl; package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopUserFlow; import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.ShopUserFlowService; import com.czg.account.service.ShopUserFlowService;
import com.czg.service.account.mapper.ShopUserFlowMapper; import com.czg.service.account.mapper.ShopUserFlowMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
/** /**
* 用户余额流水 服务层实现 * 用户余额流水 服务层实现
@ -14,6 +13,6 @@ import org.springframework.stereotype.Service;
* @since 2025-02-13 * @since 2025-02-13
*/ */
@DubboService @DubboService
public class ShopUserFlowServiceImpl extends ServiceImpl<ShopUserFlowMapper, ShopUserFlow> implements ShopUserFlowService{ public class ShopUserFlowServiceImpl extends ServiceImpl<ShopUserFlowMapper, ShopUserFlow> implements ShopUserFlowService {
} }

View File

@ -91,15 +91,14 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
throw new ApiNotPrintException("增减用户余额操作失败"); throw new ApiNotPrintException("增减用户余额操作失败");
} }
userFlow.setIsCanRefund(0);
userFlow.setUserId(userInfo.getUserId()); userFlow.setUserId(userInfo.getUserId());
userFlow.setShopId(userInfo.getShopId()); userFlow.setShopId(userInfo.getShopId());
userFlow.setAmount(shopUserEditDTO.getMoney()); userFlow.setAmount(shopUserEditDTO.getType() == 0 ? shopUserEditDTO.getMoney().negate() : shopUserEditDTO.getMoney());
userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney())); userFlow.setBalance(shopUserEditDTO.getType() == 0 ? userInfo.getAmount().subtract(shopUserEditDTO.getMoney()) : userInfo.getAmount().add(shopUserEditDTO.getMoney()));
userFlow.setBizCode(shopUserEditDTO.getBizEnum().getCode()); userFlow.setBizCode(shopUserEditDTO.getBizEnum().getCode());
// userFlow.setType(shopUserEditDTO.getType() == 0 ? "-" : "+");
userFlow.setRemark(shopUserEditDTO.getRemark()); userFlow.setRemark(shopUserEditDTO.getRemark());
userFlow.setRelationId(shopUserEditDTO.getRelationId()); userFlow.setRelationId(shopUserEditDTO.getRelationId());
userFlow.setRechargeId(shopUserEditDTO.getRechargeId());
shopUserFlowService.save(userFlow); shopUserFlowService.save(userFlow);
return userFlow.getId(); return userFlow.getId();
} }

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.ShopExtendMapper">
</mapper>

View File

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

View File

@ -0,0 +1,47 @@
package com.czg.service.order.dto;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author ww
* @description
*/
@Data
public class VipRefundDTO {
/**
* 店铺id
*/
@NotNull(message = "店铺不能为空")
private Long shopId;
/**
* 店铺用户id
*/
@NotNull(message = "店铺用户不能为空")
private Long shopUserId;
/**
* 退款id 会员流水id tb_shop_user_flow.id
*/
@NotNull(message = "会员流水不能为空")
private Long flowId;
/**
* 退款金额
*/
private BigDecimal refAmount;
/**
* 退款原因
*/
private String remark;
/**
* 超额退款
*/
private boolean outOfRange;
//现金退款
private boolean cashRefund;
private String platformType;
}

View File

@ -5,6 +5,7 @@ import com.czg.entity.resp.CzgRefundResp;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.service.order.dto.OrderPayParamDTO; import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO; import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Map; import java.util.Map;
@ -75,6 +76,16 @@ public interface PayService {
*/ */
CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam); CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam);
/**
* 退款前校验
*/
CzgResult<Map<String, BigDecimal>> refundVipBefore(VipRefundDTO payParam);
/**
* 会员退款
*/
CzgResult<Object> refundVip(VipRefundDTO payParam);
/** /**
* 订单退款 * 订单退款

View File

@ -10,6 +10,7 @@ import com.czg.account.service.ShopActivateService;
import com.czg.account.service.ShopUserService; import com.czg.account.service.ShopUserService;
import com.czg.config.RabbitPublisher; import com.czg.config.RabbitPublisher;
import com.czg.entity.notify.CzgPayNotifyDTO; import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.order.dto.OrderInfoQueryDTO; import com.czg.order.dto.OrderInfoQueryDTO;
import com.czg.order.entity.OrderDetail; import com.czg.order.entity.OrderDetail;
@ -33,6 +34,7 @@ import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -97,7 +99,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
@Override @Override
@Transactional @Transactional
public void payCallBackOrder(@NotBlank String orderNo, @NotBlank JSONObject resultJson) { public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson) {
CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class); CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class);
OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one(); OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one();
paymentService.updateChain() paymentService.updateChain()
@ -146,8 +148,21 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
} }
@Override @Override
public void refundCallBackOrder() { public void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson) {
CzgRefundNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgRefundNotifyDTO.class);
OrderPayment payment = paymentService.queryChain().eq(OrderPayment::getOrderNo, orderNo).one();
paymentService.updateChain()
.set(OrderPayment::getTradeNumber, czgCallBackDto.getRefundOrderId())
.set(OrderPayment::getRespJson, resultJson.toString())
.where(OrderPayment::getId).eq(payment.getId())
.update();
if (!"SUCCESS".equals(czgCallBackDto.getState())) {
if ("refund".equals(payment.getPayType())) {
//订单退款回滚
} else if ("memberRefund".equals(payment.getPayType())) {
//会员退款回滚
}
}
} }

View File

@ -5,10 +5,7 @@ import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO; import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopInfo; import com.czg.account.entity.*;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.*; import com.czg.account.service.*;
import com.czg.config.RabbitPublisher; import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst; import com.czg.config.RedisCst;
@ -25,6 +22,7 @@ import com.czg.service.CzgPayService;
import com.czg.service.RedisService; import com.czg.service.RedisService;
import com.czg.service.order.dto.OrderPayParamDTO; import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO; import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import com.czg.service.order.service.PayService; import com.czg.service.order.service.PayService;
import com.czg.system.enums.SysParamCodeEnum; import com.czg.system.enums.SysParamCodeEnum;
import com.czg.system.service.SysParamsService; import com.czg.system.service.SysParamsService;
@ -62,6 +60,10 @@ public class PayServiceImpl implements PayService {
private ShopInfoService shopInfoService; private ShopInfoService shopInfoService;
@DubboReference @DubboReference
private ShopActivateService shopActivateService; private ShopActivateService shopActivateService;
@DubboReference
private ShopUserFlowService userFlowService;
@DubboReference
private ShopActivateInRecordService inRecordService;
@Resource @Resource
private RabbitPublisher rabbitPublisher; private RabbitPublisher rabbitPublisher;
@Resource @Resource
@ -294,6 +296,96 @@ public class PayServiceImpl implements PayService {
"会员充值", payParam.getAuthCode(), payParam.getBuyerRemark(), "")); "会员充值", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
} }
@Override
public CzgResult<Map<String, BigDecimal>> refundVipBefore(VipRefundDTO payParam) {
Map<String, BigDecimal> resultMap = new HashMap<>(5);
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
AssertUtil.isNull(shopUser, "该店铺用户不存在");
ShopUserFlow inFlow = userFlowService.queryChain().select(ShopUserFlow::getAmount)
.eq(ShopUserFlow::getId, payParam.getFlowId()).one();
AssertUtil.isNull(inFlow, "充值记录不存在");
ShopUserFlow giftFlow = userFlowService.queryChain().select(ShopUserFlow::getAmount)
.eq(ShopUserFlow::getRelationId, payParam.getFlowId())
.eq(ShopUserFlow::getBizCode, ShopUserFlowBizEnum.AWARD_IN.getCode())
.one();
resultMap.put("amount", shopUser.getAmount());
resultMap.put("inAmount", inFlow.getAmount( ));
resultMap.put("inRefundAmount", inFlow.getRefundAmount());
resultMap.put("giftAmount", giftFlow == null ? BigDecimal.ZERO : giftFlow.getAmount());
resultMap.put("giftRefundAmount", giftFlow == null ? BigDecimal.ZERO : giftFlow.getRefundAmount());
return CzgResult.success(resultMap);
}
@Override
public CzgResult<Object> refundVip(VipRefundDTO refPayParam) {
ShopUser shopUser = shopUserService.getById(refPayParam.getShopUserId());
ShopUserFlow inFlow = userFlowService.queryChain().select(ShopUserFlow::getAmount)
.eq(ShopUserFlow::getId, refPayParam.getFlowId()).one();
AssertUtil.isNull(inFlow, "充值记录不存在");
ShopUserFlow giftFlow = userFlowService.queryChain().select(ShopUserFlow::getAmount)
.eq(ShopUserFlow::getRelationId, refPayParam.getFlowId())
.eq(ShopUserFlow::getBizCode, ShopUserFlowBizEnum.AWARD_IN.getCode())
.one();
if ((inFlow.getAmount().subtract(inFlow.getRefundAmount())).compareTo(refPayParam.getRefAmount()) < 0) {
return CzgResult.failure("退款失败,退款金额不可大于可退金额");
}
//用户余额减去赠送金额 小于 退款金额 则需要勾选 超额退款
if (giftFlow != null) {
if (shopUser.getAmount().subtract(giftFlow.getAmount().subtract(giftFlow.getRefundAmount())).compareTo(refPayParam.getRefAmount()) < 0 && !refPayParam.isOutOfRange()) {
return CzgResult.failure("超额退款,请勾选 超额退款后重试");
}
} else {
if (shopUser.getAmount().compareTo(refPayParam.getRefAmount()) < 0 && !refPayParam.isOutOfRange()) {
return CzgResult.failure("超额退款,请勾选 超额退款后重试");
}
}
Long refPaymentId = null;
if (!refPayParam.isCashRefund()) {
OrderPayment payment = null;
if (inFlow.getRelationId() != null) {
payment = paymentService.getById(inFlow.getRelationId());
} else {
return CzgResult.failure("退款失败,该充值记录不存在");
}
String refPayOrderNo = "REF" + refPayParam.getPlatformType() + IdUtil.getSnowflakeNextId();
refPaymentId = initOrderPayment(new OrderPayment(refPayParam.getShopId(), refPayParam.getShopUserId(),
"memberRefund", refPayOrderNo, null, refPayParam.getRefAmount()));
CzgResult<CzgRefundResp> res = refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
refPayParam.getRefAmount().multiply(MONEY_RATE).longValue(), payment.getOrderNo(), ""));
if (res.getCode() != 200 || res.getData() == null) {
return CzgResult.failure(res.getMsg());
}
} else {
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(shopUser.getId())
.money(refPayParam.getRefAmount())
.type(0)
.remark("退款")
.bizEnum(ShopUserFlowBizEnum.RECHARGE_REFUND)
.relationId(refPaymentId)
.rechargeId(inFlow.getId())
.build();
//更新会员余额 并生成流水
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
userFlowService.updateChain()
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + refPayParam.getRefAmount())
.eq(ShopUserFlow::getId, inFlow.getId())
.update();
if (giftFlow != null) {
userFlowService.updateChain()
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + giftFlow.getAmount())
.eq(ShopUserFlow::getId, giftFlow.getId())
.update();
}
inRecordService.updateChain()
.set(ShopActivateInRecord::getOverNum, 0)
.eq(ShopActivateInRecord::getId, inFlow.getId())
.update();
}
return CzgResult.success();
}
@Override @Override
@Transactional @Transactional