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.
 
 
 
 
 

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