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.
 
 
 
 
 

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