Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

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