Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

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