后台服务
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

420 rindas
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="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="getMerchantCount" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
  182. select cs.merchant_id as merchantId, count(1) as count
  183. from wx_card_spend cs
  184. where cs.`owner_id` = #{ownerId} and cs.`tenant_id` = #{tenantId}
  185. <if test=" null != parentTenantId and '' != parentTenantId">
  186. and cs.`parent_tenant_id` = #{parentTenantId}
  187. </if>
  188. <if test=" null != startdate and null!=enddate">
  189. and cs.`create_date` between #{startdate} and #{enddate}
  190. </if>
  191. <if test=" 0 == timeSlot">
  192. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  193. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  194. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  195. </if>
  196. <if test=" 1 == timeSlot">
  197. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  198. and date_format(cs.create_date,'%w') in (1,2,3,4))
  199. or
  200. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  201. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  202. </if>
  203. <if test=" 2 == timeSlot">
  204. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  205. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  206. and date_format(cs.create_date,'%w') in (0,6)
  207. </if>
  208. <if test=" 3 == timeSlot">
  209. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  210. and date_format(cs.create_date,'%w') in (5,6,0))
  211. or
  212. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  213. and date_format(cs.create_date,'%w') in (6,0)))
  214. </if>
  215. group by cs.merchant_id
  216. </select>
  217. <resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
  218. <id column="id" jdbcType="BIGINT" property="id"/>
  219. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  220. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  221. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  222. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  223. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  224. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  225. <result column="pos_order_id" jdbcType="BIGINT" property="posOrderId"/>
  226. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  227. <result column="payment" jdbcType="INTEGER" property="payment"/>
  228. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  229. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  230. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  231. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  232. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  233. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  234. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  235. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  236. <result column="title" jdbcType="VARCHAR" property="title"/>
  237. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  238. <result column="subsidy" jdbcType="INTEGER" property="subsidy"/>
  239. <result column="real_subsidy" jdbcType="INTEGER" property="realSubsidy"/>
  240. <result column="status" jdbcType="INTEGER" property="status"/>
  241. <result column="onick_name" jdbcType="VARCHAR" property="onickName"/>
  242. <result column="ou_phone" jdbcType="VARCHAR" property="ouPhone"/>
  243. </resultMap>
  244. <sql id="allVoColumns">
  245. 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`,
  246. cs.`card_remain_amount`,cs.`card_before_amount`,cs.`card_remain_real_amount`,cs.`card_before_real_amount`,
  247. cs.`create_date`,cs.`update_date`, cs.`pay_status`,
  248. m.`name`, c.`title`,
  249. ms.`subsidy`,ms.`real_subsidy`,ms.`status`,
  250. ou.`nick_name` as onick_name, ou.`phone` as ou_phone
  251. </sql>
  252. <sql id="dynamicVoWhereConditions">
  253. where 1 = 1
  254. <if test=" null != id ">
  255. and cs.`id` = #{id}
  256. </if>
  257. <if test=" null != tenantId and '' != tenantId">
  258. and cs.`tenant_id` = #{tenantId}
  259. </if>
  260. <if test=" null != parentTenantId and '' != parentTenantId">
  261. and cs.`parent_tenant_id` = #{parentTenantId}
  262. </if>
  263. <if test=" null != cardId ">
  264. and cs.`card_id` = #{cardId}
  265. </if>
  266. <if test=" null != ownerId ">
  267. and cs.`owner_id` = #{ownerId}
  268. </if>
  269. <if test=" null != merchantId ">
  270. and cs.`merchant_id` = #{merchantId}
  271. </if>
  272. <if test=" null != orderId ">
  273. and cs.`order_id` = #{orderId}
  274. </if>
  275. <if test=" null != deductionAmount ">
  276. and cs.`deduction_amount` = #{deductionAmount}
  277. </if>
  278. <if test=" null != payment ">
  279. and cs.`payment` = #{payment}
  280. </if>
  281. <if test=" null != realPayment ">
  282. and cs.`real_payment` = #{realPayment}
  283. </if>
  284. <if test=" null != cardRemainAmount ">
  285. and cs.`card_remain_amount` = #{cardRemainAmount}
  286. </if>
  287. <if test=" null != cardBeforeAmount ">
  288. and cs.`card_before_amount` = #{cardBeforeAmount}
  289. </if>
  290. <if test=" null != cardRemainRealAmount ">
  291. and cs.`card_remain_real_amount` = #{cardRemainRealAmount}
  292. </if>
  293. <if test=" null != cardBeforeRealAmount ">
  294. and cs.`card_before_real_amount` = #{cardBeforeRealAmount}
  295. </if>
  296. <if test=" null != payStatus ">
  297. and cs.`pay_status` = #{payStatus}
  298. </if>
  299. <if test=" null != status ">
  300. and ms.`status` = #{status}
  301. </if>
  302. <if test=" null != sources ">
  303. and ( ms.source is null or ms.source in
  304. <foreach collection="sources" index="index" item="sourceItem" open="(" separator="," close=")">
  305. #{sourceItem}
  306. </foreach>
  307. )
  308. </if>
  309. <if test=" null != cardSpendListShow ">
  310. and ( ms.card_spend_list_show is null or ms.card_spend_list_show = #{cardSpendListShow} )
  311. </if>
  312. <if test=" null != ouPhone and '' != ouPhone ">
  313. and ou.`phone` = #{ouPhone}
  314. </if>
  315. <if test=" null != startdate and null!=enddate">
  316. and cs.`create_date` between #{startdate} and #{enddate}
  317. </if>
  318. <if test=" null != payStatusS ">
  319. and cs.`pay_status` in
  320. <foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
  321. #{sItem}
  322. </foreach>
  323. </if>
  324. <if test=" null != ids ">
  325. and cs.id in
  326. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  327. #{idItem}
  328. </foreach>
  329. </if>
  330. </sql>
  331. <select id="findCardSpendVoList" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultMap="VoResultMap">
  332. select
  333. <include refid="allVoColumns"/>
  334. from wx_card_spend cs
  335. left join wx_coupon_order co on co.id = cs.card_id
  336. left join wx_coupon c on c.id = co.coupon_id
  337. left join wx_merchant m on m.id = cs.merchant_id
  338. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  339. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  340. <include refid="dynamicVoWhereConditions"/>
  341. order by cs.create_date DESC
  342. </select>
  343. <select id="sumCardSpendVoForMerchant" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  344. select cs.merchant_id, m.name as merchantName,
  345. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  346. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  347. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  348. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  349. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  350. from wx_card_spend cs
  351. left join wx_coupon_order co on co.id = cs.card_id
  352. left join wx_coupon c on c.id = co.coupon_id
  353. left join wx_merchant m on m.id = cs.merchant_id
  354. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  355. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  356. <include refid="dynamicVoWhereConditions"/>
  357. group by cs.merchant_id
  358. </select>
  359. <select id="sumCardSpendVoForOwner" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  360. select cs.owner_id,
  361. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  362. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  363. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  364. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  365. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  366. from wx_card_spend cs
  367. left join wx_coupon_order co on co.id = cs.card_id
  368. left join wx_coupon c on c.id = co.coupon_id
  369. left join wx_merchant m on m.id = cs.merchant_id
  370. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  371. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  372. <include refid="dynamicVoWhereConditions"/>
  373. group by cs.owner_id
  374. </select>
  375. <select id="sumRealPayment" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="Integer">
  376. select
  377. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment
  378. from wx_card_spend cs
  379. where cs.`tenant_id` = #{tenantId}
  380. and cs.`merchant_id` = #{merchantId}
  381. <if test=" null != startdate ">
  382. AND cs.`create_date` &gt;= #{startdate}
  383. </if>
  384. <if test=" null != enddate ">
  385. AND cs.`create_date` &lt;= #{enddate}
  386. </if>
  387. </select>
  388. </mapper>