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

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