TOrderMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.szwl.mapper.TOrderMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.szwl.model.entity.TOrder">
  6. <id column="id" property="id" />
  7. <result column="create_date" property="createDate" />
  8. <result column="modify_date" property="modifyDate" />
  9. <result column="admin_id" property="adminId" />
  10. <result column="admin_proportion" property="adminProportion" />
  11. <result column="agency_id" property="agencyId" />
  12. <result column="agency_proportion" property="agencyProportion" />
  13. <result column="alt_info" property="altInfo" />
  14. <result column="client_id" property="clientId" />
  15. <result column="equipment_id" property="equipmentId" />
  16. <result column="frp_code" property="frpCode" />
  17. <result column="merchant_id" property="merchantId" />
  18. <result column="merchant_proportion" property="merchantProportion" />
  19. <result column="pay_date" property="payDate" />
  20. <result column="personage_id" property="personageId" />
  21. <result column="personage_proportion" property="personageProportion" />
  22. <result column="price" property="price" />
  23. <result column="product_id" property="productId" />
  24. <result column="product_name" property="productName" />
  25. <result column="refund_date" property="refundDate" />
  26. <result column="sn" property="sn" />
  27. <result column="status" property="status" />
  28. <result column="type" property="type" />
  29. <result column="trx_no" property="trxNo" />
  30. <result column="refund_trx_no" property="refundTrxNo" />
  31. <result column="es" property="es" />
  32. <result column="refund_amount" property="refundAmount" />
  33. <result column="note" property="note" />
  34. <result column="pay_platform" property="payPlatform" />
  35. <result column="is_settlement" property="isSettlement" />
  36. <result column="proportion_desc" property="proportionDesc" />
  37. </resultMap>
  38. <resultMap id="chartBean" type="com.szwl.model.bean.ChartBean">
  39. <result column="categorie" jdbcType="VARCHAR" property="categorie" />
  40. <!--<result column="saleNum" jdbcType="INTEGER" property="saleNum" />-->
  41. <result column="saleNum" jdbcType="FLOAT" property="saleNum" />
  42. <!--<result column="salePrice" jdbcType="DECIMAL" property="salePrice" />-->
  43. <result column="salePrice" jdbcType="FLOAT" property="salePrice" />
  44. </resultMap>
  45. <!-- 通用查询结果列 -->
  46. <sql id="Base_Column_List">
  47. id, create_date, modify_date, admin_id, admin_proportion, agency_id, agency_proportion, alt_info, client_id, equipment_id, frp_code, merchant_id, merchant_proportion, pay_date, personage_id, personage_proportion, price, product_id, product_name, refund_date, sn, status, type, trx_no, refund_trx_no, es, refund_amount, note, pay_platform, is_settlement, proportion_desc
  48. </sql>
  49. <!-- 日统计select concat(DATE_FORMAT( a.create_date,'%H'),'点') as categorie,count(1) as saleNum,sum(a.price) as salePrice -->
  50. <select id="getDayStatistics" resultMap="chartBean" parameterType="com.szwl.model.query.StatisticsParam">
  51. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  52. select concat(DATE_FORMAT( a.create_date,'%H'),'点') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  53. from t_order a where a.status='1' -- 支付成功
  54. </if>
  55. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  56. select concat(DATE_FORMAT( a.pay_date,'%H'),'点') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  57. from t_coin_order a where 1=1
  58. </if>
  59. <if test="adminId != null and adminId !=''">
  60. and a.admin_id= #{adminId} -- 所属商家id
  61. </if>
  62. <if test="agencyId != null and agencyId !=''">
  63. and a.agency_id= #{agencyId} and a.type > '1'
  64. </if>
  65. <if test="merchantId != null and merchantId !=''">
  66. and a.merchant_id= #{merchantId} and a.type > '2'
  67. </if>
  68. <if test="equipmentId != null and equipmentId !=''">
  69. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  70. and a.equipment_id= #{equipmentId} -- 设备id
  71. </if>
  72. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  73. and a.client_id= #{clientId} -- 设备编号
  74. </if>
  75. </if>
  76. <if test="ifForeign != null and ifForeign ==1 and payType != null"> -- 国外用户
  77. and a.pay_type= #{payType} -- 国外支付方式
  78. </if>
  79. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  80. and DATE_FORMAT( a.create_date,'%Y/%m/%d') = #{startDate}
  81. group by DATE_FORMAT( a.create_date,'%H')
  82. </if>
  83. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  84. and DATE_FORMAT( a.pay_date,'%Y/%m/%d') = #{startDate}
  85. group by DATE_FORMAT( a.pay_date,'%H')
  86. </if>
  87. order by categorie
  88. </select>
  89. <!--and DATE_FORMAT( a.create_date,'%Y/%m/%d') = #{startDate}-->
  90. <!--group by DATE_FORMAT( a.create_date,'%H')-->
  91. <!-- 周统计 -->
  92. <select id="getWeekStatistics" resultMap="chartBean" parameterType="com.szwl.model.query.StatisticsParam">
  93. SELECT tab1.categorie,ifnull(tab2.saleNum,0) as saleNum,ifnull(tab2.salePrice,0) as salePrice from (
  94. select '周1' as categorie from dual UNION all
  95. select '周2' as categorie from dual UNION all
  96. select '周3' as categorie from dual UNION all
  97. select '周4' as categorie from dual UNION all
  98. select '周5' as categorie from dual UNION all
  99. select '周6' as categorie from dual UNION all
  100. select '周日' as categorie from dual) tab1
  101. left join (
  102. -- select case DATE_FORMAT( a.create_date,'%w') when 0 then '周日' else CONCAT('周',DATE_FORMAT( a.create_date,'%w')) end as categorie,
  103. -- count(1) as saleNum,sum(a.price) as salePrice
  104. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  105. select case DATE_FORMAT( a.create_date,'%w') when 0 then '周日' else CONCAT('周',DATE_FORMAT( a.create_date,'%w')) end as categorie,
  106. count(1) as saleNum,sum(a.price) as salePrice
  107. from t_order a where a.status='1' -- 支付成功
  108. </if>
  109. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  110. select case DATE_FORMAT( a.pay_date,'%w') when 0 then '周日' else CONCAT('周',DATE_FORMAT( a.pay_date,'%w')) end as categorie,
  111. count(1) as saleNum,sum(a.price) as salePrice
  112. from t_coin_order a where 1=1
  113. </if>
  114. <if test="adminId != null and adminId !=''">
  115. and a.admin_id= #{adminId} -- 所属商家id
  116. </if>
  117. <if test="agencyId != null and agencyId !=''">
  118. and a.agency_id= #{agencyId} and a.type > '1'
  119. </if>
  120. <if test="merchantId != null and merchantId !=''">
  121. and a.merchant_id= #{merchantId} and a.type > '2'
  122. </if>
  123. <if test="equipmentId != null and equipmentId !=''">
  124. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  125. and a.equipment_id= #{equipmentId} -- 设备id
  126. </if>
  127. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  128. and a.client_id= #{clientId} -- 设备编号
  129. </if>
  130. </if>
  131. <if test="ifForeign != null and ifForeign ==1 and payType != null"> -- 国外用户
  132. and a.pay_type= #{payType} -- 国外支付方式
  133. </if>
  134. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  135. AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  136. <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  137. group by DATE_FORMAT( a.create_date,'%w')
  138. ) tab2 on tab1.categorie = tab2.categorie
  139. </if>
  140. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  141. AND a.pay_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  142. <![CDATA[ AND a.pay_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  143. group by DATE_FORMAT( a.pay_date,'%w')
  144. ) tab2 on tab1.categorie = tab2.categorie
  145. </if>
  146. </select>
  147. <!-- 月统计 -->
  148. <select id="getMonthStatistics" resultMap="chartBean" parameterType="com.szwl.model.query.StatisticsParam">
  149. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  150. select DATE_FORMAT( a.create_date,'%m月%d') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  151. from t_order a where a.status='1' -- 支付成功
  152. </if>
  153. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  154. select DATE_FORMAT( a.pay_date,'%m月%d') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  155. from t_coin_order a where 1=1
  156. </if>
  157. <if test="adminId != null and adminId !=''">
  158. and a.admin_id= #{adminId} -- 所属商家id
  159. </if>
  160. <if test="agencyId != null and agencyId !=''">
  161. and a.agency_id= #{agencyId} and a.type > '1'
  162. </if>
  163. <if test="merchantId != null and merchantId !=''">
  164. and a.merchant_id= #{merchantId} and a.type > '2'
  165. </if>
  166. <if test="equipmentId != null and equipmentId !=''">
  167. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  168. and a.equipment_id= #{equipmentId} -- 设备id
  169. </if>
  170. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  171. and a.client_id= #{clientId} -- 设备编号
  172. </if>
  173. </if>
  174. <if test="ifForeign != null and ifForeign ==1 and payType != null"> -- 国外用户
  175. and a.pay_type= #{payType} -- 国外支付方式
  176. </if>
  177. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  178. AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  179. <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  180. group by DATE_FORMAT( a.create_date,'%m月%d')
  181. </if>
  182. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  183. AND a.pay_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  184. <![CDATA[ AND a.pay_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  185. group by DATE_FORMAT( a.pay_date,'%m月%d')
  186. </if>
  187. </select>
  188. <!-- 年统计 -->
  189. <select id="getYearStatistics" resultMap="chartBean" parameterType="com.szwl.model.query.StatisticsParam">
  190. SELECT tab1.categorie,ifnull(tab2.saleNum,0) as saleNum,ifnull(tab2.salePrice,0) as salePrice from (
  191. select '01月' as categorie from dual UNION all
  192. select '02月' as categorie from dual UNION all
  193. select '03月' as categorie from dual UNION all
  194. select '04月' as categorie from dual UNION all
  195. select '05月' as categorie from dual UNION all
  196. select '06月' as categorie from dual UNION all
  197. select '07月' as categorie from dual UNION all
  198. select '08月' as categorie from dual UNION all
  199. select '09月' as categorie from dual UNION all
  200. select '10月' as categorie from dual UNION all
  201. select '11月' as categorie from dual UNION all
  202. select '12月' as categorie from dual) tab1
  203. left join (
  204. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  205. select concat(DATE_FORMAT( a.create_date,'%m'),'月') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  206. from t_order a where a.status='1' -- 支付成功
  207. </if>
  208. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  209. select concat(DATE_FORMAT( a.pay_date,'%m'),'月') as categorie,count(1) as saleNum,sum(a.price) as salePrice
  210. from t_coin_order a where 1=1
  211. </if>
  212. <if test="adminId != null and adminId !=''">
  213. and a.admin_id= #{adminId} -- 所属商家id
  214. </if>
  215. <if test="agencyId != null and agencyId !=''">
  216. and a.agency_id= #{agencyId} and a.type > '1'
  217. </if>
  218. <if test="merchantId != null and merchantId !=''">
  219. and a.merchant_id= #{merchantId} and a.type > '2'
  220. </if>
  221. <if test="equipmentId != null and equipmentId !=''">
  222. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  223. and a.equipment_id= #{equipmentId} -- 设备id
  224. </if>
  225. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  226. and a.client_id= #{clientId} -- 设备编号
  227. </if>
  228. </if>
  229. <if test="ifForeign != null and ifForeign ==1 and payType != null"> -- 国外用户
  230. and a.pay_type= #{payType} -- 国外支付方式
  231. </if>
  232. <if test="ifForeign != null and ifForeign ==0"> -- 国内用户
  233. AND a.create_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  234. <![CDATA[ AND a.create_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  235. group by DATE_FORMAT( a.create_date,'%m')
  236. ) tab2 on tab1.categorie = tab2.categorie
  237. </if>
  238. <if test="ifForeign != null and ifForeign ==1"> -- 国外用户
  239. AND a.pay_date >= STR_TO_DATE(CONCAT(#{startDate},' 00:00:00'),'%Y/%m/%d %H:%i:%s')
  240. <![CDATA[ AND a.pay_date <= STR_TO_DATE(CONCAT(#{endDate},' 23:59:59'),'%Y/%m/%d %H:%i:%s') ]]>
  241. group by DATE_FORMAT( a.pay_date,'%m')) tab2 on tab1.categorie = tab2.categorie
  242. </if>
  243. </select>
  244. </mapper>