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.
 
 
 
 
 

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