Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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