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.
 
 
 
 
 

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