From b46a7b875e1167810f747771d2c2bede289f63d7 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Sun, 13 Oct 2024 20:59:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E7=8E=B0=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8F=90=E7=8E=B0=E6=B8=A0=E9=81=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E8=B0=83=E6=95=B4=E7=94=9F=E6=88=90=E8=B4=A6?= =?UTF-8?q?=E5=8F=98=E8=AE=B0=E5=BD=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appadmin/AppAdminController.java | 15 ++ .../web/controller/rl/RlUserController.java | 163 ++++++++++++------ .../common/constant/ServiceConstants.java | 34 ++-- .../common/core/domain/entity/RlUserVO.java | 4 +- .../com/ruoyi/system/domain/RlMsgLog.java | 2 +- .../channelWithdraw/ChannelWithdraw.java | 8 +- .../system/domain/userExt/RlUserExt.java | 7 + .../ruoyi/system/domain/vo/RlUserQuery.java | 21 +++ .../system/domain/withdraw/RlWithdraw.java | 12 +- .../ruoyi/system/mapper/RlUserExtMapper.java | 8 + .../service/IRlChangeBalanceService.java | 17 ++ .../system/service/IRlUserExtService.java | 8 + .../service/impl/CallbackServiceImpl.java | 24 +-- .../impl/RlChangeBalanceServiceImpl.java | 65 ++++++- .../service/impl/RlUserExtServiceImpl.java | 13 ++ .../service/impl/RlUserServiceImpl.java | 91 ++++++++-- .../mapper/system/RlChannelWithdrawMapper.xml | 31 ++-- .../mapper/system/RlMsgLogMapper.xml | 10 +- .../mapper/system/RlUserExtMapper.xml | 13 +- .../resources/mapper/system/RlUserMapper.xml | 9 +- .../mapper/system/RlWithdrawMapper.xml | 18 +- 21 files changed, 417 insertions(+), 156 deletions(-) diff --git a/ridelease-admin/src/main/java/com/ruoyi/web/controller/appadmin/AppAdminController.java b/ridelease-admin/src/main/java/com/ruoyi/web/controller/appadmin/AppAdminController.java index c4ca35e..9b02e91 100644 --- a/ridelease-admin/src/main/java/com/ruoyi/web/controller/appadmin/AppAdminController.java +++ b/ridelease-admin/src/main/java/com/ruoyi/web/controller/appadmin/AppAdminController.java @@ -19,6 +19,8 @@ import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.system.domain.agent.RlAgentVO; import com.ruoyi.system.domain.changeBalance.RlChangeBalance; import com.ruoyi.system.domain.changeBalance.RlChangeBalanceQuery; +import com.ruoyi.system.domain.channelWithdraw.ChannelWithdrawQuery; +import com.ruoyi.system.domain.channelWithdraw.ChannelWithdrawVO; import com.ruoyi.system.domain.deliveryOrder.RlDeliveryOrderVO; import com.ruoyi.system.domain.device.RlDeviceQuery; import com.ruoyi.system.domain.device.RlDeviceVO; @@ -90,6 +92,9 @@ public class AppAdminController extends BaseController @Resource private IRlAgentService rlAgentService; + @Autowired + private RlChannelWithdrawService etChannelWithdrawService; + /** * 首页统计 */ @@ -278,6 +283,16 @@ public class AppAdminController extends BaseController return toAjax(i); } + /** + * 查询提现渠道列表 + */ + @GetMapping("/withdrawList") + public AjaxResult withdrawList(ChannelWithdrawQuery query) + { + List list = etChannelWithdrawService.selectChannelWithdrawList(query); + return success(list); + } + /** * 获取商户详细信息 */ diff --git a/ridelease-admin/src/main/java/com/ruoyi/web/controller/rl/RlUserController.java b/ridelease-admin/src/main/java/com/ruoyi/web/controller/rl/RlUserController.java index 4876059..2887e5b 100644 --- a/ridelease-admin/src/main/java/com/ruoyi/web/controller/rl/RlUserController.java +++ b/ridelease-admin/src/main/java/com/ruoyi/web/controller/rl/RlUserController.java @@ -1,20 +1,31 @@ package com.ruoyi.web.controller.rl; import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.RlUser; import com.ruoyi.common.core.domain.entity.RlUserVO; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.system.domain.agent.RlAgentVO; +import com.ruoyi.system.domain.userExt.RlUserExt; import com.ruoyi.system.domain.vo.RlUserQuery; +import com.ruoyi.system.service.IRlAgentService; +import com.ruoyi.system.service.IRlUserExtService; import com.ruoyi.system.service.IRlUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; import java.util.List; /** @@ -27,7 +38,16 @@ import java.util.List; public class RlUserController extends BaseController { @Resource - private IRlUserService eUserService; + private IRlUserService userService; + + @Autowired + private TransactionTemplate transactionTemplate; + + @Autowired + private IRlUserExtService userExtService; + + @Autowired + private IRlAgentService agentService; /** * 获取用户列表 @@ -36,7 +56,7 @@ public class RlUserController extends BaseController public TableDataInfo list(RlUserQuery rlUser) { startPage(); - List list = eUserService.selectUserList(rlUser); + List list = userService.selectUserList(rlUser); return getDataTable(list); } @@ -78,58 +98,101 @@ public class RlUserController extends BaseController AjaxResult ajax = AjaxResult.success(); if (StringUtils.isNotNull(userId)) { - RlUser rlUser = eUserService.selectUserById(userId); + RlUser rlUser = userService.selectUserById(userId); ajax.put(AjaxResult.DATA_TAG, rlUser); } return ajax; } -// /** -// * 新增用户 -// */ -// @Log(title = "用户管理", businessType = BusinessType.INSERT) -// @PostMapping -// public AjaxResult add(@Validated @RequestBody EUser user) -// { -// if (!eUserService.checkUserNameUnique(user)) -// { -// return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); -// } -// else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !eUserService.checkPhoneUnique(user)) -// { -// return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); -// } -// else if (StringUtils.isNotEmpty(user.getEmail()) && !eUserService.checkEmailUnique(user)) -// { -// return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); -// } -// user.setCreateBy(getUsername()); -// user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); -// return toAjax(eUserService.insertUser(user)); -// } -// -// /** -// * 修改用户 -// */ -// @Log(title = "用户管理", businessType = BusinessType.UPDATE) -// @PutMapping -// public AjaxResult edit(@Validated @RequestBody EUser user) -// { -// if (!eUserService.checkUserNameUnique(user)) -// { -// return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); -// } -// else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !eUserService.checkPhoneUnique(user)) -// { -// return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); -// } -// else if (StringUtils.isNotEmpty(user.getEmail()) && !eUserService.checkEmailUnique(user)) -// { -// return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); -// } -// user.setUpdateBy(getUsername()); -// return toAjax(eUserService.updateUser(user)); -// } + /** + * 新增商户 + */ + @Log(title = "用户管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody RlUserQuery user) + { + if (!userService.checkUserNameUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); + } + else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); + } + else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) + { + return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + user.setCreateBy(getUsername()); + user.setUserType(ServiceConstants.USER_TYPE_MERCHANT); + user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); + Boolean execute = transactionTemplate.execute(e -> { + int i = userService.insertUser(user); + if(i == 0){ + throw new ServiceException("【新增用户】失败"); + } + /** 新增用户扩展表 */ + saveUserExt(user); + return Boolean.TRUE; + }); + if(!execute)throw new ServiceException("【新增商户】失败"); + return toAjax(1); + } + + private void saveUserExt(RlUserQuery user) { + RlUserExt userExt = new RlUserExt(); + userExt.setUserId(user.getUserId()); + userExt.setDividendProportion(user.getDividendProportion().divide(BigDecimal.valueOf(100))); + userExt.setCooperationTime(user.getCooperationTime()); + userExt.setDividendStatus(user.getDividendStatus()); + userExt.setHandlingChargeType(user.getHandlingChargeType()); + userExt.setWithdrawHandlingCharge(user.getWithdrawHandlingCharge()); + RlAgentVO agentVO = agentService.selectRlAgentByCityId(user.getCityId()); + userExt.setAgentId(agentVO.getAgentId()); + int i1 = userExtService.insertRlUserExt(userExt); + if(i1 == 0){ + throw new ServiceException("【新增用户扩展表】失败"); + } + } + + /** + * 修改用户 + */ + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody RlUserQuery user) + { + if (!userService.checkUserNameUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); + } + else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); + } + else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + user.setUpdateBy(getUsername()); + user.setUserType(ServiceConstants.USER_TYPE_MERCHANT); + Boolean execute = transactionTemplate.execute(e -> { + int i = userService.updateUser(user); + if(i == 0){ + throw new ServiceException("【修改商户】失败"); + } + int i3 = userExtService.deleteRlUserExtByUserId(user.getUserId()); + if(i3 == 0){ + throw new ServiceException("【删除用户扩展表】失败"); + }else{ + /** 修改用户扩展表 */ + saveUserExt(user); + } + return Boolean.TRUE; + }); + if(!execute)throw new ServiceException("【修改商户】失败"); + return toAjax(1); + } // /** @@ -176,7 +239,7 @@ public class RlUserController extends BaseController public AjaxResult changeStatus(@RequestBody RlUser user) { user.setUpdateBy(getUsername()); - return toAjax(eUserService.updateUserStatus(user)); + return toAjax(userService.updateUserStatus(user)); } diff --git a/ridelease-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java b/ridelease-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java index ffd472c..b1538b4 100644 --- a/ridelease-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java +++ b/ridelease-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java @@ -747,31 +747,19 @@ public class ServiceConstants { /**----------------------------业务类型start----------------------------*/ - /** 业务类型:1-骑行订单;2-押金订单;3-押金订单退款;4-骑行订单退款(包含调度费、停车点外调度费)5-提现;6-提现失败;7-车损收入;8-短信扣费 */ - /** 业务类型:1-骑行订单 */ + /** 业务类型:1-订单收入;2-续租订单收入;4-订单退款5-提现;6-提现失败;8-短信扣费 */ + /** 业务类型:1-订单收入 */ public static final String RIDE_ORDER = "1"; - - /** 业务类型:2-押金订单 */ - public static final String DEPOSIT_ORDER = "2"; - - /** 业务类型:3-押金订单退款 */ - public static final String DEPOSIT_REFUND_ORDER = "3"; - - /** 业务类型:4-骑行订单退款(包含调度费、停车点外调度费) */ - public static final String RIDE_REFUND_ORDER = "4"; - - /** 业务类型:5-提现 */ + /** 续租订单收入 */ + public static final String RENEW_ORDER = "2"; + /** 订单退款 */ + public static final String ORDER_REFUND = "4"; + /** 提现 */ public static final String WITHDRAWAL = "5"; - - /** 业务类型:6-提现失败 */ - public static final String WITHDRAWAL_FAILURE = "6"; - - /** 业务类型:7-车损收入 */ - public static final String CAR_DAMAGE_INCOME = "7"; - - /** 业务类型:8-短信扣费 */ - public static final String SMS_FEE_DEDUCTION = "8"; - + /** 提现失败 */ + public static final String WITHDRAWAL_FAILED = "6"; + /** 短信扣费 */ + public static final String SMS_DEDUCTION = "8"; /**----------------------------业务类型end----------------------------*/ /**----------------------------用户类型start----------------------------*/ diff --git a/ridelease-common/src/main/java/com/ruoyi/common/core/domain/entity/RlUserVO.java b/ridelease-common/src/main/java/com/ruoyi/common/core/domain/entity/RlUserVO.java index 3a315fd..3e94f10 100644 --- a/ridelease-common/src/main/java/com/ruoyi/common/core/domain/entity/RlUserVO.java +++ b/ridelease-common/src/main/java/com/ruoyi/common/core/domain/entity/RlUserVO.java @@ -4,7 +4,6 @@ import lombok.Data; import java.math.BigDecimal; import java.util.Date; -import java.util.List; @Data public class RlUserVO extends RlUser{ @@ -18,6 +17,9 @@ public class RlUserVO extends RlUser{ /** 店铺名称 */ private String storeName; + /** 城市名称 */ + private String cityName; + /** 扩展id */ private Long extId; diff --git a/ridelease-system/src/main/java/com/ruoyi/system/domain/RlMsgLog.java b/ridelease-system/src/main/java/com/ruoyi/system/domain/RlMsgLog.java index 48226ef..b803abf 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/domain/RlMsgLog.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/domain/RlMsgLog.java @@ -5,7 +5,7 @@ import com.ruoyi.common.core.domain.BaseEntity; import lombok.Data; /** - * 短信日志对象 et_msg_log + * 短信日志对象 rl_msg_log * * @author qiuzhenzhen * @date 2024-07-24 diff --git a/ridelease-system/src/main/java/com/ruoyi/system/domain/channelWithdraw/ChannelWithdraw.java b/ridelease-system/src/main/java/com/ruoyi/system/domain/channelWithdraw/ChannelWithdraw.java index 8153fcd..0a6af82 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/domain/channelWithdraw/ChannelWithdraw.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/domain/channelWithdraw/ChannelWithdraw.java @@ -25,17 +25,13 @@ public class ChannelWithdraw extends BaseEntity @ApiModelProperty("渠道名称") private String name; - @Excel(name = "对应账户类型") - @ApiModelProperty("对应账户类型") - private String accountType; - @Excel(name = "服务费收取类型") @ApiModelProperty("服务费收取类型") - private String serviceType; + private String handlingChargeType; @Excel(name = "服务费") @ApiModelProperty("服务费") - private BigDecimal serviceRate; + private BigDecimal withdrawHandlingCharge; @Excel(name = "是否启用") @ApiModelProperty("是否启用") diff --git a/ridelease-system/src/main/java/com/ruoyi/system/domain/userExt/RlUserExt.java b/ridelease-system/src/main/java/com/ruoyi/system/domain/userExt/RlUserExt.java index e00f773..220de74 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/domain/userExt/RlUserExt.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/domain/userExt/RlUserExt.java @@ -3,6 +3,7 @@ package com.ruoyi.system.domain.userExt; import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; @@ -50,4 +51,10 @@ public class RlUserExt extends BaseEntity /** 代理商id */ private Long agentId; + + /** 提现手续费类型:1-按比例,2-按每笔 */ + private String handlingChargeType; + + /** 服务费 */ + private BigDecimal withdrawHandlingCharge; } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/domain/vo/RlUserQuery.java b/ridelease-system/src/main/java/com/ruoyi/system/domain/vo/RlUserQuery.java index a5050f3..9e95d44 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/domain/vo/RlUserQuery.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/domain/vo/RlUserQuery.java @@ -3,10 +3,31 @@ package com.ruoyi.system.domain.vo; import com.ruoyi.common.core.domain.entity.RlUser; import lombok.Data; +import java.math.BigDecimal; +import java.util.Date; + @Data public class RlUserQuery extends RlUser { private String[] typeList; private Long agentId; + + /** 城市id */ + private Long cityId; + + /** 分红比例:百分比 */ + private BigDecimal dividendProportion; + + /** 合作时间 */ + private Date cooperationTime; + + /** 分账状态 */ + private Boolean dividendStatus; + + /** 服务费收取类型 */ + private String handlingChargeType; + + /** 服务费 */ + private BigDecimal withdrawHandlingCharge; } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/domain/withdraw/RlWithdraw.java b/ridelease-system/src/main/java/com/ruoyi/system/domain/withdraw/RlWithdraw.java index 3e10a77..e0e04f7 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/domain/withdraw/RlWithdraw.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/domain/withdraw/RlWithdraw.java @@ -58,8 +58,14 @@ public class RlWithdraw extends BaseEntity @Excel(name = "成本") private BigDecimal cost; - /** 打款方式 */ - @Excel(name = "打款方式") - private String paymentMethod; + /** 提现渠道id */ + @Excel(name = "提现渠道id") + private Long withdrawChannelId; + + /** 提现手续费类型:1-按比例,2-按每笔 */ + private String handlingChargeType; + + /** 服务费 */ + private BigDecimal withdrawHandlingCharge; } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/mapper/RlUserExtMapper.java b/ridelease-system/src/main/java/com/ruoyi/system/mapper/RlUserExtMapper.java index fa4af54..ed3b377 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/mapper/RlUserExtMapper.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/mapper/RlUserExtMapper.java @@ -67,4 +67,12 @@ public interface RlUserExtMapper * @return 结果 */ public int deleteRlUserExtByExtIds(Long[] extIds); + + /** + * 根据userId删除用户扩展信息 + * + * @param userId 用户id + * @return 结果 + */ + int deleteRlUserExtByUserId(Long userId); } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/IRlChangeBalanceService.java b/ridelease-system/src/main/java/com/ruoyi/system/service/IRlChangeBalanceService.java index 9fb4bb4..d40a4f3 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/IRlChangeBalanceService.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/IRlChangeBalanceService.java @@ -2,7 +2,9 @@ package com.ruoyi.system.service; import com.ruoyi.system.domain.changeBalance.RlChangeBalance; import com.ruoyi.system.domain.changeBalance.RlChangeBalanceQuery; +import com.ruoyi.system.domain.order.RlOrder; +import java.math.BigDecimal; import java.util.List; /** @@ -69,4 +71,19 @@ public interface IRlChangeBalanceService * @return 结果 */ public int deleteRlChangeBalanceByChangeId(Long changeId); + + /** + * 根据订单信息生成账变记录 + * + * @param orderNo 订单号 + * @param outTradeNo 第三方流水号 + * @param type 收支类型:1-收入;2-支出 + * @param busType 业务类型 + * @param payFee 支付金额 + * @param userId 用户id + * @param userName 用户名称 + * @param phone 用户电话 + * @return 结果 + */ + public int generateChanggeBalance(String orderNo, String outTradeNo, String type, String busType, BigDecimal payFee, Long userId, String userName, String phone); } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/IRlUserExtService.java b/ridelease-system/src/main/java/com/ruoyi/system/service/IRlUserExtService.java index ae613ed..ed6299c 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/IRlUserExtService.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/IRlUserExtService.java @@ -67,4 +67,12 @@ public interface IRlUserExtService * @return 结果 */ public int deleteRlUserExtByExtId(Long extId); + + /** + * 删除用户扩展信息 + * + * @param userId 用户扩展主键 + * @return 结果 + */ + public int deleteRlUserExtByUserId(Long userId); } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java index 685ef1d..d85f00b 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java @@ -137,7 +137,8 @@ public class CallbackServiceImpl implements CallbackService { Boolean execute = transactionTemplate.execute(e -> { /** 生成账变记录*/ - generateChanggeBalance(originalOrder); + changeBalanceService.generateChanggeBalance(originalOrder.getOrderNo(), outTradeNo, ServiceConstants.FLOW_TYPE_INCOME, + ServiceConstants.RIDE_ORDER, originalOrder.getPayFee(), originalOrder.getUserId(), originalOrder.getUserName(), originalOrder.getPhone()); updateOrder.setPaid("1"); updateOrder.setPayTime(DateUtils.getNowDate()); updateOrder.setPayType(payType); @@ -243,26 +244,7 @@ public class CallbackServiceImpl implements CallbackService { } - private void generateChanggeBalance(RlOrder order) { - RlChangeBalance rlChangeBalance = new RlChangeBalance(); - rlChangeBalance.setOrderNo(order.getOrderNo()); - rlChangeBalance.setOutTradeNo(order.getOutTradeNo()); - rlChangeBalance.setType("1"); - rlChangeBalance.setBusType(ServiceConstants.RIDE_ORDER); - BigDecimal balance = userService.selectUserBalanceById(order.getUserId()); - rlChangeBalance.setBeforeBalance(balance); - rlChangeBalance.setAfterBalance(balance.add(order.getPayFee())); - rlChangeBalance.setAmount(order.getPayFee()); - rlChangeBalance.setOwnerId(order.getUserId()); - rlChangeBalance.setOwnerName(order.getUserName()); - rlChangeBalance.setOwnerPhone(order.getPhone()); - rlChangeBalance.setCreateTime(DateUtils.getNowDate()); - rlChangeBalance.setReason("租赁订单:"+ order.getOrderNo()); - int i = changeBalanceService.insertRlChangeBalance(rlChangeBalance); - if(i>0){ - logger.info("【微信支付回调】账变记录插入成功"); - } - } + private BigDecimal getCost(ChannelVO channel,BigDecimal payFee) { // 获取到渠道成本 diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlChangeBalanceServiceImpl.java b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlChangeBalanceServiceImpl.java index b8e5cc7..e1031bd 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlChangeBalanceServiceImpl.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlChangeBalanceServiceImpl.java @@ -5,9 +5,12 @@ import com.ruoyi.system.domain.changeBalance.RlChangeBalance; import com.ruoyi.system.domain.changeBalance.RlChangeBalanceQuery; import com.ruoyi.system.mapper.RlChangeBalanceMapper; import com.ruoyi.system.service.IRlChangeBalanceService; +import com.ruoyi.system.service.IRlUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.List; /** @@ -19,9 +22,12 @@ import java.util.List; @Service public class RlChangeBalanceServiceImpl implements IRlChangeBalanceService { - @Autowired + @Resource private RlChangeBalanceMapper rlChangeBalanceMapper; + @Autowired + private IRlUserService userService; + /** * 查询余额变动 * @@ -107,4 +113,61 @@ public class RlChangeBalanceServiceImpl implements IRlChangeBalanceService { return rlChangeBalanceMapper.deleteRlChangeBalanceByChangeId(changeId); } + + /** + * 根据订单信息生成账变记录 + * + * @param orderNo 订单号 + * @param outTradeNo 第三方流水号 + * @param type 收支类型:1-收入;2-支出 + * @param busType 业务类型 + * @param payFee 支付金额 + * @param userId 用户id + * @param userName 用户名称 + * @param phone 用户电话 + * @return 结果 + */ + @Override + public int generateChanggeBalance(String orderNo,String outTradeNo,String type,String busType,BigDecimal payFee,Long userId,String userName,String phone) { + RlChangeBalance rlChangeBalance = new RlChangeBalance(); + rlChangeBalance.setOrderNo(orderNo); + rlChangeBalance.setOutTradeNo(outTradeNo); + rlChangeBalance.setType(type); + rlChangeBalance.setBusType(busType); + BigDecimal balance = userService.selectUserBalanceById(userId); + rlChangeBalance.setBeforeBalance(balance); + rlChangeBalance.setAfterBalance(balance.add(payFee)); + rlChangeBalance.setAmount(payFee); + rlChangeBalance.setOwnerId(userId); + rlChangeBalance.setOwnerName(userName); + rlChangeBalance.setOwnerPhone(phone); + rlChangeBalance.setCreateTime(DateUtils.getNowDate()); + // 根据 busType 生成不同的 reason 描述 + String reason = ""; + switch (busType) { + case "1": + reason = "订单收入:" + orderNo; + break; + case "2": + reason = "续租订单收入:" + orderNo; + break; + case "4": + reason = "订单退款:" + orderNo; + break; + case "5": + reason = "提现"; + break; + case "6": + reason = "提现失败"; + break; + case "8": + reason = "短信扣费"; + break; + default: + reason = "未知业务类型"; + break; + } + rlChangeBalance.setReason(reason); + return insertRlChangeBalance(rlChangeBalance); + } } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserExtServiceImpl.java b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserExtServiceImpl.java index 942a6ad..644128c 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserExtServiceImpl.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserExtServiceImpl.java @@ -102,4 +102,17 @@ public class RlUserExtServiceImpl implements IRlUserExtService { return rlUserExtMapper.deleteRlUserExtByExtId(extId); } + + /** + * 根据userId删除用户扩展信息 + * + * @param userId 用户id + * @return 结果 + */ + @Override + public int deleteRlUserExtByUserId(Long userId) + { + return rlUserExtMapper.deleteRlUserExtByUserId(userId); + } + } diff --git a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserServiceImpl.java b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserServiceImpl.java index 533f81b..e1786d4 100644 --- a/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserServiceImpl.java +++ b/ridelease-system/src/main/java/com/ruoyi/system/service/impl/RlUserServiceImpl.java @@ -7,6 +7,7 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; import com.aliyuncs.exceptions.ClientException; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.ServiceConstants; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.ChangeBalanceInterface; import com.ruoyi.common.core.domain.entity.RlUser; import com.ruoyi.common.core.domain.entity.RlUserVO; @@ -21,6 +22,7 @@ import com.ruoyi.system.domain.agent.RlAgentVO; import com.ruoyi.system.domain.changeBalance.RlChangeBalance; import com.ruoyi.system.domain.changeBalance.RlChangeBalanceQuery; import com.ruoyi.system.domain.channel.ChannelVO; +import com.ruoyi.system.domain.channelWithdraw.ChannelWithdrawVO; import com.ruoyi.system.domain.query.AuthenticationQuery; import com.ruoyi.system.domain.userExt.RlUserExt; import com.ruoyi.system.domain.vo.RlUserQuery; @@ -35,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; import javax.annotation.Resource; import javax.validation.Validator; @@ -87,6 +90,15 @@ public class RlUserServiceImpl implements IRlUserService{ @Autowired private IRlMsgLogService msgLogService; + @Autowired + private RlChannelWithdrawService etChannelWithdrawService; + + @Autowired + private TransactionTemplate transactionTemplate; + + @Autowired + private IRlChangeBalanceService changeBalanceService; + @Value("${aliyun.accessKeyId}") private String accessKeyId; @@ -622,7 +634,13 @@ public class RlUserServiceImpl implements IRlUserService{ @Override public boolean checkUserNameUnique(RlUser user) { - return false; + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + RlUser info = rlUserMapper.checkUserNameUnique(user.getUserName()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; } @Override @@ -632,12 +650,24 @@ public class RlUserServiceImpl implements IRlUserService{ @Override public boolean checkPhoneUnique(RlUser user) { - return false; + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + RlUser info = rlUserMapper.checkPhoneUnique(user.getPhonenumber()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; } @Override public boolean checkEmailUnique(RlUser user) { - return false; + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + RlUser info = rlUserMapper.checkEmailUnique(user.getEmail()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; } @Override @@ -723,11 +753,23 @@ public class RlUserServiceImpl implements IRlUserService{ /** 1. 获取当前用户*/ RlUser user = rlUserMapper.selectUserById(SecurityUtils.getUserId()); RlUserExt rlUserExt = userExtService.selectRlUserExtByUserId(user.getUserId()); - RlAgentVO rlAgentVO = agentService.selectRlAgentByAgentId(rlUserExt.getAgentId()); - ChannelVO channelVO = channelService.selectSmChannelByChannelId(rlAgentVO.getPayChannel()); -// log.info(); - /** 2. 记录提现记录*/ + Boolean execute = transactionTemplate.execute(e -> { + /** 2. 记录提现记录*/ + withdrawalRecord(withdraw, orderNo, user, rlUserExt); + /** 3. 扣余额,记录账变 */ + int i = changeBalanceService.generateChanggeBalance(orderNo, null, ServiceConstants.FLOW_TYPE_DISBURSE, + ServiceConstants.WITHDRAWAL, withdraw.getAmount(), user.getUserId(), user.getUserName(), user.getPhonenumber()); + if(i<=0)throw new ServiceException("【提现】记录账变失败"); + // 发短信通知转账人 + asynchronousMsg(user.getUserName()); + return Boolean.TRUE; + }); + if(!execute)throw new ServiceException("【提现】失败"); + return 1; + } + + private void withdrawalRecord(RlWithdrawQuery withdraw, String orderNo, RlUser user, RlUserExt rlUserExt) { RlWithdraw rlWithdraw = new RlWithdraw(); rlWithdraw.setWithdrawNo(orderNo); rlWithdraw.setCreateTime(DateUtils.getNowDate()); @@ -736,16 +778,33 @@ public class RlUserServiceImpl implements IRlUserService{ rlWithdraw.setOwnerId(user.getUserId()); rlWithdraw.setOwnerName(user.getUserName()); rlWithdraw.setOwnerPhone(user.getPhonenumber()); -// rlWithdraw.setHandlingCharge(new BigDecimal(0));手续费、成本 - rlWithdraw.setPaymentMethod(withdraw.getPaymentMethod()); + ChannelWithdrawVO channelWithdrawVO = etChannelWithdrawService.selectChannelWithdrawByChannelId(withdraw.getWithdrawChannelId()); + if(ObjectUtil.isNull(channelWithdrawVO)){ + throw new ServiceException("提现渠道不存在"); + } + BigDecimal cost; + if(channelWithdrawVO.getHandlingChargeType().equals(ServiceConstants.HANDLING_CHARGE_TYPE_PERCENT)){ + cost = channelWithdrawVO.getCostRate().divide(new BigDecimal(100)).multiply(withdraw.getAmount()).setScale(2, RoundingMode.HALF_UP); + }else{ + cost = channelWithdrawVO.getWithdrawHandlingCharge(); + } + rlWithdraw.setCost(cost); + rlWithdraw.setWithdrawChannelId(withdraw.getWithdrawChannelId()); + BigDecimal handlingCharge; + if(rlUserExt.getHandlingChargeType().equals(ServiceConstants.HANDLING_CHARGE_TYPE_PERCENT)){ + BigDecimal handlingCharge1 = rlUserExt.getWithdrawHandlingCharge();// 5.4 + BigDecimal bigDecimal = handlingCharge1.divide(new BigDecimal(100), 6, BigDecimal.ROUND_HALF_UP);// 0.0054 + handlingCharge = bigDecimal.multiply(withdraw.getAmount()).setScale(2, RoundingMode.HALF_UP);// 0.0054 * 1000 = 0.54 + }else{ + handlingCharge = rlUserExt.getWithdrawHandlingCharge(); + } + rlWithdraw.setHandlingCharge(handlingCharge); + rlWithdraw.setHandlingChargeType(rlUserExt.getHandlingChargeType()); + rlWithdraw.setWithdrawHandlingCharge(rlUserExt.getWithdrawHandlingCharge()); int i = rlWithdrawService.insertRlWithdraw(rlWithdraw); - - - - - // 发短信通知转账人 - asynchronousMsg(user.getUserName()); - return 0; + if(i == 0){ + throw new ServiceException("新增记录提现记录失败"); + } } private void asynchronousMsg(String userName) { diff --git a/ridelease-system/src/main/resources/mapper/system/RlChannelWithdrawMapper.xml b/ridelease-system/src/main/resources/mapper/system/RlChannelWithdrawMapper.xml index b54325c..2fc333f 100644 --- a/ridelease-system/src/main/resources/mapper/system/RlChannelWithdrawMapper.xml +++ b/ridelease-system/src/main/resources/mapper/system/RlChannelWithdrawMapper.xml @@ -5,7 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -13,9 +13,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select scw.channel_id, scw.name, - scw.account_type, - scw.service_type, - scw.service_rate, + scw.handling_charge_type, + scw.withdraw_handling_charge, scw.enabled, scw.cost_rate, scw.picture, @@ -27,15 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and scw.channel_id = #{query.channelId} and scw.name like concat('%', #{query.name}, '%') - and scw.account_type = #{query.accountType} - and scw.service_type = #{query.serviceType} + and scw.handling_charge_type = #{query.handlingChargeType} and scw.enabled = #{query.enabled} - - and scw.account_type in - - #{item} - - @@ -33,7 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - insert into et_msg_log + insert into rl_msg_log type, templateCode, @@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update et_msg_log + update rl_msg_log type = #{type}, templateCode = #{templateCode}, @@ -66,11 +66,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from et_msg_log where id = #{id} + delete from rl_msg_log where id = #{id} - delete from et_msg_log where id in + delete from rl_msg_log where id in #{id} diff --git a/ridelease-system/src/main/resources/mapper/system/RlUserExtMapper.xml b/ridelease-system/src/main/resources/mapper/system/RlUserExtMapper.xml index 78265e5..6f052fa 100644 --- a/ridelease-system/src/main/resources/mapper/system/RlUserExtMapper.xml +++ b/ridelease-system/src/main/resources/mapper/system/RlUserExtMapper.xml @@ -7,7 +7,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select ext_id, user_id, balance, dividend_proportion, cooperation_time, dividend_status, wx_collection_code, ali_collection_code, agent_id from rl_user_ext + select ext_id, user_id, balance, dividend_proportion, cooperation_time, dividend_status, wx_collection_code, + ali_collection_code, agent_id, handling_charge_type, withdraw_handling_charge from rl_user_ext select u.user_id, u.nick_name, u.user_name, u.real_name,u.email, u.avatar, u.phonenumber,u.user_type, - u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.is_authentication, - ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus, s.name storeName,s.store_id, + u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.is_authentication,a.city_id,c.name cityName, + ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus,ex.agent_id, s.name storeName,s.store_id, u.wxopenid from rl_user u left join rl_user_ext ex on u.user_id = ex.user_id left join rl_store s on s.merchant_id = u.user_id + left join rl_agent a on a.agent_id = ex.agent_id + left join rl_city c on c.city_id = a.city_id where u.del_flag = '0' AND u.user_id = #{userId} @@ -185,6 +187,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" user_id, user_name, real_name, + user_type, id_card, nick_name, email, @@ -201,6 +204,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{userId}, #{userName}, #{realName}, + #{userType}, #{idCard}, #{nickName}, #{email}, @@ -223,6 +227,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" real_name = #{realName}, id_card = #{idCard}, nick_name = #{nickName}, + user_type = #{userType}, email = #{email}, phonenumber = #{phonenumber}, is_authentication = #{isAuthentication}, diff --git a/ridelease-system/src/main/resources/mapper/system/RlWithdrawMapper.xml b/ridelease-system/src/main/resources/mapper/system/RlWithdrawMapper.xml index b950076..987912c 100644 --- a/ridelease-system/src/main/resources/mapper/system/RlWithdrawMapper.xml +++ b/ridelease-system/src/main/resources/mapper/system/RlWithdrawMapper.xml @@ -7,7 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, withdraw_no, amount, status, create_time, reject_reason, owner_name, owner_id, owner_phone, handling_charge, cost, payment_method from rl_withdraw + select id, withdraw_no, amount, status, create_time, reject_reason, owner_name, owner_id, owner_phone, handling_charge, cost, withdraw_channel_id, handling_charge_type, withdraw_handling_charge from rl_withdraw @@ -50,7 +52,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" owner_phone, handling_charge, cost, - payment_method, + withdraw_channel_id, + handling_charge_type, + withdraw_handling_charge, #{withdrawNo}, @@ -63,7 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{ownerPhone}, #{handlingCharge}, #{cost}, - #{paymentMethod}, + #{withdrawChannelId}, + #{handlingChargeType}, + #{withdrawHandlingCharge}, @@ -80,7 +86,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" owner_phone = #{ownerPhone}, handling_charge = #{handlingCharge}, cost = #{cost}, - payment_method = #{paymentMethod}, + withdraw_channel_id = #{withdrawChannelId}, + handling_charge_type = #{handlingChargeType}, + withdraw_handling_charge = #{withdrawHandlingCharge}, where id = #{id}