Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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