Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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