|
|
@@ -320,56 +320,62 @@
|
|
|
</select>
|
|
|
|
|
|
<select id="getTagUserData" resultType="com.cyksj.model.views.UserOrderDetailView">
|
|
|
- select count(if(status != 'refund', 1, NULL)) as numOfOrder, (sum(money) - sum(ifnull(refund_money, 0))) / 100
|
|
|
- as orderMoney,
|
|
|
- count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
|
|
|
- (sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as epOrderMoney
|
|
|
- from (select cu.user_id
|
|
|
- from (select relation_id
|
|
|
+ select count(if(status != 'refund', 1, NULL)) as numOfOrder,
|
|
|
+ (sum(money) - sum(ifnull(refund_money, 0))) / 100 as orderMoney,
|
|
|
+ count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
|
|
|
+ (sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as epOrderMoney,
|
|
|
+ count(distinct corpUserId) as numOfUser
|
|
|
+ from (select cu.id as corpUserId,
|
|
|
+ cu.user_id,
|
|
|
+ s.created_time
|
|
|
+ from (select relation_id,
|
|
|
+ min(ct.created_time) as created_time
|
|
|
from `corp_user_tag` ct
|
|
|
where tag_id = #{tagIdStr}
|
|
|
+ group by ct.relation_id
|
|
|
<if test="startTime != null">
|
|
|
- and ct.created_time >= #{startTime}
|
|
|
+ having min(ct.created_time) >= #{startTime}
|
|
|
</if>
|
|
|
<if test="endTime != null">
|
|
|
- and ct.created_time < #{endTime}
|
|
|
+ and min(ct.created_time) < #{endTime}
|
|
|
</if>) s
|
|
|
left join corp_user_follow_relation cufr on cufr.id = s.relation_id
|
|
|
left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
|
|
|
- left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
|
|
|
- s.user_id
|
|
|
+ left join corp_user cu on cu.id = ca.corp_user_id) s
|
|
|
+ left join order_don o on o.user_id = s.user_id and o.user_id != 0
|
|
|
and o.status not in ('close', 'noPayment')
|
|
|
and o.money > 0
|
|
|
- and o.money > ifnull(o.refund_money,0)
|
|
|
- <if test="startTime != null">
|
|
|
- and o.created_time >= #{startTime}
|
|
|
+ and o.created_time > s.created_time
|
|
|
+ <if test="consumeStTime != null">
|
|
|
+ and o.created_time >= #{consumeStTime}
|
|
|
+ </if>
|
|
|
+ <if test="consumeEtTime != null">
|
|
|
+ and o.created_time < #{consumeEtTime}
|
|
|
</if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getTagUserDataPage" resultType="com.cyksj.model.views.UserOrderDetailView">
|
|
|
- select count(if(status != 'refund', 1, NULL)) as numOfOrder, (sum(money) - sum(ifnull(refund_money, 0))) / 100
|
|
|
- as orderMoney,date_format(o.created_time,'%Y-%m-%d') as date from (select cu.user_id
|
|
|
- from (select relation_id
|
|
|
- from `corp_user_tag` ct
|
|
|
- where tag_id = #{tagIdStr}
|
|
|
- <if test="startTime != null">
|
|
|
- and ct.created_time >= #{startTime}
|
|
|
- </if>
|
|
|
- <if test="endTime != null">
|
|
|
- and ct.created_time < #{endTime}
|
|
|
- </if>) s
|
|
|
- left join corp_user_follow_relation cufr on cufr.id = s.relation_id
|
|
|
- left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
|
|
|
- left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
|
|
|
- s.user_id
|
|
|
- and o.status not in ('close', 'noPayment')
|
|
|
+ select joinTime as `date`,
|
|
|
+ count(DISTINCT corpUserId) as numOfUser,
|
|
|
+ count(if(status != 'refund', 1, NULL)) as numOfOrder,
|
|
|
+ (ifnull(sum(money), 0) - sum(ifnull(refund_money, 0))) / 100 as orderMoney
|
|
|
+ from (select cu.id as corpUserId,
|
|
|
+ cu.user_id,
|
|
|
+ date_format(s.created_time, '%Y-%m-%d') joinTime
|
|
|
+ from (select relation_id,
|
|
|
+ min(ct.created_time) as created_time
|
|
|
+ from `corp_user_tag` ct
|
|
|
+ where tag_id = #{tagIdStr}
|
|
|
+ group by ct.relation_id) s
|
|
|
+ left join corp_user_follow_relation cufr on cufr.id = s.relation_id
|
|
|
+ left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
|
|
|
+ left join corp_user cu on cu.id = ca.corp_user_id) s
|
|
|
+ left join order_don o on o.user_id = s.user_id and o.user_id != 0
|
|
|
+ and o.status not in ('close','noPayment')
|
|
|
+ and date_format(o.created_time, '%Y-%m-%d') = joinTime
|
|
|
and o.money > 0
|
|
|
- and o.money > ifnull(o.refund_money,0)
|
|
|
- <if test="startTime != null">
|
|
|
- and o.created_time >= #{startTime}
|
|
|
- </if>
|
|
|
- group by date_format(o.created_time,'%Y-%m-%d')
|
|
|
- order by date_format(o.created_time,'%Y-%m-%d') desc
|
|
|
+ group by joinTime
|
|
|
+ order by joinTime desc
|
|
|
</select>
|
|
|
|
|
|
<select id="getTagUserTimeOrderData" resultType="com.cyksj.model.views.CorpTagUserOrderDataView">
|
|
|
@@ -377,22 +383,20 @@
|
|
|
(select nickname from user u where u.id = o.user_id limit 1),
|
|
|
o.order_no,o.goods_id,g.title,o.sku_id,sku.spec_val,
|
|
|
o.money/100 as money,o.created_time
|
|
|
- from (select
|
|
|
- cu.user_id
|
|
|
- from (select relation_id
|
|
|
+ from (select cu.id as corpUserId,
|
|
|
+ cu.user_id,
|
|
|
+ date_format(s.created_time, '%Y-%m-%d') joinTime
|
|
|
+ from (select relation_id,
|
|
|
+ min(ct.created_time) as created_time
|
|
|
from `corp_user_tag` ct
|
|
|
where tag_id = #{tagIdStr}
|
|
|
- <if test="startTime != null">
|
|
|
- and ct.created_time >= #{startTime}
|
|
|
- </if>
|
|
|
- <if test="endTime != null">
|
|
|
- and ct.created_time < #{endTime}
|
|
|
- </if>) s
|
|
|
+ group by ct.relation_id) s
|
|
|
left join corp_user_follow_relation cufr on cufr.id = s.relation_id
|
|
|
left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
|
|
|
- left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0) s inner join order_don o on o.user_id =
|
|
|
- s.user_id
|
|
|
+ left join corp_user cu on cu.id = ca.corp_user_id) s
|
|
|
+ inner join order_don o on o.user_id = s.user_id and o.user_id != 0
|
|
|
and o.status not in ('close', 'noPayment','refund')
|
|
|
+ and date_format(o.created_time, '%Y-%m-%d') = joinTime
|
|
|
and o.money > 0
|
|
|
<if test="toDate != null and toDate != ''">
|
|
|
and date_format(o.created_time,'%Y-%m-%d') = #{toDate}
|
|
|
@@ -455,4 +459,32 @@
|
|
|
and o.created_time > #{invitedTime}
|
|
|
and o.created_time < #{limitTime}
|
|
|
</select>
|
|
|
+
|
|
|
+ <select id="getPastRecord" resultType="com.cyksj.model.views.UserOrderDetailView">
|
|
|
+ select date_format(o.created_time,'%Y-%m-%d') as `date`,
|
|
|
+ count(if(status != 'refund', 1, NULL)) as numOfOrder,
|
|
|
+ (ifnull(sum(money),0) - sum(ifnull(refund_money, 0))) / 100 as orderMoney
|
|
|
+ from (select cu.id as corpUserId,
|
|
|
+ cu.user_id,
|
|
|
+ date_format(s.created_time, '%Y-%m-%d') joinTime
|
|
|
+ from (select relation_id,
|
|
|
+ min(ct.created_time) as created_time
|
|
|
+ from `corp_user_tag` ct
|
|
|
+ where tag_id = #{tagIdStr}
|
|
|
+ group by ct.relation_id) s
|
|
|
+ left join corp_user_follow_relation cufr on cufr.id = s.relation_id
|
|
|
+ left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
|
|
|
+ left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0)s
|
|
|
+ inner join order_don o on o.user_id = s.user_id
|
|
|
+ and o.status not in ('close','noPayment')
|
|
|
+ and date_format(o.created_time, '%Y-%m-%d') > joinTime
|
|
|
+ <if test="consumeStTime != null">
|
|
|
+ and o.created_time >= #{consumeStTime}
|
|
|
+ </if>
|
|
|
+ <if test="consumeEtTime != null">
|
|
|
+ and o.created_time < #{consumeEtTime}
|
|
|
+ </if>
|
|
|
+ group by date_format(o.created_time,'%Y-%m-%d')
|
|
|
+ order by date_format(o.created_time,'%Y-%m-%d') desc
|
|
|
+ </select>
|
|
|
</mapper>
|