| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- <?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.cyksj.mapper.manage.statistics.StatisticsExportMapper">
- <select id="getMonthNfExNumOfUser" resultType="java.lang.Integer">
- select count(distinct user_id)
- from (select user_id
- from `order_don`
- where sku_id = 4
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastMonth} and #{thisMonth}
- union all
- select user_id
- from `order_don`
- where sku_id = 5
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastThreeMonth} and #{lastTwoMonth}
- union all
- select user_id
- from `order_don`
- where sku_id = 6
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastYearMonth}
- and #{lastElevMonth}
- ) s
- </select>
- <select id="getMonthNfExNumOfUserByType" resultType="java.lang.Integer">
- select count(distinct user_id)
- from (select user_id
- from `order_don`
- where sku_id = 4
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastMonth} and #{thisMonth}
- union all
- select user_id
- from `order_don`
- where sku_id = 5
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastThreeMonth} and #{lastTwoMonth}
- union all
- select user_id
- from `order_don`
- where sku_id = 6
- and status not in ('close', 'noPayment', 'refund')
- and created_time between #{lastYearMonth}
- and #{lastElevMonth}) s
- where EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and created_time between #{thisMonth} and #{nextMonth}
- and order_type = #{type}
- and od.user_id = s.user_id
- and goods_id = #{goodsId})
- </select>
- <select id="getMonthNfRenewNumOfUser" resultType="java.lang.Integer">
- select count(distinct user_id)
- from `order_don`
- where goods_id = #{goodsId}
- and order_type = 2
- and status not in ('close', 'refund', 'noPayment')
- and created_time between #{thisMonth} and #{nextMonth}
- </select>
- <select id="getAiMonthPlus" resultType="java.lang.Long">
- select id
- from `goods_don_sku`
- where goods_id = #{goodsId}
- and months = 1
- </select>
- <select id="getMonthAiExNumOfUser" resultType="java.lang.Integer">
- select count(distinct user_id)
- from `order_don` od
- where status not in ('close','noPayment')
- and (refund_money is null or refund_money != money)
- and created_time BETWEEN #{lastMonth} and #{thisMonth}
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </select>
- <select id="getMonthAiExNumOfUserByType" resultType="java.lang.Integer">
- select count(distinct user_id) from (select user_id
- from `order_don` od
- where status not in ('close','noPayment')
- and (refund_money is null or refund_money != money)
- and created_time BETWEEN #{lastMonth} and #{thisMonth}
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>) s where EXISTS(select id
- from order_don
- where status not in ('close','noPayment')
- and (refund_money is null or refund_money != money)
- and created_time between #{thisMonth} and #{nextMonth}
- and order_type = #{type}
- and user_id = s.user_id
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- )
- </select>
- <select id="getMonthAiRenewNumOfUser" resultType="java.lang.Integer">
- select count(distinct user_id)
- from `order_don` od
- where status not in ('close','noPayment')
- and (refund_money is null or refund_money != money)
- and created_time BETWEEN #{thisMonth} and #{nextMonth}
- and order_type = 2
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </select>
- <select id="getMonthStreamingNewNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 2)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- </select>
- <select id="getMonthStreamingNewPayOtherNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 2)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- and EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time between
- #{thisMonth} and #{nextMonth}
- and od.created_time > s.created_time)
- </select>
- <select id="getMonthStreamingNewPayAiNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 2)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- and EXISTS(select id
- from (select id, goods_id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time between #{thisMonth} and #{nextMonth}
- order by od.created_time limit 1,1) s
- where s.goods_id in (select goods_id
- from `goods_don_category_relate`
- where category = 1))
- </select>
- <select id="getMonthAiNewNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 1)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- </select>
- <select id="getMonthAiNewPayOtherNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 1)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- and EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time between #{thisMonth} and #{nextMonth}
- and od.created_time > s.created_time)
- </select>
- <select id="getMonthAiNewPayStreamingNumOfUser" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from (select user_id, created_time
- from `order_don`
- where goods_id in
- (select goods_id
- from `goods_don_category_relate`
- where category = 1)
- and status not in ('close', 'refund', 'noPayment')
- and created_time BETWEEN
- #{thisMonth} and #{nextMonth}) s
- where not EXISTS(select id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time <
- s.created_time)
- and EXISTS(select id
- from (select id, goods_id
- from order_don od
- where status not in ('close', 'refund', 'noPayment')
- and od.user_id = s.user_id
- and od.created_time between #{thisMonth} and #{nextMonth}
- order by od.created_time limit 1,1) s
- where s.goods_id in (select goods_id
- from `goods_don_category_relate`
- where category = 2))
- </select>
- <select id="getMonthPrivateCorpNumOfUser" resultType="java.lang.Integer">
- select count(distinct s.user_id) from (select user_id from (select user_id,created_time from `order_don` where
- goods_id in
- (select id from goods_don
- <where>
- <if test="category!=null">
- and category = #{category}
- </if>
- <if test="type!=null">
- and `type` = #{type}
- </if>
- </where>
- )
- and status not in ('close','noPayment','refund')) s where not exists (select id from `order_don` where status
- not
- in ('close','noPayment','refund')
- and user_id= s.user_id and created_time < s.created_time)) s inner join user u on u.id = s.user_id and
- u.unionid != '' inner join corp_user cu on cu.user_id =
- u.id
- inner join corp_user_auth ca on ca.corp_user_id = cu.id and ca.wx_corp_id = 2
- </select>
- <select id="getShouldApplyMoney" resultType="java.math.BigDecimal">
- select sum(points) / 1000
- from `distribute_waiting_send_points`
- where send_status = 'success'
- and created_time < #{endDate}
- </select>
- <select id="getRealApplyMoney" resultType="java.math.BigDecimal">
- select sum(money) / 100
- from `distribute_money_apply`
- where `verify_status` = 'success'
- and created_time < #{endDate}
- </select>
- <select id="getMonthUserSourceNumByType" resultType="java.lang.Integer">
- select count(u.id)
- from (select id from `user` where created_time >= #{startDate} and created_time < #{endDate}) u
- left join user_distribute_shared us on us.user_id = u.id
- left join user_distribute ud on ud.user_id = us.shared_id
- <where>
- <choose>
- <when test="type == 1">
- us.id is null
- </when>
- <otherwise>
- us.id is not null
- </otherwise>
- </choose>
- </where>
- </select>
- <select id="getNfTicketNumOfUser" resultType="java.lang.Integer">
- select count(distinct user_id)
- from `order_don`
- where goods_id = #{goodsId}
- and status not in ('close', 'noPayment', 'refund')
- </select>
- <select id="getAiTicketNumOfUser" resultType="java.lang.Integer">
- select count(distinct o.user_id)
- from `order_don` o
- left join goods_don g on g.id = o.goods_id
- where g.id in (select goods_id
- from `goods_don_category_relate`
- where category = 1)
- and o.status not in ('close', 'noPayment', 'refund')
- </select>
- <select id="getNfAiTicketNumOfUser" resultType="java.lang.Integer">
- select count(distinct o.user_id)
- from `order_don` o
- left join order_don o2 on o2.user_id = o.user_id
- left join goods_don g on g.id = o2.goods_id
- where o.goods_id = #{goodsId}
- and o.status not in ('close', 'noPayment', 'refund')
- and o2.status not in ('close', 'noPayment', 'refund')
- and g.id in (select goods_id
- from `goods_don_category_relate`
- where category = 1)
- </select>
- <select id="getMonthAmountOfOrderByType" resultType="java.math.BigDecimal">
- select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
- us on us.user_id = o.user_Id
- left join `user_distribute` ud on ud.user_id = us.shared_id and ud.deleted is true
- where
- <choose>
- <when test="type == 1">
- us.id is null
- </when>
- <when test="type == 2">
- us.id is not null and ud.id is null
- </when>
- <when test="type == 3">
- ud.id is not null
- </when>
- </choose>
- and o.created_time >= #{startDate} and o.created_time < #{endDate}
- and status not in ('close', 'noPayment')
- </select>
- <select id="getMonthGoodsTypeAmountOfOrderByType" resultType="java.math.BigDecimal">
- select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
- us on us.user_id = o.user_Id
- left join `user_distribute` ud on ud.user_id = us.shared_id and ud.deleted is true
- where
- <choose>
- <when test="type == 1">
- us.id is null
- </when>
- <when test="type == 4">
- us.id is not null
- <if test="isBind != null">
- and us.is_bind = 0
- </if>
- </when>
- <otherwise>
- us.id is not null
- <if test="isBind != null">
- and us.is_bind = 1
- </if>
- </otherwise>
- </choose>
- <if test="startDate != null">
- and o.created_time >= #{startDate}
- </if>
- <if test="endDate != null">
- and o.created_time < #{endDate}
- </if>
- and status not in ('close', 'noPayment')
- and goods_id in (select id from goods_don
- <where>
- <if test="goodsType != null">
- `type` = #{goodsType}
- </if>
- <if test="category!=null">
- and id in (select goods_id from goods_don_category_relate where category = #{category})
- </if>
- </where>
- )
- </select>
- <select id="getMonthUserSourceNumOrderByType" resultType="java.lang.Integer">
- select count(distinct s.id) from (select u.id
- from (select id from `user` where created_time >= #{startDate} and created_time < #{endDate}) u
- left join user_distribute_shared us on us.user_id = u.id
- left join user_distribute ud on ud.user_id = us.shared_id
- <where>
- <choose>
- <when test="type == 1">
- us.id is null
- </when>
- <otherwise>
- us.id is not null
- </otherwise>
- </choose>
- </where>
- ) s left join order_don o on o.user_id = s.id where o.status not in ('close', 'noPayment','refund')
- and o.created_time >= #{startDate} and o.created_time < #{endDate}
- </select>
- <select id="getAppleOneDataThisMonth" resultType="com.cyksj.model.excel.statistics.ExcelAppleOneData">
- select count(distinct if(status = 'refund',NUll,user_id)) as numOfUser,
- count(if(status = 'refund',NULL,id)) as numOfOrder,
- cast((ifnull(sum(money),0)-ifnull(sum(refund_money),0))/100 as decimal(10,2)) as money,
- count(if(type = 'EX_CODE' and status != 'refund',id,NULL)) as numOfExCodeOrder,
- count(if(is_distribute = 1 and status != 'refund',id,NULL)) as disOrder,
- cast((sum(if(is_distribute = 1,money,0))-ifnull(sum(if(is_distribute = 1,refund_money,0)),0))/100 as
- decimal(10,2)) as disMoney
- from `order_don`
- where sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and status not in ('close','noPayment')
- <if test="startDate != null">
- and created_time >= #{startDate}
- </if>
- <if test="endDate != null">
- and created_time < #{endDate}
- </if>
- </select>
- <select id="getAppleOnePayMonthTypeOrderThisMonth" resultType="java.lang.Integer">
- select count(*) from `order_don` where sku_id = #{skuId}
- and status not in ('close','noPayment','refund')
- <if test="startDate != null">
- and created_time >= #{startDate}
- </if>
- <if test="endDate != null">
- and created_time < #{endDate}
- </if>
- </select>
- <select id="getTransferData" resultType="java.util.Map">
- select sum(if(money <= 40000, money, 0)) autoMoney,
- sum(if(type = 'usdt', money, 0)) usdtMoney,
- sum(if(money > 40000 and type != 'usdt', money, 0)) manualMoney
- from distribute_money_apply
- where created_time >= #{startDate}
- and created_time < #{endDate}
- and verify_status = 'success'
- </select>
- <select id="getGroupsOrderData" resultType="com.cyksj.model.dto.NatureOrderDataDto">
- select type,
- ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as money from (select money,
- refund_money,
- (case
- when us.id is null then 1
- when us.id is not null and ud.id is null then 2
- when ud.id is not null and us.is_bind = 1 then 3
- when ud.id is not null and us.is_bind = 0 then 4
- else 1
- end) as `type`
- from `order_don` o
- left join `user_distribute_shared` us on us.user_id = o.user_Id
- left join `user_distribute` ud on ud.user_id = us.shared_id and ud.deleted is true
- where status not in ('close', 'noPayment')
- <if test="startDate != null">
- and o.created_time >= #{startDate}
- </if>
- <if test="endDate != null">
- and o.created_time < #{endDate}
- </if>) s group by `type`
- </select>
- <select id="getMonthlyUserOrderDetail" resultType="com.cyksj.model.dto.MonthlyUserOrderDetailDto">
- select cast(((sum(money) - sum(ifnull(refund_money, 0))) / 100) as decimal(10,2)) as money,
- count(if(`status` != 'refund', 1, NUll)) as orders,
- 1 type
- from `order_don` o
- left join user u on u.id = o.user_id
- where o.status not in ('close', 'noPayment')
- and o.created_time BETWEEN #{thisMonth} and #{nextMonth}
- and u.created_time < #{thisMonth}
- union all
- select cast(((sum(money) - sum(ifnull(refund_money, 0))) / 100) as decimal(10,2)) as money,
- count(if(`status` != 'refund', 1, NUll)) as orders,
- 2 type
- from `order_don` o
- left join user u on u.id = o.user_id
- where o.status not in ('close', 'noPayment')
- and o.created_time BETWEEN #{thisMonth} and #{nextMonth}
- and u.created_time BETWEEN #{thisMonth} and #{nextMonth}
- </select>
- <select id="getEpOrderNumsGroupSource" resultType="java.util.Map">
- select count(if(is_distribute = 0,1,NULL)) naturalEpOrders,count(if(is_distribute = 1,1,NULL)) distributeOrders
- from order_don
- where status not in ('close', 'noPayment', 'refund')
- and goods_id = 15
- <if test="startDate != null">
- and created_time >= #{startDate}
- </if>
- <if test="endDate != null">
- and created_time < #{endDate}
- </if>
- group by DATE_FORMAT(created_time, '%Y-%m')
- </select>
- <select id="getOverPayByGoodsId" resultType="java.lang.Integer">
- select count(DISTINCT user_id)
- from order_don o
- where created_time < #{lastMonth}
- <if test="goodsId !=null">
- and goods_id = #{goodsId}
- </if>
- <if test="skuIds!=null">
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- and `status` not in ('close', 'noPayment', 'refund')
- and NOT EXISTS (select 1
- from order_don
- where created_time BETWEEN #{lastMonth} and #{thisMonth}
- and `status` not in ('close', 'noPayment', 'refund')
- AND user_id = o.user_id
- <if test="goodsId !=null">
- and goods_id = #{goodsId}
- </if>
- <if test="skuIds!=null">
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- )
- and EXISTS (select 1
- from order_don
- where created_time BETWEEN #{thisMonth} and #{nextMonth}
- and `status` not in ('close', 'noPayment', 'refund')
- and user_id = o.user_id
- <if test="goodsId !=null">
- and goods_id = #{goodsId}
- </if>
- <if test="skuIds!=null">
- and sku_id in
- <foreach collection="skuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- )
- </select>
- <select id="getYearNumOfRenewalsByGoodsId" resultType="java.lang.Integer">
- select count(distinct user_id)
- from order_don
- where created_time BETWEEN #{lastYearMonth} and #{lastElevMonth}
- and `status` not in ('close', 'noPayment', 'refund')
- and goods_id = #{goodsId}
- </select>
- <select id="getActualNumberOfRenewalsByGoodsId" resultType="java.lang.Integer">
- select count(distinct user_id)
- from order_don o
- where created_time BETWEEN #{lastYearMonth} and #{lastElevMonth}
- and `status` not in ('close', 'noPayment', 'refund')
- and goods_id = #{goodsId}
- and exists (select 1 from order_don where created_time > #{lastElevMonth}
- and `status` not in ('close', 'noPayment', 'refund')
- and goods_id = #{goodsId} and user_id = o.user_id limit 1)
- </select>
- </mapper>
|