Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

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