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.
 
 
 
 
 

691 lines
32 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.WxOrderMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxOrder">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  7. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  8. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  9. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  10. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  11. <result column="type" jdbcType="TINYINT" property="type"/>
  12. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  13. <result column="payment" jdbcType="INTEGER" property="payment"/>
  14. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  15. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  16. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  17. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  18. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  19. <result column="press_end_date" jdbcType="TIMESTAMP" property="pressEndDate"/>
  20. <result column="press_current_num" jdbcType="INTEGER" property="pressCurrentNum"/>
  21. <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/>
  22. <result column="order_group_id" jdbcType="BIGINT" property="orderGroupId"/>
  23. </resultMap>
  24. <sql id="allColumns">
  25. `id`,`order_number`,`tenant_id`,`c_user_id`,`coupon_channel_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`,
  26. `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id`
  27. </sql>
  28. <sql id="dynamicWhereConditions">
  29. where 1 = 1
  30. <if test=" null != id ">
  31. and `id` = #{id}
  32. </if>
  33. <if test=" null != orderNumber ">
  34. and `order_number` = #{orderNumber}
  35. </if>
  36. <if test=" null != tenantId ">
  37. and `tenant_id` = #{tenantId}
  38. </if>
  39. <if test=" null != cUserId ">
  40. and `c_user_id` = #{cUserId}
  41. </if>
  42. <if test=" null != couponChannelId ">
  43. and `coupon_channel_id` = #{couponChannelId}
  44. </if>
  45. <if test=" null != productId ">
  46. and `product_id` = #{productId}
  47. </if>
  48. <if test=" null != type ">
  49. and `type` = #{type}
  50. </if>
  51. <if test=" null != paymentType ">
  52. and `payment_type` = #{paymentType}
  53. </if>
  54. <if test=" null != payment ">
  55. and `payment` = #{payment}
  56. </if>
  57. <if test=" null != paymentTime ">
  58. and `payment_time` = #{paymentTime}
  59. </if>
  60. <if test=" null != orderStatus ">
  61. and `order_status` = #{orderStatus}
  62. </if>
  63. <if test=" null != createDate ">
  64. and `create_date` = #{createDate}
  65. </if>
  66. <if test=" null != updateDate ">
  67. and `update_date` = #{updateDate}
  68. </if>
  69. <if test=" null != detail ">
  70. and `detail` like concat('%', #{detail},'%')
  71. </if>
  72. <if test=" null != pressEndDate ">
  73. and `press_end_date` = #{pressEndDate}
  74. </if>
  75. <if test=" null != pressCurrentNum ">
  76. and `press_current_num` = #{pressCurrentNum}
  77. </if>
  78. <if test=" null != pressCurrentValue ">
  79. and `press_current_value` = #{pressCurrentValue}
  80. </if>
  81. <if test=" null != orderGroupId ">
  82. and `order_group_id` = #{orderGroupId}
  83. </if>
  84. <if test=" null != statusS ">
  85. and `order_status` in
  86. <foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")">
  87. #{sItem}
  88. </foreach>
  89. </if>
  90. <if test=" null != ids ">
  91. and id in
  92. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  93. #{idItem}
  94. </foreach>
  95. </if>
  96. <if test=" null != sortColumns">order by ${sortColumns}</if>
  97. </sql>
  98. <select id="findList" parameterType="com.iformall.domain.po.WxOrder" resultMap="BaseResultMap">
  99. select
  100. <include refid="allColumns"/>
  101. from wx_order
  102. <include refid="dynamicWhereConditions"/>
  103. </select>
  104. <select id="countList" parameterType="com.iformall.domain.po.WxOrder" resultType="java.lang.Integer">
  105. select count(*) from wx_order
  106. <include refid="dynamicWhereConditions"/>
  107. </select>
  108. <select id="findListOfUnpaidOrderByDate" parameterType="map" resultMap="BaseResultMap">
  109. select
  110. <include refid="allColumns"/>
  111. from wx_order
  112. where order_status = '0' and press_end_date is null
  113. <if test="type != null">
  114. AND type = #{type,jdbcType=TINYINT}
  115. </if>
  116. <if test="startDate != null">
  117. AND unix_timestamp(`create_date`) &gt; unix_timestamp(#{startDate,jdbcType=TIMESTAMP})
  118. </if>
  119. <if test="endDate != null">
  120. AND unix_timestamp(`create_date`) &lt; unix_timestamp(#{endDate,jdbcType=TIMESTAMP})
  121. </if>
  122. </select>
  123. <select id="findListOfUnpaidPressOrderByDate" parameterType="map" resultMap="BaseResultMap">
  124. select
  125. <include refid="allColumns"/>
  126. from wx_order
  127. where press_end_date is not null and (order_status = 6 or order_status = 7)
  128. <if test="type != null">
  129. AND type = #{type,jdbcType=TINYINT}
  130. </if>
  131. <if test="startDate != null">
  132. AND unix_timestamp(`create_date`) &gt; unix_timestamp(#{startDate,jdbcType=TIMESTAMP})
  133. </if>
  134. <if test="endDate != null">
  135. AND unix_timestamp(`press_end_date`) &lt; unix_timestamp(#{endDate,jdbcType=TIMESTAMP})
  136. </if>
  137. </select>
  138. <sql id="allCUserOrderListColumns">
  139. o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,o.create_date,o.update_date,
  140. c.type,c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.valid_start_date,c.valid_end_date,
  141. cal.channel_type as send_channel_type
  142. </sql>
  143. <sql id="allCUserOrderDetailColumns">
  144. o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,o.create_date,o.update_date,
  145. c.type,c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.detail,c.remark,c.valid_start_date,c.valid_end_date,
  146. co.id as coupon_order_id,co.coupon_order_status,c.support_transfer
  147. </sql>
  148. <update id="updateStatusByPressCouponId" parameterType="com.iformall.domain.po.WxOrder">
  149. update wx_order set order_status=#{orderStatus}
  150. where product_id=#{productId}
  151. and press_end_date is not null and order_status in (6,7)
  152. <if test=" null != tenantId ">
  153. and `tenant_id` = #{tenantId}
  154. </if>
  155. </update>
  156. <resultMap id="CVoResultMap" type="com.iformall.domain.vo.WxOrderCouponVo">
  157. <id column="id" jdbcType="BIGINT" property="id"/>
  158. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  159. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  160. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  161. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  162. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  163. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  164. <result column="payment" jdbcType="INTEGER" property="payment"/>
  165. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  166. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  167. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  168. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  169. <result column="type" jdbcType="INTEGER" property="type"/>
  170. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  171. <result column="title" jdbcType="VARCHAR" property="title"/>
  172. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  173. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  174. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  175. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  176. <result column="price" jdbcType="INTEGER" property="price"/>
  177. <result column="unit" jdbcType="INTEGER" property="unit"/>
  178. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  179. <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate"/>
  180. <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate"/>
  181. <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId"/>
  182. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus"/>
  183. <result column="send_channel_type" jdbcType="INTEGER" property="sendChannelType" />
  184. <result column="support_transfer" jdbcType="INTEGER" property="supportTransfer"/>
  185. <collection column="{productId=product_id}" property="merchantVoList"
  186. ofType="com.iformall.domain.vo.WxMerchantVo"
  187. javaType="java.util.List"
  188. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  189. </collection>
  190. </resultMap>
  191. <select id="findListOfCUser" parameterType="com.iformall.domain.po.WxOrder" resultMap="CVoResultMap">
  192. select
  193. <include refid="allCUserOrderListColumns"/>
  194. from wx_coupon c,wx_order o
  195. left join wx_coupon_order co on co.order_id = o.id
  196. left join wx_coupon_action_log cal on cal.coupon_order_id = co.id
  197. where o.product_id = c.id
  198. <if test="cUserId != null">
  199. and o.c_user_id = #{cUserId}
  200. </if>
  201. <if test="tenantId != null">
  202. and o.tenant_id = #{tenantId}
  203. </if>
  204. <if test="orderStatus != null">
  205. AND o.order_status = #{orderStatus}
  206. </if>
  207. <if test=" null != sortColumns">order by ${sortColumns}</if>
  208. </select>
  209. <select id="selectDetailOfCUser" parameterType="com.iformall.domain.po.WxOrder" resultMap="CVoResultMap">
  210. select
  211. <include refid="allCUserOrderDetailColumns"/>
  212. FROM wx_order o
  213. left join wx_coupon c ON o.product_id = c.id
  214. left join wx_coupon_order co on o.id = co.order_id
  215. where o.product_id = c.id
  216. <if test="cUserId != null">
  217. and o.c_user_id = #{cUserId}
  218. </if>
  219. <if test="tenantId != null">
  220. and o.tenant_id = #{tenantId}
  221. </if>
  222. <if test="id != null">
  223. and o.id = #{id}
  224. </if>
  225. </select>
  226. <select id="dayMicroPayAmountList" parameterType="map" resultType="map">
  227. select count(*) as count, IFNULL(sum(o.payment), 0) as total_price
  228. from wx_order o
  229. inner join wx_merchant_b_user bu on bu.id = product_id
  230. inner join wx_merchant m on m.id = bu.merchant_id
  231. where o.`type` = 1 and o.`order_status` = 1
  232. <if test=" null != tenantId ">
  233. and o.`tenant_id` = #{tenantId}
  234. </if>
  235. <if test=" null != merchantId ">
  236. and bu.`merchant_id` = #{merchantId}
  237. </if>
  238. <if test=" null != cUserId ">
  239. and o.`c_user_id` = #{cUserId}
  240. </if>
  241. <if test=" null != bUserId ">
  242. and bu.`id` = #{bUserId}
  243. </if>
  244. <if test=" null != couponChannelId ">
  245. and o.`coupon_channel_id` = #{couponChannelId}
  246. </if>
  247. <if test=" null != productId ">
  248. and o.`product_id` = #{productId}
  249. </if>
  250. <if test="startDate != null">
  251. AND o.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  252. </if>
  253. <if test="endDate != null">
  254. AND o.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  255. </if>
  256. </select>
  257. <resultMap id="PayVoResultMap" type="com.iformall.domain.vo.WxOrderPayVo">
  258. <id column="id" jdbcType="BIGINT" property="id"/>
  259. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  260. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  261. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  262. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  263. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  264. <result column="type" jdbcType="TINYINT" property="type"/>
  265. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  266. <result column="payment" jdbcType="INTEGER" property="payment"/>
  267. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  268. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  269. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  270. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  271. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  272. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  273. <result column="name" jdbcType="VARCHAR" property="bUserName" />
  274. <result column="bphone" jdbcType="VARCHAR" property="bUserPhone" />
  275. <result column="phone" jdbcType="VARCHAR" property="cUserPhone" />
  276. <result column="nick_name" jdbcType="VARCHAR" property="nickName" />
  277. <result column="c_user_name" jdbcType="VARCHAR" property="cUserName" />
  278. </resultMap>
  279. <sql id="allPayOrderColumns">
  280. o.`id`,o.`order_number`,o.`tenant_id`,o.`c_user_id`,o.`coupon_channel_id`,o.`product_id`,o.`type`,
  281. o.`payment_type`,o.`payment`,o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`,o.`detail`,
  282. m.name as merchant_name, bu.name, bu.phone as bphone,
  283. cu.phone, cu.nick_name, cubi.name c_user_name
  284. </sql>
  285. <select id="findListOfMicroPayOrderByDate" parameterType="map" resultMap="PayVoResultMap">
  286. select
  287. <include refid="allPayOrderColumns"/>
  288. from wx_order o
  289. inner join wx_merchant_b_user bu on bu.id = o.product_id
  290. inner join wx_merchant m on m.id = bu.merchant_id
  291. LEFT JOIN wx_c_user cu on cu.id = o.c_user_id
  292. LEFT JOIN wx_c_user_basic_info cubi on cubi.id = o.c_user_id
  293. where o.order_status = '1' and o.`type` = 1
  294. <if test=" null != tenantId ">
  295. and o.`tenant_id` = #{tenantId}
  296. </if>
  297. <if test=" null != merchantId ">
  298. and bu.`merchant_id` = #{merchantId}
  299. </if>
  300. <if test=" null != bUserId ">
  301. and bu.`id` = #{bUserId}
  302. </if>
  303. <if test="startDate != null">
  304. AND o.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  305. </if>
  306. <if test="endDate != null">
  307. AND o.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  308. </if>
  309. order by o.create_date desc
  310. </select>
  311. <select id="queryForSceneRepotyHistory" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="hashmap">
  312. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime, count(o.id) triggerCount
  313. from wx_order o
  314. where o.`tenant_id` = #{tenantId} and o.`type` = #{type}
  315. <if test=" null != startTime and null != endTime">
  316. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  317. </if>
  318. group by xTime
  319. </select>
  320. <select id="listOrderReportByDate" resultType="com.iformall.domain.vo.WxOrderReportVo" parameterType="hashmap">
  321. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime,
  322. count(o.id) count,
  323. IFNULL (SUM(o.payment),0) amount
  324. from wx_order o
  325. where o.`tenant_id` = #{tenantId}
  326. <if test=" null != tenantId">
  327. and o.`tenant_id` = #{tenantId}
  328. </if>
  329. <if test=" null != type">
  330. and o.`type` = #{type}
  331. </if>
  332. <if test=" null != orderStatus">
  333. and o.`order_status` = #{orderStatus}
  334. </if>
  335. <if test=" null != startTime and null != endTime">
  336. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  337. </if>
  338. group by xTime
  339. </select>
  340. <select id="listMicroPayOrderReportByDateAndMerchant" resultType="com.iformall.domain.vo.WxOrderReportVo" parameterType="hashmap">
  341. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime, count(o.id) count, IFNULL (SUM(o.payment),0) amount
  342. from wx_order o
  343. inner join wx_merchant_b_user bu on bu.id = o.product_id
  344. inner join wx_merchant m on m.id = bu.merchant_id
  345. where m.`id` = #{merchantId} and o.`type` = 1
  346. <if test=" null != startTime and null != endTime">
  347. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  348. </if>
  349. group by xTime
  350. </select>
  351. <resultMap id="WxMerchantMicroPayVo" type="com.iformall.domain.vo.WxMerchantMicroPayVo">
  352. <id column="id" jdbcType="BIGINT" property="id" />
  353. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  354. <result column="trade_amt" jdbcType="DECIMAL" property="tradeAmt" />
  355. <result column="report_date" jdbcType="VARCHAR" property="reportDate" />
  356. <result column="merchant_phone" jdbcType="VARCHAR" property="merchantPhone" />
  357. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  358. </resultMap>
  359. <sql id="WxMerchantMicroPayColumnsVo">
  360. wm.id as id,
  361. wm.tenant_id as tenant_id,
  362. wm.name as merchant_name,
  363. wm.link_phone as merchant_phone,
  364. mo.xTime as report_date,
  365. (case when mo.amount > 0 then mo.amount else 0 end) trade_amt
  366. </sql>
  367. <select id="findListOfMerchantMicroPayOrderByDate" parameterType="map" resultMap="WxMerchantMicroPayVo">
  368. select
  369. <include refid="WxMerchantMicroPayColumnsVo"/>
  370. from wx_merchant wm
  371. left join
  372. (select m.id as mid, IFNULL(sum(o.payment),0) amount,DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime
  373. from wx_merchant m, wx_order o, wx_merchant_b_user bu
  374. where bu.id = o.product_id
  375. and m.status = 1
  376. and m.id = bu.merchant_id
  377. and o.order_status = '1'
  378. and o.type = 1
  379. <if test="startTime != null">
  380. AND o.create_date &gt; #{startTime}
  381. </if>
  382. <if test="endTime != null">
  383. AND o.create_date &lt; #{endTime}
  384. </if>
  385. group by m.id,xTime) mo on mo.mid = wm.id
  386. where wm.status = 1
  387. <if test=" null != merchantName ">
  388. and wm.name like concat('%', #{merchantName},'%')
  389. </if>
  390. order by wm.create_date desc
  391. </select>
  392. <resultMap id="orderMap" type="com.iformall.domain.po.WxOrder">
  393. <id column="id" jdbcType="BIGINT" property="id"/>
  394. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  395. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  396. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  397. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  398. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  399. <result column="type" jdbcType="TINYINT" property="type"/>
  400. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  401. <result column="payment" jdbcType="INTEGER" property="payment"/>
  402. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  403. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  404. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  405. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  406. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  407. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
  408. <result column="c_user_name" jdbcType="VARCHAR" property="cUserName"/>
  409. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  410. </resultMap>
  411. <select id="findListOrder" resultMap="orderMap" parameterType="com.iformall.domain.vo.WxOrderQueryVo">
  412. select o.* from (
  413. select o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.type,o.payment_type,o.payment,o.payment_time,
  414. o.order_status,o.create_date,o.update_date,o.detail,'[多商户交易]' merchant_name,cubi.`name` c_user_name,cubi.phone
  415. from
  416. (
  417. select o.* from wx_order o where o.type=0 and o.order_status in (1,4) and o.id in(
  418. select o.id from wx_order o left join wx_coupon_merchant cm
  419. on o.product_id=cm.product_id group by o.id having count(o.id)>1)) o
  420. left join wx_c_user_basic_info cubi on o.c_user_id=cubi.id
  421. union all
  422. select o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.type,o.payment_type,o.payment,o.payment_time,
  423. o.order_status,o.create_date,o.update_date,o.detail,m.`name` merchant_name,cubi.`name` c_user_name,cubi.phone
  424. from(
  425. select o.*,cm.merchant_id from (
  426. select o.* from wx_order o where o.type=0 and o.order_status in (1,4) and o.id not in(
  427. select o.id from wx_order o left join wx_coupon_merchant cm
  428. on o.product_id=cm.product_id group by o.id having count(o.id)>1)
  429. ) o
  430. left join wx_coupon_merchant cm on o.product_id=cm.product_id
  431. union all
  432. select o.*,mbu.merchant_id from wx_order o
  433. left join wx_merchant_b_user mbu on o.product_id=mbu.id
  434. where o.type in (1,2) and o.order_status in (1,4) ) o
  435. left join wx_merchant m on o.merchant_id=m.id
  436. left join wx_c_user_basic_info cubi on o.c_user_id=cubi.id
  437. ) o
  438. <where>
  439. <if test="tenantId!=null">
  440. and o.tenant_id =#{tenantId}
  441. </if>
  442. <if test="merchantName!=null and merchantName!=''">
  443. and o.`merchant_name` like concat('%',#{merchantName},'%')
  444. </if>
  445. <if test="startdate!=null and enddate!=null">
  446. and o.create_date between #{startdate} and #{enddate}
  447. </if>
  448. </where>
  449. order by o.id desc
  450. </select>
  451. <select id="queryOrderForMerchantCount" resultType="Long" parameterType="hashmap">
  452. select count(*) merchantCount from (
  453. select distinct merchant_id from (
  454. select o.*, m.`name` merchantName from (
  455. select o.*,cm.merchant_id from wx_order o
  456. left join wx_coupon_merchant cm on o.product_id=cm.product_id
  457. where o.type = 0 and o.order_status in (1,4)) o
  458. left join wx_merchant m on o.merchant_id=m.id
  459. union all
  460. select o.*,m.`name` merchantName from (
  461. select o.*,mbu.merchant_id from wx_order o
  462. left join wx_merchant_b_user mbu on o.product_id=mbu.id
  463. where o.type in (1,2) and o.order_status in (1,4)) o
  464. left join wx_merchant m on o.merchant_id=m.id
  465. ) o
  466. <where>
  467. <if test="tenantId!=null">
  468. and o.tenant_id =#{tenantId}
  469. </if>
  470. <if test="startdate!=null and enddate!=null">
  471. and o.create_date between #{startdate} and #{enddate}
  472. </if>
  473. </where>
  474. ) o
  475. </select>
  476. <select id="queryOrderForSum" resultType="Long" parameterType="hashmap">
  477. select ifnull(sum(o.payment),0) payment from (
  478. select o.* from wx_order o
  479. where o.type in (0,1,2) and o.order_status = #{order_status}
  480. ) o
  481. <where>
  482. <if test="tenantId!=null">
  483. and o.tenant_id =#{tenantId}
  484. </if>
  485. <if test="startdate!=null and enddate!=null">
  486. and o.create_date between #{startdate} and #{enddate}
  487. </if>
  488. </where>
  489. </select>
  490. <resultMap id="PressVoResultMap" type="com.iformall.domain.vo.WxOrderCouponPressVo">
  491. <id column="id" jdbcType="BIGINT" property="id"/>
  492. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  493. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  494. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  495. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  496. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  497. <result column="type" jdbcType="INTEGER" property="type"/>
  498. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  499. <result column="payment" jdbcType="INTEGER" property="payment"/>
  500. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  501. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  502. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  503. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  504. <result column="press_end_date" jdbcType="TIMESTAMP" property="pressEndDate"/>
  505. <result column="press_current_num" jdbcType="INTEGER" property="pressCurrentNum"/>
  506. <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/>
  507. <result column="coupon_type" jdbcType="INTEGER" property="couponType"/>
  508. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  509. <result column="title" jdbcType="VARCHAR" property="title"/>
  510. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  511. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  512. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  513. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  514. <result column="price" jdbcType="INTEGER" property="price"/>
  515. <result column="unit" jdbcType="INTEGER" property="unit"/>
  516. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  517. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  518. <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId"/>
  519. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus"/>
  520. </resultMap>
  521. <resultMap id="PressVoDetailResultMap" type="com.iformall.domain.vo.WxOrderCouponPressVo">
  522. <id column="id" jdbcType="BIGINT" property="id"/>
  523. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  524. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  525. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  526. <result column="coupon_channel_id" jdbcType="BIGINT" property="couponChannelId"/>
  527. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  528. <result column="type" jdbcType="INTEGER" property="type"/>
  529. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  530. <result column="payment" jdbcType="INTEGER" property="payment"/>
  531. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  532. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  533. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  534. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  535. <result column="press_end_date" jdbcType="TIMESTAMP" property="pressEndDate"/>
  536. <result column="press_current_num" jdbcType="INTEGER" property="pressCurrentNum"/>
  537. <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/>
  538. <result column="coupon_type" jdbcType="INTEGER" property="couponType"/>
  539. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  540. <result column="title" jdbcType="VARCHAR" property="title"/>
  541. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  542. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  543. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  544. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  545. <result column="price" jdbcType="INTEGER" property="price"/>
  546. <result column="unit" jdbcType="INTEGER" property="unit"/>
  547. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  548. <result column="press_limit_num" jdbcType="INTEGER" property="pressLimitNum"/>
  549. <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId"/>
  550. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus"/>
  551. <collection column="{orderId=order_number}" property="orderPressList"
  552. ofType="com.iformall.domain.vo.WxOrderPressVo"
  553. javaType="java.util.List"
  554. select="com.iformall.mapper.WxOrderPressMapper.findPressList" >
  555. </collection>
  556. </resultMap>
  557. <sql id="allOrderPressListColumns">
  558. o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,
  559. o.create_date,o.update_date,o.press_end_date,o.press_current_num,o.press_current_value,
  560. c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.press_limit_num
  561. </sql>
  562. <sql id="allOrderPressDetailColumns">
  563. o.id,o.order_number,o.tenant_id,o.c_user_id,o.coupon_channel_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,
  564. o.create_date,o.update_date,o.press_end_date,o.press_current_num,o.press_current_value,
  565. c.type as coupon_type,c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.detail,c.remark,c.press_limit_num,
  566. co.id as coupon_order_id,co.coupon_order_status
  567. </sql>
  568. <select id="findListOfPress" parameterType="com.iformall.domain.po.WxOrder" resultMap="PressVoResultMap">
  569. select
  570. <include refid="allOrderPressListColumns"/>
  571. from wx_coupon c,wx_order o
  572. left join wx_coupon_order co on co.order_id = o.id
  573. where o.product_id = c.id and c.type = 8 and o.order_status in (6,7,8,9)
  574. <if test="cUserId != null">
  575. and o.c_user_id = #{cUserId}
  576. </if>
  577. <if test="tenantId != null">
  578. and o.tenant_id = #{tenantId}
  579. </if>
  580. <if test="orderStatus != null">
  581. AND o.order_status = #{orderStatus}
  582. </if>
  583. <if test=" null != sortColumns">order by ${sortColumns}</if>
  584. </select>
  585. <select id="selectDetailOfPress" parameterType="com.iformall.domain.po.WxOrder" resultMap="PressVoDetailResultMap">
  586. select
  587. <include refid="allOrderPressDetailColumns"/>
  588. FROM wx_order o
  589. left join wx_coupon c ON o.product_id = c.id
  590. left join wx_coupon_order co on o.id = co.order_id
  591. where o.product_id = c.id
  592. <if test="cUserId != null">
  593. and o.c_user_id = #{cUserId}
  594. </if>
  595. <if test="tenantId != null">
  596. and o.tenant_id = #{tenantId}
  597. </if>
  598. <if test="id != null">
  599. and o.id = #{id}
  600. </if>
  601. </select>
  602. <update id="updateStatusByOrderGroupId" parameterType="com.iformall.domain.po.WxOrder">
  603. update wx_order set order_status=#{orderStatus} where tenant_id=#{tenantId} and order_group_id=#{orderGroupId}
  604. </update>
  605. </mapper>