You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

909 lines
33 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.WxCouponMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCoupon">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="type" jdbcType="INTEGER" property="type"/>
  8. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  9. <result column="title" jdbcType="VARCHAR" property="title"/>
  10. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  11. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  12. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  13. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  14. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  15. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  16. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  17. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  18. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  19. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  20. <result column="price" jdbcType="INTEGER" property="price"/>
  21. <result column="unit" jdbcType="INTEGER" property="unit"/>
  22. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  23. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  24. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  25. <result column="status" jdbcType="INTEGER" property="status"/>
  26. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  27. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  28. <result column="business" jdbcType="INTEGER" property="business"/>
  29. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  30. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  31. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  32. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  33. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  34. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  35. <result column="sale_count" property="saleCount"/>
  36. <result column="transfer_count" property="transferCount"/>
  37. <result column="sale_amount" property="saleAmount"/>
  38. <result column="sum_payment" property="sumPayment"/>
  39. <result column="press_count" property="pressSendCount"/>
  40. <result column="press_succ_count" property="pressSuccCount"/>
  41. <result column="join_count" property="pressJoinCount"/>
  42. <result column="sum_subsidy" property="sumSubsidy"/>
  43. <result column="payment_rate" property="paymentRate"/>
  44. </resultMap>
  45. <sql id="allColumns">
  46. `id`,`tenant_id`,`type`,`cover_img`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`,
  47. `valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`,
  48. `remark`,`status`,`create_date`,`update_date`,`business`,`support_transfer`,`subsidy_num`,`subsidy_type`,
  49. `press_limit_num`, `press_limit_hours`, `auto_refund`,subsidy_num
  50. </sql>
  51. <sql id="dynamicWhereConditions">
  52. where 1 = 1
  53. <if test=" null != id ">
  54. and `id` = #{id}
  55. </if>
  56. <if test=" null != tenantId ">
  57. and `tenant_id` = #{tenantId}
  58. </if>
  59. <if test=" null != type ">
  60. and `type` = #{type}
  61. </if>
  62. <if test=" null != coverImg ">
  63. and `cover_img` like concat('%', #{coverImg},'%')
  64. </if>
  65. <if test=" null != title and ''!=title">
  66. and `title` like concat('%', #{title},'%')
  67. </if>
  68. <if test=" null != subTitle ">
  69. and `sub_title` like concat('%', #{subTitle},'%')
  70. </if>
  71. <if test=" null != salePrice ">
  72. and `sale_price` = #{salePrice}
  73. </if>
  74. <if test=" null != usePrice ">
  75. and `use_price` = #{usePrice}
  76. </if>
  77. <if test=" null != useLimitQuantity ">
  78. and `use_limit_quantity` = #{useLimitQuantity}
  79. </if>
  80. <if test=" null != sendType ">
  81. and `send_type` = #{sendType}
  82. </if>
  83. <if test=" null != validType ">
  84. and `valid_type` = #{validType}
  85. </if>
  86. <if test=" null != validStartDate ">
  87. and `valid_start_date` = #{validStartDate}
  88. </if>
  89. <if test=" null != validEndDate ">
  90. and `valid_end_date` = #{validEndDate}
  91. </if>
  92. <if test=" null != validDays ">
  93. and `valid_days` = #{validDays}
  94. </if>
  95. <if test=" null != detail ">
  96. and `detail` like concat('%', #{detail},'%')
  97. </if>
  98. <if test=" null != price ">
  99. and `price` = #{price}
  100. </if>
  101. <if test=" null != unit ">
  102. and `unit` = #{unit}
  103. </if>
  104. <if test=" null != remainInventory ">
  105. and `remain_inventory` = #{remainInventory}
  106. </if>
  107. <if test=" null != inventory ">
  108. and `inventory` = #{inventory}
  109. </if>
  110. <if test=" null != remark ">
  111. and `remark` like concat('%', #{remark},'%')
  112. </if>
  113. <if test=" null != status">
  114. and `status` = #{status}
  115. </if>
  116. <if test=" null != startdate and null!=enddate">
  117. and `create_date` between #{startdate} and #{enddate}
  118. </if>
  119. <if test=" null != updateDate ">
  120. and `update_date` = #{updateDate}
  121. </if>
  122. <if test=" null != business ">
  123. and `business` = #{business}
  124. </if>
  125. <if test=" null != supportTransfer ">
  126. and `support_transfer` = #{supportTransfer}
  127. </if>
  128. <if test=" null != subsidyType ">
  129. and `subsidy_type` = #{subsidyType}
  130. </if>
  131. <if test=" null != subsidyNum ">
  132. and `subsidy_num` = #{subsidyNum}
  133. </if>
  134. <if test=" null != pressLimitNum ">
  135. and `press_limit_num` = #{pressLimitNum}
  136. </if>
  137. <if test=" null != pressLimitHours ">
  138. and `press_limit_hours` = #{pressLimitHours}
  139. </if>
  140. <if test=" null != autoRefund ">
  141. and `auto_refund` = #{autoRefund}
  142. </if>
  143. <if test=" null != ids ">
  144. and id in
  145. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  146. #{idItem}
  147. </foreach>
  148. </if>
  149. <if test=" null != sortColumns">order by ${sortColumns}</if>
  150. </sql>
  151. <select id="findList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  152. select
  153. <include refid="allColumns"/>
  154. from wx_coupon
  155. <include refid="dynamicWhereConditions"/>
  156. </select>
  157. <sql id="dynamicWhereConditionsForCard">
  158. where `type` = 100
  159. <if test=" null != id ">
  160. and `id` = #{id}
  161. </if>
  162. <if test=" null != tenantId ">
  163. and `tenant_id` = #{tenantId}
  164. </if>
  165. <if test=" null != type ">
  166. and `type` = #{type}
  167. </if>
  168. <if test=" null != coverImg ">
  169. and `cover_img` like concat('%', #{coverImg},'%')
  170. </if>
  171. <if test=" null != title and ''!=title">
  172. and `title` like concat('%', #{title},'%')
  173. </if>
  174. <if test=" null != subTitle ">
  175. and `sub_title` like concat('%', #{subTitle},'%')
  176. </if>
  177. <if test=" null != salePrice ">
  178. and `sale_price` = #{salePrice}
  179. </if>
  180. <if test=" null != usePrice ">
  181. and `use_price` = #{usePrice}
  182. </if>
  183. <if test=" null != useLimitQuantity ">
  184. and `use_limit_quantity` = #{useLimitQuantity}
  185. </if>
  186. <if test=" null != sendType ">
  187. and `send_type` = #{sendType}
  188. </if>
  189. <if test=" null != validType ">
  190. and `valid_type` = #{validType}
  191. </if>
  192. <if test=" null != validStartDate ">
  193. and `valid_start_date` = #{validStartDate}
  194. </if>
  195. <if test=" null != validEndDate ">
  196. and `valid_end_date` = #{validEndDate}
  197. </if>
  198. <if test=" null != validDays ">
  199. and `valid_days` = #{validDays}
  200. </if>
  201. <if test=" null != detail ">
  202. and `detail` like concat('%', #{detail},'%')
  203. </if>
  204. <if test=" null != price ">
  205. and `price` = #{price}
  206. </if>
  207. <if test=" null != unit ">
  208. and `unit` = #{unit}
  209. </if>
  210. <if test=" null != remainInventory ">
  211. and `remain_inventory` = #{remainInventory}
  212. </if>
  213. <if test=" null != inventory ">
  214. and `inventory` = #{inventory}
  215. </if>
  216. <if test=" null != remark ">
  217. and `remark` like concat('%', #{remark},'%')
  218. </if>
  219. <if test=" null != status">
  220. and `status` = #{status}
  221. </if>
  222. <if test=" null != startdate and null!=enddate">
  223. and `create_date` between #{startdate} and #{enddate}
  224. </if>
  225. <if test=" null != updateDate ">
  226. and `update_date` = #{updateDate}
  227. </if>
  228. <if test=" null != business ">
  229. and `business` = #{business}
  230. </if>
  231. <if test=" null != supportTransfer ">
  232. and `support_transfer` = #{supportTransfer}
  233. </if>
  234. <if test=" null != subsidyType ">
  235. and `subsidy_type` = #{subsidyType}
  236. </if>
  237. <if test=" null != subsidyNum ">
  238. and `subsidy_num` = #{subsidyNum}
  239. </if>
  240. <if test=" null != pressLimitNum ">
  241. and `press_limit_num` = #{pressLimitNum}
  242. </if>
  243. <if test=" null != pressLimitHours ">
  244. and `press_limit_hours` = #{pressLimitHours}
  245. </if>
  246. <if test=" null != ids ">
  247. and id in
  248. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  249. #{idItem}
  250. </foreach>
  251. </if>
  252. <if test=" null != sortColumns">order by ${sortColumns}</if>
  253. </sql>
  254. <select id="findCardList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  255. select
  256. <include refid="allColumns"/>
  257. from wx_coupon
  258. <include refid="dynamicWhereConditionsForCard"/>
  259. </select>
  260. <sql id="dynamicWhereConditionsForCoupon">
  261. where `type` &lt; 7
  262. <if test=" null != id ">
  263. and `id` = #{id}
  264. </if>
  265. <if test=" null != tenantId ">
  266. and `tenant_id` = #{tenantId}
  267. </if>
  268. <if test=" null != type ">
  269. and `type` = #{type}
  270. </if>
  271. <if test=" null != coverImg ">
  272. and `cover_img` like concat('%', #{coverImg},'%')
  273. </if>
  274. <if test=" null != title and ''!=title">
  275. and `title` like concat('%', #{title},'%')
  276. </if>
  277. <if test=" null != subTitle ">
  278. and `sub_title` like concat('%', #{subTitle},'%')
  279. </if>
  280. <if test=" null != salePrice ">
  281. and `sale_price` = #{salePrice}
  282. </if>
  283. <if test=" null != usePrice ">
  284. and `use_price` = #{usePrice}
  285. </if>
  286. <if test=" null != useLimitQuantity ">
  287. and `use_limit_quantity` = #{useLimitQuantity}
  288. </if>
  289. <if test=" null != sendType ">
  290. and `send_type` = #{sendType}
  291. </if>
  292. <if test=" null != validType ">
  293. and `valid_type` = #{validType}
  294. </if>
  295. <if test=" null != validStartDate ">
  296. and `valid_start_date` = #{validStartDate}
  297. </if>
  298. <if test=" null != validEndDate ">
  299. and `valid_end_date` = #{validEndDate}
  300. </if>
  301. <if test=" null != validDays ">
  302. and `valid_days` = #{validDays}
  303. </if>
  304. <if test=" null != detail ">
  305. and `detail` like concat('%', #{detail},'%')
  306. </if>
  307. <if test=" null != price ">
  308. and `price` = #{price}
  309. </if>
  310. <if test=" null != unit ">
  311. and `unit` = #{unit}
  312. </if>
  313. <if test=" null != remainInventory ">
  314. and `remain_inventory` = #{remainInventory}
  315. </if>
  316. <if test=" null != inventory ">
  317. and `inventory` = #{inventory}
  318. </if>
  319. <if test=" null != remark ">
  320. and `remark` like concat('%', #{remark},'%')
  321. </if>
  322. <if test=" null != status">
  323. and `status` = #{status}
  324. </if>
  325. <if test=" null != startdate and null!=enddate">
  326. and `create_date` between #{startdate} and #{enddate}
  327. </if>
  328. <if test=" null != updateDate ">
  329. and `update_date` = #{updateDate}
  330. </if>
  331. <if test=" null != business ">
  332. and `business` = #{business}
  333. </if>
  334. <if test=" null != supportTransfer ">
  335. and `support_transfer` = #{supportTransfer}
  336. </if>
  337. <if test=" null != subsidyType ">
  338. and `subsidy_type` = #{subsidyType}
  339. </if>
  340. <if test=" null != subsidyNum ">
  341. and `subsidy_num` = #{subsidyNum}
  342. </if>
  343. <if test=" null != pressLimitNum ">
  344. and `press_limit_num` = #{pressLimitNum}
  345. </if>
  346. <if test=" null != pressLimitHours ">
  347. and `press_limit_hours` = #{pressLimitHours}
  348. </if>
  349. <if test=" null != ids ">
  350. and id in
  351. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  352. #{idItem}
  353. </foreach>
  354. </if>
  355. <if test=" null != sortColumns">order by ${sortColumns}</if>
  356. </sql>
  357. <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  358. select
  359. <include refid="allColumns"/>
  360. from wx_coupon
  361. <include refid="dynamicWhereConditionsForCoupon"/>
  362. </select>
  363. <sql id="dynamicWhereConditionsForPress">
  364. where `type` = 8
  365. <if test=" null != id ">
  366. and `id` = #{id}
  367. </if>
  368. <if test=" null != tenantId ">
  369. and `tenant_id` = #{tenantId}
  370. </if>
  371. <if test=" null != type ">
  372. and `type` = #{type}
  373. </if>
  374. <if test=" null != coverImg ">
  375. and `cover_img` like concat('%', #{coverImg},'%')
  376. </if>
  377. <if test=" null != title and ''!=title">
  378. and `title` like concat('%', #{title},'%')
  379. </if>
  380. <if test=" null != subTitle ">
  381. and `sub_title` like concat('%', #{subTitle},'%')
  382. </if>
  383. <if test=" null != salePrice ">
  384. and `sale_price` = #{salePrice}
  385. </if>
  386. <if test=" null != usePrice ">
  387. and `use_price` = #{usePrice}
  388. </if>
  389. <if test=" null != useLimitQuantity ">
  390. and `use_limit_quantity` = #{useLimitQuantity}
  391. </if>
  392. <if test=" null != sendType ">
  393. and `send_type` = #{sendType}
  394. </if>
  395. <if test=" null != validType ">
  396. and `valid_type` = #{validType}
  397. </if>
  398. <if test=" null != validStartDate ">
  399. and `valid_start_date` = #{validStartDate}
  400. </if>
  401. <if test=" null != validEndDate ">
  402. and `valid_end_date` = #{validEndDate}
  403. </if>
  404. <if test=" null != validDays ">
  405. and `valid_days` = #{validDays}
  406. </if>
  407. <if test=" null != detail ">
  408. and `detail` like concat('%', #{detail},'%')
  409. </if>
  410. <if test=" null != price ">
  411. and `price` = #{price}
  412. </if>
  413. <if test=" null != unit ">
  414. and `unit` = #{unit}
  415. </if>
  416. <if test=" null != remainInventory ">
  417. and `remain_inventory` = #{remainInventory}
  418. </if>
  419. <if test=" null != inventory ">
  420. and `inventory` = #{inventory}
  421. </if>
  422. <if test=" null != remark ">
  423. and `remark` like concat('%', #{remark},'%')
  424. </if>
  425. <if test=" null != status">
  426. and `status` = #{status}
  427. </if>
  428. <if test=" null != startdate and null!=enddate">
  429. and `create_date` between #{startdate} and #{enddate}
  430. </if>
  431. <if test=" null != updateDate ">
  432. and `update_date` = #{updateDate}
  433. </if>
  434. <if test=" null != business ">
  435. and `business` = #{business}
  436. </if>
  437. <if test=" null != supportTransfer ">
  438. and `support_transfer` = #{supportTransfer}
  439. </if>
  440. <if test=" null != subsidyType ">
  441. and `subsidy_type` = #{subsidyType}
  442. </if>
  443. <if test=" null != subsidyNum ">
  444. and `subsidy_num` = #{subsidyNum}
  445. </if>
  446. <if test=" null != pressLimitNum ">
  447. and `press_limit_num` = #{pressLimitNum}
  448. </if>
  449. <if test=" null != pressLimitHours ">
  450. and `press_limit_hours` = #{pressLimitHours}
  451. </if>
  452. <if test=" null != ids ">
  453. and id in
  454. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  455. #{idItem}
  456. </foreach>
  457. </if>
  458. <if test=" null != sortColumns">order by ${sortColumns}</if>
  459. </sql>
  460. <select id="findPressList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  461. select
  462. <include refid="allColumns"/>
  463. from wx_coupon
  464. <include refid="dynamicWhereConditionsForPress"/>
  465. </select>
  466. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  467. <id column="id" jdbcType="BIGINT" property="id"/>
  468. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  469. <result column="type" jdbcType="INTEGER" property="type"/>
  470. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  471. <result column="title" jdbcType="VARCHAR" property="title"/>
  472. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  473. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  474. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  475. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  476. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  477. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  478. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  479. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  480. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  481. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  482. <result column="price" jdbcType="INTEGER" property="price"/>
  483. <result column="unit" jdbcType="INTEGER" property="unit"/>
  484. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  485. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  486. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  487. <result column="status" jdbcType="INTEGER" property="status"/>
  488. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  489. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  490. <result column="business" jdbcType="INTEGER" property="business"/>
  491. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  492. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  493. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  494. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  495. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  496. <result column="xtime" property="xtime"/>
  497. <result column="xcount" property="xcount"/>
  498. <result column="sale_count" property="saleCount"/>
  499. <result column="transfer_count" property="transferCount"/>
  500. <result column="sale_amount" property="saleAmount"/>
  501. <result column="sum_payment" property="sumPayment"/>
  502. <result column="backpay_count" property="backpayCount"/>
  503. <collection column="{productId=id}" property="merchantVoList"
  504. ofType="com.iformall.domain.vo.WxMerchantVo"
  505. javaType="java.util.List"
  506. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList" >
  507. </collection>
  508. </resultMap>
  509. <select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  510. select
  511. <include refid="allColumns"/>
  512. from wx_coupon
  513. where id = #{id}
  514. </select>
  515. <update id="reduceInventory">
  516. update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number}
  517. </update>
  518. <update id="offExpiriedCouponByValidDate">
  519. update wx_coupon SET status = 1, update_date = now()
  520. where status = 0 and valid_type = 1 and valid_end_date &lt; now()
  521. </update>
  522. <update id="offExpiriedCouponByMerchantStatus">
  523. update wx_coupon c
  524. SET c.status = 1, c.update_date = now()
  525. where c.status = 0 and
  526. (select count(*) from wx_coupon_merchant cm, wx_merchant m
  527. where m.id = cm.merchant_id
  528. and c.id = cm.product_id
  529. and cm.status = 0
  530. and m.status = 1) = 0
  531. </update>
  532. <select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  533. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(ci.sale_amount) xcount from wx_card_info ci
  534. left join wx_coupon c on c.id = ci.coupon_id
  535. where c.type = 100
  536. and ci.create_date between #{startdate} and #{enddate}
  537. group by xtime
  538. </select>
  539. <select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  540. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(wcs.payment) xcount from wx_card_info ci
  541. left join wx_coupon c on c.id = ci.coupon_id
  542. left join wx_card_spend wcs on wcs.card_id = ci.id
  543. where c.type = 100
  544. and ci.create_date between #{startdate} and #{enddate}
  545. group by xtime
  546. </select>
  547. <select id="findSaleCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  548. select count(co.id)
  549. from wx_card_info ci
  550. left join wx_coupon c on c.id = ci.coupon_id
  551. left join wx_coupon_order co on co.id = ci.id
  552. where c.type = 100
  553. and c.create_date between #{startdate} and #{enddate}
  554. </select>
  555. <select id="findTranCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  556. select count(distinct wcs.coupon_order_id) from wx_card_info ci
  557. left join wx_coupon c on c.id = ci.coupon_id
  558. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  559. where c.type = 100 and c.create_date between #{startdate} and #{enddate}
  560. </select>
  561. <select id="findSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  562. select sum(subsidy_num) from wx_coupon c
  563. where c.type = 100 and c.create_date between #{startdate} and #{enddate}
  564. <if test="id != null">
  565. and c.id = #{id}
  566. </if>
  567. </select>
  568. <select id="findCountData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  569. select c.*,
  570. (select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
  571. (select count(distinct wcs.coupon_order_id) from wx_card_info ci
  572. left join wx_coupon wc on wc.id = ci.coupon_id
  573. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  574. where wc.id = c.id) as transfer_count,
  575. (select sum(ci.sale_amount) from wx_card_info ci
  576. left join wx_coupon wc on wc.id = ci.coupon_id
  577. where wc.id = c.id) as sale_amount,
  578. (select sum(wcs.payment) from wx_card_info ci
  579. left join wx_coupon wc on wc.id = ci.coupon_id
  580. left join wx_card_spend wcs on wcs.card_id = ci.id
  581. where c.type = 100
  582. and wc.id = c.id) as sum_payment
  583. from wx_coupon c where 1=1
  584. <if test="id != null">
  585. and c.id = #{id}
  586. </if>
  587. order by status asc,create_date desc
  588. </select>
  589. <select id="findCouponData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  590. select c.*,
  591. (select count(distinct wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
  592. (select count(distinct wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 1 and wc.id = c.id) as payment_count,
  593. (select count(distinct wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count
  594. from wx_coupon c where c.type not in(8,9,100)
  595. <if test=" 1 == type ">
  596. and c.sale_price > 0
  597. </if>
  598. <if test=" 2 == type ">
  599. and c.sale_price = 0
  600. </if>
  601. <if test="id != null">
  602. and c.id = #{id}
  603. </if>
  604. order by status asc,create_date desc
  605. </select>
  606. <select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  607. select c.*,
  608. (select count(wop.id) from wx_coupon wc
  609. left join wx_order wo on wo.product_id = wc.id
  610. left join wx_order_press wop on wop.order_id = wo.id
  611. where wop.first = 1 and wc.id = c.id) as press_count,
  612. (select count(wo.id) from wx_coupon wc
  613. left join wx_order wo on wo.product_id = wc.id
  614. where wo.order_status = 7 and wc.id = c.id) as press_succ_count,
  615. (select count(wop.id) from wx_coupon wc
  616. left join wx_order wo on wo.product_id = wc.id
  617. left join wx_order_press wop on wop.order_id = wo.id
  618. where wc.id = c.id) as join_count,
  619. round(
  620. (select count(wco.id) xcount from wx_coupon wc
  621. left join wx_coupon_order wco on wco.coupon_id = wc.id
  622. where wc.type = 8 and wco.coupon_order_status = 1
  623. and wc.id = c.id)
  624. /
  625. (select count(wop.id) from wx_coupon wc
  626. left join wx_order wo on wo.product_id = wc.id
  627. left join wx_order_press wop on wop.order_id = wo.id
  628. where wop.first = 1 and wc.id = c.id)
  629. *100,2) as payment_rate,
  630. (select sum(wc.subsidy_num) from wx_coupon wc
  631. left join wx_order wo on wo.product_id = wc.id
  632. where wo.order_status = 7 and wc.id = c.id) as sum_subsidy
  633. from wx_coupon c where c.type = 8
  634. <if test="id != null">
  635. and c.id = #{id}
  636. </if>
  637. order by status asc,create_date desc
  638. </select>
  639. <!--
  640. <select id="findCouponSendCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  641. select DATE_FORMAT(c.create_time,'%Y-%m-%d') xtime,count(id) xcount from wx_coupon_action_log c
  642. where c.create_time between #{startdate} and #{enddate}
  643. group by xtime
  644. </select>
  645. <select id="findCouponGetCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  646. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
  647. left join wx_coupon_order wco on c.id = wco.coupon_id
  648. where 1=1
  649. and wco.create_date between #{startdate} and #{enddate}
  650. and wco.coupon_price = 0
  651. group by xtime
  652. </select>
  653. -->
  654. <select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  655. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
  656. left join wx_coupon_order wco on c.id = wco.coupon_id
  657. where c.type not in(8,9,100)
  658. and wco.create_date between #{startdate} and #{enddate}
  659. group by xtime
  660. </select>
  661. <select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  662. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  663. where c.type not in(8,9,100)
  664. and wco.coupon_id = c.id and wco.coupon_order_status = 1
  665. and wco.create_date between #{startdate} and #{enddate}
  666. group by xtime
  667. </select>
  668. <select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  669. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  670. where c.type not in(8,9,100)
  671. and wco.coupon_id = c.id and wco.coupon_price > 0
  672. and wco.create_date between #{startdate} and #{enddate}
  673. group by xtime
  674. </select>
  675. <select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  676. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  677. where c.type not in(8,9,100)
  678. and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
  679. and wco.create_date between #{startdate} and #{enddate}
  680. group by xtime
  681. </select>
  682. <select id="findSumPriceSaleMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  683. select sum(wco.coupon_price) from wx_coupon c,wx_coupon_order wco
  684. where wco.coupon_id = c.id and wco.coupon_price > 0
  685. and wco.create_date between #{startdate} and #{enddate}
  686. </select>
  687. <select id="findSumPricePayMent" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  688. select sum(wco.coupon_price) from wx_coupon c,wx_coupon_order wco
  689. where wco.coupon_id = c.id and wco.coupon_price > 0 and wco.coupon_order_status = 1
  690. and wco.create_date between #{startdate} and #{enddate}
  691. </select>
  692. <select id="findSumSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  693. select sum(c.subsidy_num) from wx_coupon c,wx_coupon_order wco
  694. where wco.coupon_id = c.id
  695. and wco.create_date between #{startdate} and #{enddate}
  696. </select>
  697. <!--砍价-->
  698. <select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  699. select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount from wx_coupon wc
  700. left join wx_order wo on wo.product_id = wc.id
  701. left join wx_order_press wop on wop.order_id = wo.id
  702. where wc.type = 8 and wop.first = 1 and
  703. wop.create_date between #{startdate} and #{enddate}
  704. group by xtime
  705. </select>
  706. <select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  707. select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount from wx_coupon wc
  708. left join wx_order wo on wo.product_id = wc.id
  709. where wc.type = 8 and wo.order_status = 7
  710. and wo.create_date between #{startdate} and #{enddate}
  711. group by xtime
  712. </select>
  713. <select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  714. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon wc
  715. left join wx_coupon_order wco on wco.coupon_id = wc.id
  716. where wc.type = 8 and wco.coupon_order_status = 1
  717. and wco.create_date between #{startdate} and #{enddate}
  718. group by xtime
  719. </select>
  720. <select id="pressSuccRate" parameterType="com.iformall.domain.po.WxCoupon" resultType="java.lang.String">
  721. select
  722. round(
  723. (select count(wo.id) from wx_coupon wc
  724. left join wx_order wo on wo.product_id = wc.id
  725. where wo.order_status = 7 and wc.type = 8
  726. and wo.create_date between #{startdate} and #{enddate})
  727. /
  728. (select count(wop.id) from wx_coupon wc
  729. left join wx_order wo on wo.product_id = wc.id
  730. left join wx_order_press wop on wop.order_id = wo.id
  731. where wop.first = 1 and wc.type = 8
  732. and wop.create_date between #{startdate} and #{enddate})
  733. * 100
  734. ,2)
  735. </select>
  736. <select id="sumJoin" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  737. select count(wop.id) from wx_coupon wc
  738. left join wx_order wo on wo.product_id = wc.id
  739. left join wx_order_press wop on wop.order_id = wo.id
  740. where wc.type = 8
  741. and wop.create_date between #{startdate} and #{enddate}
  742. </select>
  743. </mapper>