Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

435 righe
18 KiB

  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.iformall.mapper.WxCardSpendMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCardSpend">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  8. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  9. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  10. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  11. <result column="pos_order_id" jdbcType="BIGINT" property="posOrderId"/>
  12. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  13. <result column="payment" jdbcType="INTEGER" property="payment"/>
  14. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  15. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  16. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  17. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  18. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  19. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  20. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  21. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  22. <result column="pay_from" jdbcType="INTEGER" property="payFrom"/>
  23. </resultMap>
  24. <sql id="allColumns">
  25. `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`,
  26. `deduction_amount`,`payment`,`real_payment`, `card_remain_amount`,
  27. `card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`,
  28. `create_date`, `update_date`, `pay_status`, `pay_from`
  29. </sql>
  30. <sql id="dynamicWhereConditions">
  31. where 1 = 1
  32. <if test=" null != id ">
  33. and `id` = #{id}
  34. </if>
  35. <if test=" null != tenantId ">
  36. and `tenant_id` = #{tenantId}
  37. </if>
  38. <if test=" null != cardId ">
  39. and `card_id` = #{cardId}
  40. </if>
  41. <if test=" null != ownerId ">
  42. and `owner_id` = #{ownerId}
  43. </if>
  44. <if test=" null != merchantId ">
  45. and `merchant_id` = #{merchantId}
  46. </if>
  47. <if test=" null != orderId ">
  48. and `order_id` = #{orderId}
  49. </if>
  50. <if test=" null != posOrderId ">
  51. and `pos_order_id` = #{posOrderId}
  52. </if>
  53. <if test=" null != deductionAmount ">
  54. and `deduction_amount` = #{deductionAmount}
  55. </if>
  56. <if test=" null != payment ">
  57. and `payment` = #{payment}
  58. </if>
  59. <if test=" null != realPayment ">
  60. and `real_payment` = #{realPayment}
  61. </if>
  62. <if test=" null != cardRemainAmount ">
  63. and `card_remain_amount` = #{cardRemainAmount}
  64. </if>
  65. <if test=" null != cardBeforeAmount ">
  66. and `card_before_amount` = #{cardBeforeAmount}
  67. </if>
  68. <if test=" null != cardRemainRealAmount ">
  69. and `card_remain_real_amount` = #{cardRemainRealAmount}
  70. </if>
  71. <if test=" null != cardBeforeRealAmount ">
  72. and `card_before_real_amount` = #{cardBeforeRealAmount}
  73. </if>
  74. <if test=" null != createDate ">
  75. and `create_date` = #{createDate}
  76. </if>
  77. <if test=" null != updateDate ">
  78. and `update_date` = #{updateDate}
  79. </if>
  80. <if test=" null != payStatus ">
  81. and `pay_status` = #{payStatus}
  82. </if>
  83. <if test=" null != payFrom ">
  84. and `pay_from` = #{payFrom}
  85. </if>
  86. <if test=" null != startdate and null!=enddate">
  87. and `create_date` between #{startdate} and #{enddate}
  88. </if>
  89. <if test=" null != ids ">
  90. and id in
  91. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  92. #{idItem}
  93. </foreach>
  94. </if>
  95. <if test=" null != sortColumns">order by ${sortColumns}</if>
  96. </sql>
  97. <select id="findList" parameterType="com.iformall.domain.po.WxCardSpend" resultMap="BaseResultMap">
  98. select
  99. <include refid="allColumns"/>
  100. from wx_card_spend
  101. <include refid="dynamicWhereConditions"/>
  102. </select>
  103. <select id="updateByCond" parameterType="com.iformall.domain.po.WxCardSpend">
  104. update wx_card_spend
  105. set `pay_status` = #{payStatus}, `update_date` = #{updateDate}
  106. <where>
  107. <if test=" null != tenantId ">
  108. and `tenant_id` = #{tenantId}
  109. </if>
  110. <if test=" null != startdate and null!=enddate">
  111. and `create_date` between #{startdate} and #{enddate}
  112. </if>
  113. <if test=" null != ids ">
  114. and id in
  115. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  116. #{idItem}
  117. </foreach>
  118. </if>
  119. </where>
  120. </select>
  121. <delete id="deleteForPrevCancel" parameterType="com.iformall.domain.po.WxCardSpend">
  122. delete from wx_card_spend
  123. where `tenant_id` = #{tenantId} and `id` = #{id} and `pay_status` = #{payStatus}
  124. </delete>
  125. <select id="findCount" parameterType="com.iformall.domain.po.WxCardSpend" resultType="Integer">
  126. select count(*)
  127. from wx_card_spend cs
  128. <if test=" null != businessId ">
  129. inner join wx_merchant m
  130. on m.id = cs.merchant_id
  131. and m.business_id = #{businessId}
  132. <if test=" null != subBusinessId ">
  133. and m.sub_business_id = #{subBusinessId}
  134. </if>
  135. </if>
  136. where 1 = 1
  137. <if test=" null != ownerId ">
  138. and cs.`owner_id` = #{ownerId}
  139. </if>
  140. <if test=" null != tenantId ">
  141. and cs.`tenant_id` = #{tenantId}
  142. </if>
  143. <if test=" null != startdate and null!=enddate">
  144. and cs.`create_date` between #{startdate} and #{enddate}
  145. </if>
  146. <if test=" 0 == timeSlot">
  147. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  148. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  149. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  150. </if>
  151. <if test=" 1 == timeSlot">
  152. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  153. and date_format(cs.create_date,'%w') in (1,2,3,4))
  154. or
  155. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  156. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  157. </if>
  158. <if test=" 2 == timeSlot">
  159. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  160. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  161. and date_format(cs.create_date,'%w') in (0,6)
  162. </if>
  163. <if test=" 3 == timeSlot">
  164. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  165. and date_format(cs.create_date,'%w') in (5,6,0))
  166. or
  167. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  168. and date_format(cs.create_date,'%w') in (6,0)))
  169. </if>
  170. </select>
  171. <select id="getCountByBusinessId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
  172. select m.business_id, count(m.business_id) bu_count
  173. from wx_card_spend cs
  174. inner join wx_merchant m on m.id = cs.merchant_id
  175. where 1 = 1
  176. <if test=" null != ownerId ">
  177. and cs.`owner_id` = #{ownerId}
  178. </if>
  179. <if test=" null != tenantId ">
  180. and cs.`tenant_id` = #{tenantId}
  181. </if>
  182. <if test=" null != startdate and null!=enddate">
  183. and cs.`create_date` between #{startdate} and #{enddate}
  184. </if>
  185. <if test=" 0 == timeSlot">
  186. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  187. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  188. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  189. </if>
  190. <if test=" 1 == timeSlot">
  191. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  192. and date_format(cs.create_date,'%w') in (1,2,3,4))
  193. or
  194. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  195. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  196. </if>
  197. <if test=" 2 == timeSlot">
  198. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  199. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  200. and date_format(cs.create_date,'%w') in (0,6)
  201. </if>
  202. <if test=" 3 == timeSlot">
  203. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  204. and date_format(cs.create_date,'%w') in (5,6,0))
  205. or
  206. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  207. and date_format(cs.create_date,'%w') in (6,0)))
  208. </if>
  209. group by m.business_id
  210. </select>
  211. <select id="getCountBySubBusinessId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
  212. select m.sub_business_id, count(m.sub_business_id) bu_count
  213. from wx_card_spend cs
  214. <if test=" null != businessId ">
  215. inner join wx_merchant m on m.id = cs.merchant_id and m.business_id = #{businessId}
  216. </if>
  217. where 1 = 1
  218. <if test=" null != ownerId ">
  219. and cs.`owner_id` = #{ownerId}
  220. </if>
  221. <if test=" null != tenantId ">
  222. and cs.`tenant_id` = #{tenantId}
  223. </if>
  224. <if test=" null != startdate and null!=enddate">
  225. and cs.`create_date` between #{startdate} and #{enddate}
  226. </if>
  227. <if test=" 0 == timeSlot">
  228. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  229. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  230. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  231. </if>
  232. <if test=" 1 == timeSlot">
  233. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  234. and date_format(cs.create_date,'%w') in (1,2,3,4))
  235. or
  236. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  237. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  238. </if>
  239. <if test=" 2 == timeSlot">
  240. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  241. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  242. and date_format(cs.create_date,'%w') in (0,6)
  243. </if>
  244. <if test=" 3 == timeSlot">
  245. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  246. and date_format(cs.create_date,'%w') in (5,6,0))
  247. or
  248. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  249. and date_format(cs.create_date,'%w') in (6,0)))
  250. </if>
  251. group by m.sub_business_id
  252. </select>
  253. <resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
  254. <id column="id" jdbcType="BIGINT" property="id"/>
  255. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  256. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  257. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  258. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  259. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  260. <result column="pos_order_id" jdbcType="BIGINT" property="posOrderId"/>
  261. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  262. <result column="payment" jdbcType="INTEGER" property="payment"/>
  263. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  264. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  265. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  266. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  267. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  268. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  269. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  270. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  271. <result column="title" jdbcType="VARCHAR" property="title"/>
  272. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  273. <result column="subsidy" jdbcType="INTEGER" property="subsidy"/>
  274. <result column="real_subsidy" jdbcType="INTEGER" property="realSubsidy"/>
  275. <result column="status" jdbcType="INTEGER" property="status"/>
  276. <result column="onick_name" jdbcType="VARCHAR" property="onickName"/>
  277. <result column="ou_phone" jdbcType="VARCHAR" property="ouPhone"/>
  278. </resultMap>
  279. <sql id="allVoColumns">
  280. cs.`id`,cs.`tenant_id`,cs.`card_id`,cs.`owner_id`,cs.`merchant_id`,cs.`order_id`,cs.`deduction_amount`,cs.`payment`,cs.`real_payment`,
  281. cs.`card_remain_amount`,cs.`card_before_amount`,cs.`card_remain_real_amount`,cs.`card_before_real_amount`,
  282. cs.`create_date`,cs.`update_date`, cs.`pay_status`,
  283. m.`name`, c.`title`,
  284. ms.`subsidy`,ms.`real_subsidy`,ms.`status`,
  285. ou.`nick_name` as onick_name, ou.`phone` as ou_phone
  286. </sql>
  287. <sql id="dynamicVoWhereConditions">
  288. where 1 = 1
  289. <if test=" null != id ">
  290. and cs.`id` = #{id}
  291. </if>
  292. <if test=" null != tenantId ">
  293. and cs.`tenant_id` = #{tenantId}
  294. </if>
  295. <if test=" null != cardId ">
  296. and cs.`card_id` = #{cardId}
  297. </if>
  298. <if test=" null != ownerId ">
  299. and cs.`owner_id` = #{ownerId}
  300. </if>
  301. <if test=" null != merchantId ">
  302. and cs.`merchant_id` = #{merchantId}
  303. </if>
  304. <if test=" null != orderId ">
  305. and cs.`order_id` = #{orderId}
  306. </if>
  307. <if test=" null != deductionAmount ">
  308. and cs.`deduction_amount` = #{deductionAmount}
  309. </if>
  310. <if test=" null != payment ">
  311. and cs.`payment` = #{payment}
  312. </if>
  313. <if test=" null != realPayment ">
  314. and cs.`real_payment` = #{realPayment}
  315. </if>
  316. <if test=" null != cardRemainAmount ">
  317. and cs.`card_remain_amount` = #{cardRemainAmount}
  318. </if>
  319. <if test=" null != cardBeforeAmount ">
  320. and cs.`card_before_amount` = #{cardBeforeAmount}
  321. </if>
  322. <if test=" null != cardRemainRealAmount ">
  323. and cs.`card_remain_real_amount` = #{cardRemainRealAmount}
  324. </if>
  325. <if test=" null != cardBeforeRealAmount ">
  326. and cs.`card_before_real_amount` = #{cardBeforeRealAmount}
  327. </if>
  328. <if test=" null != createDate ">
  329. and cs.`create_date` = #{createDate}
  330. </if>
  331. <if test=" null != updateDate ">
  332. and cs.`update_date` = #{updateDate}
  333. </if>
  334. <if test=" null != payStatus ">
  335. and cs.`pay_status` = #{payStatus}
  336. </if>
  337. <if test=" null != status ">
  338. and ms.`status` = #{status}
  339. </if>
  340. <if test=" null != ouPhone and '' != ouPhone ">
  341. and ou.`phone` = #{ouPhone}
  342. </if>
  343. <if test=" null != startdate and null!=enddate">
  344. and cs.`create_date` between #{startdate} and #{enddate}
  345. </if>
  346. <if test=" null != payStatusS ">
  347. and cs.`pay_status` in
  348. <foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
  349. #{sItem}
  350. </foreach>
  351. </if>
  352. <if test=" null != ids ">
  353. and cs.id in
  354. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  355. #{idItem}
  356. </foreach>
  357. </if>
  358. </sql>
  359. <select id="findCardSpendVoList" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultMap="VoResultMap">
  360. select
  361. <include refid="allVoColumns"/>
  362. from wx_card_spend cs
  363. left join wx_coupon_order co on co.id = cs.card_id
  364. left join wx_coupon c on c.id = co.coupon_id
  365. left join wx_merchant m on m.id = cs.merchant_id
  366. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  367. left join wx_c_user ou on ou.id = co.owner_id
  368. <include refid="dynamicVoWhereConditions"/>
  369. order by cs.create_date DESC
  370. </select>
  371. <select id="sumCardSpendVoForMerchant" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  372. select cs.merchant_id, m.name as merchantName,
  373. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  374. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  375. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  376. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  377. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  378. from wx_card_spend cs
  379. left join wx_coupon_order co on co.id = cs.card_id
  380. left join wx_coupon c on c.id = co.coupon_id
  381. left join wx_merchant m on m.id = cs.merchant_id
  382. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  383. left join wx_c_user ou on ou.id = co.owner_id
  384. <include refid="dynamicVoWhereConditions"/>
  385. group by cs.merchant_id
  386. </select>
  387. <select id="sumCardSpendVoForOwner" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  388. select cs.owner_id,
  389. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  390. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  391. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  392. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  393. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  394. from wx_card_spend cs
  395. left join wx_coupon_order co on co.id = cs.card_id
  396. left join wx_coupon c on c.id = co.coupon_id
  397. left join wx_merchant m on m.id = cs.merchant_id
  398. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  399. left join wx_c_user ou on ou.id = co.owner_id
  400. <include refid="dynamicVoWhereConditions"/>
  401. group by cs.owner_id
  402. </select>
  403. </mapper>