You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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