CountMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.gree.mall.manager.commonmapper.CountMapper">
  4. <select id="countInfo" resultType="com.gree.mall.manager.bean.count.CountBean">
  5. select
  6. sum(if(order_status not in ('NOPAY','CLOSE'),total_num,0)) 'total',
  7. sum(if(order_status not in ('NOPAY','CLOSE','OVER'),total_num,0)) 'sold',
  8. sum(if(order_status ='DFH',1,0)) 'dfh',
  9. (select count(1) from order_refund where order_status not in ('OVER','CLOSE')
  10. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  11. and company_wechat_id in
  12. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  13. #{item}
  14. </foreach>
  15. </if>
  16. ) 'refund',
  17. sum(if(create_time between date(now()) and now() and order_status !='CLOSE',1,0)) 'todayOrder',
  18. sum(if(create_time between date_sub(date(now()), interval 1 day) and date(now()) and order_status !='CLOSE',1,0)) 'yestodayOrder',
  19. sum(if(create_time between date(now()) and now() and order_status not in ('NOPAY','CLOSE'),pay_amount,0)) 'todayProfit',
  20. sum(if(create_time between date_sub(date(now()), interval 1 day) and date(now()) and order_status not in ('NOPAY','CLOSE'),pay_amount,0)) 'yestodayProfit',
  21. if(count(if(create_time between date(now()) and now(),1,null))=0,0,
  22. round(
  23. sum(if(order_status not in ('NOPAY','CLOSE') and create_time between date(now()) and now(),1,0))
  24. /count(if(create_time between date(now()) and now(),1,null))*100
  25. ,2)
  26. ) 'orderTax'
  27. from order_info
  28. <where>
  29. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  30. and company_wechat_id in
  31. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  32. #{item}
  33. </foreach>
  34. </if>
  35. </where>
  36. </select>
  37. <select id="countSaleOrder" resultType="com.gree.mall.manager.bean.count.CountOrderBean">
  38. select
  39. count(DISTINCT a.order_id) orderNum,
  40. sum(b.pay_amount) amount,
  41. round(sum(b.pay_amount)/if(count(DISTINCT a.user_id)=0,1,count(DISTINCT a.user_id)),2) avgAmount
  42. from order_info a
  43. join order_detail b on a.order_id=b.order_id
  44. where a.order_status not in ('NOPAY','CLOSE')
  45. and a.pay_time between #{startTime} and #{endTime}
  46. <if test="workOrderType != null and workOrderType !=''">
  47. and b.work_order_type=#{workOrderType}
  48. </if>
  49. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  50. and a.company_wechat_id in
  51. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  52. #{item}
  53. </foreach>
  54. </if>
  55. <!-- <if test="websitIds != null and websitIds.size > 0">
  56. and a.websit_id in
  57. <foreach item="item" index="index" collection="websitIds" open="(" separator="," close=")">
  58. #{item}
  59. </foreach>
  60. </if>-->
  61. </select>
  62. <select id="countGoodsRank" resultType="com.gree.mall.manager.bean.count.GoodsRankBean">
  63. select * from (
  64. select count(1) num,b.goods_id,sum(b.pay_amount) pay_amount,b.goods_name from order_info a join order_detail b on a.order_id = b.order_id
  65. where a.create_time BETWEEN #{startTime} and #{endTime} and a.order_status not in ('NOPAY','CLOSE')
  66. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  67. and a.company_wechat_id in
  68. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  69. #{item}
  70. </foreach>
  71. </if>
  72. <!-- <if test="websitIds != null and websitIds.size > 0">
  73. and a.websit_id in
  74. <foreach item="item" index="index" collection="websitIds" open="(" separator="," close=")">
  75. #{item}
  76. </foreach>
  77. </if>-->
  78. group by b.goods_id
  79. order by count(1) desc
  80. ) t limit 7
  81. </select>
  82. <select id="countVisit" resultType="java.lang.Integer">
  83. select count(DISTINCT user_id) total from user_visit where visit_time BETWEEN #{startTime} and #{endTime}
  84. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  85. and company_wechat_id in
  86. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  87. #{item}
  88. </foreach>
  89. </if>
  90. </select>
  91. <select id="countWorkAmount" resultType="java.util.Map">
  92. select
  93. a.worker_phone,
  94. sum(a.pay_amount) - sum(b.refund_amount) 'total_amount'
  95. from order_info a
  96. join order_detail b on a.order_id = b.order_id
  97. join goods c on c.goods_id = b.goods_id
  98. where a.order_status in ('DFH','YFH','OVER')
  99. and c.category_id not in (
  100. select category_id from goods_category where name like '%清洗%'
  101. )
  102. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  103. and a.company_wechat_id in
  104. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  105. #{item}
  106. </foreach>
  107. </if>
  108. <if test="websitIds != null and websitIds.size > 0">
  109. and a.websit_id in
  110. <foreach item="item" index="index" collection="websitIds" open="(" separator="," close=")">
  111. #{item}
  112. </foreach>
  113. </if>
  114. and pay_time between #{startTime} and #{endTime}
  115. group by a.worker_phone
  116. </select>
  117. <select id="countWebsitAmount" resultType="java.util.Map">
  118. select
  119. sum(pay_amount) 'amount',
  120. sum(total_num) 'num'
  121. from order_info where order_status in ('DFH','YFH','OVER')
  122. and pay_time between #{startTime} and #{endTime}
  123. <if test="websitNumbers != null and websitNumbers.size > 0">
  124. and websit_number in
  125. <foreach item="item" index="index" collection="websitNumbers" open="(" separator="," close=")">
  126. #{item}
  127. </foreach>
  128. </if>
  129. </select>
  130. <select id="queryExchangeCodeCountList" resultType="com.gree.mall.manager.bean.exchange.GiftExchangeCodeBean">
  131. select
  132. count(1) 'num',
  133. min(bind_time) 'first_time',
  134. sum(amount) 'total_amount',
  135. sum(if(status=1,1,0)) 'use_num' ,
  136. a.*
  137. from gift_exchange_code a
  138. where type='SUB' and user_id !=''
  139. <if test="keyword != null and keyword !=''">
  140. and (a.nick_name like concat('%',#{keyword},'%') or a.user_phone like concat('%',#{keyword},'%'))
  141. </if>
  142. <if test="adminWebsitId != null and adminWebsitId !=''">
  143. and a.admin_websit_id = #{adminWebsitId}
  144. </if>
  145. <if test="companyWechatIds != null and companyWechatIds.size > 0">
  146. and a.company_wechat_id in
  147. <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
  148. #{item}
  149. </foreach>
  150. </if>
  151. group by user_id
  152. </select>
  153. <select id="countTotalSettleExpense" resultType="com.gree.mall.manager.bean.settle.DataBoardBean">
  154. SELECT
  155. SUM(a.settle_order_count) AS waitGatherCount,
  156. SUM(a.settle_amount) AS waitGatherAmount
  157. FROM
  158. settle_expense a
  159. WHERE
  160. a.company_wechat_id = #{companyWechatId}
  161. AND a.status IN ('NO', 'NOT')
  162. <if test="websitId != null and websitId != ''">
  163. AND a.websit_id = #{websitId}
  164. </if>
  165. </select>
  166. <select id="countTotalSettleSend" resultType="com.gree.mall.manager.bean.settle.DataBoardBean">
  167. SELECT
  168. SUM(a.wait_by_count) AS waitSendByCount,
  169. SUM(a.wait_amount) AS waitSendAmount
  170. FROM
  171. settle_month_wages a
  172. WHERE
  173. a.company_wechat_id = #{companyWechatId}
  174. AND a.status IN ('NOT', 'PART')
  175. </select>
  176. <select id="countTotalSettleExpenseItem" resultType="com.gree.mall.manager.bean.settle.DataBoardBean">
  177. SELECT
  178. SUM(IF(b.category_type = 'INSTALL_HOME', 1, 0)) AS waitGatherInstallHomeCount,
  179. SUM(IF(b.category_type = 'INSTALL_HOME', b.worker_settle_amount1 + b.worker_settle_amount2, 0)) AS waitGatherInstallHomeAmount,
  180. SUM(IF(b.category_type = 'INSTALL_OTHER', 1, 0)) AS waitGatherInstallCount,
  181. SUM(IF(b.category_type = 'INSTALL_OTHER', b.worker_settle_amount1 + IFNULL(b.worker_settle_amount2, 0), 0)) AS waitGatherInstallAmount,
  182. SUM(IF(b.category_type = 'REPAIR', 1, 0)) AS waitGatherRepairCount,
  183. SUM(IF(b.category_type = 'REPAIR', b.worker_settle_amount1 + IFNULL(b.worker_settle_amount2, 0), 0)) AS waitGatherRepairAmount,
  184. SUM(IF(b.category_type = 'OTHER', 1, 0)) AS waitGatherOtherCount,
  185. SUM(IF(b.category_type = 'OTHER', b.worker_settle_amount1 + IFNULL(b.worker_settle_amount2, 0), 0)) AS waitGatherOtherAmount
  186. FROM
  187. settle_expense a JOIN settle_expense_item b ON a.id = b.settle_expense_id
  188. WHERE
  189. a.company_wechat_id = #{companyWechatId}
  190. AND a.status IN ('NO', 'NOT')
  191. <if test="websitId != null and websitId != ''">
  192. AND a.websit_id = #{websitId}
  193. </if>
  194. </select>
  195. <select id="countTotalSettleSendItemAmount" resultType="com.gree.mall.manager.bean.settle.DataBoardBean">
  196. SELECT
  197. SUM(a.install_home_amount) AS waitSendInstallHomeAmount,
  198. SUM(a.install_other_amount) AS waitSendInstallAmount,
  199. SUM(a.repair_amount) AS waitSendRepairAmount,
  200. SUM(a.other_amount) AS waitSendOtherAmount
  201. FROM
  202. settle_month_wages_worker a
  203. WHERE
  204. a.company_wechat_id = #{companyWechatId}
  205. AND a.status = 'NOT'
  206. </select>
  207. <select id="countTotalSettleSendItemCount" resultType="com.gree.mall.manager.bean.settle.DataBoardBean">
  208. SELECT
  209. <if test="categoryName != null and categoryName == 'installHome'">
  210. COUNT(DISTINCT a.worker_id) AS waitSendByInstallHomeCount
  211. </if>
  212. <if test="categoryName != null and categoryName == 'installOther'">
  213. COUNT(DISTINCT a.worker_id) AS waitSendByInstallCount
  214. </if>
  215. <if test="categoryName != null and categoryName == 'repair'">
  216. COUNT(DISTINCT a.worker_id) AS waitSendByRepairCount
  217. </if>
  218. <if test="categoryName != null and categoryName == 'other'">
  219. COUNT(DISTINCT a.worker_id) AS waitSendByOtherCount
  220. </if>
  221. FROM
  222. settle_month_wages_worker a
  223. WHERE
  224. a.company_wechat_id = #{companyWechatId}
  225. AND a.status = 'NOT'
  226. <if test="categoryName != null and categoryName == 'installHome'">
  227. AND a.install_home_amount <![CDATA[ <> ]]> 0
  228. </if>
  229. <if test="categoryName != null and categoryName == 'installOther'">
  230. AND a.install_other_amount <![CDATA[ <> ]]> 0
  231. </if>
  232. <if test="categoryName != null and categoryName == 'repair'">
  233. AND a.repair_amount <![CDATA[ <> ]]> 0
  234. </if>
  235. <if test="categoryName != null and categoryName == 'other'">
  236. AND a.other_amount <![CDATA[ <> ]]> 0
  237. </if>
  238. </select>
  239. <select id="monthSendData" resultType="com.gree.mall.manager.bean.settle.MonthSendWorkerBean">
  240. SELECT
  241. a.worker_id,
  242. a.settle_amount,
  243. b.send_date
  244. FROM
  245. settle_month_wages_worker a
  246. JOIN settle_month_wages_detail b ON a.settle_month_wages_detail_id = b.id
  247. WHERE
  248. a.company_wechat_id = #{companyWechatId}
  249. AND a.`status` = 'END'
  250. AND b.send_date BETWEEN #{startMonth} AND #{endMonth}
  251. </select>
  252. <select id="countEsInfo" resultType="com.gree.mall.manager.bean.count.EsCountBean">
  253. select
  254. sum(if(`status` not in ('WAIT','CANCEL','REFUND','TIMEOUT'),num,0)) 'total',
  255. sum(if(`status` not in ('WAIT','CANCEL','COMPLETE','TIMEOUT'),num,0)) 'sold',
  256. sum(if(`status` ='WAIT_SEND',1,0)) 'dfh',
  257. sum(if(`status` in ('REFUND','TIMEOUT'),1,0)) 'refund',
  258. sum(if(create_time between date(now()) and now() and `status` not in ('WAIT','CANCEL','TIMEOUT','REFUND'),1,0)) 'todayOrder',
  259. sum(if(create_time between date_sub(date(now()), interval 1 day) and date(now())
  260. and `status` not in ('WAIT','CANCEL','REFUND','TIMEOUT'),1,0)) 'yestodayOrder',
  261. sum(if(create_time between date(now()) and now() and `status` not in ('WAIT','CANCEL','REFUND','TIMEOUT'),total_amount,0)) 'todayProfit',
  262. sum(if(create_time between date_sub(date(now()), interval 1 day) and date(now())
  263. and `status` not in ('WAIT','CANCEL','REFUND','TIMEOUT'),total_amount,0)) 'yestodayProfit',
  264. if(count(if(create_time between date(now()) and now(),1,null))=0,0,
  265. round(
  266. sum(if(`status` not in ('NOPAY','CANCEL','TIMEOUT') and create_time between date(now()) and now(),1,0))
  267. /count(if(create_time between date(now()) and now(),1,null))*100
  268. ,2)
  269. ) 'orderTax'
  270. from es_order_info
  271. where 1=1
  272. <if test="companyWechatId != null and companyWechatId != ''">
  273. and company_wechat_id = #{companyWechatId}
  274. </if>
  275. </select>
  276. <select id="countEsGoodsRank" resultType="com.gree.mall.manager.bean.count.EsGoodsRankBean">
  277. select
  278. es_order_id,
  279. es_goods_name,
  280. num,
  281. status
  282. from es_order_info
  283. where status not in ('WAIT','CANCEL','REFUND','TIMEOUT')
  284. and create_time between #{startTime} and #{endTime}
  285. <if test="companyWechatId != null and companyWechatId != ''">
  286. and company_wechat_id = #{companyWechatId}
  287. </if>
  288. order by 3 desc
  289. </select>
  290. <select id="countEsSaleOrder" resultType="com.gree.mall.manager.bean.count.CountOrderBean">
  291. select
  292. count(DISTINCT a.es_order_id) orderNum,
  293. sum(a.total_amount) amount,
  294. round(sum(a.total_amount)/if(count(DISTINCT a.wechat_user_id)=0,1,count(DISTINCT a.wechat_user_id)),2) avgAmount
  295. from es_order_info a
  296. where a.status not in ('WAIT','CANCEL','REFUND','TIMEOUT')
  297. and a.create_time between #{startTime} and #{endTime}
  298. </select>
  299. </mapper>