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.
 
 
 
 
 

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