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.
 
 
 
 
 

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