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.
 
 
 
 
 

1637 lines
78 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="coupon_id" jdbcType="BIGINT" property="couponId"/>
  7. <result column="version" jdbcType="INTEGER" property="version"/>
  8. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  9. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  10. <result column="make_merchant_id" jdbcType="BIGINT" property="makeMerchantId"/>
  11. <result column="brand" jdbcType="BIGINT" property="brand"/>
  12. <result column="type" jdbcType="INTEGER" property="type"/>
  13. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  14. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  15. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  16. <result column="title" jdbcType="VARCHAR" property="title"/>
  17. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  18. <result column="item_group" jdbcType="VARCHAR" property="itemGroup"/>
  19. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  20. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  21. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  22. <result column="use_limit_rule" jdbcType="INTEGER" property="useLimitRule"/>
  23. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  24. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  25. <result column="sold_start_time" jdbcType="TIMESTAMP" property="soldStartTime"/>
  26. <result column="sold_end_time" jdbcType="TIMESTAMP" property="soldEndTime"/>
  27. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  28. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  29. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  30. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  31. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  32. <result column="price" jdbcType="INTEGER" property="price"/>
  33. <result column="tail_price" jdbcType="INTEGER" property="tailPrice"/>
  34. <result column="orig_price" jdbcType="INTEGER" property="origPrice"/>
  35. <result column="unit" jdbcType="INTEGER" property="unit"/>
  36. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  37. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  38. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  39. <result column="status" jdbcType="INTEGER" property="status"/>
  40. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  41. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  42. <result column="business" jdbcType="INTEGER" property="business"/>
  43. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  44. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  45. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  46. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  47. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  48. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  49. <result column="press_pay_reduce_stock" jdbcType="INTEGER" property="pressPayReduceStock"/>
  50. <result column="press_support_is_new" jdbcType="INTEGER" property="pressSupportIsNew"/>
  51. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  52. <result column="credit_price" jdbcType="INTEGER" property="creditPrice"/>
  53. <result column="credit_refund" jdbcType="INTEGER" property="creditRefund"/>
  54. <result column="is_del" property="isDel"/>
  55. <result column="put_apply_status" property="putApplyStatus"/>
  56. <result column="stock_apply_status" property="stockApplyStatus"/>
  57. <result column="cancle_apply_status" property="cancleApplyStatus"/>
  58. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  59. <result column="approval_type" property="approvalType"/>
  60. <result column="password_support" property="passwordSupport"/>
  61. <result column="is_recharge" jdbcType="INTEGER" property="isRecharge"/>
  62. <result column="used_password" jdbcType="VARCHAR" property="usedPassword"/>
  63. <result column="card_score_rule" jdbcType="INTEGER" property="cardScoreRule"/>
  64. <result column="content_type" property="contentType"/>
  65. <result column="html" property="html"/>
  66. <result column="source_type" jdbcType="INTEGER" property="sourceType"/>
  67. <result column="merchant_type" jdbcType="INTEGER" property="merchantType"/>
  68. <result column="gift_list" jdbcType="VARCHAR" property="giftList"/>
  69. <result column="product_type" jdbcType="INTEGER" property="productType"/>
  70. <result column="category_id" jdbcType="INTEGER" property="categoryId"/>
  71. <result column="goods_id" jdbcType="VARCHAR" property="goodsId"/>
  72. <result column="product_attrs" jdbcType="VARCHAR" property="productAttrs"/>
  73. <result column="sku_attrs" jdbcType="VARCHAR" property="skuAttrs"/>
  74. <result column="is_after_set_price" jdbcType="INTEGER" property="isAfterSetPrice"/>
  75. <result column="spu_id" jdbcType="VARCHAR" property="spuId"/>
  76. <result column="poi_status" jdbcType="INTEGER" property="poiStatus"/>
  77. <result column="status_desc" jdbcType="VARCHAR" property="statusDesc"/>
  78. <result column="last_status" jdbcType="INTEGER" property="lastStatus"/>
  79. <result column="last_status_desc" jdbcType="VARCHAR" property="lastStatusDesc"/>
  80. </resultMap>
  81. <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo">
  82. <id column="id" jdbcType="BIGINT" property="id"/>
  83. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  84. <result column="version" jdbcType="INTEGER" property="version"/>
  85. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  86. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  87. <result column="make_merchant_id" jdbcType="BIGINT" property="makeMerchantId"/>
  88. <result column="brand" jdbcType="BIGINT" property="brand"/>
  89. <result column="type" jdbcType="INTEGER" property="type"/>
  90. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  91. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  92. <result column="title" jdbcType="VARCHAR" property="title"/>
  93. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  94. <result column="item_group" jdbcType="VARCHAR" property="itemGroup"/>
  95. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  96. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  97. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  98. <result column="use_limit_rule" jdbcType="INTEGER" property="useLimitRule"/>
  99. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  100. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  101. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  102. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  103. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  104. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  105. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  106. <result column="price" jdbcType="INTEGER" property="price"/>
  107. <result column="unit" jdbcType="INTEGER" property="unit"/>
  108. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  109. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  110. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  111. <result column="status" jdbcType="INTEGER" property="status"/>
  112. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  113. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  114. <result column="business" jdbcType="INTEGER" property="business"/>
  115. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  116. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  117. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  118. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  119. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  120. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  121. <result column="press_pay_reduce_stock" jdbcType="INTEGER" property="pressPayReduceStock"/>
  122. <result column="press_support_is_new" jdbcType="INTEGER" property="pressSupportIsNew"/>
  123. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  124. <result column="sale_count" property="saleCount"/>
  125. <result column="transfer_count" property="transferCount"/>
  126. <result column="sale_amount" property="saleAmount"/>
  127. <result column="sum_payment" property="sumPayment"/>
  128. <result column="press_count" property="pressSendCount"/>
  129. <result column="press_succ_count" property="pressSuccCount"/>
  130. <result column="join_count" property="pressJoinCount"/>
  131. <result column="sum_subsidy" property="sumSubsidy"/>
  132. <result column="payment_rate" property="paymentRate"/>
  133. <result column="change_rate" property="changeRate"/>
  134. <result column="source_type" jdbcType="INTEGER" property="sourceType"/>
  135. <result column="merchant_type" jdbcType="INTEGER" property="merchantType"/>
  136. </resultMap>
  137. <sql id="allColumns">
  138. c.`id`,c.`coupon_id`,c.`version`,c.`tenant_id`,c.`parent_tenant_id`,c.`make_merchant_id`,c.`brand`,c.`type`,c.`cover_img`,c.`cover_picture`,c.`detail_picture`,
  139. c.`title`,c.`sub_title`,c.`item_group`,c.`sale_price`,c.`freight_price`,c.`use_price`,c.`use_limit_rule`,c.`use_limit_quantity`,c.`send_type`,
  140. c.`sold_start_time`,c.`sold_end_time`,c.`valid_type`,c.`valid_start_date`,c.`valid_end_date`,c.`valid_days`,c.`detail`,c.`price`,c.tail_price,c.orig_price,c.`unit`,c.`remain_inventory`,c.`inventory`,
  141. c.`remark`,c.`status`,c.`create_date`,c.`update_date`,c.`business`,c.`sub_business`,c.`support_transfer`,c.`subsidy_num`,c.`subsidy_type`,c.`is_after_set_price`,c.`card_score_rule`,
  142. c.`press_limit_num`, c.`press_limit_hours`,c.`press_pay_reduce_stock`,c.`press_support_is_new`, c.`auto_refund`,c.`credit_price`,c.`credit_refund`,c.`put_apply_status`,c.`stock_apply_status`,c.`cancle_apply_status`,
  143. c.`conditions`,c.approval_type,c.content_type,c.source_type,c.merchant_type,c.password_support,c.is_recharge,c.used_password,c.gift_list,c.product_type,c.category_id,c.goods_id
  144. </sql>
  145. <sql id="dynamicWhereConditions">
  146. where version = 0
  147. <if test=" null != id ">
  148. and `id` = #{id}
  149. </if>
  150. <if test=" null != couponId ">
  151. and `coupon_id` = #{couponId}
  152. </if>
  153. <if test=" null != tenantId and '' != tenantId">
  154. and `tenant_id` = #{tenantId}
  155. </if>
  156. <if test=" null != parentTenantId and '' != parentTenantId">
  157. and `parent_tenant_id` = #{parentTenantId}
  158. </if>
  159. <if test=" null != makeMerchantId ">
  160. and `make_merchant_id` = #{makeMerchantId}
  161. </if>
  162. <if test=" null != brand ">
  163. and `brand` = #{brand}
  164. </if>
  165. <if test=" null != type ">
  166. and `type` = #{type}
  167. </if>
  168. <if test=" null != coverImg ">
  169. and `cover_img` like concat('%', #{coverImg},'%')
  170. </if>
  171. <if test=" null != title and ''!=title">
  172. and `title` like concat('%', #{title},'%')
  173. </if>
  174. <if test=" null != subTitle ">
  175. and `sub_title` like concat('%', #{subTitle},'%')
  176. </if>
  177. <if test=" null != salePrice ">
  178. and `sale_price` = #{salePrice}
  179. </if>
  180. <if test=" null != usePrice ">
  181. and `use_price` = #{usePrice}
  182. </if>
  183. <if test=" null != useLimitRule ">
  184. and `use_limit_rule` = #{useLimitRule}
  185. </if>
  186. <if test=" null != useLimitQuantity ">
  187. and `use_limit_quantity` = #{useLimitQuantity}
  188. </if>
  189. <if test=" null != sendType ">
  190. and `send_type` = #{sendType}
  191. </if>
  192. <if test=" null != validType ">
  193. and `valid_type` = #{validType}
  194. </if>
  195. <if test=" null != validStartDate ">
  196. and `valid_start_date` = #{validStartDate}
  197. </if>
  198. <if test=" null != validEndDate ">
  199. and `valid_end_date` = #{validEndDate}
  200. </if>
  201. <if test=" null != validDays ">
  202. and `valid_days` = #{validDays}
  203. </if>
  204. <if test=" null != detail ">
  205. and `detail` like concat('%', #{detail},'%')
  206. </if>
  207. <if test=" null != price ">
  208. and `price` = #{price}
  209. </if>
  210. <if test=" null != unit ">
  211. and `unit` = #{unit}
  212. </if>
  213. <if test=" null != remainInventory ">
  214. and `remain_inventory` = #{remainInventory}
  215. </if>
  216. <if test=" null != inventory ">
  217. and `inventory` = #{inventory}
  218. </if>
  219. <if test=" null != remark ">
  220. and `remark` like concat('%', #{remark},'%')
  221. </if>
  222. <if test=" null != status">
  223. and `status` = #{status}
  224. </if>
  225. <if test=" null != startdate and null!=enddate">
  226. and `create_date` between #{startdate} and #{enddate}
  227. </if>
  228. <if test=" null != updateDate ">
  229. and `update_date` = #{updateDate}
  230. </if>
  231. <if test=" null != business ">
  232. and `business` = #{business}
  233. </if>
  234. <if test=" null != subBusiness ">
  235. and `sub_business` = #{subBusiness}
  236. </if>
  237. <if test=" null != supportTransfer ">
  238. and `support_transfer` = #{supportTransfer}
  239. </if>
  240. <if test=" null != subsidyType ">
  241. and `subsidy_type` = #{subsidyType}
  242. </if>
  243. <if test=" null != subsidyNum ">
  244. and `subsidy_num` = #{subsidyNum}
  245. </if>
  246. <if test=" null != pressLimitNum ">
  247. and `press_limit_num` = #{pressLimitNum}
  248. </if>
  249. <if test=" null != pressLimitHours ">
  250. and `press_limit_hours` = #{pressLimitHours}
  251. </if>
  252. <if test=" null != pressPayReduceStock ">
  253. and `press_pay_reduce_stock` = #{pressPayReduceStock}
  254. </if>
  255. <if test=" null != pressSupportIsNew ">
  256. and `press_support_is_new` = #{pressSupportIsNew}
  257. </if>
  258. <if test=" null != autoRefund ">
  259. and `auto_refund` = #{autoRefund}
  260. </if>
  261. <if test=" null != creditPrice ">
  262. and `credit_price` = #{creditPrice}
  263. </if>
  264. <if test=" null != userCredit ">
  265. and `credit_price` &lt;= #{userCredit}
  266. </if>
  267. <if test=" null != creditRefund ">
  268. and `credit_refund` = #{creditRefund}
  269. </if>
  270. <if test=" 1 == filterCanPut ">
  271. and `credit_refund` = #{creditRefund}
  272. </if>
  273. <if test=" null != contentType ">
  274. and `content_type` = #{contentType}
  275. </if>
  276. <if test=" null != putApplyStatus and putApplyStatus == 2">
  277. and `put_apply_status` = #{putApplyStatus}
  278. </if>
  279. <if test=" null != putApplyStatus and putApplyStatus == -1">
  280. and `put_apply_status` != 2
  281. </if>
  282. <if test=" null != stockApplyStatus ">
  283. and `stock_apply_status` = #{stockApplyStatus}
  284. </if>
  285. <if test=" null != cancleApplyStatus ">
  286. and `cancle_apply_status` = #{cancleApplyStatus}
  287. </if>
  288. <if test=" null != sourceType ">
  289. and `source_type` = #{sourceType}
  290. </if>
  291. <if test=" null != merchantType ">
  292. and `merchant_type` = #{merchantType}
  293. </if>
  294. <if test=" null != giftList">
  295. and JSON_CONTAINS(gift_list,json_array(#{giftList}))
  296. </if>
  297. <if test=" null != isAfterSetPrice">
  298. and `is_after_set_price` = #{isAfterSetPrice}
  299. </if>
  300. <if test=" null != ids ">
  301. and id in
  302. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  303. #{idItem}
  304. </foreach>
  305. </if>
  306. <if test=" null != notinTypes ">
  307. and type not in
  308. <foreach collection="notinTypes" index="index" item="ntypeItem" open="(" separator="," close=")">
  309. #{ntypeItem}
  310. </foreach>
  311. </if>
  312. <if test=" null != types ">
  313. and type in
  314. <foreach collection="types" index="index" item="typeItem" open="(" separator="," close=")">
  315. #{typeItem}
  316. </foreach>
  317. </if>
  318. <if test=" null != couponIds ">
  319. and id in
  320. <foreach collection="couponIds" index="index" item="couponIdsItem" open="(" separator="," close=")">
  321. #{couponIdsItem}
  322. </foreach>
  323. </if>
  324. <if test=" null != sortColumns">order by ${sortColumns}</if>
  325. </sql>
  326. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  327. select <include refid="allColumns"/> ,c.html from wx_coupon c where id = #{id} and tenant_id = #{tenantId}
  328. </select>
  329. <resultMap id="AttrsResultMap" type="com.iformall.domain.po.WxCoupon">
  330. <id column="id" jdbcType="BIGINT" property="id"/>
  331. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  332. <result column="version" jdbcType="INTEGER" property="version"/>
  333. <result column="product_type" jdbcType="INTEGER" property="productType"/>
  334. <result column="category_id" jdbcType="INTEGER" property="categoryId"/>
  335. <result column="product_attrs" jdbcType="VARCHAR" property="productAttrs"/>
  336. <result column="sku_attrs" jdbcType="VARCHAR" property="skuAttrs"/>
  337. </resultMap>
  338. <select id="getAttrsById" parameterType="java.util.HashMap" resultMap="AttrsResultMap">
  339. select id,coupon_id,version,product_type,category_id,product_attrs,sku_attrs
  340. from wx_coupon where id = #{id} and tenant_id = #{tenantId}
  341. </select>
  342. <select id="getPriceAndStock" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  343. select c.id,c.coupon_id,c.version,c.sale_price,c.price,c.remain_inventory,c.inventory,c.credit_price
  344. from wx_coupon c
  345. where c.`version` = 0 and id = #{id} and tenant_id = #{tenantId}
  346. </select>
  347. <select id="batchGetPriceAndStock" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  348. select c.id,c.coupon_id,c.version,c.sale_price,c.price,c.remain_inventory,c.inventory,c.credit_price
  349. from wx_coupon c
  350. where c.`version` = 0 and tenant_id = #{tenantId}
  351. and id in
  352. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  353. #{idItem}
  354. </foreach>
  355. </select>
  356. <select id="findTenantSimpleList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  357. select id,coupon_id,c.version,title,sale_price,use_price,price,tail_price,orig_price,auto_refund,business,subsidy_type,source_type,merchant_type,type,unit,cover_img,
  358. sub_title,item_group,sold_start_time,sold_end_time,valid_type,valid_start_date,valid_end_date,is_after_set_price,card_score_rule
  359. from wx_coupon c
  360. where c.`version` = 0 and c.`tenant_id` = #{tenantId}
  361. <if test=" null != ids ">
  362. and id in
  363. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  364. #{idItem}
  365. </foreach>
  366. </if>
  367. <if test=" null != types ">
  368. and type in
  369. <foreach collection="types" index="index" item="typeItem" open="(" separator="," close=")">
  370. #{typeItem}
  371. </foreach>
  372. </if>
  373. </select>
  374. <select id="findSimpleDetail" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  375. select c.id,c.coupon_id,c.version,c.type,c.cover_img,c.title,c.sub_title,c.item_group,c.sale_price,c.use_price,c.price,c.tail_price,c.orig_price,c.unit,c.detail,c.remark,
  376. c.sold_start_time,c.sold_end_time,c.valid_type,c.valid_start_date,c.valid_end_date,
  377. c.auto_refund,c.business,c.subsidy_type,c.source_type,c.merchant_type,c.content_type,c.gift_list,c.support_transfer,c.subsidy_num,
  378. c.is_after_set_price,c.card_score_rule
  379. from wx_coupon c
  380. where c.`version` = 0 and c.id = #{id}
  381. and c.`tenant_id` = #{tenantId}
  382. </select>
  383. <select id="findCouponCVoDetail" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  384. select c.id,c.coupon_id,c.version,c.type,c.cover_img,c.cover_picture,c.detail_picture,c.title,c.sub_title,c.item_group,c.sale_price,c.use_price,
  385. c.use_limit_rule,c.use_limit_quantity,c.send_type,c.sold_start_time,c.sold_end_time,c.valid_type,c.valid_start_date,c.valid_end_date,
  386. c.valid_days,c.detail,c.price,c.tail_price,c.orig_price,c.unit,c.remain_inventory,c.inventory,c.remark,c.status,c.is_after_set_price,c.card_score_rule,
  387. c.create_date,c.update_date,c.business,c.sub_business,c.support_transfer,c.press_limit_num, c.auto_refund,c.credit_price,c.conditions,c.content_type
  388. from wx_coupon c where c.`version` = 0 and c.id = #{id} and c.`tenant_id` = #{tenantId}
  389. </select>
  390. <select id="findSimpleDetailList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  391. select c.id,c.coupon_id,c.version,c.type,c.cover_img,c.title,c.sub_title,c.item_group,c.sale_price,c.use_price,c.price,c.tail_price,c.orig_price,c.unit,c.detail,c.remark,
  392. c.sold_start_time,c.sold_end_time,c.valid_type,c.valid_start_date,c.valid_end_date,
  393. c.auto_refund,c.business,c.subsidy_type,c.source_type,c.merchant_type,c.content_type,c.is_after_set_price,c.card_score_rule
  394. from wx_coupon c
  395. <include refid="dynamicWhereConditions"/>
  396. </select>
  397. <select id="findIdList" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  398. select id
  399. from wx_coupon c
  400. <include refid="dynamicWhereConditions"/>
  401. </select>
  402. <select id="findSendCouponIds" parameterType="java.util.HashMap" resultType="Long">
  403. select id
  404. from wx_coupon
  405. where `version` = 0 and `tenant_id` = #{tenantId}
  406. and ((valid_type=1
  407. <choose>
  408. <when test="expired == 0">
  409. and <![CDATA[ valid_end_date >= now() ]]>
  410. </when>
  411. <when test="expired == 1">
  412. and <![CDATA[ valid_end_date < now() ]]>
  413. </when>
  414. <otherwise>
  415. </otherwise>
  416. </choose>
  417. )
  418. <choose>
  419. <when test="expired == 0">
  420. or <![CDATA[ valid_type = 2 ]]>
  421. </when>
  422. <when test="expired == 1">
  423. </when>
  424. <otherwise>
  425. or <![CDATA[ valid_type = 2 ]]>
  426. </otherwise>
  427. </choose>
  428. )
  429. </select>
  430. <select id="findSendCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  431. select
  432. c.id,c.coupon_id,c.version,c.remain_inventory, c.use_limit_rule,c.use_limit_quantity, c.inventory, c.valid_start_date, c.valid_end_date,c.valid_type,c.valid_days
  433. from wx_coupon c
  434. where c.`version` = 0 and c.`tenant_id` = #{tenantId}
  435. <if test=" null != ids ">
  436. and id in
  437. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  438. #{idItem}
  439. </foreach>
  440. </if>
  441. </select>
  442. <delete id="deleteById" parameterType="java.util.HashMap">
  443. update wx_coupon set is_del = 1 where id = #{id} and tenant_id = #{tenantId}
  444. </delete>
  445. <select id="findList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  446. select
  447. <include refid="allColumns"/>
  448. from wx_coupon c
  449. <include refid="dynamicWhereConditions"/>
  450. </select>
  451. <update id="updateStockAndValidDate" parameterType="com.iformall.domain.po.WxCoupon">
  452. update wx_coupon
  453. SET
  454. `remain_inventory` = #{remainInventory}, `inventory` = #{inventory},
  455. `valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays}
  456. WHERE id = #{id}
  457. <if test=" null != tenantId and '' != tenantId">
  458. and `tenant_id` = #{tenantId}
  459. </if>
  460. <if test=" null != parentTenantId and '' != parentTenantId">
  461. and `parent_tenant_id` = #{parentTenantId}
  462. </if>
  463. and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory}
  464. </update>
  465. <sql id="dynamicWhereConditionsForCoupon">
  466. <if test=" null != id ">
  467. and c.`id` = #{id}
  468. </if>
  469. <if test=" null != couponId ">
  470. and c.`coupon_id` = #{couponId}
  471. </if>
  472. <if test=" null != tenantId and '' != tenantId">
  473. and c.`tenant_id` = #{tenantId}
  474. </if>
  475. <if test=" null != parentTenantId and '' != parentTenantId">
  476. and c.`parent_tenant_id` = #{parentTenantId}
  477. </if>
  478. <if test=" null != type ">
  479. and c.`type` = #{type}
  480. </if>
  481. <if test=" null != coverImg ">
  482. and c.`cover_img` like concat('%', #{coverImg},'%')
  483. </if>
  484. <if test=" null != title and ''!=title">
  485. and c.`title` like concat('%', #{title},'%')
  486. </if>
  487. <if test=" null != subTitle ">
  488. and c.`sub_title` like concat('%', #{subTitle},'%')
  489. </if>
  490. <if test=" null != salePrice ">
  491. and c.`sale_price` = #{salePrice}
  492. </if>
  493. <if test=" null != usePrice ">
  494. and c.`use_price` = #{usePrice}
  495. </if>
  496. <if test=" null != useLimitRule ">
  497. and c.`use_limit_rule` = #{useLimitRule}
  498. </if>
  499. <if test=" null != useLimitQuantity ">
  500. and c.`use_limit_quantity` = #{useLimitQuantity}
  501. </if>
  502. <if test=" null != sendType ">
  503. and c.`send_type` = #{sendType}
  504. </if>
  505. <if test=" null != validType ">
  506. and c.`valid_type` = #{validType}
  507. </if>
  508. <if test=" null != validStartDate ">
  509. and c.`valid_start_date` = #{validStartDate}
  510. </if>
  511. <if test=" null != validEndDate ">
  512. and c.`valid_end_date` = #{validEndDate}
  513. </if>
  514. <if test=" null != validDays ">
  515. and c.`valid_days` = #{validDays}
  516. </if>
  517. <if test=" null != detail ">
  518. and c.`detail` like concat('%', #{detail},'%')
  519. </if>
  520. <if test=" null != price ">
  521. and c.`price` = #{price}
  522. </if>
  523. <if test=" null != unit ">
  524. and c.`unit` = #{unit}
  525. </if>
  526. <if test=" null != remainInventory ">
  527. and c.`remain_inventory` = #{remainInventory}
  528. </if>
  529. <if test=" null != inventory ">
  530. and c.`inventory` = #{inventory}
  531. </if>
  532. <if test=" null != remark ">
  533. and c.`remark` like concat('%', #{remark},'%')
  534. </if>
  535. <if test=" null != status">
  536. and c.`status` = #{status}
  537. </if>
  538. <if test=" null != startdate and null!=enddate">
  539. and c.`create_date` between #{startdate} and #{enddate}
  540. </if>
  541. <if test=" null != updateDate ">
  542. and c.`update_date` = #{updateDate}
  543. </if>
  544. <if test=" null != business ">
  545. and c.`business` = #{business}
  546. </if>
  547. <if test=" null != subBusiness ">
  548. and c.`sub_business` = #{subBusiness}
  549. </if>
  550. <if test=" null != supportTransfer ">
  551. and c.`support_transfer` = #{supportTransfer}
  552. </if>
  553. <if test=" null != subsidyType ">
  554. and c.`subsidy_type` = #{subsidyType}
  555. </if>
  556. <if test=" null != subsidyNum ">
  557. and c.`subsidy_num` = #{subsidyNum}
  558. </if>
  559. <if test=" null != pressLimitNum ">
  560. and c.`press_limit_num` = #{pressLimitNum}
  561. </if>
  562. <if test=" null != pressLimitHours ">
  563. and c.`press_limit_hours` = #{pressLimitHours}
  564. </if>
  565. <if test=" null != pressPayReduceStock ">
  566. and c.`press_pay_reduce_stock` = #{pressPayReduceStock}
  567. </if>
  568. <if test=" null != pressSupportIsNew ">
  569. and c.`press_support_is_new` = #{pressSupportIsNew}
  570. </if>
  571. <if test=" null != autoRefund ">
  572. and c.`auto_refund` = #{autoRefund}
  573. </if>
  574. <if test=" null != contentType ">
  575. and c.`content_type` = #{contentType}
  576. </if>
  577. <if test=" null != putApplyStatus and putApplyStatus == 2">
  578. and c.`put_apply_status` = #{putApplyStatus}
  579. </if>
  580. <if test=" null != putApplyStatus and putApplyStatus == -1">
  581. and c.`put_apply_status` != 2
  582. </if>
  583. <if test=" null != stockApplyStatus ">
  584. and c.`stock_apply_status` = #{stockApplyStatus}
  585. </if>
  586. <if test=" null != cancleApplyStatus ">
  587. and c.`cancle_apply_status` = #{cancleApplyStatus}
  588. </if>
  589. <if test=" null != sourceType ">
  590. and c.`source_type` = #{sourceType}
  591. </if>
  592. <if test=" null != merchantType ">
  593. and c.`merchant_type` = #{merchantType}
  594. </if>
  595. <if test=" null != giftList">
  596. and JSON_CONTAINS(c.gift_list,json_array(#{giftList}))
  597. </if>
  598. <if test=" null != targetAd ">
  599. and 0 = (select count(*) from wx_coupon_channel cc
  600. where c.`id` = cc.coupon_id
  601. and cc.status = 0
  602. and cc.target_ad = #{targetAd})
  603. </if>
  604. <if test=" null != isAfterSetPrice ">
  605. and c.`is_after_set_price` = #{isAfterSetPrice}
  606. </if>
  607. <if test=" null != ids ">
  608. and c.id in
  609. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  610. #{idItem}
  611. </foreach>
  612. </if>
  613. <if test=" null != types ">
  614. and c.type in
  615. <foreach collection="types" index="index" item="typesItem" open="(" separator="," close=")">
  616. #{typesItem}
  617. </foreach>
  618. </if>
  619. <if test=" null != sendTypes ">
  620. and c.send_type in
  621. <foreach collection="sendTypes" index="index" item="typesItem" open="(" separator="," close=")">
  622. #{typesItem}
  623. </foreach>
  624. </if>
  625. </sql>
  626. <select id="findCouponList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  627. select
  628. <include refid="allColumns"/>
  629. <if test="plat != null and plat == 3">
  630. ,poi.spu_id,poi.status poi_status,poi.status_desc,poi.last_status,poi.last_status_desc
  631. </if>
  632. from wx_coupon c
  633. <if test="plat != null and plat == 3">
  634. left join tt_coupon_channel_poi poi on poi.id = c.id
  635. </if>
  636. where c.is_del = 0 and c.version = 0
  637. <if test="plat != null and plat == 3">
  638. <if test=" null != spuId and '' != spuId">
  639. and poi.`spu_id` = #{spuId}
  640. </if>
  641. <if test=" null != poiStatus">
  642. and poi.`status` = #{poiStatus}
  643. </if>
  644. <if test=" null != lastStatus">
  645. and poi.`last_status` = #{lastStatus}
  646. </if>
  647. </if>
  648. <include refid="dynamicWhereConditionsForCoupon"/>
  649. <if test=" null != sortColumns">order by ${sortColumns}</if>
  650. <if test="null != limitStart and null != limitEnd">
  651. limit #{limitStart},#{limitEnd}
  652. </if>
  653. </select>
  654. <select id="findCouponListCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Integer">
  655. select
  656. count(c.id)
  657. from wx_coupon c
  658. <if test="plat != null and plat == 3">
  659. left join tt_coupon_channel_poi poi on poi.id = c.id
  660. </if>
  661. where c.is_del = 0 and c.version = 0
  662. <if test="plat != null and plat == 3">
  663. <if test=" null != spuId and '' != spuId">
  664. and poi.`spu_id` = #{spuId}
  665. </if>
  666. <if test=" null != poiStatus">
  667. and poi.`status` = #{poiStatus}
  668. </if>
  669. <if test=" null != lastStatus">
  670. and poi.`last_status` = #{lastStatus}
  671. </if>
  672. </if>
  673. <include refid="dynamicWhereConditionsForCoupon"/>
  674. </select>
  675. <resultMap id="WxCouponCVoMap" type="com.iformall.domain.vo.WxCouponCVo">
  676. <id column="id" jdbcType="BIGINT" property="id"/>
  677. <result column="coupon_id" jdbcType="INTEGER" property="couponId"/>
  678. <result column="version" jdbcType="BIGINT" property="version"/>
  679. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  680. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  681. <result column="type" jdbcType="INTEGER" property="type"/>
  682. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  683. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  684. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  685. <result column="title" jdbcType="VARCHAR" property="title"/>
  686. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  687. <result column="item_group" jdbcType="VARCHAR" property="itemGroup"/>
  688. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  689. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  690. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  691. <result column="use_limit_rule" jdbcType="INTEGER" property="useLimitRule"/>
  692. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  693. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  694. <result column="sold_start_time" jdbcType="TIMESTAMP" property="soldStartTime"/>
  695. <result column="sold_end_time" jdbcType="TIMESTAMP" property="soldEndTime"/>
  696. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  697. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  698. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  699. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  700. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  701. <result column="price" jdbcType="INTEGER" property="price"/>
  702. <result column="tail_price" jdbcType="INTEGER" property="tailPrice"/>
  703. <result column="orig_price" jdbcType="INTEGER" property="origPrice"/>
  704. <result column="unit" jdbcType="INTEGER" property="unit"/>
  705. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  706. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  707. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  708. <result column="status" jdbcType="INTEGER" property="status"/>
  709. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  710. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  711. <result column="business" jdbcType="INTEGER" property="business"/>
  712. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  713. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  714. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  715. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  716. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  717. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  718. <result column="press_pay_reduce_stock" jdbcType="INTEGER" property="pressPayReduceStock"/>
  719. <result column="press_support_is_new" jdbcType="INTEGER" property="pressSupportIsNew"/>
  720. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  721. <result column="content_type" jdbcType="INTEGER" property="contentType"/>
  722. <result column="source_type" jdbcType="INTEGER" property="sourceType"/>
  723. <result column="merchant_type" jdbcType="INTEGER" property="merchantType"/>
  724. <result column="gift_list" jdbcType="VARCHAR" property="giftList"></result>
  725. <result column="product_type" jdbcType="INTEGER" property="productType"/>
  726. <result column="category_id" jdbcType="INTEGER" property="categoryId"/>
  727. </resultMap>
  728. <resultMap id="WxCouponCVoMapL" type="com.iformall.domain.vo.WxCouponCVo">
  729. <id column="id" jdbcType="BIGINT" property="id"/>
  730. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  731. <result column="version" jdbcType="BIGINT" property="version"/>
  732. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  733. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  734. <result column="type" jdbcType="INTEGER" property="type"/>
  735. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  736. <result column="cover_picture" jdbcType="VARCHAR" property="coverPicture"/>
  737. <result column="detail_picture" jdbcType="VARCHAR" property="detailPicture"/>
  738. <result column="title" jdbcType="VARCHAR" property="title"/>
  739. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  740. <result column="item_group" jdbcType="VARCHAR" property="itemGroup"/>
  741. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  742. <result column="freight_price" jdbcType="INTEGER" property="freightPrice"/>
  743. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  744. <result column="use_limit_rule" jdbcType="INTEGER" property="useLimitRule"/>
  745. <result column="use_limit_quantity" jdbcType="INTEGER" property="useLimitQuantity"/>
  746. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  747. <result column="sold_start_time" jdbcType="TIMESTAMP" property="soldStartTime"/>
  748. <result column="sold_end_time" jdbcType="TIMESTAMP" property="soldEndTime"/>
  749. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  750. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  751. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  752. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  753. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  754. <result column="price" jdbcType="INTEGER" property="price"/>
  755. <result column="tail_price" jdbcType="INTEGER" property="tailPrice"/>
  756. <result column="orig_price" jdbcType="INTEGER" property="origPrice"/>
  757. <result column="unit" jdbcType="INTEGER" property="unit"/>
  758. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  759. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  760. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  761. <result column="status" jdbcType="INTEGER" property="status"/>
  762. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  763. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  764. <result column="business" jdbcType="INTEGER" property="business"/>
  765. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  766. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  767. <result column="subsidy_type" jdbcType="INTEGER" property="subsidyType"/>
  768. <result column="subsidy_num" jdbcType="INTEGER" property="subsidyNum"/>
  769. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  770. <result column="press_limit_hours" jdbcType="INTEGER" property="pressLimitHours"/>
  771. <result column="press_pay_reduce_stock" jdbcType="INTEGER" property="pressPayReduceStock"/>
  772. <result column="press_support_is_new" jdbcType="INTEGER" property="pressSupportIsNew"/>
  773. <result column="conditions" jdbcType="VARCHAR" property="conditions"/>
  774. <result column="content_type" jdbcType="INTEGER" property="contentType"/>
  775. <result column="source_type" jdbcType="INTEGER" property="sourceType"/>
  776. <result column="merchant_type" jdbcType="INTEGER" property="merchantType"/>
  777. </resultMap>
  778. <select id="findVoDetail" parameterType="java.util.HashMap" resultMap="WxCouponCVoMap">
  779. select
  780. <include refid="allColumns"/>
  781. from wx_coupon c
  782. where id = #{id} and tenant_id =#{tenantId}
  783. </select>
  784. <select id="findVoStatusDetail" parameterType="java.util.HashMap" resultMap="WxCouponCVoMapL">
  785. select id, coupon_id,version,remain_inventory, status
  786. from wx_coupon
  787. where id = #{id} and tenant_id =#{tenantId}
  788. </select>
  789. <update id="reduceInventory">
  790. update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and tenant_id =#{tenantId} and remain_inventory - #{number} &gt;= 0
  791. </update>
  792. <update id="backInventory">
  793. update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and tenant_id =#{tenantId} and remain_inventory + #{number} &lt;= inventory
  794. </update>
  795. <update id="offExpiriedCouponByValidDate" parameterType="String">
  796. update wx_coupon SET status = 1, update_date = now()
  797. where status = 0 and tenant_id =#{tenantId} and valid_type = 1 and valid_end_date &lt; now()
  798. </update>
  799. <update id="offExpiriedCouponByMerchantStatus" parameterType="HashMap">
  800. update wx_coupon c
  801. SET c.status = 1, c.update_date = now()
  802. where c.status = 0 and c.tenant_id =#{tenantId}
  803. <!-- type=12 礼包卷没有门店 -->
  804. and c.type != 12
  805. <if test=" null != validIds ">
  806. and c.id not in
  807. <foreach collection="validIds" index="index" item="idItem" open="(" separator="," close=")">
  808. #{idItem}
  809. </foreach>
  810. </if>
  811. </update>
  812. <select id="getValidMerchantProductIds" resultType="Long">
  813. select cm.product_id from wx_coupon_merchant cm, wx_merchant m
  814. where m.id = cm.merchant_id
  815. and cm.status = 0
  816. and m.status = 1
  817. </select>
  818. <select id="findSaleMoneyByDate"
  819. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  820. select DATE_FORMAT(ci.create_date,'%Y-%m-%d') xtime,sum(round(ci.sale_amount/100,2)) xcount
  821. from wx_card_info ci
  822. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  823. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  824. </foreach>) c on c.id = ci.coupon_id
  825. where c.type = 100
  826. and ci.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  827. group by xtime
  828. </select>
  829. <select id="findPaymentByDate"
  830. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  831. select DATE_FORMAT(wcs.create_date,'%Y-%m-%d') xtime,sum(round(wcs.real_payment/100,2)) xcount
  832. from wx_card_info ci
  833. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  834. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  835. </foreach>) c on c.id = ci.coupon_id
  836. left join wx_card_spend wcs on wcs.card_id = ci.id
  837. where c.type = 100
  838. and wcs.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  839. group by xtime
  840. </select>
  841. <select id="findSaleCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  842. select count(co.id)
  843. from wx_card_info ci
  844. left join wx_coupon c on c.id = ci.coupon_id
  845. left join wx_coupon_order co on co.id = ci.id
  846. where c.type = 100
  847. and co.create_date between #{startdate} and #{enddate}
  848. </select>
  849. <select id="findTranCardCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  850. select count(distinct wcs.coupon_order_id) from wx_card_info ci
  851. left join wx_coupon c on c.id = ci.coupon_id
  852. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  853. where c.type = 100 and wcs.create_date between #{startdate} and #{enddate}
  854. </select>
  855. <select id="findSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  856. select sum(round(sc.subsidy/100,2)) from wx_card_info ci
  857. left join wx_coupon c on c.id = ci.coupon_id
  858. left join wx_merchant_subsidy sc on sc.coupon_order_id = ci.id
  859. where c.type = 100 and sc.create_date between #{startdate} and #{enddate}
  860. </select>
  861. <select id="findCountData" resultMap="statisMap">
  862. select c.*,
  863. IFNULL(round((select sum(wcs.real_payment) from wx_card_info ci
  864. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  865. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  866. </foreach>) wc on wc.id = ci.coupon_id
  867. left join wx_card_spend wcs on wcs.card_id = ci.id
  868. where wc.id = c.id)/(select sum(ci.sale_amount) from wx_card_info ci
  869. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  870. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  871. </foreach>) wc on wc.id = ci.coupon_id
  872. where wc.id = c.id)*100,2),0) payment_rate,
  873. (select count(wco.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  874. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  875. </foreach>) wc
  876. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  877. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  878. </foreach>) wco on wc.id = wco.coupon_id
  879. where wc.id = c.id) as sale_count,
  880. (select count(distinct wcs.coupon_order_id) from wx_card_info ci
  881. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  882. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  883. </foreach>) wc on wc.id = ci.coupon_id
  884. left join wx_card_transfer_info wcs on wcs.coupon_order_id = ci.id
  885. where wc.id = c.id) as transfer_count,
  886. (select sum(ci.sale_amount) from wx_card_info ci
  887. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  888. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  889. </foreach>) wc on wc.id = ci.coupon_id
  890. where wc.id = c.id) as sale_amount,
  891. (select sum(wcs.real_payment) from wx_card_info ci
  892. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  893. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  894. </foreach>) wc on wc.id = ci.coupon_id
  895. left join wx_card_spend wcs on wcs.card_id = ci.id
  896. where wc.id = c.id) as sum_payment,
  897. (select sum(sc.subsidy) from wx_card_info ci
  898. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  899. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  900. </foreach>) wc on wc.id = ci.coupon_id
  901. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  902. SELECT * from wx_merchant_subsidy${tenantEntity.shardTableSuffix}
  903. </foreach>) sc on sc.coupon_order_id = ci.id
  904. where wc.id = c.id) as sum_subsidy
  905. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  906. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  907. </foreach>) c where c.version = 0 and c.type = 100
  908. <if test="wxCoupon.title != null and wxCoupon.title !=''">
  909. and c.title like concat('%', #{wxCoupon.title},'%')
  910. </if>
  911. <if test="wxCoupon.id != null">
  912. and c.id = #{wxCoupon.id}
  913. </if>
  914. <if test=" null != wxCoupon.ids ">
  915. and c.id in
  916. <foreach collection="wxCoupon.ids" index="index" item="idItem" open="(" separator="," close=")">
  917. #{idItem}
  918. </foreach>
  919. </if>
  920. <if test=" null != wxCoupon.sortColumns">order by ${wxCoupon.sortColumns}</if>
  921. <if test=" null == wxCoupon.sortColumns">order by c.status asc,c.create_date desc</if>
  922. </select>
  923. <select id="findCouponData" resultMap="statisMap">
  924. select c.*,
  925. IFNULL(round((select count(wco.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  926. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  927. </foreach>) wc,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  928. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  929. </foreach>) wco where wco.coupon_id = wc.id and
  930. 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">
  931. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  932. </foreach>) wco where wco.coupon_id
  933. = c.id)*100,2),0) payment_rate,
  934. (select count(wco.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  935. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  936. </foreach>) wco where wco.coupon_id = c.id) as sale_count,
  937. (select count(wco.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  938. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  939. </foreach>) wc,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  940. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  941. </foreach>) wco where wco.coupon_id = wc.id and
  942. wco.coupon_order_status = 1 and wc.id = c.id) as sum_payment,
  943. (select count(wco.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  944. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  945. </foreach>) wc,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  946. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  947. </foreach>) wco where wco.coupon_id = wc.id and
  948. wco.coupon_order_status = 3 and wc.id = c.id) as backpay_count,
  949. (select sum(sc.subsidy) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  950. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  951. </foreach>) wc
  952. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  953. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  954. </foreach>) wo on wo.coupon_id = wc.id
  955. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  956. SELECT * from wx_merchant_subsidy${tenantEntity.shardTableSuffix}
  957. </foreach>) sc on sc.coupon_order_id = wo.id
  958. where wc.id = c.id) as sum_subsidy
  959. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  960. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  961. </foreach>) c where c.version = 0 and c.type not in(8,9,100)
  962. <if test=" 1 == wxCoupon.type ">
  963. and c.sale_price > 0
  964. </if>
  965. <if test=" 2 == wxCoupon.type ">
  966. and c.sale_price = 0
  967. </if>
  968. <if test="wxCoupon.title != null and wxCoupon.title != ''">
  969. and c.title like concat('%', #{wxCoupon.title},'%')
  970. </if>
  971. <if test="wxCoupon.id != null">
  972. and c.id = #{wxCoupon.id}
  973. </if>
  974. <if test=" null != wxCoupon.ids ">
  975. and c.id in
  976. <foreach collection="wxCoupon.ids" index="index" item="idItem" open="(" separator="," close=")">
  977. #{idItem}
  978. </foreach>
  979. </if>
  980. <if test=" null != wxCoupon.sortColumns">order by ${wxCoupon.sortColumns}</if>
  981. <if test=" null == wxCoupon.sortColumns">order by c.status asc,c.create_date desc</if>
  982. </select>
  983. <select id="findPressData" resultMap="statisMap">
  984. select c.id,c.tenant_id, c.`cover_img`,c.`title`,c.`sale_price`,c.`freight_price`,c.`price`,
  985. ifnull(op.press_count,0) as press_count,
  986. ifnull(o.press_succ_count,0) as press_succ_count,
  987. ifnull(op2.join_count,0) as join_count,
  988. ifnull(round(o.press_succ_count/op.press_count*100,2),0) as change_rate,
  989. ifnull(round(cop.xCount/op.press_count*100,2),0) as payment_rate
  990. FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  991. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  992. </foreach>) c
  993. left join (SELECT count(id) as press_count, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  994. SELECT * from wx_order_press${tenantEntity.shardTableSuffix}
  995. </foreach>) wx_order_press WHERE `first` = 1
  996. <if test=" null != wxCoupon.tenantId and '' != wxCoupon.tenantId">
  997. and `tenant_id` = #{wxCoupon.tenantId}
  998. </if>
  999. <if test=" null != wxCoupon.parentTenantId and '' != wxCoupon.parentTenantId">
  1000. and `parent_tenant_id` = #{wxCoupon.parentTenantId}
  1001. </if>
  1002. group by coupon_id) op on op.coupon_id = c.id
  1003. left join (SELECT count(id) as press_succ_count, product_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1004. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1005. </foreach>) wx_order WHERE order_status = 1
  1006. <if test=" null != wxCoupon.tenantId and '' != wxCoupon.tenantId">
  1007. and `tenant_id` = #{wxCoupon.tenantId}
  1008. </if>
  1009. <if test=" null != wxCoupon.parentTenantId and '' != wxCoupon.parentTenantId">
  1010. and `parent_tenant_id` = #{wxCoupon.parentTenantId}
  1011. </if>
  1012. group by product_id) o on o.product_id = c.id
  1013. left join (SELECT count(id) as join_count, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1014. SELECT * from wx_order_press${tenantEntity.shardTableSuffix}
  1015. </foreach>) wx_order_press WHERE 1=1
  1016. <if test=" null != wxCoupon.tenantId and '' != wxCoupon.tenantId">
  1017. and `tenant_id` = #{wxCoupon.tenantId}
  1018. </if>
  1019. <if test=" null != wxCoupon.parentTenantId and '' != wxCoupon.parentTenantId">
  1020. and `parent_tenant_id` = #{wxCoupon.parentTenantId}
  1021. </if>
  1022. group by coupon_id) op2 on op2.coupon_id = c.id
  1023. left join (SELECT count(id) as xCount, coupon_id FROM (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1024. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1025. </foreach>) wx_coupon_order WHERE coupon_order_status = 1
  1026. <if test=" null != wxCoupon.tenantId and '' != wxCoupon.tenantId">
  1027. and `tenant_id` = #{wxCoupon.tenantId}
  1028. </if>
  1029. <if test=" null != wxCoupon.parentTenantId and '' != wxCoupon.parentTenantId">
  1030. and `parent_tenant_id` = #{wxCoupon.parentTenantId}
  1031. </if>
  1032. group by coupon_id) cop on cop.coupon_id = c.id
  1033. where c.version = 0 and c.type = 8
  1034. <if test=" null != wxCoupon.tenantId and '' != wxCoupon.tenantId">
  1035. and c.`tenant_id` = #{wxCoupon.tenantId}
  1036. </if>
  1037. <if test=" null != wxCoupon.parentTenantId and '' != wxCoupon.parentTenantId">
  1038. and c.`parent_tenant_id` = #{wxCoupon.parentTenantId}
  1039. </if>
  1040. <if test="wxCoupon.id != null">
  1041. and c.id = #{wxCoupon.id}
  1042. </if>
  1043. <if test="wxCoupon.title != null and wxCoupon.title != ''">
  1044. and c.title like concat('%', #{wxCoupon.title},'%')
  1045. </if>
  1046. <if test=" null != wxCoupon.ids ">
  1047. and c.id in
  1048. <foreach collection="wxCoupon.ids" index="index" item="idItem" open="(" separator="," close=")">
  1049. #{idItem}
  1050. </foreach>
  1051. </if>
  1052. <if test=" null != wxCoupon.sortColumns">order by ${wxCoupon.sortColumns}</if>
  1053. <if test=" null == wxCoupon.sortColumns">order by c.status asc,c.create_date desc</if>
  1054. </select>
  1055. <select id="findCouponOrderCount"
  1056. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1057. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount
  1058. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1059. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1060. </foreach>) c
  1061. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1062. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1063. </foreach>) wco on c.id = wco.coupon_id
  1064. where c.type not in(8,9,100)
  1065. and wco.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1066. group by xtime
  1067. </select>
  1068. <select id="findCouponPaymentCount"
  1069. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1070. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount
  1071. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1072. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1073. </foreach>) c,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1074. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1075. </foreach>) wco
  1076. where c.type not in(8,9,100)
  1077. and wco.coupon_id = c.id and wco.coupon_order_status = 1
  1078. and wco.update_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1079. group by xtime
  1080. </select>
  1081. <select id="priceCouponSaleCount"
  1082. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1083. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount
  1084. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1085. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1086. </foreach>) c,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1087. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1088. </foreach>) wco
  1089. where c.type not in(8,9,100)
  1090. and wco.coupon_id = c.id and wco.coupon_price > 0
  1091. and wco.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1092. group by xtime
  1093. </select>
  1094. <select id="priceCouponPaymentCount"
  1095. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1096. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount
  1097. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1098. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1099. </foreach>) c,(<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1100. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1101. </foreach>) wco
  1102. where c.type not in(8,9,100)
  1103. and wco.coupon_id = c.id and wco.coupon_order_status = 1 and wco.coupon_price > 0
  1104. and wco.update_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1105. group by xtime
  1106. </select>
  1107. <select id="findSumPriceSaleMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  1108. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  1109. where wco.coupon_id = c.id and wco.coupon_price > 0
  1110. and wco.create_date between #{startdate} and #{enddate}
  1111. </select>
  1112. <select id="findSumPricePayMent" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  1113. select sum(round(c.sale_price/100,2)) from wx_coupon c,wx_coupon_order wco
  1114. where wco.coupon_id = c.id and wco.coupon_price > 0 and wco.coupon_order_status = 1
  1115. and wco.update_date between #{startdate} and #{enddate}
  1116. </select>
  1117. <select id="findSumSubsidyMoney" parameterType="com.iformall.domain.po.WxCoupon" resultType="String">
  1118. select sum(round(sc.subsidy/100,2)) from wx_coupon c
  1119. left join wx_coupon_order wo on wo.coupon_id = c.id
  1120. left join wx_merchant_subsidy sc on sc.coupon_order_id = wo.id
  1121. where c.type not in(8,9,100) and wo.coupon_order_status = 1
  1122. and sc.create_date between #{startdate} and #{enddate}
  1123. </select>
  1124. <!--砍价-->
  1125. <select id="pressSendHistory"
  1126. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1127. select DATE_FORMAT(wop.create_date,'%Y-%m-%d') xtime,count(wop.id) xcount
  1128. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1129. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1130. </foreach>) wc
  1131. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1132. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1133. </foreach>) wo on wo.product_id = wc.id
  1134. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1135. SELECT * from wx_order_press${tenantEntity.shardTableSuffix}
  1136. </foreach>) wop on wop.order_id = wo.id
  1137. where wc.type = 8 and wop.first = 1 and
  1138. wop.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1139. group by xtime
  1140. </select>
  1141. <select id="pressSuccHistory"
  1142. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1143. select DATE_FORMAT(wo.create_date,'%Y-%m-%d') xtime,count(wo.id) xcount
  1144. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1145. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1146. </foreach>) wc
  1147. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1148. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1149. </foreach>) wo on wo.product_id = wc.id
  1150. where wc.type = 8 and wo.order_status = 1
  1151. and wo.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1152. group by xtime
  1153. </select>
  1154. <select id="pressPaymentHistory"
  1155. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1156. select DATE_FORMAT(wco.create_date,'%Y-%m-%d') xtime,count(wco.id) xcount
  1157. from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1158. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1159. </foreach>) wc
  1160. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1161. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1162. </foreach>) wco on wco.coupon_id = wc.id
  1163. where wc.type = 8 and wco.coupon_order_status = 1
  1164. and wco.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1165. group by xtime
  1166. </select>
  1167. <select id="pressSuccRate" resultType="java.lang.String">
  1168. select
  1169. round(
  1170. (select count(wo.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1171. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1172. </foreach>) wc
  1173. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1174. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1175. </foreach>) wo on wo.product_id = wc.id
  1176. where wo.order_status = 1 and wc.type = 8
  1177. and wo.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1178. )
  1179. /
  1180. (select count(wop.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1181. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1182. </foreach>) wc
  1183. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1184. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1185. </foreach>) wo on wo.product_id = wc.id
  1186. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1187. SELECT * from wx_order_press${tenantEntity.shardTableSuffix}
  1188. </foreach>) wop on wop.order_id = wo.id
  1189. where wop.first = 1 and wc.type = 8
  1190. and wop.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1191. )
  1192. * 100
  1193. ,2)
  1194. </select>
  1195. <select id="sumJoin" resultType="Long">
  1196. select count(wop.id) from (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1197. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1198. </foreach>) wc
  1199. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1200. SELECT * from wx_order${tenantEntity.shardTableSuffix}
  1201. </foreach>) wo on wo.product_id = wc.id
  1202. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1203. SELECT * from wx_order_press${tenantEntity.shardTableSuffix}
  1204. </foreach>) wop on wop.order_id = wo.id
  1205. where wc.type = 8
  1206. and wop.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1207. </select>
  1208. <select id="priceCouponCancelCount" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  1209. select count(c.id) from wx_coupon c
  1210. left join wx_coupon_order wco on c.id = wco.coupon_id
  1211. where c.type not in(8,9,100)
  1212. and wco.create_date between #{startdate} and #{enddate}
  1213. and wco.coupon_order_status = 3
  1214. </select>
  1215. <select id="findSaleCardCountHistory"
  1216. resultType="com.iformall.domain.vo.WxCouponStatisVo">
  1217. select DATE_FORMAT(co.create_date,'%Y-%m-%d') xtime,count(co.id) xcount
  1218. from wx_card_info ci
  1219. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1220. SELECT * from wx_coupon${tenantEntity.shardTableSuffix}
  1221. </foreach>) c on c.id = ci.coupon_id
  1222. left join (<foreach collection="tenantEntitys" item="tenantEntity" index="index" separator="union all">
  1223. SELECT * from wx_coupon_order${tenantEntity.shardTableSuffix}
  1224. </foreach>) co on co.id = ci.id
  1225. where c.type = 100
  1226. and co.create_date between #{wxCoupon.startdate} and #{wxCoupon.enddate}
  1227. group by xtime
  1228. </select>
  1229. <select id="findCouponByTopic" parameterType="com.iformall.domain.po.WxTopic"
  1230. resultType="com.iformall.domain.po.WxCoupon">
  1231. select ct.id as id,wc.id as couponId,
  1232. wc.tenant_id,wc.parent_tenant_id,wc.`type`,wc.`cover_img`,wc.`cover_picture`,wc.`detail_picture`,wc.`title`,wc.`sub_title`,wc.`item_group`,wc.`sale_price`,wc.`freight_price`,wc.`use_price`,wc.`use_limit_rule`,wc.`use_limit_quantity`,wc.`send_type`,
  1233. wc.sold_start_time,wc.sold_end_time,wc.`valid_type`,wc.`valid_start_date`,wc.`valid_end_date`,wc.`valid_days`,wc.`detail`,wc.`price`,wc.tail_price,wc.orig_price,wc.`unit`,wc.`remain_inventory`,wc.`inventory`,
  1234. wc.`remark`,wc.`status`,wc.`create_date`,wc.`update_date`,wc.`business`,wc.`sub_business`,wc.`support_transfer`,wc.`subsidy_num`,wc.`subsidy_type`,
  1235. wc.`press_limit_num`, wc.`press_limit_hours`,wc.`press_pay_reduce_stock`,wc.`press_support_is_new`, wc.`auto_refund`,wc.`credit_price`,wc.`credit_refund`,wc.`conditions`,
  1236. wc.title as couponName,wc.`cover_img` as couponPic,wc.`cover_picture` as couponPicture,wc.`detail_picture` as detailPicture
  1237. from wx_coupon_channel ct
  1238. left join wx_coupon wc on wc.id = ct.coupon_id
  1239. where ct.`sub_target_id` = #{id} and ct.status = 0
  1240. </select>
  1241. <select id="findCouponModel" parameterType="com.iformall.domain.po.WxCoupon" resultType="com.iformall.domain.po.WxCoupon">
  1242. select
  1243. max(case type when 9 then model_id else 0 end) couponModelId,
  1244. max(case type when 10 then model_id else 0 end) cardModelId,
  1245. max(case type when 11 then model_id else 0 end) groupModelId,
  1246. max(case type when 12 then model_id else 0 end) pressModelId
  1247. from wx_flow_config
  1248. where type in(9,10,11,12)
  1249. <if test=" null != tenantId and '' != tenantId">
  1250. and `tenant_id` = #{tenantId}
  1251. </if>
  1252. <if test=" null != parentTenantId and '' != parentTenantId">
  1253. and `parent_tenant_id` = #{parentTenantId}
  1254. </if>
  1255. </select>
  1256. <update id="updateValidEndDate" parameterType="com.iformall.domain.po.WxCoupon">
  1257. update wx_coupon set valid_end_date = #{validEndDate} , update_date = #{updateDate} where id = #{id}
  1258. </update>
  1259. <select id="newfindCList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
  1260. select id,coupon_id,version,remain_inventory,inventory,cover_img,title,sub_title,item_group,sale_price,use_price,price,tail_price,
  1261. orig_price,unit,use_limit_rule,use_limit_quantity,send_type,support_transfer,press_limit_num,auto_refund,
  1262. conditions,valid_type,sold_start_time,sold_end_time,valid_start_date,valid_end_date,valid_days,credit_price,
  1263. remark,content_type,source_type,merchant_type
  1264. from wx_coupon
  1265. where `version` = 0
  1266. and `tenant_id` = #{tenantId}
  1267. <if test=" null != id ">
  1268. and `id` = #{id}
  1269. </if>
  1270. <if test=" null != business ">
  1271. and `business` = #{business}
  1272. </if>
  1273. <if test=" null != subBusiness ">
  1274. and `sub_business` = #{subBusiness}
  1275. </if>
  1276. <if test=" null != ids ">
  1277. and id in
  1278. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  1279. #{idItem}
  1280. </foreach>
  1281. </if>
  1282. </select>
  1283. <select id="findIdsListHasConditons" parameterType="com.iformall.domain.po.WxCoupon" resultType="Long">
  1284. select c.id
  1285. from wx_coupon c
  1286. where c.`tenant_id` = #{tenantId}
  1287. and c.`version` = 0 and c.conditions is not null
  1288. /*and JSON_EXTRACT(c.conditions, '$.type') = 1*/
  1289. <if test=" null != parentTenantId and '' != parentTenantId">
  1290. and c.`parent_tenant_id` = #{parentTenantId}
  1291. </if>
  1292. </select>
  1293. <resultMap id="TtCouponVoResultMap" type="com.iformall.domain.vo.TtCouponVo">
  1294. <id column="id" jdbcType="BIGINT" property="id"/>
  1295. <result column="coupon_id" jdbcType="BIGINT" property="couponId"/>
  1296. <result column="version" jdbcType="INTEGER" property="version"/>
  1297. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  1298. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  1299. <result column="type" jdbcType="INTEGER" property="type"/>
  1300. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  1301. <result column="title" jdbcType="VARCHAR" property="title"/>
  1302. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  1303. <result column="send_type" jdbcType="INTEGER" property="sendType"/>
  1304. <result column="sold_start_time" jdbcType="TIMESTAMP" property="soldStartTime"/>
  1305. <result column="sold_end_time" jdbcType="TIMESTAMP" property="soldEndTime"/>
  1306. <result column="valid_type" jdbcType="INTEGER" property="validType"/>
  1307. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  1308. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  1309. <result column="valid_days" jdbcType="INTEGER" property="validDays"/>
  1310. <result column="price" jdbcType="INTEGER" property="price"/>
  1311. <result column="tail_price" jdbcType="INTEGER" property="tailPrice"/>
  1312. <result column="orig_price" jdbcType="INTEGER" property="origPrice"/>
  1313. <result column="unit" jdbcType="INTEGER" property="unit"/>
  1314. <result column="remain_inventory" jdbcType="INTEGER" property="remainInventory"/>
  1315. <result column="inventory" jdbcType="INTEGER" property="inventory"/>
  1316. <result column="status" jdbcType="INTEGER" property="status"/>
  1317. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  1318. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  1319. <result column="business" jdbcType="INTEGER" property="business"/>
  1320. <result column="sub_business" jdbcType="INTEGER" property="subBusiness"/>
  1321. <result column="auto_refund" jdbcType="INTEGER" property="autoRefund"/>
  1322. <result column="credit_price" jdbcType="INTEGER" property="creditPrice"/>
  1323. <result column="credit_refund" jdbcType="INTEGER" property="creditRefund"/>
  1324. <result column="content_type" property="contentType"/>
  1325. <result column="source_type" jdbcType="INTEGER" property="sourceType"/>
  1326. <result column="merchant_type" jdbcType="INTEGER" property="merchantType"/>
  1327. <result column="product_type" jdbcType="INTEGER" property="productType"/>
  1328. <result column="category_id" jdbcType="INTEGER" property="categoryId"/>
  1329. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  1330. <result column="spu_id" jdbcType="VARCHAR" property="spuId"/>
  1331. <result column="poi_status" jdbcType="INTEGER" property="poiStatus"/>
  1332. <result column="status_desc" jdbcType="VARCHAR" property="statusDesc"/>
  1333. <result column="last_status" jdbcType="INTEGER" property="lastStatus"/>
  1334. <result column="last_status_desc" jdbcType="VARCHAR" property="lastStatusDesc"/>
  1335. </resultMap>
  1336. <select id="ttCouponList" parameterType="com.iformall.domain.vo.TtCouponVo" resultMap="TtCouponVoResultMap">
  1337. select c.`id`,c.`coupon_id`,c.`version`,c.`tenant_id`,c.`parent_tenant_id`,c.`type`,c.`cover_img`,
  1338. c.`title`,c.`sub_title`,c.`sale_price`,c.`freight_price`,c.`send_type`,
  1339. c.sold_start_time,c.sold_end_time,c.`valid_type`,c.`valid_start_date`,c.`valid_end_date`,
  1340. c.`valid_days`,c.`price`,c.tail_price,c.orig_price,c.`unit`,c.`remain_inventory`,c.`inventory`,
  1341. c.`status`,c.`create_date`,c.`update_date`,c.`business`,c.`sub_business`,
  1342. c.`auto_refund`,c.`credit_price`,c.`credit_refund`,
  1343. c.content_type,c.source_type,c.merchant_type,c.product_type,c.category_id,
  1344. poi.coupon_channel_id,poi.spu_id,poi.status poi_status,poi.status_desc,poi.last_status,poi.last_status_desc
  1345. from wx_coupon c
  1346. left join tt_coupon_channel_poi poi on poi.id = c.id
  1347. where c.`version` = 0 and c.`type` = #{type}
  1348. <if test=" null != id ">
  1349. and c.`id` = #{id}
  1350. </if>
  1351. <if test=" null != couponId ">
  1352. and c.`coupon_id` = #{couponId}
  1353. </if>
  1354. <if test=" null != tenantId and '' != tenantId">
  1355. and c.`tenant_id` = #{tenantId}
  1356. </if>
  1357. <if test=" null != parentTenantId and '' != parentTenantId">
  1358. and c.`parent_tenant_id` = #{parentTenantId}
  1359. </if>
  1360. <if test=" null != title and ''!=title">
  1361. and c.`title` like concat('%', #{title},'%')
  1362. </if>
  1363. <if test=" null != sendType ">
  1364. and c.`send_type` = #{sendType}
  1365. </if>
  1366. <if test=" null != status">
  1367. and c.`status` = #{status}
  1368. </if>
  1369. <if test=" null != startdate and null!=enddate">
  1370. and c.`create_date` between #{startdate} and #{enddate}
  1371. </if>
  1372. <if test=" null != sourceType ">
  1373. and c.`source_type` = #{sourceType}
  1374. </if>
  1375. <if test=" null != merchantType ">
  1376. and c.`merchant_type` = #{merchantType}
  1377. </if>
  1378. <if test=" null != couponChannelId ">
  1379. and poi.`coupon_channel_id` = #{couponChannelId}
  1380. </if>
  1381. <if test=" null != spuId and '' != spuId">
  1382. and poi.`spu_id` = #{spuId}
  1383. </if>
  1384. <if test=" null != poiStatus">
  1385. and poi.`status` = #{poiStatus}
  1386. </if>
  1387. <if test=" null != lastStatus">
  1388. and poi.`last_status` = #{lastStatus}
  1389. </if>
  1390. <if test=" null != sortColumns">order by ${sortColumns}</if>
  1391. </select>
  1392. <select id="findCategoryIdById" parameterType="java.util.HashMap" resultType="Integer">
  1393. select category_id
  1394. from wx_coupon
  1395. where id = #{id}
  1396. and tenant_id = #{tenantId}
  1397. </select>
  1398. <select id="selectDraftCoupon" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  1399. select <include refid="allColumns"/> ,c.html,c.gift_list,c.product_attrs,c.sku_attrs
  1400. from wx_coupon c
  1401. where c.`version` = 1 and coupon_id = #{couponId} and tenant_id = #{tenantId}
  1402. </select>
  1403. <select id="selectOnlineCoupon" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  1404. select <include refid="allColumns"/> ,c.html,c.gift_list,c.product_attrs,c.sku_attrs
  1405. from wx_coupon c
  1406. where id = #{id} and tenant_id = #{tenantId}
  1407. </select>
  1408. <select id="selectDraftId" parameterType="java.util.HashMap" resultType="Long">
  1409. select c.id
  1410. from wx_coupon c
  1411. where c.`version` = 1 and coupon_id = #{couponId} and tenant_id = #{tenantId}
  1412. </select>
  1413. <select id="findDraftStatus" parameterType="java.util.HashMap" resultMap="TtCouponVoResultMap">
  1414. select c.`id`,c.`coupon_id`,c.`version`,c.`tenant_id`,c.`parent_tenant_id`,
  1415. poi.status poi_status,poi.status_desc
  1416. from wx_coupon c
  1417. left join tt_coupon_channel_poi poi on poi.id = c.id
  1418. where c.`version` = 1 and c.tenant_id = #{tenantId}
  1419. and c.coupon_id in
  1420. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  1421. #{idItem}
  1422. </foreach>
  1423. </select>
  1424. </mapper>