分账重构

This commit is contained in:
seesaw
2024-08-16 18:00:08 +08:00
parent 201da3b318
commit fc45e8b84e
57 changed files with 3535 additions and 93 deletions

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.member.dal.dataobject.rechargelog;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 负款补充 DO
*
* @author 管理员
*/
@TableName("member_recharge_log")
@KeySequence("member_recharge_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RechargeLogDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 充值
*/
private BigDecimal money;
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
}

View File

@ -31,6 +31,11 @@ public class RefundLogDO {
*/
private BigDecimal money;
/**
* 剩余退款
*/
private BigDecimal leftMoney;
/**
* 创建时间
*/

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.member.dal.mysql.rechargelog;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.rechargelog.RechargeLogDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 负款补充 Mapper
*
* @author 管理员
*/
@Mapper
public interface RechargeLogMapper extends BaseMapperX<RechargeLogDO> {
}

View File

@ -20,11 +20,11 @@ public enum TimePeriodEnum {
/**
* 早上时间段
*/
MORNING("05:00:00","10:59:59","2",5,10),
MORNING("00:00:00","9:59:59","2",0,9),
/**
* 中午时间段
*/
MIDDAY("11:00:00","15:59:59","3",11,15),
MIDDAY("10:00:00","15:59:59","3",10,15),
/**
* 晚上时间段
*/

View File

@ -15,11 +15,13 @@ import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.card.vo.FaceVo;
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import cn.iocoder.yudao.module.member.dal.dataobject.rechargelog.RechargeLogDO;
import cn.iocoder.yudao.module.member.dal.dataobject.refund.RefundDO;
import cn.iocoder.yudao.module.member.dal.dataobject.refundlog.RefundLogDO;
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper;
import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper;
import cn.iocoder.yudao.module.member.dal.mysql.rechargelog.RechargeLogMapper;
import cn.iocoder.yudao.module.member.dal.mysql.refund.IntegralRefundMapper;
import cn.iocoder.yudao.module.member.dal.mysql.refundlog.RefundLogMapper;
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
@ -40,9 +42,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -71,6 +71,9 @@ public class CardServiceImpl implements CardService {
@Resource
private RefundLogMapper refundLogMapper;
@Resource
private RechargeLogMapper rechargeLogMapper;
@Override
public Long createCard(CardSaveReqVO createReqVO) {
// 插入
@ -341,16 +344,23 @@ public class CardServiceImpl implements CardService {
BigDecimal dishWxAmount = dishOrderDO.getWxAmount();
BigDecimal dishCashAmount = dishOrderDO.getCashAmount();
BigDecimal dishGiftAmount = dishOrderDO.getGiftAmount();
BigDecimal newMoney = money;
if(oldMoney.compareTo(BigDecimal.ZERO)<0){
newMoney = cardDO.getMoney();
}
if (cardDO.getMoney().compareTo(BigDecimal.ZERO) <= 0) {
cardDO.setWxAmount(BigDecimal.ZERO);
cardDO.setGiftAmount(BigDecimal.ZERO);
cardDO.setCashAmount(BigDecimal.ZERO);
} else {
if (money.compareTo(dishGiftAmount) <= 0) {
cardDO.setGiftAmount(giftAmount.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
if (newMoney.compareTo(dishGiftAmount) <= 0) {
cardDO.setGiftAmount(giftAmount.add(newMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
} else {
cardDO.setGiftAmount(giftAmount.add(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP));
BigDecimal money1 = money.subtract(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal money1 = newMoney.subtract(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
if (money1.compareTo(dishCashAmount) <= 0) {
cardDO.setCashAmount(cashAmount.add(money1).setScale(2, BigDecimal.ROUND_HALF_UP));
@ -377,6 +387,7 @@ public class CardServiceImpl implements CardService {
BigDecimal newPayAmount = dishOrderDO.getPayAmount().subtract(money);
if (newPayAmount.compareTo(BigDecimal.ZERO) > 0) {
dishOrderDO.setPayAmount(newPayAmount);
rechargeLog(distribute(dishOrderDO, money).get("wx"));
} else {
handleOtherMoney(dishOrderDO,money);
dishOrderDO.setPayAmount(BigDecimal.ZERO);
@ -391,56 +402,39 @@ public class CardServiceImpl implements CardService {
//查找其余未支付订单
List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(Wrappers.<DishOrderDO>lambdaQuery().eq(DishOrderDO::getOrderStatus, DishOrderDO.TOCOMPLETE)
.ne(DishOrderDO::getId, dishOrderDO.getId()));
if (CollectionUtil.isNotEmpty(dishOrderDOS)){
//判断多出的金额来自哪一部分
BigDecimal payAmount = dishOrderDO.getPayAmount();
BigDecimal giftAmount = dishOrderDO.getGiftAmount();
BigDecimal cashAmount = dishOrderDO.getCashAmount();
BigDecimal wxAmount = dishOrderDO.getWxAmount();
//判断多出的金额来自哪一部分
BigDecimal payAmount = dishOrderDO.getPayAmount();
//可用金额
BigDecimal gift = BigDecimal.ZERO;
BigDecimal cash = BigDecimal.ZERO;
BigDecimal wx = BigDecimal.ZERO;
Map<String, BigDecimal> distribute = distribute(dishOrderDO, money);
//开始微信金额
BigDecimal wxStart = distribute.get("wx");
//可用金额
BigDecimal gift = distribute.get("gift");
BigDecimal cash = distribute.get("cash");
BigDecimal wx = distribute.get("wx");
//分配退款金额
if(money.compareTo(giftAmount)<=0){
gift = money;
}else {
gift = giftAmount;
BigDecimal left = money.subtract(giftAmount);
if(left.compareTo(cashAmount)<=0){
cash = left;
//去除该订单已支付的
if(payAmount.compareTo(gift)<=0){
gift = gift.subtract(payAmount);
}else {
BigDecimal left = payAmount.subtract(gift);
gift = BigDecimal.ZERO;
if(left.compareTo(cash)<=0){
cash = cash.subtract(left);
}else{
BigDecimal left1 = left.subtract(cash);
cash = BigDecimal.ZERO;
if(left1.compareTo(wx)<=0){
wx = wx.subtract(left1);
}else {
cash = cashAmount;
BigDecimal left1 = left.subtract(cashAmount);
if(left1.compareTo(wxAmount)<=0){
wx = left1;
}else {
wx = wxAmount;
}
}
}
//去除该订单已支付的
if(payAmount.compareTo(gift)<=0){
gift = gift.subtract(payAmount);
}else {
BigDecimal left = payAmount.subtract(gift);
gift = BigDecimal.ZERO;
if(left.compareTo(cash)<=0){
cash = cash.subtract(left);
}else{
BigDecimal left1 = left.subtract(cash);
cash = BigDecimal.ZERO;
if(left1.compareTo(wx)<=0){
wx = wx.subtract(left1);
}else {
wx= BigDecimal.ZERO;
}
wx= BigDecimal.ZERO;
}
}
}
if (CollectionUtil.isNotEmpty(dishOrderDOS)){
//待修改的订单
ArrayList<DishOrderDO> update = new ArrayList<>();
@ -504,9 +498,48 @@ public class CardServiceImpl implements CardService {
dishOrderMapper.updateBatch(update);
}
}
rechargeLog(wxStart.subtract(wx));
}
//退款金额记录
public void refundLog(DishOrderDO dishOrderDO,BigDecimal money){
BigDecimal wx = distribute(dishOrderDO, money).get("wx");
List<RefundLogDO> refundLogDOS = refundLogMapper.selectList(Wrappers.<RefundLogDO>lambdaQuery()
.apply("TO_DAYS(NOW())-TO_DAYS(create_time) = 0"));
if(CollectionUtil.isNotEmpty(refundLogDOS)){
RefundLogDO refundLogDO = refundLogDOS.get(0);
refundLogDO.setMoney(refundLogDO.getMoney().add(wx));
refundLogDO.setLeftMoney(refundLogDO.getLeftMoney().add(wx));
refundLogMapper.updateById(refundLogDO);
}else {
RefundLogDO refundLogDO = new RefundLogDO();
refundLogDO.setMoney(wx);
refundLogDO.setLeftMoney(wx);
refundLogDO.setCreateTime(LocalDateTime.now());
refundLogMapper.insert(refundLogDO);
}
}
//补充金额记录
public void rechargeLog(BigDecimal money){
List<RechargeLogDO> rechargeLogDOList = rechargeLogMapper.selectList(Wrappers.<RechargeLogDO>lambdaQuery()
.apply("TO_DAYS(NOW())-TO_DAYS(create_time) = 0"));
if(CollectionUtil.isNotEmpty(rechargeLogDOList)){
RechargeLogDO rechargeLogDO = rechargeLogDOList.get(0);
rechargeLogDO.setMoney(rechargeLogDO.getMoney().add(money));
rechargeLogMapper.updateById(rechargeLogDO);
}else {
RechargeLogDO rechargeLogDO = new RechargeLogDO();
rechargeLogDO.setMoney(money);
rechargeLogDO.setCreateTime(LocalDateTime.now());
rechargeLogMapper.insert(rechargeLogDO);
}
}
//分配金额
public Map<String,BigDecimal> distribute(DishOrderDO dishOrderDO,BigDecimal money){
HashMap<String, BigDecimal> map = new HashMap<>();
BigDecimal giftAmount = dishOrderDO.getGiftAmount();
BigDecimal cashAmount = dishOrderDO.getCashAmount();
BigDecimal wxAmount = dishOrderDO.getWxAmount();
@ -534,21 +567,16 @@ public class CardServiceImpl implements CardService {
}
}
}
map.put("gift",gift);
map.put("cash",cash);
map.put("wx",wx);
List<RefundLogDO> refundLogDOS = refundLogMapper.selectList(Wrappers.<RefundLogDO>lambdaQuery()
.apply("TO_DAYS(NOW())-TO_DAYS(create_time) = 0"));
if(CollectionUtil.isNotEmpty(refundLogDOS)){
RefundLogDO refundLogDO = refundLogDOS.get(0);
refundLogDO.setMoney(refundLogDO.getMoney().add(wx));
refundLogMapper.updateById(refundLogDO);
}else {
RefundLogDO refundLogDO = new RefundLogDO();
refundLogDO.setMoney(wx);
refundLogDO.setCreateTime(LocalDateTime.now());
refundLogMapper.insert(refundLogDO);
}
return map;
}
public BigDecimal checkOrder(Long userId) {
LambdaQueryWrapper<DishOrderDO> wrapper = new LambdaQueryWrapper<>();
@ -615,12 +643,15 @@ public class CardServiceImpl implements CardService {
}
void handleOrderWx(Long userId, BigDecimal money, BigDecimal giftAmount) {
BigDecimal wxMoney = money;
BigDecimal giftMoney = BigDecimal.ZERO;
if (giftAmount != null) {
wxMoney = money.subtract(giftMoney);
giftMoney = giftAmount;
}
//开始的微信金额
BigDecimal wxStart = wxMoney;
//已审核的订单
List<Long> refundOrder = getRefundOrder();
@ -660,11 +691,14 @@ public class CardServiceImpl implements CardService {
}
dishOrderDO.setWxAmount(dishOrderDO.getWxAmount().add(wxMoney));
dishOrderDO.setGiftAmount(dishOrderDO.getGiftAmount().add(giftMoney));
wxMoney =BigDecimal.ZERO;
updateList.add(dishOrderDO);
break;
}
}
}
rechargeLog(wxStart.subtract(wxMoney));
if(CollectionUtil.isNotEmpty(updateList)){
dishOrderMapper.updateBatch(updateList);
}

View File

@ -101,4 +101,10 @@ public interface ErrorCodeConstants {
ErrorCode REFUND_RECORD_NOT_EXISTS = new ErrorCode(1_007_905_001, "退款记录不存在");
ErrorCode WX_ORDER_NOT_EXISTS = new ErrorCode(1_007_906_001, "记录不存在");
ErrorCode WX_PROFITSHARING_NOT_EXISTS = new ErrorCode(1_007_906_002, "记录不存在");
ErrorCode WX_PROFITSHARING_INFO_NOT_EXISTS = new ErrorCode(1_007_906_003, "记录不存在");
ErrorCode WX_PROFITSHARING_RETURN_NOT_EXISTS = new ErrorCode(1_007_906_004, "记录不存在");
ErrorCode WX_REFUND_NOT_EXISTS = new ErrorCode(1_007_906_005, "记录不存在");
}

View File

@ -19,18 +19,24 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.divide.DivideDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyLogDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.notify.PayNotifyTaskDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundrecord.RefundRecordDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import cn.iocoder.yudao.module.pay.dal.mysql.refundrecord.RefundRecordMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxorder.WxOrderMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxrefund.WxRefundMapper;
import cn.iocoder.yudao.module.pay.service.app.PayAppService;
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
import cn.iocoder.yudao.module.pay.service.divide.DivideService;
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import cn.iocoder.yudao.module.pay.service.refund.PayRefundService;
import cn.iocoder.yudao.module.pay.service.wxprofitsharing.WxProfitsharingService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@ -66,7 +72,7 @@ public class PayNotifyController {
@Resource
private PayRefundService refundService;
@Resource
private RefundRecordMapper refundRecordMapper;
private WxProfitsharingService wxProfitsharingService;
@Resource
private PayNotifyService notifyService;
@Resource
@ -76,6 +82,10 @@ public class PayNotifyController {
@Resource
private DivideService divideService;
@Resource
private WxRefundMapper wxRefundMapper;
@Resource
private WxOrderMapper wxOrderMapper;
@Resource
private StringRedisTemplate notifyRedisTemplate;
@PostMapping(value = "/order/{channelId}")
@ -115,13 +125,12 @@ public class PayNotifyController {
}
// 2. 解析通知数据
PayRefundRespDTO notify = payClient.parseRefundNotify(params, body);
RefundRecordDO refundRecordDO = refundRecordMapper.selectOne(Wrappers.<RefundRecordDO>lambdaUpdate()
.eq(RefundRecordDO::getOutRefundNo, notify.getOutRefundNo())
WxRefundDO refundRecordDO = wxRefundMapper.selectOne(Wrappers.<WxRefundDO>lambdaUpdate()
.eq(WxRefundDO::getOutRefundNo, notify.getOutRefundNo())
.last("limit 1"));
String status = "";
if(PayRefundStatusRespEnum.SUCCESS.getStatus().equals(notify.getStatus())){
status = PayDivideRefundStatusRespEnum.SUCCESS.getStatus();
}else{
status = PayDivideRefundStatusRespEnum.ABNORMAL.getStatus();
}
@ -130,20 +139,19 @@ public class PayNotifyController {
//扣除积分
divideService.subtractWx(refundRecordDO.getTotalPrice(),Long.valueOf(refundRecordDO.getUserId()));
//更改订单
String jsonString = notifyRedisTemplate.opsForValue().get("R" + notify.getOutRefundNo());
DivideDO divideDO1 = JsonUtils.parseObject(jsonString, DivideDO.class);
divideService.updateDivideById(divideDO1);
String jsonString = notifyRedisTemplate.opsForValue().get("R" + refundRecordDO.getPayWxOrderId());
WxOrderDO orderDO = JsonUtils.parseObject(jsonString, WxOrderDO.class);
wxOrderMapper.updateById(orderDO);
notifyRedisTemplate.delete("R" + refundRecordDO.getPayWxOrderId());
//分账回退
if (divideDO1.getBackPrice()!=0){
ArrayList<DivideDO> divideDOS = new ArrayList<>();
divideDOS.add(divideDO1);
divideService.returnMoney(divideDOS);
String returnPrice = notifyRedisTemplate.opsForValue().get("R" + refundRecordDO.getOutRefundNo());
if (StringUtils.isNotEmpty(returnPrice)){
wxProfitsharingService.returnMoney(refundRecordDO.getPayWxOrderId(),Integer.parseInt(returnPrice));
}
}
refundRecordDO.setNotifyStatus("1");
refundRecordMapper.updateById(refundRecordDO);
//refundService.notifyRefund(channelId, notify);
wxRefundMapper.updateById(refundRecordDO);
return "success";
}

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxorder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import cn.iocoder.yudao.module.pay.service.wxorder.WxOrderService;
@Tag(name = "管理后台 - 微信订单")
@RestController
@RequestMapping("/pay/wx-order")
@Validated
public class WxOrderController {
@Resource
private WxOrderService wxOrderService;
@PostMapping("/create")
@Operation(summary = "创建微信订单")
@PreAuthorize("@ss.hasPermission('pay:wx-order:create')")
public CommonResult<Long> createWxOrder(@Valid @RequestBody WxOrderSaveReqVO createReqVO) {
return success(wxOrderService.createWxOrder(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新微信订单")
@PreAuthorize("@ss.hasPermission('pay:wx-order:update')")
public CommonResult<Boolean> updateWxOrder(@Valid @RequestBody WxOrderSaveReqVO updateReqVO) {
wxOrderService.updateWxOrder(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除微信订单")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wx-order:delete')")
public CommonResult<Boolean> deleteWxOrder(@RequestParam("id") Long id) {
wxOrderService.deleteWxOrder(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得微信订单")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wx-order:query')")
public CommonResult<WxOrderRespVO> getWxOrder(@RequestParam("id") Long id) {
WxOrderDO wxOrder = wxOrderService.getWxOrder(id);
return success(BeanUtils.toBean(wxOrder, WxOrderRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得微信订单分页")
@PreAuthorize("@ss.hasPermission('pay:wx-order:query')")
public CommonResult<PageResult<WxOrderRespVO>> getWxOrderPage(@Valid WxOrderPageReqVO pageReqVO) {
PageResult<WxOrderDO> pageResult = wxOrderService.getWxOrderPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, WxOrderRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出微信订单 Excel")
@PreAuthorize("@ss.hasPermission('pay:wx-order:export')")
@OperateLog(type = EXPORT)
public void exportWxOrderExcel(@Valid WxOrderPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<WxOrderDO> list = wxOrderService.getWxOrderPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "微信订单.xls", "数据", WxOrderRespVO.class,
BeanUtils.toBean(list, WxOrderRespVO.class));
}
}

View File

@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 微信订单分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxOrderPageReqVO extends PageParam {
@Schema(description = "渠道编号", example = "14125")
private Long channelId;
@Schema(description = "渠道编码")
private String channelCode;
@Schema(description = "微信用户ID", example = "26852")
private String openId;
@Schema(description = "充值金额,单位:分", example = "30914")
private Integer totalPrice;
@Schema(description = "可用于分账的金额,单位:分", example = "13002")
private Integer profitsharingPrice;
@Schema(description = "可用于退款金额,单位:分", example = "16832")
private Integer refundPrice;
@Schema(description = "商户系统内部订单号")
private String outTradeNo;
@Schema(description = "微信支付订单号", example = "9069")
private String transactionId;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 微信订单 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WxOrderRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "12136")
@ExcelProperty("主键")
private Long id;
@Schema(description = "渠道编号", example = "14125")
@ExcelProperty("渠道编号")
private Long channelId;
@Schema(description = "渠道编码")
@ExcelProperty("渠道编码")
private String channelCode;
@Schema(description = "微信用户ID", example = "26852")
@ExcelProperty("微信用户ID")
private String openId;
@Schema(description = "充值金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "30914")
@ExcelProperty("充值金额,单位:分")
private Integer totalPrice;
@Schema(description = "可用于分账的金额,单位:分", example = "13002")
@ExcelProperty("可用于分账的金额,单位:分")
private Integer profitsharingPrice;
@Schema(description = "可用于退款金额,单位:分", example = "16832")
@ExcelProperty("可用于退款金额,单位:分")
private Integer refundPrice;
@Schema(description = "商户系统内部订单号")
@ExcelProperty("商户系统内部订单号")
private String outTradeNo;
@Schema(description = "微信支付订单号", example = "9069")
@ExcelProperty("微信支付订单号")
private String transactionId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信订单新增/修改 Request VO")
@Data
public class WxOrderSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "12136")
private Long id;
@Schema(description = "渠道编号", example = "14125")
private Long channelId;
@Schema(description = "渠道编码")
private String channelCode;
@Schema(description = "微信用户ID", example = "26852")
private String openId;
@Schema(description = "充值金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "30914")
@NotNull(message = "充值金额,单位:分不能为空")
private Integer totalPrice;
@Schema(description = "可用于分账的金额,单位:分", example = "13002")
private Integer profitsharingPrice;
@Schema(description = "可用于退款金额,单位:分", example = "16832")
private Integer refundPrice;
@Schema(description = "商户系统内部订单号")
private String outTradeNo;
@Schema(description = "微信支付订单号", example = "9069")
private String transactionId;
}

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing.WxProfitsharingDO;
import cn.iocoder.yudao.module.pay.service.wxprofitsharing.WxProfitsharingService;
@Tag(name = "管理后台 - 微信分账记录")
@RestController
@RequestMapping("/pay/wx-profitsharing")
@Validated
public class WxProfitsharingController {
@Resource
private WxProfitsharingService wxProfitsharingService;
@PostMapping("/create")
@Operation(summary = "创建微信分账记录")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:create')")
public CommonResult<Long> createWxProfitsharing(@Valid @RequestBody WxProfitsharingSaveReqVO createReqVO) {
return success(wxProfitsharingService.createWxProfitsharing(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新微信分账记录")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:update')")
public CommonResult<Boolean> updateWxProfitsharing(@Valid @RequestBody WxProfitsharingSaveReqVO updateReqVO) {
wxProfitsharingService.updateWxProfitsharing(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除微信分账记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:delete')")
public CommonResult<Boolean> deleteWxProfitsharing(@RequestParam("id") Long id) {
wxProfitsharingService.deleteWxProfitsharing(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得微信分账记录")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:query')")
public CommonResult<WxProfitsharingRespVO> getWxProfitsharing(@RequestParam("id") Long id) {
WxProfitsharingDO wxProfitsharing = wxProfitsharingService.getWxProfitsharing(id);
return success(BeanUtils.toBean(wxProfitsharing, WxProfitsharingRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得微信分账记录分页")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:query')")
public CommonResult<PageResult<WxProfitsharingRespVO>> getWxProfitsharingPage(@Valid WxProfitsharingPageReqVO pageReqVO) {
PageResult<WxProfitsharingDO> pageResult = wxProfitsharingService.getWxProfitsharingPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, WxProfitsharingRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出微信分账记录 Excel")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing:export')")
@OperateLog(type = EXPORT)
public void exportWxProfitsharingExcel(@Valid WxProfitsharingPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<WxProfitsharingDO> list = wxProfitsharingService.getWxProfitsharingPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "微信分账记录.xls", "数据", WxProfitsharingRespVO.class,
BeanUtils.toBean(list, WxProfitsharingRespVO.class));
}
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 微信分账记录分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxProfitsharingPageReqVO extends PageParam {
@Schema(description = "微信订单Id", example = "32710")
private Long payWxOrderId;
@Schema(description = "分账金额,单位:分", example = "20260")
private Integer totalPrice;
@Schema(description = "可用于分账回退的金额,单位:分", example = "17899")
private Integer returnPrice;
@Schema(description = "商户分账单号")
private String outOrderNo;
@Schema(description = "微信分账单号", example = "13531")
private String orderId;
@Schema(description = "分账单状态")
private String state;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,48 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 微信分账记录 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WxProfitsharingRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "8378")
@ExcelProperty("主键")
private Long id;
@Schema(description = "微信订单Id", example = "32710")
@ExcelProperty("微信订单Id")
private Long payWxOrderId;
@Schema(description = "分账金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "20260")
@ExcelProperty("分账金额,单位:分")
private Integer totalPrice;
@Schema(description = "可用于分账回退的金额,单位:分", example = "17899")
@ExcelProperty("可用于分账回退的金额,单位:分")
private Integer returnPrice;
@Schema(description = "商户分账单号")
@ExcelProperty("商户分账单号")
private String outOrderNo;
@Schema(description = "微信分账单号", example = "13531")
@ExcelProperty("微信分账单号")
private String orderId;
@Schema(description = "分账单状态")
@ExcelProperty("分账单状态")
private String state;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信分账记录新增/修改 Request VO")
@Data
public class WxProfitsharingSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "8378")
private Long id;
@Schema(description = "微信订单Id", example = "32710")
private Long payWxOrderId;
@Schema(description = "分账金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "20260")
@NotNull(message = "分账金额,单位:分不能为空")
private Integer totalPrice;
@Schema(description = "可用于分账回退的金额,单位:分", example = "17899")
private Integer returnPrice;
@Schema(description = "商户分账单号")
private String outOrderNo;
@Schema(description = "微信分账单号", example = "13531")
private String orderId;
@Schema(description = "分账单状态")
private String state;
}

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo.WxProfitsharingInfoDO;
import cn.iocoder.yudao.module.pay.service.wxprofitsharinginfo.WxProfitsharingInfoService;
@Tag(name = "管理后台 - 微信分账明细")
@RestController
@RequestMapping("/pay/wx-profitsharing-info")
@Validated
public class WxProfitsharingInfoController {
@Resource
private WxProfitsharingInfoService wxProfitsharingInfoService;
@PostMapping("/create")
@Operation(summary = "创建微信分账明细")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:create')")
public CommonResult<Long> createWxProfitsharingInfo(@Valid @RequestBody WxProfitsharingInfoSaveReqVO createReqVO) {
return success(wxProfitsharingInfoService.createWxProfitsharingInfo(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新微信分账明细")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:update')")
public CommonResult<Boolean> updateWxProfitsharingInfo(@Valid @RequestBody WxProfitsharingInfoSaveReqVO updateReqVO) {
wxProfitsharingInfoService.updateWxProfitsharingInfo(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除微信分账明细")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:delete')")
public CommonResult<Boolean> deleteWxProfitsharingInfo(@RequestParam("id") Long id) {
wxProfitsharingInfoService.deleteWxProfitsharingInfo(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得微信分账明细")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:query')")
public CommonResult<WxProfitsharingInfoRespVO> getWxProfitsharingInfo(@RequestParam("id") Long id) {
WxProfitsharingInfoDO wxProfitsharingInfo = wxProfitsharingInfoService.getWxProfitsharingInfo(id);
return success(BeanUtils.toBean(wxProfitsharingInfo, WxProfitsharingInfoRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得微信分账明细分页")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:query')")
public CommonResult<PageResult<WxProfitsharingInfoRespVO>> getWxProfitsharingInfoPage(@Valid WxProfitsharingInfoPageReqVO pageReqVO) {
PageResult<WxProfitsharingInfoDO> pageResult = wxProfitsharingInfoService.getWxProfitsharingInfoPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, WxProfitsharingInfoRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出微信分账明细 Excel")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-info:export')")
@OperateLog(type = EXPORT)
public void exportWxProfitsharingInfoExcel(@Valid WxProfitsharingInfoPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<WxProfitsharingInfoDO> list = wxProfitsharingInfoService.getWxProfitsharingInfoPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "微信分账明细.xls", "数据", WxProfitsharingInfoRespVO.class,
BeanUtils.toBean(list, WxProfitsharingInfoRespVO.class));
}
}

View File

@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 微信分账明细分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxProfitsharingInfoPageReqVO extends PageParam {
@Schema(description = "分账记录Id", example = "30311")
private Long payWxProfitsharingId;
@Schema(description = "分账个人接收方姓名", example = "赵六")
private String name;
@Schema(description = "分账接收方类型", example = "1")
private String type;
@Schema(description = "分账接收方账号", example = "4796")
private String account;
@Schema(description = "分账金额")
private Integer amount;
@Schema(description = "描述", example = "随便")
private String description;
@Schema(description = "分账结果")
private String result;
@Schema(description = "分账失败原因", example = "不香")
private String failReason;
@Schema(description = "分账明细单号", example = "5535")
private String detailId;
@Schema(description = "分账创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private String[] dCreateTime;
@Schema(description = "分账完成时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private String[] dFinishTime;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,68 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 微信分账明细 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WxProfitsharingInfoRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "15257")
@ExcelProperty("主键")
private Long id;
@Schema(description = "分账记录Id", example = "30311")
@ExcelProperty("分账记录Id")
private Long payWxProfitsharingId;
@Schema(description = "分账个人接收方姓名", example = "赵六")
@ExcelProperty("分账个人接收方姓名")
private String name;
@Schema(description = "分账接收方类型", example = "1")
@ExcelProperty("分账接收方类型")
private String type;
@Schema(description = "分账接收方账号", example = "4796")
@ExcelProperty("分账接收方账号")
private String account;
@Schema(description = "分账金额")
@ExcelProperty("分账金额")
private Integer amount;
@Schema(description = "描述", example = "随便")
@ExcelProperty("描述")
private String description;
@Schema(description = "分账结果")
@ExcelProperty("分账结果")
private String result;
@Schema(description = "分账失败原因", example = "不香")
@ExcelProperty("分账失败原因")
private String failReason;
@Schema(description = "分账明细单号", example = "5535")
@ExcelProperty("分账明细单号")
private String detailId;
@Schema(description = "分账创建时间")
@ExcelProperty("分账创建时间")
private String dCreateTime;
@Schema(description = "分账完成时间")
@ExcelProperty("分账完成时间")
private String dFinishTime;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,48 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信分账明细新增/修改 Request VO")
@Data
public class WxProfitsharingInfoSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "15257")
private Long id;
@Schema(description = "分账记录Id", example = "30311")
private Long payWxProfitsharingId;
@Schema(description = "分账个人接收方姓名", example = "赵六")
private String name;
@Schema(description = "分账接收方类型", example = "1")
private String type;
@Schema(description = "分账接收方账号", example = "4796")
private String account;
@Schema(description = "分账金额")
private Integer amount;
@Schema(description = "描述", example = "随便")
private String description;
@Schema(description = "分账结果")
private String result;
@Schema(description = "分账失败原因", example = "不香")
private String failReason;
@Schema(description = "分账明细单号", example = "5535")
private String detailId;
@Schema(description = "分账创建时间")
private String dCreateTime;
@Schema(description = "分账完成时间")
private String dFinishTime;
}

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn.WxProfitsharingReturnDO;
import cn.iocoder.yudao.module.pay.service.wxprofitsharingreturn.WxProfitsharingReturnService;
@Tag(name = "管理后台 - 微信分账回退")
@RestController
@RequestMapping("/pay/wx-profitsharing-return")
@Validated
public class WxProfitsharingReturnController {
@Resource
private WxProfitsharingReturnService wxProfitsharingReturnService;
@PostMapping("/create")
@Operation(summary = "创建微信分账回退")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:create')")
public CommonResult<Long> createWxProfitsharingReturn(@Valid @RequestBody WxProfitsharingReturnSaveReqVO createReqVO) {
return success(wxProfitsharingReturnService.createWxProfitsharingReturn(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新微信分账回退")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:update')")
public CommonResult<Boolean> updateWxProfitsharingReturn(@Valid @RequestBody WxProfitsharingReturnSaveReqVO updateReqVO) {
wxProfitsharingReturnService.updateWxProfitsharingReturn(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除微信分账回退")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:delete')")
public CommonResult<Boolean> deleteWxProfitsharingReturn(@RequestParam("id") Long id) {
wxProfitsharingReturnService.deleteWxProfitsharingReturn(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得微信分账回退")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:query')")
public CommonResult<WxProfitsharingReturnRespVO> getWxProfitsharingReturn(@RequestParam("id") Long id) {
WxProfitsharingReturnDO wxProfitsharingReturn = wxProfitsharingReturnService.getWxProfitsharingReturn(id);
return success(BeanUtils.toBean(wxProfitsharingReturn, WxProfitsharingReturnRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得微信分账回退分页")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:query')")
public CommonResult<PageResult<WxProfitsharingReturnRespVO>> getWxProfitsharingReturnPage(@Valid WxProfitsharingReturnPageReqVO pageReqVO) {
PageResult<WxProfitsharingReturnDO> pageResult = wxProfitsharingReturnService.getWxProfitsharingReturnPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, WxProfitsharingReturnRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出微信分账回退 Excel")
@PreAuthorize("@ss.hasPermission('pay:wx-profitsharing-return:export')")
@OperateLog(type = EXPORT)
public void exportWxProfitsharingReturnExcel(@Valid WxProfitsharingReturnPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<WxProfitsharingReturnDO> list = wxProfitsharingReturnService.getWxProfitsharingReturnPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "微信分账回退.xls", "数据", WxProfitsharingReturnRespVO.class,
BeanUtils.toBean(list, WxProfitsharingReturnRespVO.class));
}
}

View File

@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 微信分账回退分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxProfitsharingReturnPageReqVO extends PageParam {
@Schema(description = "分账记录Id", example = "30531")
private Long payWxProfitsharingId;
@Schema(description = "商户回退单号")
private String outReturnNo;
@Schema(description = "微信回退单号", example = "23668")
private String returnId;
@Schema(description = "回退商户号", example = "26421")
private String returnMchid;
@Schema(description = "总回退金额(包含主体商户),单位:分", example = "20798")
private Integer totalPrice;
@Schema(description = "分账金额")
private Integer amount;
@Schema(description = "描述", example = "你猜")
private String description;
@Schema(description = "回退结果")
private String result;
@Schema(description = "回退失败原因", example = "不喜欢")
private String failReason;
@Schema(description = "回退创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private String[] dCreateTime;
@Schema(description = "回退完成时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private String[] dFinishTime;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,68 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 微信分账回退 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WxProfitsharingReturnRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "7887")
@ExcelProperty("主键")
private Long id;
@Schema(description = "分账记录Id", example = "30531")
@ExcelProperty("分账记录Id")
private Long payWxProfitsharingId;
@Schema(description = "商户回退单号")
@ExcelProperty("商户回退单号")
private String outOrderNo;
@Schema(description = "微信回退单号", example = "23668")
@ExcelProperty("微信回退单号")
private String returnId;
@Schema(description = "回退商户号", example = "26421")
@ExcelProperty("回退商户号")
private String returnMchid;
@Schema(description = "总回退金额(包含主体商户),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "20798")
@ExcelProperty("总回退金额(包含主体商户),单位:分")
private Integer totalPrice;
@Schema(description = "分账金额")
@ExcelProperty("分账金额")
private Integer amount;
@Schema(description = "描述", example = "你猜")
@ExcelProperty("描述")
private String description;
@Schema(description = "回退结果")
@ExcelProperty("回退结果")
private String result;
@Schema(description = "回退失败原因", example = "不喜欢")
@ExcelProperty("回退失败原因")
private String failReason;
@Schema(description = "回退创建时间")
@ExcelProperty("回退创建时间")
private String dCreateTime;
@Schema(description = "回退完成时间")
@ExcelProperty("回退完成时间")
private String dFinishTime;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信分账回退新增/修改 Request VO")
@Data
public class WxProfitsharingReturnSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "7887")
private Long id;
@Schema(description = "分账记录Id", example = "30531")
private Long payWxProfitsharingId;
@Schema(description = "商户回退单号")
private String outOrderNo;
@Schema(description = "微信回退单号", example = "23668")
private String returnId;
@Schema(description = "回退商户号", example = "26421")
private String returnMchid;
@Schema(description = "总回退金额(包含主体商户),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "20798")
@NotNull(message = "总回退金额(包含主体商户),单位:分不能为空")
private Integer totalPrice;
@Schema(description = "分账金额")
private Integer amount;
@Schema(description = "描述", example = "你猜")
private String description;
@Schema(description = "回退结果")
private String result;
@Schema(description = "回退失败原因", example = "不喜欢")
private String failReason;
@Schema(description = "回退创建时间")
private String dCreateTime;
@Schema(description = "回退完成时间")
private String dFinishTime;
}

View File

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxrefund;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import cn.iocoder.yudao.module.pay.service.wxrefund.WxRefundService;
@Tag(name = "管理后台 - 微信退款")
@RestController
@RequestMapping("/pay/wx-refund")
@Validated
public class WxRefundController {
@Resource
private WxRefundService wxRefundService;
@PostMapping("/create")
@Operation(summary = "创建微信退款")
@PreAuthorize("@ss.hasPermission('pay:wx-refund:create')")
public CommonResult<Long> createWxRefund(@Valid @RequestBody WxRefundSaveReqVO createReqVO) {
return success(wxRefundService.createWxRefund(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新微信退款")
@PreAuthorize("@ss.hasPermission('pay:wx-refund:update')")
public CommonResult<Boolean> updateWxRefund(@Valid @RequestBody WxRefundSaveReqVO updateReqVO) {
wxRefundService.updateWxRefund(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除微信退款")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('pay:wx-refund:delete')")
public CommonResult<Boolean> deleteWxRefund(@RequestParam("id") Long id) {
wxRefundService.deleteWxRefund(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得微信退款")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('pay:wx-refund:query')")
public CommonResult<WxRefundRespVO> getWxRefund(@RequestParam("id") Long id) {
WxRefundDO wxRefund = wxRefundService.getWxRefund(id);
return success(BeanUtils.toBean(wxRefund, WxRefundRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得微信退款分页")
@PreAuthorize("@ss.hasPermission('pay:wx-refund:query')")
public CommonResult<PageResult<WxRefundRespVO>> getWxRefundPage(@Valid WxRefundPageReqVO pageReqVO) {
PageResult<WxRefundDO> pageResult = wxRefundService.getWxRefundPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, WxRefundRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出微信退款 Excel")
@PreAuthorize("@ss.hasPermission('pay:wx-refund:export')")
@OperateLog(type = EXPORT)
public void exportWxRefundExcel(@Valid WxRefundPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<WxRefundDO> list = wxRefundService.getWxRefundPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "微信退款.xls", "数据", WxRefundRespVO.class,
BeanUtils.toBean(list, WxRefundRespVO.class));
}
}

View File

@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 微信退款分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxRefundPageReqVO extends PageParam {
@Schema(description = "微信订单Id", example = "29805")
private Long payWxOrderId;
@Schema(description = "会员编号", example = "17273")
private String userId;
@Schema(description = "总金额,单位:分", example = "16715")
private Integer totalPrice;
@Schema(description = "退款状态", example = "2")
private String status;
@Schema(description = "微信退款单号")
private String outRefundNo;
@Schema(description = "微信支付退款单号", example = "3422")
private String refundId;
@Schema(description = "是否回调 1-已回调", example = "1")
private String notifyStatus;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 微信退款 Response VO")
@Data
@ExcelIgnoreUnannotated
public class WxRefundRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "22638")
@ExcelProperty("主键")
private Long id;
@Schema(description = "微信订单Id", example = "29805")
@ExcelProperty("微信订单Id")
private Long payWxOrderId;
@Schema(description = "会员编号", example = "17273")
@ExcelProperty("会员编号")
private String userId;
@Schema(description = "总金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "16715")
@ExcelProperty("总金额,单位:分")
private Integer totalPrice;
@Schema(description = "退款状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("退款状态")
private String status;
@Schema(description = "微信退款单号")
@ExcelProperty("微信退款单号")
private String outRefundNo;
@Schema(description = "微信支付退款单号", example = "3422")
@ExcelProperty("微信支付退款单号")
private String refundId;
@Schema(description = "是否回调 1-已回调", example = "1")
@ExcelProperty("是否回调 1-已回调")
private String notifyStatus;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信退款新增/修改 Request VO")
@Data
public class WxRefundSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "22638")
private Long id;
@Schema(description = "微信订单Id", example = "29805")
private Long payWxOrderId;
@Schema(description = "会员编号", example = "17273")
private String userId;
@Schema(description = "总金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "16715")
@NotNull(message = "总金额,单位:分不能为空")
private Integer totalPrice;
@Schema(description = "退款状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotEmpty(message = "退款状态不能为空")
private String status;
@Schema(description = "微信退款单号")
private String outRefundNo;
@Schema(description = "微信支付退款单号", example = "3422")
private String refundId;
@Schema(description = "是否回调 1-已回调", example = "1")
private String notifyStatus;
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.controller.app.divide;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.pay.controller.app.divide.vo.DrawMoneyVO;
import cn.iocoder.yudao.module.pay.service.divide.DivideService;
import cn.iocoder.yudao.module.pay.service.wxprofitsharing.WxProfitsharingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
@ -22,12 +23,12 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class AppDivideController {
@Resource
private DivideService divideService;
private WxProfitsharingService profitsharingService;
@PostMapping("/drawMoney")
@Operation(summary = "提现")
public CommonResult<Boolean> createDivide(@RequestBody DrawMoneyVO drawMoneyVO) {
return success(divideService.drawMoney(drawMoneyVO));
return success(profitsharingService.drawMoney(drawMoneyVO));
}
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.rechargelog;
import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 负款补充 DO
*
* @author 管理员
*/
@TableName("member_recharge_log")
@KeySequence("member_recharge_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PayRechargeLogDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 充值
*/
private BigDecimal money;
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,44 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.refundlog;
import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 退款记录 DO
*
* @author 管理员
*/
@TableName("member_refund_log")
@KeySequence("member_refund_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PayRefundLogDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 退款
*/
private BigDecimal money;
/**
* 剩余退款
*/
private BigDecimal leftMoney;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wxorder;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 微信订单 DO
*
* @author 管理员
*/
@TableName("pay_wx_order")
@KeySequence("pay_wx_order_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxOrderDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 渠道编号
*/
private Long channelId;
/**
* 渠道编码
*/
private String channelCode;
/**
* 微信用户ID
*/
private String openId;
/**
* 充值金额,单位:分
*/
private Integer totalPrice;
/**
* 可用于分账的金额,单位:分
*/
private Integer profitsharingPrice;
/**
* 可用于退款金额,单位:分
*/
private Integer refundPrice;
/**
* 商户系统内部订单号
*/
private String outTradeNo;
/**
* 微信支付订单号
*/
private String transactionId;
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 微信分账记录 DO
*
* @author 管理员
*/
@TableName("pay_wx_profitsharing")
@KeySequence("pay_wx_profitsharing_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxProfitsharingDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 微信订单Id
*/
private Long payWxOrderId;
/**
* 分账金额,单位:分
*/
private Integer totalPrice;
/**
* 可用于分账回退的金额,单位:分
*/
private Integer returnPrice;
/**
* 商户分账单号
*/
private String outOrderNo;
/**
* 微信分账单号
*/
private String orderId;
/**
* 分账单状态
*/
private String state;
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 微信分账明细 DO
*
* @author 管理员
*/
@TableName("pay_wx_profitsharing_info")
@KeySequence("pay_wx_profitsharing_info_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxProfitsharingInfoDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 分账记录Id
*/
private Long payWxProfitsharingId;
/**
* 分账个人接收方姓名
*/
private String name;
/**
* 分账接收方类型
*/
private String type;
/**
* 分账接收方账号
*/
private String account;
/**
* 分账金额
*/
private Integer amount;
/**
* 描述
*/
private String description;
/**
* 分账结果
*/
private String result;
/**
* 分账失败原因
*/
private String failReason;
/**
* 分账明细单号
*/
private String detailId;
/**
* 分账创建时间
*/
private String dCreateTime;
/**
* 分账完成时间
*/
private String dFinishTime;
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 微信分账回退 DO
*
* @author 管理员
*/
@TableName("pay_wx_profitsharing_return")
@KeySequence("pay_wx_profitsharing_return_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxProfitsharingReturnDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 分账记录Id
*/
private Long payWxProfitsharingId;
/**
* 商户回退单号
*/
private String outReturnNo;
/**
* 微信回退单号
*/
private String returnId;
/**
* 回退商户号
*/
private String returnMchid;
/**
* 总回退金额(包含主体商户),单位:分
*/
private Integer totalPrice;
/**
* 分账金额
*/
private Integer amount;
/**
* 描述
*/
private String description;
/**
* 回退结果
*/
private String result;
/**
* 回退失败原因
*/
private String failReason;
/**
* 回退创建时间
*/
private String dCreateTime;
/**
* 回退完成时间
*/
private String dFinishTime;
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 微信退款 DO
*
* @author 管理员
*/
@TableName("pay_wx_refund")
@KeySequence("pay_wx_refund_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxRefundDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 微信订单Id
*/
private Long payWxOrderId;
/**
* 会员编号
*/
private Long userId;
/**
* 总金额,单位:分
*/
private Integer totalPrice;
/**
* 退款状态
*/
private String status;
/**
* 微信退款单号
*/
private String outRefundNo;
/**
* 微信支付退款单号
*/
private String refundId;
/**
* 是否回调 1-已回调
*/
private String notifyStatus;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.pay.dal.mysql.refundlog;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundlog.PayRefundLogDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 退款记录 Mapper
*
* @author 管理员
*/
@Mapper
public interface PayRefundLogMapper extends BaseMapperX<PayRefundLogDO> {
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wxorder;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo.WxOrderPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 微信订单 Mapper
*
* @author 管理员
*/
@Mapper
public interface WxOrderMapper extends BaseMapperX<WxOrderDO> {
default PageResult<WxOrderDO> selectPage(WxOrderPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxOrderDO>()
.eqIfPresent(WxOrderDO::getChannelId, reqVO.getChannelId())
.eqIfPresent(WxOrderDO::getChannelCode, reqVO.getChannelCode())
.eqIfPresent(WxOrderDO::getOpenId, reqVO.getOpenId())
.eqIfPresent(WxOrderDO::getTotalPrice, reqVO.getTotalPrice())
.eqIfPresent(WxOrderDO::getProfitsharingPrice, reqVO.getProfitsharingPrice())
.eqIfPresent(WxOrderDO::getRefundPrice, reqVO.getRefundPrice())
.eqIfPresent(WxOrderDO::getOutTradeNo, reqVO.getOutTradeNo())
.eqIfPresent(WxOrderDO::getTransactionId, reqVO.getTransactionId())
.betweenIfPresent(WxOrderDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(WxOrderDO::getId));
}
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharing;
import java.math.BigDecimal;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundlog.PayRefundLogDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing.WxProfitsharingDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo.*;
import org.apache.ibatis.annotations.Select;
/**
* 微信分账记录 Mapper
*
* @author 管理员
*/
@Mapper
public interface WxProfitsharingMapper extends BaseMapperX<WxProfitsharingDO> {
default PageResult<WxProfitsharingDO> selectPage(WxProfitsharingPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxProfitsharingDO>()
.eqIfPresent(WxProfitsharingDO::getPayWxOrderId, reqVO.getPayWxOrderId())
.eqIfPresent(WxProfitsharingDO::getTotalPrice, reqVO.getTotalPrice())
.eqIfPresent(WxProfitsharingDO::getReturnPrice, reqVO.getReturnPrice())
.eqIfPresent(WxProfitsharingDO::getOutOrderNo, reqVO.getOutOrderNo())
.eqIfPresent(WxProfitsharingDO::getOrderId, reqVO.getOrderId())
.eqIfPresent(WxProfitsharingDO::getState, reqVO.getState())
.betweenIfPresent(WxProfitsharingDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(WxProfitsharingDO::getId));
}
@Select("select sum(wx_amount) from member_dish_order where DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")
BigDecimal getToday();
@Select("select * from member_refund_log where left_money > 0 ")
List<PayRefundLogDO> getRefund();
@Select("select money from member_recharge_log where DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY) ")
BigDecimal getRechargeLog();
@Select("select wx_amount from member_card where user_id = #{userId} order by create_time desc limit 1")
BigDecimal getWxAmount(Long userId);
@Select("select count(1) from member_dish_order where user_id = #{userId} and order_status = '0'")
int orderCount(Long userId);
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharinginfo;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo.WxProfitsharingInfoDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo.*;
/**
* 微信分账明细 Mapper
*
* @author 管理员
*/
@Mapper
public interface WxProfitsharingInfoMapper extends BaseMapperX<WxProfitsharingInfoDO> {
default PageResult<WxProfitsharingInfoDO> selectPage(WxProfitsharingInfoPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxProfitsharingInfoDO>()
.eqIfPresent(WxProfitsharingInfoDO::getPayWxProfitsharingId, reqVO.getPayWxProfitsharingId())
.likeIfPresent(WxProfitsharingInfoDO::getName, reqVO.getName())
.eqIfPresent(WxProfitsharingInfoDO::getType, reqVO.getType())
.eqIfPresent(WxProfitsharingInfoDO::getAccount, reqVO.getAccount())
.eqIfPresent(WxProfitsharingInfoDO::getAmount, reqVO.getAmount())
.eqIfPresent(WxProfitsharingInfoDO::getDescription, reqVO.getDescription())
.eqIfPresent(WxProfitsharingInfoDO::getResult, reqVO.getResult())
.eqIfPresent(WxProfitsharingInfoDO::getFailReason, reqVO.getFailReason())
.eqIfPresent(WxProfitsharingInfoDO::getDetailId, reqVO.getDetailId())
.betweenIfPresent(WxProfitsharingInfoDO::getDCreateTime, reqVO.getDCreateTime())
.betweenIfPresent(WxProfitsharingInfoDO::getDFinishTime, reqVO.getDFinishTime())
.betweenIfPresent(WxProfitsharingInfoDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(WxProfitsharingInfoDO::getId));
}
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharingreturn;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn.WxProfitsharingReturnDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo.*;
/**
* 微信分账回退 Mapper
*
* @author 管理员
*/
@Mapper
public interface WxProfitsharingReturnMapper extends BaseMapperX<WxProfitsharingReturnDO> {
default PageResult<WxProfitsharingReturnDO> selectPage(WxProfitsharingReturnPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxProfitsharingReturnDO>()
.eqIfPresent(WxProfitsharingReturnDO::getPayWxProfitsharingId, reqVO.getPayWxProfitsharingId())
.eqIfPresent(WxProfitsharingReturnDO::getOutReturnNo, reqVO.getOutReturnNo())
.eqIfPresent(WxProfitsharingReturnDO::getReturnId, reqVO.getReturnId())
.eqIfPresent(WxProfitsharingReturnDO::getReturnMchid, reqVO.getReturnMchid())
.eqIfPresent(WxProfitsharingReturnDO::getTotalPrice, reqVO.getTotalPrice())
.eqIfPresent(WxProfitsharingReturnDO::getAmount, reqVO.getAmount())
.eqIfPresent(WxProfitsharingReturnDO::getDescription, reqVO.getDescription())
.eqIfPresent(WxProfitsharingReturnDO::getResult, reqVO.getResult())
.eqIfPresent(WxProfitsharingReturnDO::getFailReason, reqVO.getFailReason())
.betweenIfPresent(WxProfitsharingReturnDO::getDCreateTime, reqVO.getDCreateTime())
.betweenIfPresent(WxProfitsharingReturnDO::getDFinishTime, reqVO.getDFinishTime())
.betweenIfPresent(WxProfitsharingReturnDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(WxProfitsharingReturnDO::getId));
}
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wxrefund;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo.*;
/**
* 微信退款 Mapper
*
* @author 管理员
*/
@Mapper
public interface WxRefundMapper extends BaseMapperX<WxRefundDO> {
default PageResult<WxRefundDO> selectPage(WxRefundPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxRefundDO>()
.eqIfPresent(WxRefundDO::getPayWxOrderId, reqVO.getPayWxOrderId())
.eqIfPresent(WxRefundDO::getUserId, reqVO.getUserId())
.eqIfPresent(WxRefundDO::getTotalPrice, reqVO.getTotalPrice())
.eqIfPresent(WxRefundDO::getStatus, reqVO.getStatus())
.eqIfPresent(WxRefundDO::getOutRefundNo, reqVO.getOutRefundNo())
.eqIfPresent(WxRefundDO::getRefundId, reqVO.getRefundId())
.eqIfPresent(WxRefundDO::getNotifyStatus, reqVO.getNotifyStatus())
.betweenIfPresent(WxRefundDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(WxRefundDO::getId));
}
}

View File

@ -14,6 +14,8 @@ public class PayProperties {
private static final String ORDER_NO_PREFIX = "P";
private static final String REFUND_NO_PREFIX = "R";
private static final String PROFITSHARING_NO_PREFIX = "S";
private static final String RETURN_NO_PREFIX = "B";
/**
* 支付回调地址
@ -49,4 +51,10 @@ public class PayProperties {
@NotEmpty(message = "退款订单 no 的前缀不能为空")
private String refundNoPrefix = REFUND_NO_PREFIX;
@NotEmpty(message = "分账订单 no 的前缀不能为空")
private String profitsharingNoPrefix = PROFITSHARING_NO_PREFIX;
@NotEmpty(message = "分账回退订单 no 的前缀不能为空")
private String returnNoPrefix = RETURN_NO_PREFIX;
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.job.divide;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.pay.service.divide.DivideService;
import cn.iocoder.yudao.module.pay.service.wxprofitsharing.WxProfitsharingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -19,12 +20,12 @@ import javax.annotation.Resource;
public class PayDivideJob implements JobHandler {
@Resource
private DivideService divideService;
private WxProfitsharingService profitsharingService;
@Override
@TenantJob
public String execute(String param) throws Exception {
int divideCount = divideService.startDivide();
int divideCount = profitsharingService.startProfitsharing();
return String.format("执行分账 %s 个", divideCount);
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.job.divide;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.pay.service.divide.DivideService;
import cn.iocoder.yudao.module.pay.service.wxprofitsharing.WxProfitsharingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -19,13 +20,13 @@ import javax.annotation.Resource;
public class PayDivideResultJob implements JobHandler {
@Resource
private DivideService divideService;
private WxProfitsharingService profitsharingService;
@Override
@TenantJob
public String execute(String param) throws Exception {
int divideResult = divideService.getDivideResult();
return String.format("执行分账结果 %s 个", divideResult);
int divideResult = profitsharingService.getDivideResult();
return String.format("获取分账结果 %s 个", divideResult);
}
}

View File

@ -55,4 +55,8 @@ public interface DivideCompanyService {
List<DivideCompanyDO> getList();
/**
* 计算回退金额
*/
int computeAmount(String account,int totalPrice);
}

View File

@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.dividecompany.vo.DivideCompa
import cn.iocoder.yudao.module.pay.controller.admin.dividecompany.vo.DivideCompanySaveReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.dividecompany.DivideCompanyDO;
import cn.iocoder.yudao.module.pay.dal.mysql.dividecompany.DivideCompanyMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -74,4 +75,12 @@ public class DivideCompanyServiceImpl implements DivideCompanyService {
public List<DivideCompanyDO> getList() {
return divideCompanyMapper.selectList();
}
@Override
public int computeAmount(String account, int totalPrice) {
//todo:分账接收方被删除处理
List<DivideCompanyDO> divideCompanyDOS = divideCompanyMapper.selectList(Wrappers.<DivideCompanyDO>lambdaQuery().eq(DivideCompanyDO::getAccount, account));
DivideCompanyDO divideCompanyDO = divideCompanyDOS.get(0);
return (int) Math.ceil(totalPrice * Double.parseDouble(divideCompanyDO.getProportion()));
}
}

View File

@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO;
import cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo.WxOrderSaveReqVO;
import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
@ -34,6 +35,7 @@ import cn.iocoder.yudao.module.pay.service.app.PayAppService;
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
import cn.iocoder.yudao.module.pay.service.divide.DivideService;
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
import cn.iocoder.yudao.module.pay.service.wxorder.WxOrderService;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -81,6 +83,10 @@ public class PayOrderServiceImpl implements PayOrderService {
@Resource
private DivideService divideService;
@Resource
private WxOrderService wxOrderService;
@Override
public PayOrderDO getOrder(Long id) {
return orderMapper.selectById(id);
@ -299,15 +305,25 @@ public class PayOrderServiceImpl implements PayOrderService {
}
private void addDivide(PayChannelDO channel, PayOrderDO payOrderDO) {
DivideSaveReqVO divideSaveReqVO = new DivideSaveReqVO();
String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
divideSaveReqVO.setChannelId(channel.getId())
// DivideSaveReqVO divideSaveReqVO = new DivideSaveReqVO();
// String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
// divideSaveReqVO.setChannelId(channel.getId())
// .setChannelCode(channel.getCode())
// .setTotalPrice(payOrderDO.getPrice())
// .setNo(no).setStatus(PayDivideStatusRespEnum.WAITING.getStatus())
// .setChannelOrderNo(payOrderDO.getChannelOrderNo())
// .setChannelUserId(payOrderDO.getChannelUserId());
// divideService.createDivide(divideSaveReqVO);
WxOrderSaveReqVO wxOrderSaveReqVO = new WxOrderSaveReqVO();
wxOrderSaveReqVO.setChannelId(channel.getId())
.setChannelCode(channel.getCode())
.setOpenId(payOrderDO.getChannelUserId())
.setTotalPrice(payOrderDO.getPrice())
.setNo(no).setStatus(PayDivideStatusRespEnum.WAITING.getStatus())
.setChannelOrderNo(payOrderDO.getChannelOrderNo())
.setChannelUserId(payOrderDO.getChannelUserId());
divideService.createDivide(divideSaveReqVO);
.setProfitsharingPrice(payOrderDO.getPrice())
.setRefundPrice(payOrderDO.getPrice())
.setOutTradeNo(payOrderDO.getNo()).setTransactionId(payOrderDO.getChannelOrderNo());
wxOrderService.createWxOrder(wxOrderSaveReqVO);
}
/**
@ -381,7 +397,8 @@ public class PayOrderServiceImpl implements PayOrderService {
//3.添加分账
order.setChannelOrderNo(notify.getChannelOrderNo());
order.setChannelUserId(notify.getChannelUserId());
addDivide(channel,order);
order.setNo(notify.getOutTradeNo());
addDivide(channel, order);
return false;
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.service.wxorder;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 微信订单 Service 接口
*
* @author 管理员
*/
public interface WxOrderService {
/**
* 创建微信订单
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWxOrder(@Valid WxOrderSaveReqVO createReqVO);
/**
* 更新微信订单
*
* @param updateReqVO 更新信息
*/
void updateWxOrder(@Valid WxOrderSaveReqVO updateReqVO);
/**
* 删除微信订单
*
* @param id 编号
*/
void deleteWxOrder(Long id);
/**
* 获得微信订单
*
* @param id 编号
* @return 微信订单
*/
WxOrderDO getWxOrder(Long id);
/**
* 获得微信订单分页
*
* @param pageReqVO 分页查询
* @return 微信订单分页
*/
PageResult<WxOrderDO> getWxOrderPage(WxOrderPageReqVO pageReqVO);
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.pay.service.wxorder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxorder.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.dal.mysql.wxorder.WxOrderMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 微信订单 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
public class WxOrderServiceImpl implements WxOrderService {
@Resource
private WxOrderMapper wxOrderMapper;
@Override
public Long createWxOrder(WxOrderSaveReqVO createReqVO) {
// 插入
WxOrderDO wxOrder = BeanUtils.toBean(createReqVO, WxOrderDO.class);
wxOrderMapper.insert(wxOrder);
// 返回
return wxOrder.getId();
}
@Override
public void updateWxOrder(WxOrderSaveReqVO updateReqVO) {
// 校验存在
validateWxOrderExists(updateReqVO.getId());
// 更新
WxOrderDO updateObj = BeanUtils.toBean(updateReqVO, WxOrderDO.class);
wxOrderMapper.updateById(updateObj);
}
@Override
public void deleteWxOrder(Long id) {
// 校验存在
validateWxOrderExists(id);
// 删除
wxOrderMapper.deleteById(id);
}
private void validateWxOrderExists(Long id) {
if (wxOrderMapper.selectById(id) == null) {
throw exception(WX_ORDER_NOT_EXISTS);
}
}
@Override
public WxOrderDO getWxOrder(Long id) {
return wxOrderMapper.selectById(id);
}
@Override
public PageResult<WxOrderDO> getWxOrderPage(WxOrderPageReqVO pageReqVO) {
return wxOrderMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharing;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo.*;
import cn.iocoder.yudao.module.pay.controller.app.divide.vo.DrawMoneyVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.divide.DivideDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing.WxProfitsharingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 微信分账记录 Service 接口
*
* @author 管理员
*/
public interface WxProfitsharingService {
/**
* 创建微信分账记录
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWxProfitsharing(@Valid WxProfitsharingSaveReqVO createReqVO);
/**
* 更新微信分账记录
*
* @param updateReqVO 更新信息
*/
void updateWxProfitsharing(@Valid WxProfitsharingSaveReqVO updateReqVO);
/**
* 删除微信分账记录
*
* @param id 编号
*/
void deleteWxProfitsharing(Long id);
/**
* 获得微信分账记录
*
* @param id 编号
* @return 微信分账记录
*/
WxProfitsharingDO getWxProfitsharing(Long id);
/**
* 获得微信分账记录分页
*
* @param pageReqVO 分页查询
* @return 微信分账记录分页
*/
PageResult<WxProfitsharingDO> getWxProfitsharingPage(WxProfitsharingPageReqVO pageReqVO);
/**
* 分账
**/
int startProfitsharing();
/**
* 分账结果
**/
int getDivideResult();
/**
* 提现(退款)
*/
Boolean drawMoney( DrawMoneyVO drawMoneyVO);
/**
* 分账回退
*/
void returnMoney(Long payWxOrderId,int returnMoney);
}

View File

@ -0,0 +1,847 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharing;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
import cn.iocoder.yudao.framework.pay.core.client.dto.divide.PayDivideBackRespDto;
import cn.iocoder.yudao.framework.pay.core.client.dto.divide.PayDivideBackUnifiedDto;
import cn.iocoder.yudao.framework.pay.core.client.dto.divide.PayDivideRespDto;
import cn.iocoder.yudao.framework.pay.core.client.dto.divide.PayDivideUnifiedDto;
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
import cn.iocoder.yudao.framework.pay.core.enums.divide.PayDivideRefundStatusRespEnum;
import cn.iocoder.yudao.framework.pay.core.enums.divide.PayDivideStatusRespEnum;
import cn.iocoder.yudao.module.pay.controller.app.divide.vo.DrawMoneyVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.divide.DivideDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.dividecompany.DivideCompanyDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.divideinfo.DivideInfoDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.dividerecord.DivideRecordDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundlog.PayRefundLogDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.refundrecord.RefundRecordDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxorder.WxOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo.WxProfitsharingInfoDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn.WxProfitsharingReturnDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import cn.iocoder.yudao.module.pay.dal.mysql.refundlog.PayRefundLogMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxorder.WxOrderMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharinginfo.WxProfitsharingInfoMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharingreturn.WxProfitsharingReturnMapper;
import cn.iocoder.yudao.module.pay.dal.mysql.wxrefund.WxRefundMapper;
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
import cn.iocoder.yudao.module.pay.framework.pay.config.PayProperties;
import cn.iocoder.yudao.module.pay.service.channel.PayChannelService;
import cn.iocoder.yudao.module.pay.service.dividecompany.DivideCompanyService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.binarywang.wxpay.bean.profitsharing.request.ProfitSharingV3Request;
import com.github.binarywang.wxpay.bean.profitsharing.result.ProfitSharingV3Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharing.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharing.WxProfitsharingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharing.WxProfitsharingMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 微信分账记录 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
@Slf4j
public class WxProfitsharingServiceImpl implements WxProfitsharingService {
@Resource
private WxProfitsharingMapper wxProfitsharingMapper;
@Resource
private WxOrderMapper wxOrderMapper;
@Resource
private PayNoRedisDAO noRedisDAO;
@Resource
private PayProperties payProperties;
@Resource
private PayChannelService channelService;
@Resource
private DivideCompanyService divideCompanyService;
@Resource
private WxProfitsharingInfoMapper infoMapper;
@Resource
private WxProfitsharingReturnMapper returnMapper;
@Resource
private StringRedisTemplate divideRedisTemplate;
@Resource
private WxRefundMapper wxRefundMapper;
@Resource
private PayRefundLogMapper payRefundLogMapper;
@Override
public Long createWxProfitsharing(WxProfitsharingSaveReqVO createReqVO) {
// 插入
WxProfitsharingDO wxProfitsharing = BeanUtils.toBean(createReqVO, WxProfitsharingDO.class);
wxProfitsharingMapper.insert(wxProfitsharing);
// 返回
return wxProfitsharing.getId();
}
@Override
public void updateWxProfitsharing(WxProfitsharingSaveReqVO updateReqVO) {
// 校验存在
validateWxProfitsharingExists(updateReqVO.getId());
// 更新
WxProfitsharingDO updateObj = BeanUtils.toBean(updateReqVO, WxProfitsharingDO.class);
wxProfitsharingMapper.updateById(updateObj);
}
@Override
public void deleteWxProfitsharing(Long id) {
// 校验存在
validateWxProfitsharingExists(id);
// 删除
wxProfitsharingMapper.deleteById(id);
}
private void validateWxProfitsharingExists(Long id) {
if (wxProfitsharingMapper.selectById(id) == null) {
throw exception(WX_PROFITSHARING_NOT_EXISTS);
}
}
@Override
public WxProfitsharingDO getWxProfitsharing(Long id) {
return wxProfitsharingMapper.selectById(id);
}
@Override
public PageResult<WxProfitsharingDO> getWxProfitsharingPage(WxProfitsharingPageReqVO pageReqVO) {
return wxProfitsharingMapper.selectPage(pageReqVO);
}
/**
* 分账
*/
@Override
public int startProfitsharing() {
//获取昨天营业额中的微信充值金额
BigDecimal today = wxProfitsharingMapper.getToday();
if (today == null) {
return 0;
}
//转换单位 元-->分
int money = today.multiply(new BigDecimal("100")).intValue();
//加上昨天补充金额
BigDecimal rechargeLog = wxProfitsharingMapper.getRechargeLog();
if(ObjectUtil.isEmpty(rechargeLog)){
rechargeLog = BigDecimal.ZERO;
}
money = money+rechargeLog.multiply(new BigDecimal("100")).intValue();
//退款处理
money = handleRefund(new BigDecimal(money)).multiply(new BigDecimal("100")).intValue();
if(money <= 0){
return 0;
}
//查询29天内的充值订单原因微信30天自动解冻订单将不能分账
LocalDateTime now = LocalDateTime.now();
LocalDateTime thirtyDaysAgo = now.minusDays(29);
List<WxOrderDO> wxOrderDOList = wxOrderMapper.selectList(Wrappers.<WxOrderDO>lambdaQuery()
.gt(WxOrderDO::getProfitsharingPrice, 0)
.ge(WxOrderDO::getCreateTime, thirtyDaysAgo)
.orderByAsc(WxOrderDO::getCreateTime));
if (CollectionUtil.isEmpty(wxOrderDOList)) {
return 0;
}
Map<Long, WxOrderDO> orderMap = wxOrderDOList.stream().collect(Collectors.toMap(WxOrderDO::getId, vo -> vo));
//计算分账用的订单数据
List<WxProfitsharingDO> wxProfitsharingDOS = computeProfitsharing(wxOrderDOList, money);
int counter = 0;
//调用微信分账
for (WxProfitsharingDO domain : wxProfitsharingDOS) {
WxOrderDO wxOrderDO = orderMap.get(domain.getPayWxOrderId());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayDivideUnifiedDto payDivideUnifiedDto = new PayDivideUnifiedDto();
payDivideUnifiedDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(domain.getOutOrderNo())
.setUnfreezeUnsplit(wxOrderDO.getProfitsharingPrice() == 0)
.setReceivers(createReceiver(domain));
PayDivideRespDto payDivideRespDto = client.unifiedDivide(payDivideUnifiedDto);
domain.setState("PROCESSING");
domain.setOrderId(payDivideRespDto.getOrderId());
insertDB(payDivideRespDto, domain);
// 每执行250次休息一分钟
if (++counter % 250 == 0) {
try {
TimeUnit.MINUTES.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
}
return wxProfitsharingDOS.size();
}
/**
* 退款处理
*/
public BigDecimal handleRefund(BigDecimal money){
money = money.divide(new BigDecimal("100"),2, RoundingMode.HALF_UP);
//去除退款中的微信充值金额
List<PayRefundLogDO> refundLogDOList = payRefundLogMapper.selectList(Wrappers.<PayRefundLogDO>lambdaQuery()
.gt(PayRefundLogDO::getLeftMoney,0));
if(CollectionUtil.isEmpty(refundLogDOList)){
return money;
}
BigDecimal refundToday = refundLogDOList.stream().map(PayRefundLogDO::getLeftMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
if(money.compareTo(refundToday)>=0){
money = money.subtract(refundToday);
List<Long> ids = refundLogDOList.stream().map(PayRefundLogDO::getId).collect(Collectors.toList());
payRefundLogMapper.update(Wrappers.<PayRefundLogDO>lambdaUpdate().in(PayRefundLogDO::getId,ids)
.set(PayRefundLogDO::getLeftMoney,0));
}else {
ArrayList<PayRefundLogDO> updateList = new ArrayList<>();
for (PayRefundLogDO refundLogDO:refundLogDOList){
BigDecimal leftMoney = refundLogDO.getLeftMoney();
if(money.compareTo(leftMoney)<=0){
refundLogDO.setLeftMoney(leftMoney.subtract(money));
updateList.add(refundLogDO);
money = BigDecimal.ZERO;
break;
}else {
money = money.subtract(leftMoney);
refundLogDO.setLeftMoney(BigDecimal.ZERO);
updateList.add(refundLogDO);
}
}
if(CollectionUtil.isNotEmpty(updateList)){
payRefundLogMapper.updateBatch(updateList);
}
}
return money;
}
/**
* 生成分账订单
*/
public List<WxProfitsharingDO> computeProfitsharing(List<WxOrderDO> wxOrderDOList, int money) {
List<WxProfitsharingDO> returnList = new ArrayList<>();
List<WxOrderDO> updateList = new ArrayList<>();
int sum = 0;
for (WxOrderDO wxOrderDO : wxOrderDOList) {
WxProfitsharingDO wxProfitsharingDO = new WxProfitsharingDO();
wxProfitsharingDO.setPayWxOrderId(wxOrderDO.getId());
wxProfitsharingDO.setOutOrderNo(noRedisDAO.generate(payProperties.getProfitsharingNoPrefix()));
sum = sum + wxOrderDO.getProfitsharingPrice();
if (sum < money) {
wxProfitsharingDO.setTotalPrice(wxOrderDO.getProfitsharingPrice());
wxProfitsharingDO.setReturnPrice(wxOrderDO.getProfitsharingPrice());
wxOrderDO.setProfitsharingPrice(0);
returnList.add(wxProfitsharingDO);
updateList.add(wxOrderDO);
} else if (sum == money) {
wxProfitsharingDO.setTotalPrice(wxOrderDO.getProfitsharingPrice());
wxProfitsharingDO.setReturnPrice(wxOrderDO.getProfitsharingPrice());
wxOrderDO.setProfitsharingPrice(0);
returnList.add(wxProfitsharingDO);
updateList.add(wxOrderDO);
break;
} else {
int leftMoney = money + wxOrderDO.getProfitsharingPrice() - sum;
wxProfitsharingDO.setTotalPrice(leftMoney);
wxProfitsharingDO.setReturnPrice(leftMoney);
wxOrderDO.setProfitsharingPrice(wxOrderDO.getProfitsharingPrice() - leftMoney);
returnList.add(wxProfitsharingDO);
updateList.add(wxOrderDO);
break;
}
}
if(CollectionUtil.isNotEmpty(updateList)){
wxOrderMapper.updateBatch(updateList);
}
return returnList;
}
/**
* 生成分账接收方数据
*/
public List<ProfitSharingV3Request.Receiver> createReceiver(WxProfitsharingDO domain) {
List<ProfitSharingV3Request.Receiver> receivers = new ArrayList<>();
List<DivideCompanyDO> companyList = divideCompanyService.getList();
for (DivideCompanyDO divideCompanyDO : companyList) {
int money = (int) Math.ceil(domain.getTotalPrice() * Double.parseDouble(divideCompanyDO.getProportion()));
ProfitSharingV3Request.Receiver receiver = new ProfitSharingV3Request.Receiver();
receiver.setName(divideCompanyDO.getName());
receiver.setType(divideCompanyDO.getType());
receiver.setAmount(money);
receiver.setAccount(divideCompanyDO.getAccount());
receiver.setDescription("" + divideCompanyDO.getName() + "分账");
receivers.add(receiver);
}
return receivers;
}
/**
* 分账和分账明细添加数据库
*/
public void insertDB(PayDivideRespDto payDivideRespDto, WxProfitsharingDO domain) {
domain.setOrderId(payDivideRespDto.getOrderId());
domain.setState("PROCESSING");
wxProfitsharingMapper.insert(domain);
List<DivideCompanyDO> companyList = divideCompanyService.getList();
Map<String, DivideCompanyDO> companyMap = companyList.stream().collect(Collectors.toMap(DivideCompanyDO::getAccount, vo -> vo));
List<WxProfitsharingInfoDO> insertList = new ArrayList<>();
for (ProfitSharingV3Result.Receiver receiver : payDivideRespDto.getReceivers()) {
DivideCompanyDO divideCompanyDO = companyMap.get(receiver.getAccount());
if(ObjectUtil.isEmpty(divideCompanyDO)){
continue;
}
WxProfitsharingInfoDO infoDO = new WxProfitsharingInfoDO();
infoDO.setPayWxProfitsharingId(domain.getId());
infoDO.setName(divideCompanyDO.getName());
infoDO.setType(receiver.getType());
infoDO.setAccount(receiver.getAccount());
infoDO.setAmount(receiver.getAmount());
infoDO.setDescription(receiver.getDescription());
infoDO.setResult(receiver.getResult());
infoDO.setFailReason(receiver.getFailReason());
infoDO.setDetailId(receiver.getDetailId());
infoDO.setDCreateTime(receiver.getCreateTime());
infoDO.setDFinishTime(receiver.getFinishTime());
insertList.add(infoDO);
}
infoMapper.insertBatch(insertList);
}
@Override
public int getDivideResult() {
//获取待查询结果的分账订单
LambdaQueryWrapper<WxProfitsharingDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(WxProfitsharingDO::getState, "PROCESSING");
List<WxProfitsharingDO> divideRecordDOList = wxProfitsharingMapper.selectList(wrapper);
if (CollectionUtil.isEmpty(divideRecordDOList)) {
return 0;
}
//调用微信接口
for (WxProfitsharingDO domain : divideRecordDOList) {
WxOrderDO wxOrderDO = wxOrderMapper.selectById(domain.getPayWxOrderId());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayDivideUnifiedDto payDivideUnifiedDto = new PayDivideUnifiedDto();
payDivideUnifiedDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(domain.getOutOrderNo());
PayDivideRespDto payDivideRespDto = client.unifiedDivideResult(payDivideUnifiedDto);
//同步数据库结果
domain.setState(payDivideRespDto.getState());
wxProfitsharingMapper.updateById(domain);
//同步详情结果
for (ProfitSharingV3Result.Receiver receiver : payDivideRespDto.getReceivers()) {
LambdaQueryWrapper<WxProfitsharingInfoDO> infoWrapper = new LambdaQueryWrapper<>();
infoWrapper.eq(WxProfitsharingInfoDO::getPayWxProfitsharingId, domain.getId())
.eq(WxProfitsharingInfoDO::getAmount, receiver.getAmount());
List<WxProfitsharingInfoDO> infoDOList = infoMapper.selectList(infoWrapper);
if (CollectionUtil.isNotEmpty(infoDOList)) {
WxProfitsharingInfoDO infoDO = infoDOList.get(0);
infoDO.setResult(receiver.getResult());
infoDO.setFailReason(receiver.getFailReason());
infoMapper.updateById(infoDO);
}
}
}
return divideRecordDOList.size();
}
@Override
public Boolean drawMoney(DrawMoneyVO drawMoneyVO) {
//判断订单是否完成
int i = wxProfitsharingMapper.orderCount(drawMoneyVO.getUserId());
if (i > 0) {
throw new ServiceException(ORDER_NOT_COMPLETE);
}
//判断是否有金额可退款
BigDecimal wxAmount = wxProfitsharingMapper.getWxAmount(drawMoneyVO.getUserId());
if (wxAmount == null) {
throw new ServiceException(WX_ACCOUNT_NO);
}
//判断是否有金额可退款
int money = wxAmount.multiply(new BigDecimal("100")).intValue();
if (money <= 0) {
throw new ServiceException(WX_ACCOUNT_NO);
}
//指定金额
if (drawMoneyVO.getTotalPrice() != null) {
if (money < drawMoneyVO.getTotalPrice()) {
throw new ServiceException(WX_ACCOUNT_NO);
}
money = drawMoneyVO.getTotalPrice();
}
//交易时间超过一年的订单无法提交退款(按支付成功时间+365天计算
LocalDateTime now = LocalDateTime.now(); // 获取当前时间
LocalDateTime threeYearsAgo = now.minusDays(364);
//查询最近的充值订单,时间倒序退款
List<WxOrderDO> wxOrderDOList = wxOrderMapper.selectList(Wrappers.<WxOrderDO>lambdaQuery()
.eq(WxOrderDO::getOpenId, drawMoneyVO.getChannelUserId())
.gt(WxOrderDO::getRefundPrice, 0)
.ge(WxOrderDO::getCreateTime, threeYearsAgo)
.orderByDesc(WxOrderDO::getCreateTime));
Map<Long, WxOrderDO> orderMap = wxOrderDOList.stream().collect(Collectors.toMap(WxOrderDO::getId, vo -> vo));
//筛选出未分账的订单
List<WxOrderDO> unDivideList = wxOrderDOList.stream().filter(vo -> vo.getRefundPrice().equals(vo.getProfitsharingPrice())).collect(Collectors.toList());
//筛选出已分账的订单
List<WxOrderDO> divideList = wxOrderDOList.stream().filter(vo -> !vo.getRefundPrice().equals(vo.getProfitsharingPrice())).collect(Collectors.toList());
//筛选出分账完的订单
List<WxOrderDO> divideCpList = divideList.stream().filter(vo -> vo.getProfitsharingPrice() == 0).collect(Collectors.toList());
//剩下的是未分账完的订单
List<WxOrderDO> divideUnCpList = divideList.stream().filter(vo -> vo.getProfitsharingPrice() != 0).collect(Collectors.toList());
//生成退款订单
List<WxRefundDO> refundDOList = createRefund(unDivideList, divideCpList, divideUnCpList, money, drawMoneyVO.getUserId());
int failNum = 0;
//调用微信退款接口
if (CollectionUtil.isNotEmpty(refundDOList)) {
for (WxRefundDO wxRefundDO : refundDOList) {
WxOrderDO wxOrderDO = orderMap.get(wxRefundDO.getPayWxOrderId());
PayChannelDO channel = channelService.validPayChannel(wxOrderDO.getChannelId());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayRefundUnifiedReqDTO payRefundUnifiedReqDTO = new PayRefundUnifiedReqDTO();
payRefundUnifiedReqDTO.setTransactionId(wxOrderDO.getTransactionId())
.setReason("提现")
.setRefundPrice(wxRefundDO.getTotalPrice())
.setOutRefundNo(wxRefundDO.getOutRefundNo())
.setPayPrice(wxOrderDO.getTotalPrice())
.setNotifyUrl(genChannelRefundNotifyUrl(channel));
PayRefundRespDTO payRefundRespDTO = client.unifiedRefund(payRefundUnifiedReqDTO);
String channelRefundNo = payRefundRespDTO.getChannelRefundNo();
wxRefundDO.setRefundId(channelRefundNo);
if (cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum.WAITING.getStatus().equals(payRefundRespDTO.getStatus())) {
wxRefundDO.setStatus(PayDivideRefundStatusRespEnum.PROCESSING.getStatus());
} else if (cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum.SUCCESS.getStatus().equals(payRefundRespDTO.getStatus())) {
wxRefundDO.setStatus(PayDivideRefundStatusRespEnum.SUCCESS.getStatus());
} else {
failNum++;
wxRefundDO.setStatus(PayDivideRefundStatusRespEnum.ABNORMAL.getStatus());
}
wxRefundMapper.insert(wxRefundDO);
}
}
return failNum <= 0;
}
/**
* 生成退款订单
*/
public List<WxRefundDO> createRefund(List<WxOrderDO> unDivideList, List<WxOrderDO> divideCpList
, List<WxOrderDO> divideUnCpList, int money, Long userId) {
//退款订单
List<WxRefundDO> backList = new ArrayList<>();
int sum = 0;
//先从未分账的订单计算
for (WxOrderDO wxOrderDO : unDivideList) {
Integer totalPrice = wxOrderDO.getRefundPrice();
sum = sum + totalPrice;
WxRefundDO wxRefundDO = new WxRefundDO();
wxRefundDO.setPayWxOrderId(wxOrderDO.getId());
wxRefundDO.setUserId(userId);
wxRefundDO.setOutRefundNo(noRedisDAO.generate(payProperties.getRefundNoPrefix()));
if (sum < money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
wxOrderDO.setProfitsharingPrice(0);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
backList.add(wxRefundDO);
} else if (sum == money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
wxOrderDO.setProfitsharingPrice(0);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
backList.add(wxRefundDO);
break;
} else {
int leftMoney = money + totalPrice - sum;
wxRefundDO.setTotalPrice(leftMoney);
wxOrderDO.setRefundPrice(totalPrice - leftMoney);
wxOrderDO.setProfitsharingPrice(totalPrice - leftMoney);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
backList.add(wxRefundDO);
break;
}
}
//从分账完的订单进行退款
if (sum < money) {
for (WxOrderDO wxOrderDO : divideCpList) {
Integer totalPrice = wxOrderDO.getRefundPrice();
sum = sum + totalPrice;
WxRefundDO wxRefundDO = new WxRefundDO();
wxRefundDO.setPayWxOrderId(wxOrderDO.getId());
wxRefundDO.setUserId(userId);
wxRefundDO.setOutRefundNo(noRedisDAO.generate(payProperties.getRefundNoPrefix()));
if (sum < money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(totalPrice));
backList.add(wxRefundDO);
} else if (sum == money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(totalPrice));
backList.add(wxRefundDO);
break;
} else {
int leftMoney = money + totalPrice - sum;
wxRefundDO.setTotalPrice(leftMoney);
wxOrderDO.setRefundPrice(totalPrice - leftMoney);
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(totalPrice));
backList.add(wxRefundDO);
break;
}
}
}
//从部分分账完的订单进行退款
if (sum < money) {
for (WxOrderDO wxOrderDO : divideUnCpList) {
//还能退款的金额
Integer totalPrice = wxOrderDO.getRefundPrice();
//查询分账出去的金额
int profitsharingPrice = getProfitsharingPrice(wxOrderDO.getId());
//该订单还冻结的金额
int freeze = totalPrice - profitsharingPrice;
//未解冻资金中还未分账的金额
Integer unps = wxOrderDO.getProfitsharingPrice();
//拿来分账的金额
Integer ps = totalPrice - unps;
sum = sum + totalPrice;
WxRefundDO wxRefundDO = new WxRefundDO();
wxRefundDO.setPayWxOrderId(wxOrderDO.getId());
wxRefundDO.setUserId(userId);
wxRefundDO.setOutRefundNo(noRedisDAO.generate(payProperties.getRefundNoPrefix()));
if (sum < money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
wxOrderDO.setProfitsharingPrice(0);
//先解冻剩余资金
String unFreeNo = noRedisDAO.generate(payProperties.getOrderNoPrefix());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayDivideUnifiedDto payDivideUnifiedDto = new PayDivideUnifiedDto();
payDivideUnifiedDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
client.unifiedDivideFreeze(payDivideUnifiedDto);
String state = "";
do {
try {
//等待解冻成功
TimeUnit.SECONDS.sleep(15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
PayDivideUnifiedDto resultDto = new PayDivideUnifiedDto();
resultDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
PayDivideRespDto payDivideRespDto = client.unifiedDivideResult(resultDto);
state = payDivideRespDto.getState();
} while ("PROCESSING".equals(state));
//计算回退资金
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(ps));
backList.add(wxRefundDO);
} else if (sum == money) {
wxRefundDO.setTotalPrice(totalPrice);
wxOrderDO.setRefundPrice(0);
wxOrderDO.setProfitsharingPrice(0);
//先解冻剩余资金
String unFreeNo = noRedisDAO.generate(payProperties.getOrderNoPrefix());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayDivideUnifiedDto payDivideUnifiedDto = new PayDivideUnifiedDto();
payDivideUnifiedDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
client.unifiedDivideFreeze(payDivideUnifiedDto);
String state = "";
do {
try {
//等待解冻成功
TimeUnit.SECONDS.sleep(15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
PayDivideUnifiedDto resultDto = new PayDivideUnifiedDto();
resultDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
PayDivideRespDto payDivideRespDto = client.unifiedDivideResult(resultDto);
state = payDivideRespDto.getState();
} while ("PROCESSING".equals(state));
//计算回退资金
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(ps));
backList.add(wxRefundDO);
break;
} else {
int leftMoney = money + totalPrice - sum;
wxRefundDO.setTotalPrice(leftMoney);
wxOrderDO.setRefundPrice(totalPrice - leftMoney);
wxOrderDO.setProfitsharingPrice(Math.max(unps - leftMoney, 0));
//是否解冻判定
if (freeze < leftMoney) {
String unFreeNo = noRedisDAO.generate(payProperties.getOrderNoPrefix());
PayClient client = channelService.getPayClient(wxOrderDO.getChannelId());
PayDivideUnifiedDto payDivideUnifiedDto = new PayDivideUnifiedDto();
payDivideUnifiedDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
client.unifiedDivideFreeze(payDivideUnifiedDto);
String state = "";
do {
try {
//等待解冻成功
TimeUnit.SECONDS.sleep(15);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
PayDivideUnifiedDto resultDto = new PayDivideUnifiedDto();
resultDto.setTransactionId(wxOrderDO.getTransactionId())
.setOutOrderNo(unFreeNo);
PayDivideRespDto payDivideRespDto = client.unifiedDivideResult(resultDto);
state = payDivideRespDto.getState();
} while ("PROCESSING".equals(state));
}
//计算回退资金
String jsonString = JsonUtils.toJsonString(wxOrderDO);
divideRedisTemplate.opsForValue().set("R" + wxOrderDO.getId(), jsonString);
if (unps < leftMoney) {
divideRedisTemplate.opsForValue().set("R" + wxRefundDO.getOutRefundNo(), String.valueOf(leftMoney - unps));
}
backList.add(wxRefundDO);
break;
}
}
}
return backList;
}
/**
* 获取已分账金额
*/
public int getProfitsharingPrice(Long orderId) {
List<WxProfitsharingDO> wxProfitsharingDOS = wxProfitsharingMapper.selectList(Wrappers.<WxProfitsharingDO>lambdaQuery().eq(WxProfitsharingDO::getPayWxOrderId, orderId));
if (CollectionUtil.isNotEmpty(wxProfitsharingDOS)) {
List<Long> ids = wxProfitsharingDOS.stream().map(WxProfitsharingDO::getId).collect(Collectors.toList());
List<WxProfitsharingInfoDO> wxProfitsharingInfoDOS = infoMapper.selectList(Wrappers.<WxProfitsharingInfoDO>lambdaQuery().in(WxProfitsharingInfoDO::getPayWxProfitsharingId, ids));
if (CollectionUtil.isNotEmpty(wxProfitsharingInfoDOS)) {
int sum = wxProfitsharingInfoDOS.stream().filter(vo -> ObjectUtil.isNotEmpty(vo.getAccount()))
.mapToInt(WxProfitsharingInfoDO::getAmount)
.sum();
return sum;
}
}
return 0;
}
/**
* 退款回调地址
*/
private String genChannelRefundNotifyUrl(PayChannelDO channel) {
return payProperties.getRefundNotifyUrl() + "/" + channel.getId();
}
@Override
public void returnMoney(Long payWxOrderId, int returnMoney) {
List<WxProfitsharingDO> wxProfitsharingDOS = wxProfitsharingMapper.selectList(Wrappers.<WxProfitsharingDO>lambdaQuery().eq(WxProfitsharingDO::getPayWxOrderId, payWxOrderId));
List<WxProfitsharingReturnDO> returnDOList = new ArrayList<>();
int sum = 0;
Map<Long,WxProfitsharingDO> map = new HashMap<>();
for (WxProfitsharingDO domain : wxProfitsharingDOS) {
int totalPrice = domain.getReturnPrice();
sum = sum + totalPrice;
List<WxProfitsharingInfoDO> infoDOList = infoMapper.selectList(Wrappers.<WxProfitsharingInfoDO>lambdaQuery()
.eq(WxProfitsharingInfoDO::getPayWxProfitsharingId, domain.getId()));
if (sum < returnMoney) {
domain.setReturnPrice(0);
map.put(domain.getId(),domain);
for (WxProfitsharingInfoDO infoDO : infoDOList){
WxProfitsharingReturnDO returnDO = new WxProfitsharingReturnDO();
returnDO.setPayWxProfitsharingId(domain.getId());
returnDO.setOutReturnNo(noRedisDAO.generate(payProperties.getReturnNoPrefix()));
returnDO.setAmount(infoDO.getAmount());
returnDO.setDescription("分账回退");
returnDO.setReturnMchid(infoDO.getAccount());
returnDO.setTotalPrice(totalPrice);
returnDOList.add(returnDO);
}
}else if (sum == returnMoney){
domain.setReturnPrice(0);
map.put(domain.getId(),domain);
for (WxProfitsharingInfoDO infoDO : infoDOList){
WxProfitsharingReturnDO returnDO = new WxProfitsharingReturnDO();
returnDO.setPayWxProfitsharingId(domain.getId());
returnDO.setOutReturnNo(noRedisDAO.generate(payProperties.getReturnNoPrefix()));
returnDO.setAmount(infoDO.getAmount());
returnDO.setDescription("分账回退");
returnDO.setReturnMchid(infoDO.getAccount());
returnDO.setTotalPrice(totalPrice);
returnDOList.add(returnDO);
}
break;
}else {
int leftMoney = returnMoney - (sum - totalPrice);
domain.setReturnPrice(totalPrice-leftMoney);
map.put(domain.getId(),domain);
for (WxProfitsharingInfoDO infoDO : infoDOList){
WxProfitsharingReturnDO returnDO = new WxProfitsharingReturnDO();
returnDO.setPayWxProfitsharingId(domain.getId());
returnDO.setOutReturnNo(noRedisDAO.generate(payProperties.getReturnNoPrefix()));
returnDO.setAmount(divideCompanyService.computeAmount(infoDO.getAccount(),leftMoney));
returnDO.setDescription("分账回退");
returnDO.setReturnMchid(infoDO.getAccount());
returnDO.setTotalPrice(leftMoney);
returnDOList.add(returnDO);
returnDOList.add(returnDO);
}
break;
}
}
PayClient client = channelService.getPayClient(wxOrderMapper.selectById(payWxOrderId).getChannelId());
//调微信接口
for(WxProfitsharingReturnDO returnDO:returnDOList){
WxProfitsharingDO wxProfitsharingDO = map.get(returnDO.getPayWxProfitsharingId());
PayDivideBackUnifiedDto payDivideBackUnifiedDto = new PayDivideBackUnifiedDto();
payDivideBackUnifiedDto.setAmount(returnDO.getAmount().longValue());
payDivideBackUnifiedDto.setDescription(returnDO.getDescription());
payDivideBackUnifiedDto.setOrderId(wxProfitsharingDO.getOrderId());
payDivideBackUnifiedDto.setReturnMchid(returnDO.getReturnMchid());
payDivideBackUnifiedDto.setOutOrderNo(wxProfitsharingDO.getOutOrderNo());
payDivideBackUnifiedDto.setOutReturnNo(returnDO.getOutReturnNo());
PayDivideBackRespDto respDto = client.unifiedDivideback(payDivideBackUnifiedDto);
log.info("订单:" + respDto.getOrderId() + "回退结果:" + respDto.getResult());
returnDO.setResult(respDto.getResult());
returnDO.setReturnId(respDto.getReturnId());
returnDO.setFailReason(respDto.getFailReason());
returnDO.setDFinishTime(respDto.getFinishTime());
returnDO.setDCreateTime(respDto.getCreateTime());
returnMapper.insert(returnDO);
wxProfitsharingMapper.updateById(wxProfitsharingDO);
}
}
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharinginfo;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo.WxProfitsharingInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 微信分账明细 Service 接口
*
* @author 管理员
*/
public interface WxProfitsharingInfoService {
/**
* 创建微信分账明细
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWxProfitsharingInfo(@Valid WxProfitsharingInfoSaveReqVO createReqVO);
/**
* 更新微信分账明细
*
* @param updateReqVO 更新信息
*/
void updateWxProfitsharingInfo(@Valid WxProfitsharingInfoSaveReqVO updateReqVO);
/**
* 删除微信分账明细
*
* @param id 编号
*/
void deleteWxProfitsharingInfo(Long id);
/**
* 获得微信分账明细
*
* @param id 编号
* @return 微信分账明细
*/
WxProfitsharingInfoDO getWxProfitsharingInfo(Long id);
/**
* 获得微信分账明细分页
*
* @param pageReqVO 分页查询
* @return 微信分账明细分页
*/
PageResult<WxProfitsharingInfoDO> getWxProfitsharingInfoPage(WxProfitsharingInfoPageReqVO pageReqVO);
}

View File

@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharinginfo;
import cn.iocoder.yudao.module.pay.dal.dataobject.divideinfo.DivideInfoDO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharinginfo.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharinginfo.WxProfitsharingInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharinginfo.WxProfitsharingInfoMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 微信分账明细 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
public class WxProfitsharingInfoServiceImpl implements WxProfitsharingInfoService {
@Resource
private WxProfitsharingInfoMapper wxProfitsharingInfoMapper;
@Override
public Long createWxProfitsharingInfo(WxProfitsharingInfoSaveReqVO createReqVO) {
// 插入
WxProfitsharingInfoDO wxProfitsharingInfo = BeanUtils.toBean(createReqVO, WxProfitsharingInfoDO.class);
wxProfitsharingInfoMapper.insert(wxProfitsharingInfo);
// 返回
return wxProfitsharingInfo.getId();
}
@Override
public void updateWxProfitsharingInfo(WxProfitsharingInfoSaveReqVO updateReqVO) {
// 校验存在
validateWxProfitsharingInfoExists(updateReqVO.getId());
// 更新
WxProfitsharingInfoDO updateObj = BeanUtils.toBean(updateReqVO, WxProfitsharingInfoDO.class);
wxProfitsharingInfoMapper.updateById(updateObj);
}
@Override
public void deleteWxProfitsharingInfo(Long id) {
// 校验存在
validateWxProfitsharingInfoExists(id);
// 删除
wxProfitsharingInfoMapper.deleteById(id);
}
private void validateWxProfitsharingInfoExists(Long id) {
if (wxProfitsharingInfoMapper.selectById(id) == null) {
throw exception(WX_PROFITSHARING_INFO_NOT_EXISTS);
}
}
@Override
public WxProfitsharingInfoDO getWxProfitsharingInfo(Long id) {
return wxProfitsharingInfoMapper.selectById(id);
}
@Override
public PageResult<WxProfitsharingInfoDO> getWxProfitsharingInfoPage(WxProfitsharingInfoPageReqVO pageReqVO) {
PageResult<WxProfitsharingInfoDO> pageResult = wxProfitsharingInfoMapper.selectPage(pageReqVO);
for (WxProfitsharingInfoDO infoDO:pageResult.getList()){
if(StringUtils.isNotBlank(infoDO.getDCreateTime())){
// 解析时间字符串
ZonedDateTime zonedDateTime = ZonedDateTime.parse(infoDO.getDCreateTime());
// 定义所需的时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 格式化时间字符串
infoDO.setDCreateTime(zonedDateTime.format(formatter));
}
}
return pageResult;
}
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharingreturn;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn.WxProfitsharingReturnDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 微信分账回退 Service 接口
*
* @author 管理员
*/
public interface WxProfitsharingReturnService {
/**
* 创建微信分账回退
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWxProfitsharingReturn(@Valid WxProfitsharingReturnSaveReqVO createReqVO);
/**
* 更新微信分账回退
*
* @param updateReqVO 更新信息
*/
void updateWxProfitsharingReturn(@Valid WxProfitsharingReturnSaveReqVO updateReqVO);
/**
* 删除微信分账回退
*
* @param id 编号
*/
void deleteWxProfitsharingReturn(Long id);
/**
* 获得微信分账回退
*
* @param id 编号
* @return 微信分账回退
*/
WxProfitsharingReturnDO getWxProfitsharingReturn(Long id);
/**
* 获得微信分账回退分页
*
* @param pageReqVO 分页查询
* @return 微信分账回退分页
*/
PageResult<WxProfitsharingReturnDO> getWxProfitsharingReturnPage(WxProfitsharingReturnPageReqVO pageReqVO);
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.pay.service.wxprofitsharingreturn;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxprofitsharingreturn.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxprofitsharingreturn.WxProfitsharingReturnDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.dal.mysql.wxprofitsharingreturn.WxProfitsharingReturnMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 微信分账回退 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
public class WxProfitsharingReturnServiceImpl implements WxProfitsharingReturnService {
@Resource
private WxProfitsharingReturnMapper wxProfitsharingReturnMapper;
@Override
public Long createWxProfitsharingReturn(WxProfitsharingReturnSaveReqVO createReqVO) {
// 插入
WxProfitsharingReturnDO wxProfitsharingReturn = BeanUtils.toBean(createReqVO, WxProfitsharingReturnDO.class);
wxProfitsharingReturnMapper.insert(wxProfitsharingReturn);
// 返回
return wxProfitsharingReturn.getId();
}
@Override
public void updateWxProfitsharingReturn(WxProfitsharingReturnSaveReqVO updateReqVO) {
// 校验存在
validateWxProfitsharingReturnExists(updateReqVO.getId());
// 更新
WxProfitsharingReturnDO updateObj = BeanUtils.toBean(updateReqVO, WxProfitsharingReturnDO.class);
wxProfitsharingReturnMapper.updateById(updateObj);
}
@Override
public void deleteWxProfitsharingReturn(Long id) {
// 校验存在
validateWxProfitsharingReturnExists(id);
// 删除
wxProfitsharingReturnMapper.deleteById(id);
}
private void validateWxProfitsharingReturnExists(Long id) {
if (wxProfitsharingReturnMapper.selectById(id) == null) {
throw exception(WX_PROFITSHARING_RETURN_NOT_EXISTS);
}
}
@Override
public WxProfitsharingReturnDO getWxProfitsharingReturn(Long id) {
return wxProfitsharingReturnMapper.selectById(id);
}
@Override
public PageResult<WxProfitsharingReturnDO> getWxProfitsharingReturnPage(WxProfitsharingReturnPageReqVO pageReqVO) {
return wxProfitsharingReturnMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.pay.service.wxrefund;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 微信退款 Service 接口
*
* @author 管理员
*/
public interface WxRefundService {
/**
* 创建微信退款
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createWxRefund(@Valid WxRefundSaveReqVO createReqVO);
/**
* 更新微信退款
*
* @param updateReqVO 更新信息
*/
void updateWxRefund(@Valid WxRefundSaveReqVO updateReqVO);
/**
* 删除微信退款
*
* @param id 编号
*/
void deleteWxRefund(Long id);
/**
* 获得微信退款
*
* @param id 编号
* @return 微信退款
*/
WxRefundDO getWxRefund(Long id);
/**
* 获得微信退款分页
*
* @param pageReqVO 分页查询
* @return 微信退款分页
*/
PageResult<WxRefundDO> getWxRefundPage(WxRefundPageReqVO pageReqVO);
}

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.pay.service.wxrefund;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.pay.controller.admin.wxrefund.vo.*;
import cn.iocoder.yudao.module.pay.dal.dataobject.wxrefund.WxRefundDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.dal.mysql.wxrefund.WxRefundMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
/**
* 微信退款 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
public class WxRefundServiceImpl implements WxRefundService {
@Resource
private WxRefundMapper wxRefundMapper;
@Override
public Long createWxRefund(WxRefundSaveReqVO createReqVO) {
// 插入
WxRefundDO wxRefund = BeanUtils.toBean(createReqVO, WxRefundDO.class);
wxRefundMapper.insert(wxRefund);
// 返回
return wxRefund.getId();
}
@Override
public void updateWxRefund(WxRefundSaveReqVO updateReqVO) {
// 校验存在
validateWxRefundExists(updateReqVO.getId());
// 更新
WxRefundDO updateObj = BeanUtils.toBean(updateReqVO, WxRefundDO.class);
wxRefundMapper.updateById(updateObj);
}
@Override
public void deleteWxRefund(Long id) {
// 校验存在
validateWxRefundExists(id);
// 删除
wxRefundMapper.deleteById(id);
}
private void validateWxRefundExists(Long id) {
if (wxRefundMapper.selectById(id) == null) {
throw exception(WX_REFUND_NOT_EXISTS);
}
}
@Override
public WxRefundDO getWxRefund(Long id) {
return wxRefundMapper.selectById(id);
}
@Override
public PageResult<WxRefundDO> getWxRefundPage(WxRefundPageReqVO pageReqVO) {
return wxRefundMapper.selectPage(pageReqVO);
}
}