You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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