25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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