Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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