فهرست منبع

修改期初和期末金额算法,商户余额字段修改

wanxl 1 سال پیش
والد
کامیت
5e8d75ee79

+ 3 - 62
src/main/java/com/sqx/modules/reconciliation/mapper/PlatformBillMapper.java

@@ -22,71 +22,10 @@ import java.util.List;
 @Mapper
 public interface PlatformBillMapper extends BaseMapper<PlatformBill> {
 
-    @Insert("INSERT INTO `tcwm2.5`.platform_bill \n" +
-            "(day_id, user_id, shop_name, `type`, start_money, revenue, revenue_count, \n" +
-            "shop_payouts, shop_payouts_rates, shop_payouts_count, rider_payouts, rider_payouts_rates,\n" +
-            "rider_payouts_count, refund_money, refund_count, end_money,sys_gift_amount, platform_rates,total_income,pay_money,create_time,update_time)\n" +
-            "select #{dayId}, tu.user_id, null,2,null,sum(ti.rider_money),count(ti.rider_money),null,null,null,\n" +
-            "sum(co.money),sum(co.rate), count(co.money),null,null,max(tu.balance),\n" +
-            "(select sum(money) b from  user_money_details ud1 where ud1.user_id =tu.user_id and ud1.title like '系统赠送%' \n" +
-            "and ud1.create_time>#{startTime} and ud1.create_time <=#{endTime})\n" +
-            "-(select sum(money) a from  user_money_details ud2 where ud2.user_id =tu.user_id and ud2.title like '系统扣除%' \n" +
-            "and ud2.create_time>#{startTime} and ud2.create_time <= #{endTime}) as gift_amount,null,\n" +
-            "sum(ti.rider_money),null,#{now},#{now}\n" +
-            "from tb_user tu USE INDEX(tb_user_rider_open_id_IDX)\n" +
-            "left join tb_indent ti USE INDEX(tb_indent_finish_time_IDX) on  \n" +
-            " ti.finish_time >#{startTime} \n" +
-            "and ti.finish_time <= #{endTime}\n" +
-            "and ti.rider_user_id =tu.user_id\n" +
-            "and ti.indent_state ='6'\n" +
-            "left join cash_out co on co.user_id =tu.user_id and co.type =1 and co.state=1\n" +
-            "and co.out_at >#{startTime} \n" +
-            "and co.out_at <=#{endTime}\n" +
-            "where tu.rider_open_id is not null \n" +
-            "group by tu.user_id \n" +
-            "union all \n" +
-            "select #{dayId}, tu.user_id, null,1,null,sum(tor.shop_income_money),count(tor.shop_income_money),\n" +
-            "sum(co.money),sum(co.rate),count(co.money),null,null,null,sum(to1.pay_money),count(to1.pay_money),max(um.money),\n" +
-            "(select sum(money) b from  user_money_details ud1 where ud1.user_id =tu.user_id and ud1.title like '系统赠送%' \n" +
-            "and ud1.create_time>#{startTime} and ud1.create_time <=#{endTime})\n" +
-            "-(select sum(money) a from  user_money_details ud2 where ud2.user_id =tu.user_id and ud2.title like '系统扣除%' \n" +
-            "and ud2.create_time>#{startTime} and ud2.create_time <=#{endTime}) as gift_amount\n" +
-            ",sum(tor.shop_income_money*(1-gs.shop_rate)/gs.shop_rate) platform_rates,sum(tor.shop_income_money),\n" +
-            "sum(tor.pay_money),#{now},#{now} \n" +
-            "from tb_user tu \n" +
-            "left join goods_shop gs on tu.user_id =gs.user_id\n" +
-            "left join tb_order  tor USE INDEX(tb_order_update_time_IDX) on gs.shop_id =tor.shop_id \n" +
-            "and tor.update_time >#{startTime}\n" +
-            "and tor.update_time <=#{endTime}\n" +
-            "and tor.status=4\n" +
-            "left join tb_order  to1 USE INDEX(tb_order_update_time_IDX) on gs.shop_id =to1.shop_id \n" +
-            "and to1.update_time >#{startTime}\n" +
-            "and to1.update_time <=#{endTime}\n" +
-            "and to1.status in(5,8)\n" +
-            "left join cash_out co on co.user_id =tu.user_id and co.type =2 and co.state=1\n" +
-            "and co.out_at >#{startTime} \n" +
-            "and co.out_at <=#{endTime}\n" +
-            "left join user_money um on um.user_id =tu.user_id\n" +
-            "where  tu.admin_user_id is not null\n" +
-            "group by tu.user_id ")
     Integer insertPlatformBill(@Param("dayId") String dayId,@Param("startTime") String startTime, @Param("endTime")String endTime, @Param("now") String now);
 
-    @Update("update platform_bill a join platform_bill b on a.user_id =b.user_id and a.type =b.type and  TO_DAYS(a.day_id)-TO_DAYS(b.day_id)= 1 " +
-            "set a.start_money=b.end_money,a.end_money=b.end_money+a.end_money\n" +
-            "where a.day_id =#{dayId} ")
-    Integer updateStartMoney(@Param("dayId") String dayId);
+    Integer updateShopStartMoney(@Param("dayId") String dayId);
 
-    @Insert("INSERT INTO `tcwm2.5`.platform_bill \n" +
-            "(day_id, user_id, shop_name, `type`, start_money, revenue, revenue_count, \n" +
-            "shop_payouts, shop_payouts_rates, shop_payouts_count, rider_payouts, rider_payouts_rates,\n" +
-            "rider_payouts_count, refund_money, refund_count, end_money,sys_gift_amount, platform_rates,total_income,pay_money,create_time,update_time)\n" +
-            "select\n" +
-            "day_id,null,null,0,sum(if(type=1, start_money ,0)),sum(if(type=1, revenue,0)),sum(if(type=1, revenue_count,0)),\n" +
-            "sum(if(type=1, shop_payouts ,0)),sum(if(type=1, shop_payouts_rates ,0)),sum(if(type=1, shop_payouts_count ,0)),\n" +
-            "sum(if(type=2, rider_payouts ,0)),sum(if(type=2, rider_payouts_rates ,0)),sum(if(type=2, rider_payouts_count ,0)),\n" +
-            "sum(if(type=1, refund_money ,0)),sum(if(type=1, refund_count ,0)),sum(if(type=1, end_money ,0)),null,\n" +
-            "sum(if(type=1, platform_rates ,0)),null,null,max(create_time) ,max(update_time) \n" +
-            "from platform_bill pb where day_id =#{dayId}\n")
     Integer insertTotalPlatformBill(@Param("dayId") String dayId);
 
     IPage<PlatformBill> platformBill(@Param("page")Page<PlatformBill> pages, @Param("params")PlatformBillDto platformBillDto);
@@ -100,4 +39,6 @@ public interface PlatformBillMapper extends BaseMapper<PlatformBill> {
     List<ShopBillVo> excelShopBillList(@Param("params") PlatformBillDto query);
 
     List<PlatformBill> excelPlatformBillList(@Param("params") PlatformBillDto query);
+
+    Integer updateRiderStartMoney(@Param("dayId") String dayId);
 }

+ 3 - 0
src/main/java/com/sqx/modules/reconciliation/model/PlatformBill.java

@@ -103,4 +103,7 @@ public class PlatformBill implements Serializable {
     @ApiModelProperty(value = "用户支付金额")
     private String payMoney;
 
+    @ApiModelProperty(value = "商户余额")
+    private String shopBalance;
+
 }

+ 8 - 4
src/main/java/com/sqx/modules/reconciliation/service/impl/PlatformBillServiceImpl.java

@@ -53,13 +53,17 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
         //导入商家和骑手对账
         Integer count1 =baseMapper.insertPlatformBill(dayId,startTime,endTime,now);
         log.info("导入商家和骑手对账:{}条",count1);
-        //导入账期开始金额
-        Integer count2=baseMapper.updateStartMoney(dayId);
-        log.info("导入账期开始金额:{}条",count2);
         //导入平台对账
         Integer count3 =baseMapper.insertTotalPlatformBill(dayId);
+        //导入商户账期开始金额
+        Integer count2=baseMapper.updateShopStartMoney(dayId);
+        log.info("导入商户账期开始金额:{}条",count2);
+        //导入骑手账期开始金额
+        Integer count4=baseMapper.updateRiderStartMoney(dayId);
+        log.info("导入骑手、平台账期开始金额:{}条",count2);
+
         log.info("导入平台对账:{}条",count3);
-        if(count1<1||count2<1||count3<1){
+        if(count1<1||count3<1){
             return 0;
         }
         return count3;

+ 1 - 0
src/main/java/com/sqx/scheduler/reconciliation/BillsScheduler.java

@@ -30,6 +30,7 @@ public class BillsScheduler {
      */
     @Async
     @Scheduled(cron = "30 2 0 * * ?", zone = "Asia/Shanghai")
+//    @Scheduled(cron = "30 * * * * ?", zone = "Asia/Shanghai")
     public void insertPlatformBill(){
         int errorCount = 0 ;
         log.info("开始统计对账数据");

+ 79 - 0
src/main/resources/mapper/reconciliation/PlatformBillMapper.xml

@@ -109,6 +109,7 @@
         </where>
         order by pb.bill_id desc
     </select>
+
     <select id="excelPlatformBillList" resultType="com.sqx.modules.reconciliation.model.PlatformBill">
         select pb.*
         from platform_bill pb
@@ -123,4 +124,82 @@
         </where>
         order by pb.bill_id desc
     </select>
+
+    <update id="updateShopStartMoney">
+        update platform_bill a join platform_bill b on a.user_id =b.user_id and a.type =b.type and  TO_DAYS(a.day_id)-TO_DAYS(b.day_id)= 1
+        set a.start_money=b.end_money
+        where a.day_id =#{dayId} and a.type = 1
+    </update>
+
+    <update id="updateRiderStartMoney">
+        update platform_bill a join platform_bill b on a.user_id =b.user_id and a.type =b.type and  TO_DAYS(a.day_id)-TO_DAYS(b.day_id)= 1
+        set a.start_money=b.end_money
+        where a.day_id =#{dayId} and a.type in(0,2)
+    </update>
+
+    <insert id="insertPlatformBill">
+        INSERT INTO `tcwm2.5`.platform_bill
+        (day_id, user_id, shop_name, `type`, start_money, revenue, revenue_count,
+        shop_payouts, shop_payouts_rates, shop_payouts_count, rider_payouts, rider_payouts_rates,
+        rider_payouts_count, refund_money, refund_count, end_money,sys_gift_amount, platform_rates,total_income,pay_money,create_time,update_time,shop_balance)
+        select #{dayId}, tu.user_id, null,2,0,ifnull(sum(ti.rider_money),0),count(ti.rider_money),null,null,null,
+        ifnull(sum(co.money),0),ifnull(sum(co.rate),0), count(co.money),null,null,ifnull(max(tu.balance),0),
+        ifnull((select sum(money) b from  user_money_details ud1 where ud1.user_id =tu.user_id and ud1.title like '系统赠送%'
+        and ud1.create_time>#{startTime} and ud1.create_time <![CDATA[ <= ]]>#{endTime})
+        -(select sum(money) a from  user_money_details ud2 where ud2.user_id =tu.user_id and ud2.title like '系统扣除%'
+        and ud2.create_time>#{startTime} and ud2.create_time <![CDATA[ <= ]]> #{endTime}),0) as gift_amount,null,
+        ifnull(sum(ti.rider_money),0),null,#{now},#{now},0
+        from tb_user tu USE INDEX(tb_user_rider_open_id_IDX)
+        left join tb_indent ti USE INDEX(tb_indent_finish_time_IDX) on
+        ti.finish_time >#{startTime}
+        and ti.finish_time <![CDATA[ <= ]]> #{endTime}
+        and ti.rider_user_id =tu.user_id
+        and ti.indent_state ='6'
+        left join cash_out co on co.user_id =tu.user_id and co.type =1 and co.state=1
+        and co.out_at >#{startTime}
+        and co.out_at <![CDATA[ <= ]]>#{endTime}
+        where tu.rider_open_id is not null
+        group by tu.user_id
+        union all
+        select #{dayId}, tu.user_id, null,1,0,ifnull(sum(tor.shop_income_money),0),count(tor.shop_income_money),
+               ifnull(sum(co.money),0),ifnull(sum(co.rate),0),count(co.money),null,null,null,ifnull(sum(to1.pay_money),0),
+               count(to1.pay_money),ifnull((select sum(to2.shop_income_money) from tb_order to2 where to2.status =4 and to2.shop_id=gs.shop_id),0),
+               ifnull((select sum(money) b from  user_money_details ud1 where ud1.user_id =tu.user_id and ud1.title like '系统赠送%'
+        and ud1.create_time>#{startTime} and ud1.create_time <![CDATA[ <= ]]>#{endTime})
+        -(select sum(money) a from  user_money_details ud2 where ud2.user_id =tu.user_id and ud2.title like '系统扣除%'
+        and ud2.create_time>#{startTime} and ud2.create_time <![CDATA[ <= ]]>#{endTime}),0) as gift_amount
+        ,ifnull(round(sum(tor.shop_income_money*(1-ifnull(gs.shop_rate,1))/ifnull(gs.shop_rate,1)),2),0) platform_rates,ifnull(sum(tor.shop_income_money),0),
+               ifnull(sum(tor.pay_money),0),#{now},#{now},ifnull(max(um.money),0)
+        from tb_user tu
+        left join goods_shop gs on tu.user_id =gs.user_id
+        left join tb_order  tor USE INDEX(tb_order_update_time_IDX) on gs.shop_id =tor.shop_id
+        and tor.update_time >#{startTime}
+        and tor.update_time <![CDATA[ <= ]]>#{endTime}
+        and tor.status=4
+        left join tb_order  to1 USE INDEX(tb_order_update_time_IDX) on gs.shop_id =to1.shop_id
+        and to1.update_time >#{startTime}
+        and to1.update_time <![CDATA[ <= ]]>#{endTime}
+        and to1.status in(5,8)
+        left join cash_out co on co.user_id =tu.user_id and co.type =2 and co.state=1
+        and co.out_at >#{startTime}
+        and co.out_at <![CDATA[ <= ]]>#{endTime}
+        left join user_money um on um.user_id =tu.user_id
+        where  tu.admin_user_id is not null
+        group by tu.user_id
+    </insert>
+
+    <insert id="insertTotalPlatformBill">
+        INSERT INTO `tcwm2.5`.platform_bill
+        (day_id, user_id, shop_name, `type`, start_money, revenue, revenue_count,
+         shop_payouts, shop_payouts_rates, shop_payouts_count, rider_payouts, rider_payouts_rates,
+         rider_payouts_count, refund_money, refund_count, end_money,sys_gift_amount, platform_rates,total_income,pay_money,create_time,update_time)
+        select
+            day_id,null,null,0,0,sum(if(type=1, revenue,0)),sum(if(type=1, revenue_count,0)),
+            sum(if(type=1, shop_payouts ,0)),sum(if(type=1, shop_payouts_rates ,0)),sum(if(type=1, shop_payouts_count ,0)),
+            sum(if(type=2, rider_payouts ,0)),sum(if(type=2, rider_payouts_rates ,0)),sum(if(type=2, rider_payouts_count ,0)),
+            sum(if(type=1, refund_money ,0)),sum(if(type=1, refund_count ,0)),(select ifnull(sum(pay_money), 0) from tb_order where status in (3,4,6,7)),null,
+            sum(if(type=1, platform_rates ,0)),null,null,max(create_time) ,max(update_time)
+        from platform_bill pb where day_id =#{dayId}
+    </insert>
+
 </mapper>