Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

951 рядки
43 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="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  8. <result column="type" jdbcType="INTEGER" property="type"/>
  9. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  10. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  11. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  12. <result column="title" jdbcType="VARCHAR" property="title"/>
  13. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  14. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  15. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  16. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  17. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  18. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  19. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  20. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  21. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  22. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  23. <result column="price" jdbcType="INTEGER" property="price"/>
  24. <result column="unit" jdbcType="INTEGER" property="unit"/>
  25. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  26. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  27. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  28. <result column="status" jdbcType="INTEGER" property="status"/>
  29. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  30. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  31. <result column="business" jdbcType="INTEGER" property="business"/>
  32. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  33. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  34. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  35. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  36. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  37. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  38. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  39. <result column="credit_price" jdbcType="INTEGER" property="creditPrice"/>
  40. <result column="credit_refund" jdbcType="INTEGER" property="creditRefund"/>
  41. <result column="is_del" property="isDel"/>
  42. <result column="put_apply_status" property="putApplyStatus"/>
  43. <result column="stock_apply_status" property="stockApplyStatus"/>
  44. <result column="cancle_apply_status" property="cancleApplyStatus"/>
  45. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  46. <result column="approval_type" property="approvalType"/>
  47. <result column="password_support" property="passwordSupport"/>
  48. <result column="content_type" property="contentType"/>
  49. <result column="html" property="html"/>
  50. </resultMap>
  51. <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo">
  52. <id column="id" jdbcType="BIGINT" property="id"/>
  53. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  54. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  55. <result column="type" jdbcType="INTEGER" property="type"/>
  56. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  57. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  58. <result column="title" jdbcType="VARCHAR" property="title"/>
  59. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  60. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  61. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  62. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  63. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  64. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  65. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  66. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  67. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  68. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  69. <result column="price" jdbcType="INTEGER" property="price"/>
  70. <result column="unit" jdbcType="INTEGER" property="unit"/>
  71. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  72. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  73. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  74. <result column="status" jdbcType="INTEGER" property="status"/>
  75. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  76. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  77. <result column="business" jdbcType="INTEGER" property="business"/>
  78. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  79. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  80. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  81. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  82. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  83. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  84. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  85. <result column="sale_count" property="saleCount"/>
  86. <result column="transfer_count" property="transferCount"/>
  87. <result column="sale_amount" property="saleAmount"/>
  88. <result column="sum_payment" property="sumPayment"/>
  89. <result column="press_count" property="pressSendCount"/>
  90. <result column="press_succ_count" property="pressSuccCount"/>
  91. <result column="join_count" property="pressJoinCount"/>
  92. <result column="sum_subsidy" property="sumSubsidy"/>
  93. <result column="payment_rate" property="paymentRate"/>
  94. <result column="change_rate" property="changeRate"/>
  95. </resultMap>
  96. <sql id="allColumns">
  97. `id`,`tenant_id`,`parent_tenant_id`,`type`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`,
  98. `valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`,
  99. `remark`,`status`,`create_date`,`update_date`,`business`,`sub_business`,`support_transfer`,`subsidy_num`,`subsidy_type`,
  100. `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`put_apply_status`,`stock_apply_status`,`cancle_apply_status`,
  101. `conditions`,approval_type,content_type
  102. </sql>
  103. <sql id="statusColumns">
  104. `id`,`remain_inventory`,`status`
  105. </sql>
  106. <sql id="dynamicWhereConditions">
  107. where 1 = 1
  108. <if test=" null != id ">
  109. and `id` = #{id}
  110. </if>
  111. <if test=" null != tenantId and '' != tenantId">
  112. and `tenant_id` = #{tenantId}
  113. </if>
  114. <if test=" null != parentTenantId and '' != parentTenantId">
  115. and `parent_tenant_id` = #{parentTenantId}
  116. </if>
  117. <if test=" null != type ">
  118. and `type` = #{type}
  119. </if>
  120. <if test=" null != coverImg ">
  121. and `cover_img` like concat('%', #{coverImg},'%')
  122. </if>
  123. <if test=" null != title and ''!=title">
  124. and `title` like concat('%', #{title},'%')
  125. </if>
  126. <if test=" null != subTitle ">
  127. and `sub_title` like concat('%', #{subTitle},'%')
  128. </if>
  129. <if test=" null != salePrice ">
  130. and `sale_price` = #{salePrice}
  131. </if>
  132. <if test=" null != usePrice ">
  133. and `use_price` = #{usePrice}
  134. </if>
  135. <if test=" null != useLimitQuantity ">
  136. and `use_limit_quantity` = #{useLimitQuantity}
  137. </if>
  138. <if test=" null != sendType ">
  139. and `send_type` = #{sendType}
  140. </if>
  141. <if test=" null != validType ">
  142. and `valid_type` = #{validType}
  143. </if>
  144. <if test=" null != validStartDate ">
  145. and `valid_start_date` = #{validStartDate}
  146. </if>
  147. <if test=" null != validEndDate ">
  148. and `valid_end_date` = #{validEndDate}
  149. </if>
  150. <if test=" null != validDays ">
  151. and `valid_days` = #{validDays}
  152. </if>
  153. <if test=" null != detail ">
  154. and `detail` like concat('%', #{detail},'%')
  155. </if>
  156. <if test=" null != price ">
  157. and `price` = #{price}
  158. </if>
  159. <if test=" null != unit ">
  160. and `unit` = #{unit}
  161. </if>
  162. <if test=" null != remainInventory ">
  163. and `remain_inventory` = #{remainInventory}
  164. </if>
  165. <if test=" null != inventory ">
  166. and `inventory` = #{inventory}
  167. </if>
  168. <if test=" null != remark ">
  169. and `remark` like concat('%', #{remark},'%')
  170. </if>
  171. <if test=" null != status">
  172. and `status` = #{status}
  173. </if>
  174. <if test=" null != startdate and null!=enddate">
  175. and `create_date` between #{startdate} and #{enddate}
  176. </if>
  177. <if test=" null != updateDate ">
  178. and `update_date` = #{updateDate}
  179. </if>
  180. <if test=" null != business ">
  181. and `business` = #{business}
  182. </if>
  183. <if test=" null != subBusiness ">
  184. and `sub_business` = #{subBusiness}
  185. </if>
  186. <if test=" null != supportTransfer ">
  187. and `support_transfer` = #{supportTransfer}
  188. </if>
  189. <if test=" null != subsidyType ">
  190. and `subsidy_type` = #{subsidyType}
  191. </if>
  192. <if test=" null != subsidyNum ">
  193. and `subsidy_num` = #{subsidyNum}
  194. </if>
  195. <if test=" null != pressLimitNum ">
  196. and `press_limit_num` = #{pressLimitNum}
  197. </if>
  198. <if test=" null != pressLimitHours ">
  199. and `press_limit_hours` = #{pressLimitHours}
  200. </if>
  201. <if test=" null != autoRefund ">
  202. and `auto_refund` = #{autoRefund}
  203. </if>
  204. <if test=" null != creditPrice ">
  205. and `credit_price` = #{creditPrice}
  206. </if>
  207. <if test=" null != creditRefund ">
  208. and `credit_refund` = #{creditRefund}
  209. </if>
  210. <if test=" 1 == filterCanPut ">
  211. and `credit_refund` = #{creditRefund}
  212. </if>
  213. <if test=" null != contentType ">
  214. and `content_type` = #{contentType}
  215. </if>
  216. <if test=" null != ids ">
  217. and id in
  218. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  219. #{idItem}
  220. </foreach>
  221. </if>
  222. <if test=" null != notinTypes ">
  223. and type not in
  224. <foreach collection="notinTypes" index="index" item="typeItem" open="(" separator="," close=")">
  225. #{typeItem}
  226. </foreach>
  227. </if>
  228. <if test=" null != sortColumns">order by ${sortColumns}</if>
  229. </sql>
  230. <select id="findList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  231. select
  232. <include refid="allColumns"/>
  233. from wx_coupon
  234. <include refid="dynamicWhereConditions"/>
  235. </select>
  236. <update id="updateStockAndValidDate" parameterType="com.iformall.domain.po.WxCoupon">
  237. update wx_coupon
  238. SET
  239. `remain_inventory` = #{remainInventory}, `inventory` = #{inventory},
  240. `valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays}
  241. WHERE 1=1
  242. <if test=" null != tenantId and '' != tenantId">
  243. and `tenant_id` = #{tenantId}
  244. </if>
  245. <if test=" null != parentTenantId and '' != parentTenantId">
  246. and `parent_tenant_id` = #{parentTenantId}
  247. </if>
  248. and id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory}
  249. </update>
  250. <sql id="dynamicWhereConditionsForCoupon">
  251. where is_del = 0
  252. <if test=" null != targetAd ">
  253. and 0 = (select count(*) from wx_coupon_channel cc
  254. where c.`id` = cc.coupon_id
  255. and cc.status = 0
  256. and cc.target_ad = #{targetAd})
  257. </if>
  258. <if test=" null != id ">
  259. and c.`id` = #{id}
  260. </if>
  261. <if test=" null != tenantId and '' != tenantId">
  262. and c.`tenant_id` = #{tenantId}
  263. </if>
  264. <if test=" null != parentTenantId and '' != parentTenantId">
  265. and c.`parent_tenant_id` = #{parentTenantId}
  266. </if>
  267. <if test=" null == type and null == types">
  268. and c.`type` &lt; 7
  269. </if>
  270. <if test=" null != type ">
  271. and c.`type` = #{type}
  272. </if>
  273. <if test=" null != coverImg ">
  274. and c.`cover_img` like concat('%', #{coverImg},'%')
  275. </if>
  276. <if test=" null != title and ''!=title">
  277. and c.`title` like concat('%', #{title},'%')
  278. </if>
  279. <if test=" null != subTitle ">
  280. and c.`sub_title` like concat('%', #{subTitle},'%')
  281. </if>
  282. <if test=" null != salePrice ">
  283. and c.`sale_price` = #{salePrice}
  284. </if>
  285. <if test=" null != usePrice ">
  286. and c.`use_price` = #{usePrice}
  287. </if>
  288. <if test=" null != useLimitQuantity ">
  289. and c.`use_limit_quantity` = #{useLimitQuantity}
  290. </if>
  291. <if test=" null != sendType ">
  292. and c.`send_type` = #{sendType}
  293. </if>
  294. <if test=" null != validType ">
  295. and c.`valid_type` = #{validType}
  296. </if>
  297. <if test=" null != validStartDate ">
  298. and c.`valid_start_date` = #{validStartDate}
  299. </if>
  300. <if test=" null != validEndDate ">
  301. and c.`valid_end_date` = #{validEndDate}
  302. </if>
  303. <if test=" null != validDays ">
  304. and c.`valid_days` = #{validDays}
  305. </if>
  306. <if test=" null != detail ">
  307. and c.`detail` like concat('%', #{detail},'%')
  308. </if>
  309. <if test=" null != price ">
  310. and c.`price` = #{price}
  311. </if>
  312. <if test=" null != unit ">
  313. and c.`unit` = #{unit}
  314. </if>
  315. <if test=" null != remainInventory ">
  316. and c.`remain_inventory` = #{remainInventory}
  317. </if>
  318. <if test=" null != inventory ">
  319. and c.`inventory` = #{inventory}
  320. </if>
  321. <if test=" null != remark ">
  322. and c.`remark` like concat('%', #{remark},'%')
  323. </if>
  324. <if test=" null != status">
  325. and c.`status` = #{status}
  326. </if>
  327. <if test=" null != startdate and null!=enddate">
  328. and c.`create_date` between #{startdate} and #{enddate}
  329. </if>
  330. <if test=" null != updateDate ">
  331. and c.`update_date` = #{updateDate}
  332. </if>
  333. <if test=" null != business ">
  334. and c.`business` = #{business}
  335. </if>
  336. <if test=" null != subBusiness ">
  337. and `sub_business` = #{subBusiness}
  338. </if>
  339. <if test=" null != supportTransfer ">
  340. and c.`support_transfer` = #{supportTransfer}
  341. </if>
  342. <if test=" null != subsidyType ">
  343. and c.`subsidy_type` = #{subsidyType}
  344. </if>
  345. <if test=" null != subsidyNum ">
  346. and c.`subsidy_num` = #{subsidyNum}
  347. </if>
  348. <if test=" null != pressLimitNum ">
  349. and c.`press_limit_num` = #{pressLimitNum}
  350. </if>
  351. <if test=" null != pressLimitHours ">
  352. and c.`press_limit_hours` = #{pressLimitHours}
  353. </if>
  354. <if test=" null != autoRefund ">
  355. and c.`auto_refund` = #{autoRefund}
  356. </if>
  357. <if test=" null != contentType ">
  358. and c.`content_type` = #{contentType}
  359. </if>
  360. <!--如果配置了审批模板,需要过滤投放审批状态-->
  361. <if test="0 != filterCanPut or null ==filterCanPut ">
  362. <if test=" null != pressModelId and 0l != pressModelId">
  363. and if(type=8,put_apply_status =2 or c.id in (
  364. select coupon_id from wx_coupon_channel
  365. where status=0
  366. <if test=" null != tenantId and '' != tenantId">
  367. and `tenant_id` = #{tenantId}
  368. </if>
  369. <if test=" null != parentTenantId and '' != parentTenantId">
  370. and `parent_tenant_id` = #{parentTenantId}
  371. </if>
  372. ) ,1=1)
  373. </if>
  374. <if test=" null != groupModelId and 0l != groupModelId">
  375. and if(type=9,put_apply_status =2 or c.id in (
  376. select coupon_id from wx_coupon_channel
  377. where status=0
  378. <if test=" null != tenantId and '' != tenantId">
  379. and `tenant_id` = #{tenantId}
  380. </if>
  381. <if test=" null != parentTenantId and '' != parentTenantId">
  382. and `parent_tenant_id` = #{parentTenantId}
  383. </if>
  384. ),1=1)
  385. </if>
  386. <if test=" null != cardModelId and 0l != cardModelId">
  387. and if(type=100,put_apply_status =2 or c.id in (
  388. select coupon_id from wx_coupon_channel
  389. where status=0
  390. <if test=" null != tenantId and '' != tenantId">
  391. and `tenant_id` = #{tenantId}
  392. </if>
  393. <if test=" null != parentTenantId and '' != parentTenantId">
  394. and `parent_tenant_id` = #{parentTenantId}
  395. </if>
  396. ),1=1)
  397. </if>
  398. <if test=" null != couponModelId and 0l != couponModelId">
  399. and if(type !=8 and type !=9 and type!=100,put_apply_status =2 or c.id in (
  400. select coupon_id from wx_coupon_channel
  401. where status=0
  402. <if test=" null != tenantId and '' != tenantId">
  403. and `tenant_id` = #{tenantId}
  404. </if>
  405. <if test=" null != parentTenantId and '' != parentTenantId">
  406. and `parent_tenant_id` = #{parentTenantId}
  407. </if>
  408. ),1=1)
  409. </if>
  410. </if>
  411. <if test=" null != ids ">
  412. and c.id in
  413. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  414. #{idItem}
  415. </foreach>
  416. </if>
  417. <if test=" null != types ">
  418. and c.type in
  419. <foreach collection="types" index="index" item="typesItem" open="(" separator="," close=")">
  420. #{typesItem}
  421. </foreach>
  422. </if>
  423. <if test=" null != sortColumns">order by ${sortColumns}</if>
  424. </sql>
  425. <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  426. select
  427. <include refid="allColumns"/>
  428. from wx_coupon c
  429. <include refid="dynamicWhereConditionsForCoupon"/>
  430. <if test="null != limitStart and null != limitEnd">
  431. limit #{limitStart},#{limitEnd}
  432. </if>
  433. </select>
  434. <select id="findCouponListCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Integer">
  435. select
  436. count(*)
  437. from wx_coupon c
  438. <include refid="dynamicWhereConditionsForCoupon"/>
  439. </select>
  440. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  441. <id column="id" jdbcType="BIGINT" property="id"/>
  442. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  443. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  444. <result column="type" jdbcType="INTEGER" property="type"/>
  445. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  446. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  447. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  448. <result column="title" jdbcType="VARCHAR" property="title"/>
  449. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  450. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  451. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  452. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  453. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  454. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  455. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  456. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  457. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  458. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  459. <result column="price" jdbcType="INTEGER" property="price"/>
  460. <result column="unit" jdbcType="INTEGER" property="unit"/>
  461. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  462. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  463. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  464. <result column="status" jdbcType="INTEGER" property="status"/>
  465. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  466. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  467. <result column="business" jdbcType="INTEGER" property="business"/>
  468. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  469. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  470. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  471. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  472. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  473. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  474. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  475. <result column="content_type" jdbcType="INTEGER" property="contentType"/>
  476. <collection column="{productId=id}" property="merchantVoList"
  477. ofType="com.iformall.domain.vo.WxMerchantVo"
  478. javaType="java.util.List"
  479. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList">
  480. </collection>
  481. </resultMap>
  482. <resultMap id="WxCouponCVoMapL" type="com.iformall.domain.vo.WxCouponCVo">
  483. <id column="id" jdbcType="BIGINT" property="id"/>
  484. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  485. <result column="type" jdbcType="INTEGER" property="type"/>
  486. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  487. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  488. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  489. <result column="title" jdbcType="VARCHAR" property="title"/>
  490. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  491. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  492. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  493. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  494. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  495. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  496. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  497. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  498. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  499. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  500. <result column="price" jdbcType="INTEGER" property="price"/>
  501. <result column="unit" jdbcType="INTEGER" property="unit"/>
  502. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  503. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  504. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  505. <result column="status" jdbcType="INTEGER" property="status"/>
  506. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  507. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  508. <result column="business" jdbcType="INTEGER" property="business"/>
  509. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  510. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  511. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  512. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  513. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  514. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  515. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  516. <result column="content_type" jdbcType="INTEGER" property="contentType"/>
  517. </resultMap>
  518. <select id="findVoDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMap">
  519. select
  520. <include refid="allColumns"/>
  521. from wx_coupon
  522. where id = #{id}
  523. </select>
  524. <select id="findVoStatusDetail" parameterType="java.lang.Long" resultMap="WxCouponCVoMapL">
  525. select id, remain_inventory, status
  526. from wx_coupon
  527. where id = #{id}
  528. </select>
  529. <update id="reduceInventory">
  530. update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory - #{number} &gt;= 0
  531. </update>
  532. <update id="backInventory">
  533. update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory + #{number} &lt;= inventory
  534. </update>
  535. <update id="offExpiriedCouponByValidDate">
  536. update wx_coupon SET status = 1, update_date = now()
  537. where status = 0 and valid_type = 1 and valid_end_date &lt; now()
  538. </update>
  539. <update id="offExpiriedCouponByMerchantStatus">
  540. update wx_coupon c
  541. SET c.status = 1, c.update_date = now()
  542. where c.status = 0 and
  543. (select count(*) from wx_coupon_merchant cm, wx_merchant m
  544. where m.id = cm.merchant_id
  545. and c.id = cm.product_id
  546. and cm.status = 0
  547. and m.status = 1) = 0
  548. </update>
  549. <select id="findSaleMoneyByDate" parameterType="com.iformall.domain.po.WxCoupon"
  550. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  551. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(round(ci.sale_amount/100,2)) xcount from wx_card_info ci
  552. left join wx_coupon c on c.id = ci.coupon_id
  553. where c.type = 100
  554. and ci.create_date between #{startdate} and #{enddate}
  555. group by xtime
  556. </select>
  557. <select id="findPaymentByDate" parameterType="com.iformall.domain.po.WxCoupon"
  558. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  559. select DATE_FORMAT(wcs.create_date,'%Y-%m-%d') xtime,sum(round(wcs.real_payment/100,2)) xcount from wx_card_info ci
  560. left join wx_coupon c on c.id = ci.coupon_id
  561. left join wx_card_spend wcs on wcs.card_id = ci.id
  562. where c.type = 100
  563. and wcs.create_date between #{startdate} and #{enddate}
  564. group by xtime
  565. </select>
  566. <select id="findSaleCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  567. select count(co.id)
  568. from wx_card_info ci
  569. left join wx_coupon c on c.id = ci.coupon_id
  570. left join wx_coupon_order co on co.id = ci.id
  571. where c.type = 100
  572. and co.create_date between #{startdate} and #{enddate}
  573. </select>
  574. <select id="findTranCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  575. select count(distinct wcs.coupon_order_id) from wx_card_info ci
  576. left join wx_coupon c on c.id = ci.coupon_id
  577. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  578. where c.type = 100 and wcs.create_date between #{startdate} and #{enddate}
  579. </select>
  580. <select id="findSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  581. select sum(round(sc.subsidy/100,2)) from wx_card_info ci
  582. left join wx_coupon c on c.id = ci.coupon_id
  583. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  584. where c.type = 100 and sc.create_date between #{startdate} and #{enddate}
  585. </select>
  586. <select id="findCountData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  587. select c.*,
  588. IFNULL(round((select sum(wcs.real_payment) from wx_card_info ci
  589. left join wx_coupon wc on wc.id = ci.coupon_id
  590. left join wx_card_spend wcs on wcs.card_id = ci.id
  591. where wc.id = c.id)/(select sum(ci.sale_amount) from wx_card_info ci
  592. left join wx_coupon wc on wc.id = ci.coupon_id
  593. where wc.id = c.id)*100,2),0) payment_rate,
  594. (select count(wco.id) from wx_coupon wc
  595. left join wx_coupon_order wco on wc.id = wco.coupon_id
  596. where wc.id = c.id) as sale_count,
  597. (select count(distinct wcs.coupon_order_id) from wx_card_info ci
  598. left join wx_coupon wc on wc.id = ci.coupon_id
  599. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  600. where wc.id = c.id) as transfer_count,
  601. (select sum(ci.sale_amount) from wx_card_info ci
  602. left join wx_coupon wc on wc.id = ci.coupon_id
  603. where wc.id = c.id) as sale_amount,
  604. (select sum(wcs.real_payment) from wx_card_info ci
  605. left join wx_coupon wc on wc.id = ci.coupon_id
  606. left join wx_card_spend wcs on wcs.card_id = ci.id
  607. where wc.id = c.id) as sum_payment,
  608. (select sum(sc.subsidy) from wx_card_info ci
  609. left join wx_coupon wc on wc.id = ci.coupon_id
  610. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  611. where wc.id = c.id) as sum_subsidy
  612. from wx_coupon c where c.type = 100
  613. <if test="title != null and title !=''">
  614. and c.title like concat('%', #{title},'%')
  615. </if>
  616. <if test="id != null">
  617. and c.id = #{id}
  618. </if>
  619. <if test=" null != sortColumns">order by ${sortColumns}</if>
  620. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  621. </select>
  622. <select id="findCouponData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  623. select c.*,
  624. IFNULL(round((select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  625. wco.coupon_order_status = 1 and wc.id = c.id)/(select count(wco.id) from wx_coupon_order wco where wco.coupon_id
  626. = c.id)*100,2),0) payment_rate,
  627. (select count(wco.id) from wx_coupon_order wco where wco.coupon_id = c.id) as sale_count,
  628. (select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  629. wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
  630. (select count(wco.id) from wx_coupon wc,wx_coupon_order wco where wco.coupon_id = wc.id and
  631. wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
  632. (select sum(sc.subsidy) from wx_coupon wc
  633. left join wx_coupon_order wo on wo.coupon_id = wc.id
  634. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  635. where wc.id = c.id) as sum_subsidy
  636. from wx_coupon c where c.type not in(8,9,100)
  637. <if test=" 1 == type ">
  638. and c.sale_price > 0
  639. </if>
  640. <if test=" 2 == type ">
  641. and c.sale_price = 0
  642. </if>
  643. <if test="title != null and title != ''">
  644. and c.title like concat('%', #{title},'%')
  645. </if>
  646. <if test="id != null">
  647. and c.id = #{id}
  648. </if>
  649. <if test=" null != sortColumns">order by ${sortColumns}</if>
  650. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  651. </select>
  652. <select id="findPressData" parameterType="com.iformall.domain.po.WxCoupon" resultMap="statisMap">
  653. select c.id, c.`cover_img`,c.`title`,c.`sale_price`,c.`price`,
  654. ifnull(op.press_count,0) as press_count,
  655. ifnull(o.press_succ_count,0) as press_succ_count,
  656. ifnull(op2.join_count,0) as join_count,
  657. ifnull(round(o.press_succ_count/op.press_count*100,2),0) as change_rate,
  658. ifnull(round(cop.xCount/op.press_count*100,2),0) as payment_rate
  659. FROM wx_coupon c
  660. left join (SELECT count(id) as press_count, coupon_id FROM wx_order_press WHERE `tenant_id` = #{tenantId} AND `first` = 1 group by coupon_id) op on op.coupon_id = c.id
  661. left join (SELECT count(id) as press_succ_count, product_id FROM wx_order WHERE `tenant_id` = #{tenantId} AND order_status = 1 group by product_id) o on o.product_id = c.id
  662. left join (SELECT count(id) as join_count, coupon_id FROM wx_order_press WHERE `tenant_id` = #{tenantId} group by coupon_id) op2 on op2.coupon_id = c.id
  663. left join (SELECT count(id) as xCount, coupon_id FROM wx_coupon_order WHERE `tenant_id` = #{tenantId} AND coupon_order_status = 1 group by coupon_id) cop on cop.coupon_id = c.id
  664. where c.type = 8
  665. <if test="tenantId != null">
  666. and c.tenant_id=#{tenantId}
  667. </if>
  668. <if test="id != null">
  669. and c.id = #{id}
  670. </if>
  671. <if test="title != null and title != ''">
  672. and c.title like concat('%', #{title},'%')
  673. </if>
  674. <if test=" null != startdate and null!=enddate">
  675. and c.`create_date` between #{startdate} and #{enddate}
  676. </if>
  677. <if test=" null != sortColumns">order by ${sortColumns}</if>
  678. <if test=" null == sortColumns">order by c.status asc,c.create_date desc</if>
  679. </select>
  680. <select id="findCouponOrderCount" parameterType="com.iformall.domain.po.WxCoupon"
  681. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  682. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c
  683. left join wx_coupon_order wco on c.id = wco.coupon_id
  684. where c.type not in(8,9,100)
  685. and wco.create_date between #{startdate} and #{enddate}
  686. group by xtime
  687. </select>
  688. <select id="findCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  689. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  690. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  691. where c.type not in(8,9,100)
  692. and wco.coupon_id = c.id and wco.coupon_order_status = 1
  693. and wco.update_date between #{startdate} and #{enddate}
  694. group by xtime
  695. </select>
  696. <select id="priceCouponSaleCount" parameterType="com.iformall.domain.po.WxCoupon"
  697. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  698. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  699. where c.type not in(8,9,100)
  700. and wco.coupon_id = c.id and wco.coupon_price > 0
  701. and wco.create_date between #{startdate} and #{enddate}
  702. group by xtime
  703. </select>
  704. <select id="priceCouponPaymentCount" parameterType="com.iformall.domain.po.WxCoupon"
  705. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  706. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon c,wx_coupon_order wco
  707. where c.type not in(8,9,100)
  708. and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
  709. and wco.update_date between #{startdate} and #{enddate}
  710. group by xtime
  711. </select>
  712. <select id="findSumPriceSaleMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  713. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  714. where wco.coupon_id = c.id and wco.coupon_price > 0
  715. and wco.create_date between #{startdate} and #{enddate}
  716. </select>
  717. <select id="findSumPricePayMent" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  718. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  719. where wco.coupon_id = c.id and wco.coupon_price > 0 and wco.coupon_order_status = 1
  720. and wco.update_date between #{startdate} and #{enddate}
  721. </select>
  722. <select id="findSumSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  723. select sum(round(sc.subsidy/100,2)) from wx_coupon c
  724. left join wx_coupon_order wo on wo.coupon_id = c.id
  725. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  726. where c.type not in(8,9,100) and wo.coupon_order_status = 1
  727. and sc.create_date between #{startdate} and #{enddate}
  728. </select>
  729. <!--砍价-->
  730. <select id="pressSendHistory" parameterType="com.iformall.domain.po.WxCoupon"
  731. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  732. select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount from wx_coupon wc
  733. left join wx_order wo on wo.product_id = wc.id
  734. left join wx_order_press wop on wop.order_id = wo.id
  735. where wc.type = 8 and wop.first = 1 and
  736. wop.create_date between #{startdate} and #{enddate}
  737. group by xtime
  738. </select>
  739. <select id="pressSuccHistory" parameterType="com.iformall.domain.po.WxCoupon"
  740. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  741. select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount from wx_coupon wc
  742. left join wx_order wo on wo.product_id = wc.id
  743. where wc.type = 8 and wo.order_status = 1
  744. and wo.create_date between #{startdate} and #{enddate}
  745. group by xtime
  746. </select>
  747. <select id="pressPaymentHistory" parameterType="com.iformall.domain.po.WxCoupon"
  748. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  749. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount from wx_coupon wc
  750. left join wx_coupon_order wco on wco.coupon_id = wc.id
  751. where wc.type = 8 and wco.coupon_order_status = 1
  752. and wco.create_date between #{startdate} and #{enddate}
  753. group by xtime
  754. </select>
  755. <select id="pressSuccRate" parameterType="com.iformall.domain.po.WxCoupon" resultType="java.lang.String">
  756. select
  757. round(
  758. (select count(wo.id) from wx_coupon wc
  759. left join wx_order wo on wo.product_id = wc.id
  760. where wo.order_status = 1 and wc.type = 8
  761. and wo.create_date between #{startdate} and #{enddate}
  762. and wo.tenant_id = #{tenantId}
  763. )
  764. /
  765. (select count(wop.id) from wx_coupon wc
  766. left join wx_order wo on wo.product_id = wc.id
  767. left join wx_order_press wop on wop.order_id = wo.id
  768. where wop.first = 1 and wc.type = 8
  769. and wop.create_date between #{startdate} and #{enddate}
  770. and wo.tenant_id = #{tenantId} and wop.tenant_id = #{tenantId})
  771. * 100
  772. ,2)
  773. </select>
  774. <select id="sumJoin" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  775. select count(wop.id) from wx_coupon wc
  776. left join wx_order wo on wo.product_id = wc.id
  777. left join wx_order_press wop on wop.order_id = wo.id
  778. where wc.type = 8
  779. and wop.create_date between #{startdate} and #{enddate}
  780. </select>
  781. <select id="priceCouponCancelCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  782. select count(c.id) from wx_coupon c
  783. left join wx_coupon_order wco on c.id = wco.coupon_id
  784. where c.type not in(8,9,100)
  785. and wco.create_date between #{startdate} and #{enddate}
  786. and wco.coupon_order_status = 3
  787. </select>
  788. <select id="findSaleCardCountHistory" parameterType="com.iformall.domain.po.WxCoupon"
  789. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  790. select DATE_FORMAT(co.create_date,'%Y-%m-%d') xtime,count(co.id) xcount
  791. from wx_card_info ci
  792. left join wx_coupon c on c.id = ci.coupon_id
  793. left join wx_coupon_order co on co.id = ci.id
  794. where c.type = 100
  795. and co.create_date between #{startdate} and #{enddate}
  796. group by xtime
  797. </select>
  798. <select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic"
  799. resultType="com.iformall.domain.po.WxCoupon">
  800. select ct.id as id,wc.id as couponId,
  801. wc.tenant_id,wc.parent_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`,
  802. 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`,
  803. wc.`remark`,wc.`status`,wc.`create_date`,wc.`update_date`,wc.`business`,wc.`sub_business`,wc.`support_transfer`,wc.`subsidy_num`,wc.`subsidy_type`,
  804. wc.`press_limit_num`, wc.`press_limit_hours`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund`,wc.`conditions`,
  805. wc.title as couponName,wc.`cover_img` as couponPic,wc.`cover_picture` as couponPicture,wc.`detail_picture` as detailPicture,wc.id as couponId
  806. from wx_coupon_channel ct
  807. left join wx_coupon wc on wc.id = ct.coupon_id
  808. where ct.`sub_target_id` = #{id} and ct.status = 0
  809. </select>
  810. <select id="findCouponModel" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  811. select
  812. max(case type when 9 then model_id else 0 end) couponModelId,
  813. max(case type when 10 then model_id else 0 end) cardModelId,
  814. max(case type when 11 then model_id else 0 end) groupModelId,
  815. max(case type when 12 then model_id else 0 end) pressModelId
  816. from wx_flow_config
  817. where type in(9,10,11,12)
  818. <if test=" null != tenantId and '' != tenantId">
  819. and `tenant_id` = #{tenantId}
  820. </if>
  821. <if test=" null != parentTenantId and '' != parentTenantId">
  822. and `parent_tenant_id` = #{parentTenantId}
  823. </if>
  824. </select>
  825. </mapper>