user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/CompanyFundFlowMapper.java
New file @@ -0,0 +1,11 @@ package com.supersavedriving.user.modular.system.dao; import com.baomidou.mybatisplus.mapper.BaseMapper; import com.supersavedriving.user.modular.system.model.CompanyFundFlow; /** * @author zhibing.pu * @Date 2023/7/30 3:05 */ public interface CompanyFundFlowMapper extends BaseMapper<CompanyFundFlow> { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/RevenueMapper.java
@@ -2,10 +2,25 @@ import com.baomidou.mybatisplus.mapper.BaseMapper; import com.supersavedriving.user.modular.system.model.Revenue; import org.apache.ibatis.annotations.Param; /** * @author zhibing.pu * @date 2023/3/13 10:03 */ public interface RevenueMapper extends BaseMapper<Revenue> { /** * 获取代理商账户余额 * @param companyId * @return */ Double queryAgentBalance(@Param("companyId") Integer companyId); /** * 获取平台账户余额 * @return */ Double queryCompanyBalance(); } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/CompanyFundFlowMapper.xml
New file @@ -0,0 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.supersavedriving.user.modular.system.dao.CompanyFundFlowMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.supersavedriving.user.modular.system.model.CompanyFundFlow"> <id column="id" property="id"/> <result column="type" property="type"/> <result column="objectType" property="objectType"/> <result column="objectId" property="objectId"/> <result column="balance" property="balance"/> <result column="money" property="money"/> <result column="createTime" property="createTime"/> </resultMap> </mapper> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/dao/mapping/RevenueMapper.xml
@@ -13,4 +13,28 @@ <result column="createTime" property="createTime"/> </resultMap> <select id="queryAgentBalance" resultType="double"> select sum(aa.income) - sum(aa.disburse) as balance from ( select sum(amount) as income, 0 as disburse from t_revenue where userType = 3 and userId = #{companyId} union all select 0 as ncome, sum(amount) as disburse from t_settlement_record where type = 2 and objectId = #{companyId} ) as aa </select> <select id="queryCompanyBalance" resultType="double"> select sum(aa.income) - sum(aa.disburse) + sum(aa.recharge) as balance from ( select sum(amount) as income, 0 as disburse, 0 as recharge from t_revenue where userType = 4 union all select 0 as ncome, sum(amount) as disburse, 0 as recharge from t_settlement_record where type = 1 union all select 0 as ncome, 0 as disburse, sum(surplusDividedAmount) as recharge from t_recharge_record where type = 4 and payStatus = 2 ) as aa </select> </mapper> user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/model/CompanyFundFlow.java
New file @@ -0,0 +1,54 @@ package com.supersavedriving.user.modular.system.model; import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.IdType; import lombok.Data; import java.math.BigDecimal; import java.util.Date; /** * @author zhibing.pu * @Date 2023/7/30 3:02 */ @Data @TableName("t_company_fund_flow") public class CompanyFundFlow { /** * 主键 */ @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 变动类型(1=充值,2=提现,3=佣金收入,4=保险收入) */ @TableField("type") private Integer type; /** * 对象类型(1=平台,2=代理商) */ @TableField("objectType") private Integer objectType; /** * 代理商id */ @TableField("objectId") private Integer objectId; /** * 历史账户余额 */ @TableField("balance") private BigDecimal balance; /** * 变动金额 */ @TableField("money") private BigDecimal money; /** * 变动时间 */ @TableField("createTime") private Date createTime; } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/ICompanyFundFlowService.java
New file @@ -0,0 +1,11 @@ package com.supersavedriving.user.modular.system.service; import com.baomidou.mybatisplus.service.IService; import com.supersavedriving.user.modular.system.model.CompanyFundFlow; /** * @author zhibing.pu * @Date 2023/7/30 3:09 */ public interface ICompanyFundFlowService extends IService<CompanyFundFlow> { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/IRevenueService.java
@@ -8,4 +8,19 @@ * @date 2023/3/13 10:09 */ public interface IRevenueService extends IService<Revenue> { /** * 获取代理商账户余额 * @param companyId * @return */ Double queryAgentBalance(Integer companyId); /** * 获取平台账户余额 * @return */ Double queryCompanyBalance(); } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/CompanyFundFlowServiceImpl.java
New file @@ -0,0 +1,13 @@ package com.supersavedriving.user.modular.system.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.supersavedriving.user.modular.system.dao.CompanyFundFlowMapper; import com.supersavedriving.user.modular.system.model.CompanyFundFlow; import com.supersavedriving.user.modular.system.service.ICompanyFundFlowService; /** * @author zhibing.pu * @Date 2023/7/30 3:10 */ public class CompanyFundFlowServiceImpl extends ServiceImpl<CompanyFundFlowMapper, CompanyFundFlow> implements ICompanyFundFlowService { } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -115,6 +115,9 @@ @Autowired private IOrderService orderService; @Autowired private ICompanyFundFlowService companyFundFlowService; @Value("${wx.appletsAppid}") private String appletsAppid; @@ -1488,6 +1491,7 @@ accountChangeDetailService.saveData(accountChangeDetail); //补贴中分账 Double balance = revenueService.queryCompanyBalance();//平台账户余额 Double discountedPrice = order.getDiscountedPrice(); List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); for (RechargeRecord rechargeRecord : rechargeRecords) { @@ -1513,6 +1517,13 @@ } } CompanyFundFlow companyFundFlow = new CompanyFundFlow(); companyFundFlow.setBalance(new BigDecimal(balance)); companyFundFlow.setObjectType(1); companyFundFlow.setType(5); companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice())); companyFundFlow.setCreateTime(new Date()); companyFundFlowService.insert(companyFundFlow); } } @@ -1961,6 +1972,7 @@ } //处理代理商抽佣 if(num3 > 0 && null != driver){ Double balance = revenueService.queryAgentBalance(driver.getAgentId()); Revenue revenue = new Revenue(); revenue.setType(1); revenue.setUserType(3); @@ -1994,6 +2006,15 @@ } } } CompanyFundFlow companyFundFlow = new CompanyFundFlow(); companyFundFlow.setType(3); companyFundFlow.setObjectType(2); companyFundFlow.setObjectId(driver.getAgentId()); companyFundFlow.setBalance(new BigDecimal(balance)); companyFundFlow.setMoney(new BigDecimal(num3)); companyFundFlow.setCreateTime(new Date()); companyFundFlowService.insert(companyFundFlow); } } } @@ -2079,6 +2100,7 @@ accountChangeDetailService.saveData(accountChangeDetail); //补贴中分账 Double balance = revenueService.queryCompanyBalance(); Double discountedPrice = order.getDiscountedPrice(); List<RechargeRecord> rechargeRecords1 = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); for (RechargeRecord rechargeRecord : rechargeRecords1) { @@ -2103,6 +2125,13 @@ } } } CompanyFundFlow companyFundFlow = new CompanyFundFlow(); companyFundFlow.setBalance(new BigDecimal(balance)); companyFundFlow.setObjectType(1); companyFundFlow.setType(5); companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice())); companyFundFlow.setCreateTime(new Date()); companyFundFlowService.insert(companyFundFlow); } // TODO: 2023/6/25 折扣优惠由司机承担 @@ -2243,6 +2272,7 @@ driverService.updateById(driver); accountChangeDetailService.saveData(accountChangeDetail); //补贴中分账 Double balance = revenueService.queryCompanyBalance(); Double discountedPrice = order.getDiscountedPrice(); List<RechargeRecord> rechargeRecords = rechargeRecordService.selectList(new EntityWrapper<RechargeRecord>().eq("type", 4).eq("payStatus", 2).gt("surplusDividedAmount", 0).orderBy("createTime")); for (RechargeRecord rechargeRecord : rechargeRecords) { @@ -2268,6 +2298,14 @@ } } CompanyFundFlow companyFundFlow = new CompanyFundFlow(); companyFundFlow.setBalance(new BigDecimal(balance)); companyFundFlow.setObjectType(1); companyFundFlow.setType(5); companyFundFlow.setMoney(new BigDecimal(order.getDiscountedPrice())); companyFundFlow.setCreateTime(new Date()); companyFundFlowService.insert(companyFundFlow); } } user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/RevenueServiceImpl.java
@@ -12,4 +12,25 @@ */ @Service public class RevenueServiceImpl extends ServiceImpl<RevenueMapper, Revenue> implements IRevenueService { /** * 获取代理商账户余额 * @param companyId * @return */ @Override public Double queryAgentBalance(Integer companyId) { return this.baseMapper.queryAgentBalance(companyId); } /** * 获取平台账户余额 * @return */ @Override public Double queryCompanyBalance() { return this.baseMapper.queryCompanyBalance(); } }