25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

842 satır
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. <result column="approval_type" property="approvalType"/>
  46. </resultMap>
  47. <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo">
  48. <id column="id" jdbcType="BIGINT" property="id"/>
  49. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  50. <result column="type" jdbcType="INTEGER" property="type"/>
  51. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  52. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  53. <result column="title" jdbcType="VARCHAR" property="title"/>
  54. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  55. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  56. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  57. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  58. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  59. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  60. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  61. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  62. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  63. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  64. <result column="price" jdbcType="INTEGER" property="price"/>
  65. <result column="unit" jdbcType="INTEGER" property="unit"/>
  66. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  67. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  68. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  69. <result column="status" jdbcType="INTEGER" property="status"/>
  70. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  71. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  72. <result column="business" jdbcType="INTEGER" property="business"/>
  73. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  74. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  75. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  76. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  77. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  78. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  79. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  80. <result column="sale_count" property="saleCount"/>
  81. <result column="transfer_count" property="transferCount"/>
  82. <result column="sale_amount" property="saleAmount"/>
  83. <result column="sum_payment" property="sumPayment"/>
  84. <result column="press_count" property="pressSendCount"/>
  85. <result column="press_succ_count" property="pressSuccCount"/>
  86. <result column="join_count" property="pressJoinCount"/>
  87. <result column="sum_subsidy" property="sumSubsidy"/>
  88. <result column="payment_rate" property="paymentRate"/>
  89. <result column="change_rate" property="changeRate"/>
  90. </resultMap>
  91. <sql id="allColumns">
  92. `id`,`tenant_id`,`type`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`,
  93. `valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`,
  94. `remark`,`status`,`create_date`,`update_date`,`business`,`sub_business`,`support_transfer`,`subsidy_num`,`subsidy_type`,
  95. `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`put_apply_status`,`stock_apply_status`,`cancle_apply_status`,`conditions`,approval_type
  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=" 1 == filterCanPut ">
  199. and `credit_refund` = #{creditRefund}
  200. </if>
  201. <if test=" null != ids ">
  202. and id in
  203. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  204. #{idItem}
  205. </foreach>
  206. </if>
  207. <if test=" null != notinTypes ">
  208. and type not in
  209. <foreach collection="notinTypes" index="index" item="typeItem" open="(" separator="," close=")">
  210. #{typeItem}
  211. </foreach>
  212. </if>
  213. <if test=" null != sortColumns">order by ${sortColumns}</if>
  214. </sql>
  215. <select id="findList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  216. select
  217. <include refid="allColumns"/>
  218. from wx_coupon
  219. <include refid="dynamicWhereConditions"/>
  220. </select>
  221. <update id="updateStockAndValidDate" parameterType="com.iformall.domain.po.WxCoupon">
  222. update wx_coupon
  223. SET
  224. `remain_inventory` = #{remainInventory}, `inventory` = #{inventory},
  225. `valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays}
  226. WHERE `tenant_id` = #{tenantId} and id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory}
  227. </update>
  228. <sql id="dynamicWhereConditionsForCoupon">
  229. where is_del = 0
  230. <if test=" null != targetAd ">
  231. and 0 = (select count(*) from wx_coupon_channel cc
  232. where c.`id` = cc.coupon_id
  233. and cc.status = 0
  234. and cc.target_ad = #{targetAd})
  235. </if>
  236. <if test=" null != id ">
  237. and c.`id` = #{id}
  238. </if>
  239. <if test=" null != tenantId ">
  240. and c.`tenant_id` = #{tenantId}
  241. </if>
  242. <if test=" null == type and null == types">
  243. and c.`type` &lt; 7
  244. </if>
  245. <if test=" null != type ">
  246. and c.`type` = #{type}
  247. </if>
  248. <if test=" null != coverImg ">
  249. and c.`cover_img` like concat('%', #{coverImg},'%')
  250. </if>
  251. <if test=" null != title and ''!=title">
  252. and c.`title` like concat('%', #{title},'%')
  253. </if>
  254. <if test=" null != subTitle ">
  255. and c.`sub_title` like concat('%', #{subTitle},'%')
  256. </if>
  257. <if test=" null != salePrice ">
  258. and c.`sale_price` = #{salePrice}
  259. </if>
  260. <if test=" null != usePrice ">
  261. and c.`use_price` = #{usePrice}
  262. </if>
  263. <if test=" null != useLimitQuantity ">
  264. and c.`use_limit_quantity` = #{useLimitQuantity}
  265. </if>
  266. <if test=" null != sendType ">
  267. and c.`send_type` = #{sendType}
  268. </if>
  269. <if test=" null != validType ">
  270. and c.`valid_type` = #{validType}
  271. </if>
  272. <if test=" null != validStartDate ">
  273. and c.`valid_start_date` = #{validStartDate}
  274. </if>
  275. <if test=" null != validEndDate ">
  276. and c.`valid_end_date` = #{validEndDate}
  277. </if>
  278. <if test=" null != validDays ">
  279. and c.`valid_days` = #{validDays}
  280. </if>
  281. <if test=" null != detail ">
  282. and c.`detail` like concat('%', #{detail},'%')
  283. </if>
  284. <if test=" null != price ">
  285. and c.`price` = #{price}
  286. </if>
  287. <if test=" null != unit ">
  288. and c.`unit` = #{unit}
  289. </if>
  290. <if test=" null != remainInventory ">
  291. and c.`remain_inventory` = #{remainInventory}
  292. </if>
  293. <if test=" null != inventory ">
  294. and c.`inventory` = #{inventory}
  295. </if>
  296. <if test=" null != remark ">
  297. and c.`remark` like concat('%', #{remark},'%')
  298. </if>
  299. <if test=" null != status">
  300. and c.`status` = #{status}
  301. </if>
  302. <if test=" null != startdate and null!=enddate">
  303. and c.`create_date` between #{startdate} and #{enddate}
  304. </if>
  305. <if test=" null != updateDate ">
  306. and c.`update_date` = #{updateDate}
  307. </if>
  308. <if test=" null != business ">
  309. and c.`business` = #{business}
  310. </if>
  311. <if test=" null != subBusiness ">
  312. and `sub_business` = #{subBusiness}
  313. </if>
  314. <if test=" null != supportTransfer ">
  315. and c.`support_transfer` = #{supportTransfer}
  316. </if>
  317. <if test=" null != subsidyType ">
  318. and c.`subsidy_type` = #{subsidyType}
  319. </if>
  320. <if test=" null != subsidyNum ">
  321. and c.`subsidy_num` = #{subsidyNum}
  322. </if>
  323. <if test=" null != pressLimitNum ">
  324. and c.`press_limit_num` = #{pressLimitNum}
  325. </if>
  326. <if test=" null != pressLimitHours ">
  327. and c.`press_limit_hours` = #{pressLimitHours}
  328. </if>
  329. <if test=" null != autoRefund ">
  330. and c.`auto_refund` = #{autoRefund}
  331. </if>
  332. <!--如果配置了审批模板,需要过滤投放审批状态-->
  333. <if test="0 != filterCanPut or null ==filterCanPut ">
  334. <if test=" null != pressModelId and 0l != pressModelId">
  335. and if(type=8,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}) ,1=1)
  336. </if>
  337. <if test=" null != groupModelId and 0l != groupModelId">
  338. and if(type=9,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
  339. </if>
  340. <if test=" null != cardModelId and 0l != cardModelId">
  341. and if(type=100,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
  342. </if>
  343. <if test=" null != couponModelId and 0l != couponModelId">
  344. and if(type !=8 and type !=9 and type!=100,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
  345. </if>
  346. </if>
  347. <if test=" null != ids ">
  348. and c.id in
  349. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  350. #{idItem}
  351. </foreach>
  352. </if>
  353. <if test=" null != types ">
  354. and c.type in
  355. <foreach collection="types" index="index" item="typesItem" open="(" separator="," close=")">
  356. #{typesItem}
  357. </foreach>
  358. </if>
  359. <if test=" null != sortColumns">order by ${sortColumns}</if>
  360. </sql>
  361. <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  362. select
  363. <include refid="allColumns"/>
  364. from wx_coupon c
  365. <include refid="dynamicWhereConditionsForCoupon"/>
  366. <if test="null != limitStart and null != limitEnd">
  367. limit #{limitStart},#{limitEnd}
  368. </if>
  369. </select>
  370. <select id="findCouponListCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Integer">
  371. select
  372. count(*)
  373. from wx_coupon c
  374. <include refid="dynamicWhereConditionsForCoupon"/>
  375. </select>
  376. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  377. <id column="id" jdbcType="BIGINT" property="id"/>
  378. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  379. <result column="type" jdbcType="INTEGER" property="type"/>
  380. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  381. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  382. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  383. <result column="title" jdbcType="VARCHAR" property="title"/>
  384. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  385. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  386. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  387. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  388. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  389. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  390. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  391. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  392. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  393. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  394. <result column="price" jdbcType="INTEGER" property="price"/>
  395. <result column="unit" jdbcType="INTEGER" property="unit"/>
  396. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  397. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  398. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  399. <result column="status" jdbcType="INTEGER" property="status"/>
  400. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  401. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  402. <result column="business" jdbcType="INTEGER" property="business"/>
  403. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  404. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  405. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  406. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  407. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  408. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  409. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  410. <collection column="{productId=id}" property="merchantVoList"
  411. ofType="com.iformall.domain.vo.WxMerchantVo"
  412. javaType="java.util.List"
  413. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList">
  414. </collection>
  415. </resultMap>
  416. <select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  417. select
  418. <include refid="allColumns"/>
  419. from wx_coupon
  420. where id = #{id}
  421. </select>
  422. <update id="reduceInventory">
  423. update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number}
  424. </update>
  425. <update id="backInventory">
  426. update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory}
  427. </update>
  428. <update id="offExpiriedCouponByValidDate">
  429. update wx_coupon SET status = 1, update_date = now()
  430. where status = 0 and valid_type = 1 and valid_end_date &lt; now()
  431. </update>
  432. <update id="offExpiriedCouponByMerchantStatus">
  433. update wx_coupon c
  434. SET c.status = 1, c.update_date = now()
  435. where c.status = 0 and
  436. (select count(*) from wx_coupon_merchant cm, wx_merchant m
  437. where m.id = cm.merchant_id
  438. and c.id = cm.product_id
  439. and cm.status = 0
  440. and m.status = 1) = 0
  441. </update>
  442. <select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon"
  443. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  444. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(round(ci.sale_amount/100,2)) xcount from wx_card_info ci
  445. left join wx_coupon c on c.id = ci.coupon_id
  446. where c.type = 100
  447. and ci.create_date between #{startdate} and #{enddate}
  448. group by xtime
  449. </select>
  450. <select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon"
  451. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  452. select DATE_FORMAT(wcs.create_date,'%Y-%m-%d') xtime,sum(round(wcs.real_payment/100,2)) xcount from wx_card_info ci
  453. left join wx_coupon c on c.id = ci.coupon_id
  454. left join wx_card_spend wcs on wcs.card_id = ci.id
  455. where c.type = 100
  456. and wcs.create_date between #{startdate} and #{enddate}
  457. group by xtime
  458. </select>
  459. <select id="findSaleCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  460. select count(co.id)
  461. from wx_card_info ci
  462. left join wx_coupon c on c.id = ci.coupon_id
  463. left join wx_coupon_order co on co.id = ci.id
  464. where c.type = 100
  465. and co.create_date between #{startdate} and #{enddate}
  466. </select>
  467. <select id="findTranCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  468. select count(distinct wcs.coupon_order_id) from wx_card_info ci
  469. left join wx_coupon c on c.id = ci.coupon_id
  470. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  471. where c.type = 100 and wcs.create_date between #{startdate} and #{enddate}
  472. </select>
  473. <select id="findSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  474. select sum(round(sc.subsidy/100,2)) from wx_card_info ci
  475. left join wx_coupon c on c.id = ci.coupon_id
  476. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  477. where c.type = 100 and sc.create_date between #{startdate} and #{enddate}
  478. </select>
  479. <select id="findCountData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  480. select c.*,
  481. IFNULL(round((select sum(wcs.real_payment) from wx_card_info ci
  482. left join wx_coupon wc on wc.id = ci.coupon_id
  483. left join wx_card_spend wcs on wcs.card_id = ci.id
  484. where wc.id = c.id)/(select sum(ci.sale_amount) from wx_card_info ci
  485. left join wx_coupon wc on wc.id = ci.coupon_id
  486. where wc.id = c.id)*100,2),0) payment_rate,
  487. (select count(wco.id) from wx_coupon wc
  488. left join wx_coupon_order wco on wc.id = wco.coupon_id
  489. where wc.id = c.id) as sale_count,
  490. (select count(distinct wcs.coupon_order_id) from wx_card_info ci
  491. left join wx_coupon wc on wc.id = ci.coupon_id
  492. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  493. where wc.id = c.id) as transfer_count,
  494. (select sum(ci.sale_amount) from wx_card_info ci
  495. left join wx_coupon wc on wc.id = ci.coupon_id
  496. where wc.id = c.id) as sale_amount,
  497. (select sum(wcs.real_payment) from wx_card_info ci
  498. left join wx_coupon wc on wc.id = ci.coupon_id
  499. left join wx_card_spend wcs on wcs.card_id = ci.id
  500. where wc.id = c.id) as sum_payment,
  501. (select sum(sc.subsidy) from wx_card_info ci
  502. left join wx_coupon wc on wc.id = ci.coupon_id
  503. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  504. where wc.id = c.id) as sum_subsidy
  505. from wx_coupon c where c.type = 100
  506. <if test="title != null and title !=''">
  507. and c.title like concat('%', #{title},'%')
  508. </if>
  509. <if test="id != null">
  510. and c.id = #{id}
  511. </if>
  512. <if test=" null != sortColumns">order by ${sortColumns}</if>
  513. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  514. </select>
  515. <select id="findCouponData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  516. select c.*,
  517. IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  518. wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id
  519. = c.id)*100,2),0) payment_rate,
  520. (select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
  521. (select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  522. wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
  523. (select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  524. wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
  525. (select sum(sc.subsidy) from wx_coupon wc
  526. left join wx_coupon_order wo on wo.coupon_id = wc.id
  527. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  528. where wc.id = c.id) as sum_subsidy
  529. from wx_coupon c where c.type not in(8,9,100)
  530. <if test=" 1 == type ">
  531. and c.sale_price > 0
  532. </if>
  533. <if test=" 2 == type ">
  534. and c.sale_price = 0
  535. </if>
  536. <if test="title != null and title != ''">
  537. and c.title like concat('%', #{title},'%')
  538. </if>
  539. <if test="id != null">
  540. and c.id = #{id}
  541. </if>
  542. <if test=" null != sortColumns">order by ${sortColumns}</if>
  543. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  544. </select>
  545. <select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  546. select c.id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`,
  547. IFNULL(round((select count(o.id) from wx_order o where o.tenant_id = '1006' and o.product_id = c.id and o.order_status = 1)/
  548. (select count(op.id) from wx_order_press op where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id` and op.first = 1 )*100,2),0) change_rate,
  549. (select count(op.id) from wx_order_press op
  550. where op.`tenant_id` = '1006' and op.first = 1 and op.coupon_id = c.id) as press_count,
  551. (select count(o.id) from wx_order o
  552. where o.`tenant_id` = '1006' and o.product_id = c.id and o.order_status = 1) as press_succ_count,
  553. (select count(op.id) from wx_order_press op
  554. where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id`) as join_count,
  555. IFNULL(round((select count(wco.id) xcount from wx_coupon_order wco
  556. where wco.`tenant_id` = '1006' and wco.coupon_id = c.id and wco.coupon_order_status = 1
  557. )/(select count(op.id) from wx_order_press op
  558. where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id` and op.first = 1)
  559. *100,2),0) as payment_rate
  560. from wx_coupon c where c.type = 8
  561. <if test="tenantId != null">
  562. and c.tenant_id=#{tenantId}
  563. </if>
  564. <if test="id != null">
  565. and c.id = #{id}
  566. </if>
  567. <if test="title != null and title != ''">
  568. and c.title like concat('%', #{title},'%')
  569. </if>
  570. <if test=" null != startdate and null!=enddate">
  571. and c.`create_date` between #{startdate} and #{enddate}
  572. </if>
  573. <if test=" null != sortColumns">order by ${sortColumns}</if>
  574. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  575. </select>
  576. <select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon"
  577. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  578. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
  579. left join wx_coupon_order wco on c.id = wco.coupon_id
  580. where c.type not in(8,9,100)
  581. and wco.create_date between #{startdate} and #{enddate}
  582. group by xtime
  583. </select>
  584. <select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  585. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  586. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  587. where c.type not in(8,9,100)
  588. and wco.coupon_id = c.id and wco.coupon_order_status = 1
  589. and wco.update_date between #{startdate} and #{enddate}
  590. group by xtime
  591. </select>
  592. <select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon"
  593. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  594. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  595. where c.type not in(8,9,100)
  596. and wco.coupon_id = c.id and wco.coupon_price > 0
  597. and wco.create_date between #{startdate} and #{enddate}
  598. group by xtime
  599. </select>
  600. <select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  601. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  602. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  603. where c.type not in(8,9,100)
  604. and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
  605. and wco.update_date between #{startdate} and #{enddate}
  606. group by xtime
  607. </select>
  608. <select id="findSumPriceSaleMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  609. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  610. where wco.coupon_id = c.id and wco.coupon_price > 0
  611. and wco.create_date between #{startdate} and #{enddate}
  612. </select>
  613. <select id="findSumPricePayMent" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  614. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  615. where wco.coupon_id = c.id and wco.coupon_price > 0 and wco.coupon_order_status = 1
  616. and wco.update_date between #{startdate} and #{enddate}
  617. </select>
  618. <select id="findSumSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  619. select sum(round(sc.subsidy/100,2)) from wx_coupon c
  620. left join wx_coupon_order wo on wo.coupon_id = c.id
  621. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  622. where c.type not in(8,9,100) and wo.coupon_order_status = 1
  623. and sc.create_date between #{startdate} and #{enddate}
  624. </select>
  625. <!--砍价-->
  626. <select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon"
  627. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  628. select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount from wx_coupon wc
  629. left join wx_order wo on wo.product_id = wc.id
  630. left join wx_order_press wop on wop.order_id = wo.id
  631. where wc.type = 8 and wop.first = 1 and
  632. wop.create_date between #{startdate} and #{enddate}
  633. group by xtime
  634. </select>
  635. <select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon"
  636. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  637. select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount from wx_coupon wc
  638. left join wx_order wo on wo.product_id = wc.id
  639. where wc.type = 8 and wo.order_status = 1
  640. and wo.create_date between #{startdate} and #{enddate}
  641. group by xtime
  642. </select>
  643. <select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon"
  644. 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"
  685. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  686. select DATE_FORMAT(co.create_date,'%Y-%m-%d') xtime,count(co.id) xcount
  687. from wx_card_info ci
  688. left join wx_coupon c on c.id = ci.coupon_id
  689. left join wx_coupon_order co on co.id = ci.id
  690. where c.type = 100
  691. and co.create_date between #{startdate} and #{enddate}
  692. group by xtime
  693. </select>
  694. <select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic"
  695. resultType="com.iformall.domain.po.WxCoupon">
  696. select ct.id as id,wc.id as couponId,
  697. 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`,
  698. 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`,
  699. wc.`remark`,wc.`status`,wc.`create_date`,wc.`update_date`,wc.`business`,wc.`sub_business`,wc.`support_transfer`,wc.`subsidy_num`,wc.`subsidy_type`,
  700. wc.`press_limit_num`, wc.`press_limit_hours`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund`,wc.`conditions`
  701. ,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
  702. wx_coupon wc on wc.id = ct.coupon_id
  703. where ct.`sub_target_id` = #{id}
  704. and ct.status = 0
  705. </select>
  706. <select id="findCouponModel" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  707. select
  708. max(case type when 9 then model_id else 0 end) couponModelId,
  709. max(case type when 10 then model_id else 0 end) cardModelId,
  710. max(case type when 11 then model_id else 0 end) groupModelId,
  711. max(case type when 12 then model_id else 0 end) pressModelId
  712. from wx_flow_config where type in(9,10,11,12) and tenant_id=#{tenantId}
  713. </select>
  714. </mapper>