Parcourir la source

电销相关统计逻辑修改

hxl13994548489 il y a 1 an
Parent
commit
bbb05b3394

+ 8 - 1
src/main/java/com/ydtech/modules/admin/dao/DeptBalanceMapper.java

@@ -9,8 +9,8 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
-import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 
 @Mapper
 public interface DeptBalanceMapper {
@@ -44,4 +44,11 @@ public interface DeptBalanceMapper {
      * @return  获取代理人 总收入
      */
     HashMap<String, BigDecimal> getWalletAgentAmount(@Param("userId") String userId,@Param("beginDate") String beginDate,@Param("endDate") String endDate);
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/28 18:26
+     *  @Description: 查询电销组长的收入
+     */
+    BigDecimal getDxWalletAgentAmount(@Param("ids") List<String> userList, @Param("beginDate") String beginDate, @Param("endDate") String endDate);
 }

+ 9 - 1
src/main/java/com/ydtech/modules/admin/model/dto/SysPartnerConsoleDto.java

@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
-import java.lang.reflect.Type;
 import java.math.BigDecimal;
 import java.util.List;
 
@@ -71,4 +70,13 @@ public class SysPartnerConsoleDto implements Serializable {
 
     @ApiModelProperty(value = "提现中")
     private BigDecimal withdrawingAmount;
+
+    /***
+     * 角色id
+     */
+    private  String roleId;
+    /***
+     * 机构来源
+     */
+    private String managementSource;
 }

+ 34 - 26
src/main/java/com/ydtech/modules/admin/service/impl/DeptBalanceServiceImpl.java

@@ -2,25 +2,24 @@ package com.ydtech.modules.admin.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.admin.dao.*;
-import com.ydtech.modules.admin.model.*;
+import com.ydtech.modules.admin.model.SysAgencyFeeApproval;
+import com.ydtech.modules.admin.model.SysAgencyLeader;
+import com.ydtech.modules.admin.model.SysRelationPerson;
 import com.ydtech.modules.admin.model.dto.DeptBalanceDto;
 import com.ydtech.modules.admin.model.dto.MySumAmountQueryDto;
 import com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto;
 import com.ydtech.modules.admin.model.po.SysUserAccount;
-import com.ydtech.modules.admin.model.vo.*;
+import com.ydtech.modules.admin.model.vo.DeptBalanceVo;
+import com.ydtech.modules.admin.model.vo.PartnerBalanceVo;
 import com.ydtech.modules.admin.service.*;
 import com.ydtech.modules.base.model.vo.PageVo;
-import com.ydtech.modules.order.entity.InsAreaCompany;
-import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.service.InsOrdersService;
 import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
 import com.ydtech.utils.StringUtils;
-import io.swagger.annotations.ApiModelProperty;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -28,7 +27,10 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
 import java.util.stream.Collectors;
 
 @Service
@@ -282,28 +284,34 @@ public class DeptBalanceServiceImpl implements DeptBalanceService {
         if (!records.isEmpty()) {
             for (SysPartnerConsoleDto record : records) {
                 String userId = record.getUserId();
-                HashMap<String, BigDecimal> orderAmount = deptBalanceMapper.getWalletAgentAmount(userId,deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
-//              总金额
-                if (orderAmount != null && !orderAmount.isEmpty()) {
-                    record.setTotalIncome(orderAmount.get("totalIncome"));
-                }
-//                          已提现
-                BigDecimal ysTXAmount= insFeeOrderNewService.findMyAmountYTXmountByDate(record.getUserId(),"3",deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
-//                          未提现
+                //总收入
+                BigDecimal sumAmount =BigDecimal.ZERO;
+                //已提现
+                BigDecimal ytxAmount =BigDecimal.ZERO;
+                //提现中
+                BigDecimal sxAmount =BigDecimal.ZERO;
+                //未提现
+                BigDecimal wtxAmount =BigDecimal.ZERO;
                 MySumAmountQueryDto mySumAmountQueryDto = new MySumAmountQueryDto();
-                mySumAmountQueryDto.setAuditstatus("1");
-                SysUserAccount sysUserAccountEntity = sysUserAccountService.getById(record.getUserId());
-                BigDecimal ssKTAmount =BigDecimal.ZERO;
-                BigDecimal txzTXAmount= insFeeOrderNewService.findMyAmountYTXmountByDate(record.getUserId(),"2",deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
-
-                if(sysUserAccountEntity!=null){
-                    ssKTAmount = sysUserAccountEntity.getSumAmount()==null?BigDecimal.ZERO: sysUserAccountEntity.getSumAmount();
+                //如果是电销组长,将组员的数据算进来
+                if ("72".equals(record.getRoleId()) && "3".equals(record.getManagementSource())) {
+                    mySumAmountQueryDto.setGroupFlag(true);
+                    List<String> userList = sysUserService.getGroupByUserId(userId);
+                    //sumAmount= deptBalanceMapper.getDxWalletAgentAmount(userList,deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
+                    SysUserAccount sysUserAccountEntity = sysUserAccountService.getById(record.getUserId());
+                    // 已提现金额   查询历史表中的审核状态为3的数据
+                    ytxAmount = insFeeOrderNewService.findMyAmountYTXmountByDates(record.getUserId(), "3",true,deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
+                    // 提现中
+                    sxAmount = insFeeOrderNewService.findMyAmountYTXmountByDates(record.getUserId(), "2",true,deptBalanceVo.getBeginDate(),deptBalanceVo.getEndDate());
+                    // 可提现
+                    wtxAmount= (sysUserAccountEntity==null || sysUserAccountEntity.getSumAmount()==null)?BigDecimal.ZERO:sysUserAccountEntity.getSumAmount();
+                    //总的 =  已提现金额+  可提现金额 +  提现中
+                    sumAmount = wtxAmount.add(sxAmount).add(ytxAmount);
                 }
-                BigDecimal sumAmount=ysTXAmount.add(ssKTAmount).add(txzTXAmount);
-                record.setWithdrawn(ysTXAmount);
-                record.setNotWithdrawn(ssKTAmount);
+                record.setWithdrawn(ytxAmount);
+                record.setNotWithdrawn(wtxAmount);
                 record.setTotalIncome(sumAmount);
-                record.setWithdrawingAmount(txzTXAmount);
+                record.setWithdrawingAmount(sxAmount);
             }
         }
         return sysUserListPage;

+ 9 - 0
src/main/java/com/ydtech/modules/protocols/dao/InsFeeOrderNewMapper.java

@@ -177,6 +177,15 @@ public interface InsFeeOrderNewMapper extends BaseMapper<InsFeeOrderNew> {
      *  @Description:  按时间统计数据
      */
     BigDecimal findMyAmountYTXmountByDate(@Param("userId") String userId, @Param("status") String status, @Param("beginDate") String beginDate, @Param("endDate") String endDate);
+
+
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/6/30 19:59
+     *  @Description:  查询可提现的金额
+     */
+    BigDecimal findMyAmountYTXmountByDates(@Param("userId") String userId,@Param("status") String status,@Param("groupFlag")  boolean groupFlag, @Param("beginDate") String beginDate, @Param("endDate") String endDate);
 }
 
 

+ 7 - 0
src/main/java/com/ydtech/modules/protocols/service/InsFeeOrderNewService.java

@@ -211,4 +211,11 @@ public interface InsFeeOrderNewService extends IService<InsFeeOrderNew> {
      *  @Description:  按时间检索
      */
     BigDecimal findMyAmountYTXmountByDate(String userId, String number, String beginDate, String endDate);
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/10/28 18:43
+     *  @Description:  按时间检索
+     */
+    BigDecimal findMyAmountYTXmountByDates(String userId, String number, boolean b, String beginDate, String endDate);
 }

+ 5 - 0
src/main/java/com/ydtech/modules/protocols/service/impl/InsFeeOrderNewServiceImpl.java

@@ -211,4 +211,9 @@ public class InsFeeOrderNewServiceImpl extends ServiceImpl<InsFeeOrderNewMapper,
     public BigDecimal findMyAmountYTXmountByDate(String userId, String type, String beginDate, String endDate) {
         return baseMapper.findMyAmountYTXmountByDate(userId,type,beginDate,endDate);
     }
+
+    @Override
+    public BigDecimal findMyAmountYTXmountByDates(String userId, String type, boolean b, String beginDate, String endDate) {
+        return baseMapper.findMyAmountYTXmountByDates(userId,type,b,beginDate,endDate);
+    }
 }

+ 23 - 3
src/main/resources/mapper/modules/admin/DeptBalanceMapper.xml

@@ -119,7 +119,9 @@
         sd.id as "deptId",
         sd.name as "deptName",
         inf.url  as "filePath",
-        suif.sex as "sex"
+        suif.sex as "sex",
+        sur.role_id  as "roleId",
+        sd.management_source as managementSource
         from sys_user su
         left join sys_dept sd on sd.id=su.dept_id
         LEFT JOIN  ins_upload_files   inf on  su.head_sculpture  =inf.id
@@ -177,8 +179,7 @@
         ins_orders io
         left join ins_area_company iac on iac.orderno =io.orderno
         <where>
-            io.orderstatus ='3'
-            and iac.orderstatus ='3'
+             iac.orderstatus ='3'
             <if test="userId  != null  and  userId !=''">
              and   io.userid =#{userId}
             </if>
@@ -187,4 +188,23 @@
             </if>
         </where>
     </select>
+    <select id="getDxWalletAgentAmount" resultType="java.math.BigDecimal">
+        SELECT
+        sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
+        FROM
+        ins_orders io
+        left join ins_area_company iac on iac.orderno =io.orderno
+        <where>
+            iac.orderstatus ='3'
+            <if test="ids != null and ids.size()>0 != null">
+                and io.userid IN
+                <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+            <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
+                AND  iac.signing_time  BETWEEN  #{beginDate}  AND  #{endDate}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 20 - 0
src/main/resources/mapper/modules/ins/InsFeeOrderNewMapper.xml

@@ -1480,4 +1480,24 @@
             </if>
         </where>
     </select>
+
+    <select id="findMyAmountYTXmountByDates" resultType="java.math.BigDecimal">
+        SELECT
+        ifnull( sum( au.amount ), 0 )
+        FROM
+        sys_amount_auditing au
+        WHERE
+        <choose>
+            <when test="groupFlag">
+                au.user_id in ( select id from  sys_user  where manager_id = #{userId}   or id = #{userId}  )
+            </when>
+            <otherwise>
+                au.user_id = #{userId}
+            </otherwise>
+        </choose>
+        AND auditing_status = #{status}
+        <if test="beginDate !=null and  beginDate != '' and endDate !=null and  endDate != ''">
+            AND au.create_time  BETWEEN #{beginDate}  AND #{endDate}
+        </if>
+    </select>
 </mapper>