選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

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