Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

896 wiersze
39 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 ">
  335. and if(type=8,put_apply_status =2,1=1)
  336. </if>
  337. <if test=" null != groupModelId ">
  338. and if(type=9,put_apply_status =2,1=1)
  339. </if>
  340. <if test=" null != cardModelId ">
  341. and if(type=100,put_apply_status =2,1=1)
  342. </if>
  343. <if test=" null != couponModelId ">
  344. and if(type !=8 and type !=9 and type!=100,put_apply_status =2,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. limit #{limitStart},#{limitEnd}
  367. </select>
  368. <select id="findCouponListCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Integer">
  369. select
  370. count(*)
  371. from wx_coupon c
  372. <include refid="dynamicWhereConditionsForCoupon"/>
  373. </select>
  374. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  375. <id column="id" jdbcType="BIGINT" property="id"/>
  376. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  377. <result column="type" jdbcType="INTEGER" property="type"/>
  378. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  379. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  380. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  381. <result column="title" jdbcType="VARCHAR" property="title"/>
  382. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  383. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  384. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  385. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  386. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  387. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  388. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  389. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  390. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  391. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  392. <result column="price" jdbcType="INTEGER" property="price"/>
  393. <result column="unit" jdbcType="INTEGER" property="unit"/>
  394. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  395. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  396. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  397. <result column="status" jdbcType="INTEGER" property="status"/>
  398. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  399. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  400. <result column="business" jdbcType="INTEGER" property="business"/>
  401. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  402. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  403. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  404. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  405. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  406. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  407. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  408. <collection column="{productId=id}" property="merchantVoList"
  409. ofType="com.iformall.domain.vo.WxMerchantVo"
  410. javaType="java.util.List"
  411. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList">
  412. </collection>
  413. </resultMap>
  414. <select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  415. select
  416. <include refid="allColumns"/>
  417. from wx_coupon
  418. where id = #{id}
  419. </select>
  420. <update id="reduceInventory">
  421. update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number}
  422. </update>
  423. <update id="backInventory">
  424. update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory}
  425. </update>
  426. <update id="offExpiriedCouponByValidDate">
  427. update wx_coupon SET status = 1, update_date = now()
  428. where status = 0 and valid_type = 1 and valid_end_date &lt; now()
  429. </update>
  430. <update id="offExpiriedCouponByMerchantStatus">
  431. update wx_coupon c
  432. SET c.status = 1, c.update_date = now()
  433. where c.status = 0 and
  434. (select count(*) from wx_coupon_merchant cm, wx_merchant m
  435. where m.id = cm.merchant_id
  436. and c.id = cm.product_id
  437. and cm.status = 0
  438. and m.status = 1) = 0
  439. </update>
  440. <select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon"
  441. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  442. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(round(ci.sale_amount/100,2)) xcount from wx_card_info ci
  443. left join wx_coupon c on c.id = ci.coupon_id
  444. where c.type = 100
  445. and ci.create_date between #{startdate} and #{enddate}
  446. group by xtime
  447. </select>
  448. <select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon"
  449. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  450. select DATE_FORMAT(wcs.create_date,'%Y-%m-%d') xtime,sum(round(wcs.real_payment/100,2)) xcount from wx_card_info ci
  451. left join wx_coupon c on c.id = ci.coupon_id
  452. left join wx_card_spend wcs on wcs.card_id = ci.id
  453. where c.type = 100
  454. and wcs.create_date between #{startdate} and #{enddate}
  455. group by xtime
  456. </select>
  457. <select id="findSaleCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  458. select count(co.id)
  459. from wx_card_info ci
  460. left join wx_coupon c on c.id = ci.coupon_id
  461. left join wx_coupon_order co on co.id = ci.id
  462. where c.type = 100
  463. and co.create_date between #{startdate} and #{enddate}
  464. </select>
  465. <select id="findTranCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  466. select count(distinct wcs.coupon_order_id) from wx_card_info ci
  467. left join wx_coupon c on c.id = ci.coupon_id
  468. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  469. where c.type = 100 and wcs.create_date between #{startdate} and #{enddate}
  470. </select>
  471. <select id="findSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  472. select sum(round(sc.subsidy/100,2)) from wx_card_info ci
  473. left join wx_coupon c on c.id = ci.coupon_id
  474. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  475. where c.type = 100 and sc.create_date between #{startdate} and #{enddate}
  476. </select>
  477. <select id="findCountData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  478. select c.*,
  479. IFNULL(round((select sum(wcs.real_payment) from wx_card_info ci
  480. left join wx_coupon wc on wc.id = ci.coupon_id
  481. left join wx_card_spend wcs on wcs.card_id = ci.id
  482. where wc.id = c.id)/(select sum(ci.sale_amount) from wx_card_info ci
  483. left join wx_coupon wc on wc.id = ci.coupon_id
  484. where wc.id = c.id)*100,2),0) payment_rate,
  485. (select count(wco.id) from wx_coupon wc
  486. left join wx_coupon_order wco on wc.id = wco.coupon_id
  487. where wc.id = c.id) as sale_count,
  488. (select count(distinct wcs.coupon_order_id) from wx_card_info ci
  489. left join wx_coupon wc on wc.id = ci.coupon_id
  490. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  491. where wc.id = c.id) as transfer_count,
  492. (select sum(ci.sale_amount) from wx_card_info ci
  493. left join wx_coupon wc on wc.id = ci.coupon_id
  494. where wc.id = c.id) as sale_amount,
  495. (select sum(wcs.real_payment) from wx_card_info ci
  496. left join wx_coupon wc on wc.id = ci.coupon_id
  497. left join wx_card_spend wcs on wcs.card_id = ci.id
  498. where wc.id = c.id) as sum_payment,
  499. (select sum(sc.subsidy) from wx_card_info ci
  500. left join wx_coupon wc on wc.id = ci.coupon_id
  501. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  502. where wc.id = c.id) as sum_subsidy
  503. from wx_coupon c where c.type = 100
  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="findCouponData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  514. select c.*,
  515. IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  516. wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id
  517. = c.id)*100,2),0) payment_rate,
  518. (select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
  519. (select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  520. wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
  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 = 3 and wc.id = c.id) as backpay_count,
  523. (select sum(sc.subsidy) from wx_coupon wc
  524. left join wx_coupon_order wo on wo.coupon_id = wc.id
  525. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  526. where wc.id = c.id) as sum_subsidy
  527. from wx_coupon c where c.type not in(8,9,100)
  528. <if test=" 1 == type ">
  529. and c.sale_price > 0
  530. </if>
  531. <if test=" 2 == type ">
  532. and c.sale_price = 0
  533. </if>
  534. <if test="title != null and title != ''">
  535. and c.title like concat('%', #{title},'%')
  536. </if>
  537. <if test="id != null">
  538. and c.id = #{id}
  539. </if>
  540. <if test=" null != sortColumns">order by ${sortColumns}</if>
  541. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  542. </select>
  543. <select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  544. select c.id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`,
  545. 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)/
  546. (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,
  547. (select count(op.id) from wx_order_press op
  548. where op.`tenant_id` = '1006' and op.first = 1 and op.coupon_id = c.id) as press_count,
  549. (select count(o.id) from wx_order o
  550. where o.`tenant_id` = '1006' and o.product_id = c.id and o.order_status = 1) as press_succ_count,
  551. (select count(op.id) from wx_order_press op
  552. where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id`) as join_count,
  553. IFNULL(round((select count(wco.id) xcount from wx_coupon_order wco
  554. where wco.`tenant_id` = '1006' and wco.coupon_id = c.id and wco.coupon_order_status = 1
  555. )/(select count(op.id) from wx_order_press op
  556. where op.`tenant_id` = '1006' and op.`coupon_id` = c.`id` and op.first = 1)
  557. *100,2),0) as payment_rate
  558. from wx_coupon c where c.type = 8
  559. <if test="tenantId != null">
  560. and c.tenant_id=#{tenantId}
  561. </if>
  562. <if test="id != null">
  563. and c.id = #{id}
  564. </if>
  565. <if test="title != null and title != ''">
  566. and c.title like concat('%', #{title},'%')
  567. </if>
  568. <if test=" null != startdate and null!=enddate">
  569. and c.`create_date` between #{startdate} and #{enddate}
  570. </if>
  571. <if test=" null != sortColumns">order by ${sortColumns}</if>
  572. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  573. </select>
  574. <insert id="delPressData" parameterType="com.iformall.domain.po.WxCoupon">
  575. delete from `wx_coupon_press_data` where tenant_id = #{tenantId}
  576. </insert>
  577. <insert id="insertPressData" parameterType="com.iformall.domain.po.WxCoupon">
  578. insert into `wx_coupon_press_data`
  579. (`id`, `tenant_id`, `cover_img`, `title`, `sale_price`, `price`)
  580. select `id`, `tenant_id`, `cover_img`, `title`, `sale_price`, `price`
  581. from wx_coupon where type = 8 and tenant_id = #{tenantId}
  582. </insert>
  583. <update id="updatePressData1" parameterType="com.iformall.domain.po.WxCoupon">
  584. update wx_coupon_press_data cpd set change_rate =
  585. IFNULL(round((select count(o.id) from wx_order o
  586. where o.tenant_id = #{tenantId} and o.order_status = 1 and o.product_id = cpd.id)/
  587. (select count(wop.id) from wx_order o
  588. left join wx_order_press wop on wop.order_id = o.id
  589. where o.product_id = cpd.id and o.tenant_id = #{tenantId} and wop.first = 1)*100,2),0)
  590. where cpd.tenant_id = #{tenantId}
  591. </update>
  592. <update id="updatePressData2" parameterType="com.iformall.domain.po.WxCoupon">
  593. update wx_coupon_press_data cpd set press_count= (select count(wop.id) from wx_order o
  594. left join wx_order_press wop on wop.order_id = o.id
  595. where o.product_id = cpd.id and o.tenant_id = #{tenantId} and wop.first = 1)
  596. where cpd.tenant_id=#{tenantId}
  597. </update>
  598. <update id="updatePressData3" parameterType="com.iformall.domain.po.WxCoupon">
  599. update wx_coupon_press_data cpd set
  600. press_succ_count =
  601. (select count(o.id) from wx_order o
  602. where o.product_id = cpd.id and o.tenant_id = #{tenantId} and o.order_status = 1)
  603. where cpd.tenant_id=#{tenantId}
  604. </update>
  605. <update id="updatePressData4" parameterType="com.iformall.domain.po.WxCoupon">
  606. update wx_coupon_press_data cpd set join_count =
  607. (select count(wop.id) from wx_order o
  608. left join wx_order_press wop on wop.order_id = o.id
  609. where o.tenant_id = #{tenantId} and o.product_id = cpd.id and o.payment_type = 0)
  610. where cpd.tenant_id=#{tenantId}
  611. </update>
  612. <select id="updatePressData5" parameterType="com.iformall.domain.po.WxCoupon">
  613. update wx_coupon_press_data cpd set payment_rate = round(
  614. (select count(wco.id) xcount from wx_coupon_order wco
  615. where wco.tenant_id = #{tenantId} and wco.coupon_id = cpd.id and wco.coupon_order_status = 1)
  616. /
  617. (select count(wop.id) from wx_order o
  618. left join wx_order_press wop on wop.order_id = o.id
  619. where o.tenant_id = #{tenantId} and o.product_id = cpd.id and wop.first = 1 )
  620. *100,2)
  621. where cpd.tenant_id=#{tenantId}
  622. </select>
  623. <select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon"
  624. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  625. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
  626. left join wx_coupon_order wco on c.id = wco.coupon_id
  627. where c.type not in(8,9,100)
  628. and wco.create_date between #{startdate} and #{enddate}
  629. group by xtime
  630. </select>
  631. <select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  632. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  633. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  634. where c.type not in(8,9,100)
  635. and wco.coupon_id = c.id and wco.coupon_order_status = 1
  636. and wco.update_date between #{startdate} and #{enddate}
  637. group by xtime
  638. </select>
  639. <select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon"
  640. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  641. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  642. where c.type not in(8,9,100)
  643. and wco.coupon_id = c.id and wco.coupon_price > 0
  644. and wco.create_date between #{startdate} and #{enddate}
  645. group by xtime
  646. </select>
  647. <select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  648. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  649. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  650. where c.type not in(8,9,100)
  651. and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
  652. and wco.update_date between #{startdate} and #{enddate}
  653. group by xtime
  654. </select>
  655. <select id="findSumPriceSaleMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  656. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  657. where wco.coupon_id = c.id and wco.coupon_price > 0
  658. and wco.create_date between #{startdate} and #{enddate}
  659. </select>
  660. <select id="findSumPricePayMent" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  661. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  662. where wco.coupon_id = c.id and wco.coupon_price > 0 and wco.coupon_order_status = 1
  663. and wco.update_date between #{startdate} and #{enddate}
  664. </select>
  665. <select id="findSumSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  666. select sum(round(sc.subsidy/100,2)) from wx_coupon c
  667. left join wx_coupon_order wo on wo.coupon_id = c.id
  668. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  669. where c.type not in(8,9,100) and wo.coupon_order_status = 1
  670. and sc.create_date between #{startdate} and #{enddate}
  671. </select>
  672. <!--砍价-->
  673. <select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon"
  674. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  675. select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount from wx_coupon wc
  676. left join wx_order wo on wo.product_id = wc.id
  677. left join wx_order_press wop on wop.order_id = wo.id
  678. where wc.type = 8 and wop.first = 1 and
  679. wop.create_date between #{startdate} and #{enddate}
  680. group by xtime
  681. </select>
  682. <select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon"
  683. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  684. select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount from wx_coupon wc
  685. left join wx_order wo on wo.product_id = wc.id
  686. where wc.type = 8 and wo.order_status = 1
  687. and wo.create_date between #{startdate} and #{enddate}
  688. group by xtime
  689. </select>
  690. <select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon"
  691. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  692. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon wc
  693. left join wx_coupon_order wco on wco.coupon_id = wc.id
  694. where wc.type = 8 and wco.coupon_order_status = 1
  695. and wco.create_date between #{startdate} and #{enddate}
  696. group by xtime
  697. </select>
  698. <select id="pressSuccRate" parameterType="com.iformall.domain.po.WxCoupon" resultType="java.lang.String">
  699. select
  700. round(
  701. (select count(wo.id) from wx_coupon wc
  702. left join wx_order wo on wo.product_id = wc.id
  703. where wo.order_status = 1 and wc.type = 8
  704. and wo.create_date between #{startdate} and #{enddate}
  705. and wo.tenant_id = #{tenantId}
  706. )
  707. /
  708. (select count(wop.id) from wx_coupon wc
  709. left join wx_order wo on wo.product_id = wc.id
  710. left join wx_order_press wop on wop.order_id = wo.id
  711. where wop.first = 1 and wc.type = 8
  712. and wop.create_date between #{startdate} and #{enddate}
  713. and wo.tenant_id = #{tenantId} and wop.tenant_id = #{tenantId})
  714. * 100
  715. ,2)
  716. </select>
  717. <select id="sumJoin" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  718. select count(wop.id) from wx_coupon wc
  719. left join wx_order wo on wo.product_id = wc.id
  720. left join wx_order_press wop on wop.order_id = wo.id
  721. where wc.type = 8
  722. and wop.create_date between #{startdate} and #{enddate}
  723. </select>
  724. <select id="priceCouponCancelCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  725. select count(c.id) from wx_coupon c
  726. left join wx_coupon_order wco on c.id = wco.coupon_id
  727. where c.type not in(8,9,100)
  728. and wco.create_date between #{startdate} and #{enddate}
  729. and wco.coupon_order_status = 3
  730. </select>
  731. <select id="findSaleCardCountHistory" parameterType="com.iformall.domain.po.WxCoupon"
  732. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  733. select DATE_FORMAT(co.create_date,'%Y-%m-%d') xtime,count(co.id) xcount
  734. from wx_card_info ci
  735. left join wx_coupon c on c.id = ci.coupon_id
  736. left join wx_coupon_order co on co.id = ci.id
  737. where c.type = 100
  738. and co.create_date between #{startdate} and #{enddate}
  739. group by xtime
  740. </select>
  741. <select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic"
  742. resultType="com.iformall.domain.po.WxCoupon">
  743. select ct.id as id,wc.id as couponId,
  744. 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`,
  745. 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`,
  746. wc.`remark`,wc.`status`,wc.`create_date`,wc.`update_date`,wc.`business`,wc.`sub_business`,wc.`support_transfer`,wc.`subsidy_num`,wc.`subsidy_type`,
  747. wc.`press_limit_num`, wc.`press_limit_hours`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund`,wc.`conditions`
  748. ,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
  749. wx_coupon wc on wc.id = ct.coupon_id
  750. where ct.`sub_target_id` = #{id}
  751. and ct.status = 0
  752. </select>
  753. <select id="findCouponModel" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  754. select
  755. max(case type when 9 then model_id else 0 end) couponModelId,
  756. max(case type when 10 then model_id else 0 end) cardModelId,
  757. max(case type when 11 then model_id else 0 end) groupModelId,
  758. max(case type when 12 then model_id else 0 end) pressModelId
  759. from wx_flow_config where type in(9,10,11,12) and tenant_id=#{tenantId}
  760. </select>
  761. </mapper>