Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

492 rader
20 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="product_id" jdbcType="BIGINT" property="productId"/>
  10. <result column="type" jdbcType="TINYINT" property="type"/>
  11. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  12. <result column="payment" jdbcType="INTEGER" property="payment"/>
  13. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  14. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  15. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  16. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  17. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  18. </resultMap>
  19. <sql id="allColumns">
  20. `id`,`order_number`,`tenant_id`,`c_user_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`
  21. </sql>
  22. <sql id="dynamicWhereConditions">
  23. where 1 = 1
  24. <if test=" null != id ">
  25. and `id` = #{id}
  26. </if>
  27. <if test=" null != orderNumber ">
  28. and `order_number` = #{orderNumber}
  29. </if>
  30. <if test=" null != tenantId ">
  31. and `tenant_id` = #{tenantId}
  32. </if>
  33. <if test=" null != cUserId ">
  34. and `c_user_id` = #{cUserId}
  35. </if>
  36. <if test=" null != productId ">
  37. and `product_id` = #{productId}
  38. </if>
  39. <if test=" null != type ">
  40. and `type` = #{type}
  41. </if>
  42. <if test=" null != paymentType ">
  43. and `payment_type` = #{paymentType}
  44. </if>
  45. <if test=" null != payment ">
  46. and `payment` = #{payment}
  47. </if>
  48. <if test=" null != paymentTime ">
  49. and `payment_time` = #{paymentTime}
  50. </if>
  51. <if test=" null != orderStatus ">
  52. and `order_status` = #{orderStatus}
  53. </if>
  54. <if test=" null != createDate ">
  55. and `create_date` = #{createDate}
  56. </if>
  57. <if test=" null != updateDate ">
  58. and `update_date` = #{updateDate}
  59. </if>
  60. <if test=" null != detail ">
  61. and `detail` like concat('%', #{detail},'%')
  62. </if>
  63. <if test=" null != ids ">
  64. and id in
  65. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  66. #{idItem}
  67. </foreach>
  68. </if>
  69. <if test=" null != sortColumns">order by ${sortColumns}</if>
  70. </sql>
  71. <select id="findList" parameterType="com.iformall.domain.po.WxOrder" resultMap="BaseResultMap">
  72. select
  73. <include refid="allColumns"/>
  74. from wx_order
  75. <include refid="dynamicWhereConditions"/>
  76. </select>
  77. <select id="countList" parameterType="com.iformall.domain.po.WxOrder" resultType="java.lang.Integer">
  78. select count(*) from wx_order
  79. <include refid="dynamicWhereConditions"/>
  80. </select>
  81. <select id="dayCountList" parameterType="com.iformall.domain.po.WxOrder" resultType="java.lang.Integer">
  82. select count(*) from wx_order
  83. where 1=1
  84. <if test=" null != tenantId ">
  85. and `tenant_id` = #{tenantId}
  86. </if>
  87. <if test=" null != cUserId ">
  88. and `c_user_id` = #{cUserId}
  89. </if>
  90. <if test=" null != productId ">
  91. and `product_id` = #{productId}
  92. </if>
  93. <if test=" null != orderStatus ">
  94. and `order_status` = #{orderStatus}
  95. </if>
  96. and date(`create_date`) = curdate()
  97. </select>
  98. <select id="findListOfUnpaidOrderByDate" parameterType="map" resultMap="BaseResultMap">
  99. select
  100. <include refid="allColumns"/>
  101. from wx_order
  102. where order_status = '0'
  103. <if test="type != null">
  104. AND type = #{type,jdbcType=TINYINT}
  105. </if>
  106. <if test="startDate != null">
  107. AND create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  108. </if>
  109. <if test="endDate != null">
  110. AND create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  111. </if>
  112. </select>
  113. <sql id="allCUserOrderListColumns">
  114. o.id,o.order_number,o.tenant_id,o.c_user_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,o.create_date,o.update_date,
  115. c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit
  116. </sql>
  117. <sql id="allCUserOrderDetailColumns">
  118. o.id,o.order_number,o.tenant_id,o.c_user_id,o.product_id,o.payment_type,o.payment,o.payment_time,o.order_status,o.create_date,o.update_date,
  119. c.type,c.cover_img,c.title,c.sub_title,c.sale_price,c.use_price,c.price,c.unit,c.detail,c.remark,
  120. co.id as coupon_order_id,co.coupon_order_status
  121. </sql>
  122. <resultMap id="CVoResultMap" type="com.iformall.domain.vo.WxOrderCouponVo">
  123. <id column="id" jdbcType="BIGINT" property="id"/>
  124. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  125. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  126. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  127. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  128. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  129. <result column="payment" jdbcType="INTEGER" property="payment"/>
  130. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  131. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  132. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  133. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  134. <result column="type" jdbcType="INTEGER" property="type"/>
  135. <result column="cover_img" jdbcType="VARCHAR" property="coverImg"/>
  136. <result column="title" jdbcType="VARCHAR" property="title"/>
  137. <result column="sub_title" jdbcType="VARCHAR" property="subTitle"/>
  138. <result column="sale_price" jdbcType="INTEGER" property="salePrice"/>
  139. <result column="use_price" jdbcType="INTEGER" property="usePrice"/>
  140. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  141. <result column="price" jdbcType="INTEGER" property="price"/>
  142. <result column="unit" jdbcType="INTEGER" property="unit"/>
  143. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  144. <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId"/>
  145. <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus"/>
  146. <collection column="{productId=product_id}" property="merchantVoList"
  147. ofType="com.iformall.domain.vo.WxMerchantVo"
  148. javaType="java.util.List"
  149. select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" >
  150. </collection>
  151. </resultMap>
  152. <select id="findListOfCUser" parameterType="com.iformall.domain.po.WxOrder" resultMap="CVoResultMap">
  153. select
  154. <include refid="allCUserOrderListColumns"/>
  155. from wx_order o,wx_coupon c
  156. where o.product_id = c.id
  157. <if test="cUserId != null">
  158. and o.c_user_id = #{cUserId}
  159. </if>
  160. <if test="tenantId != null">
  161. and o.tenant_id = #{tenantId}
  162. </if>
  163. <if test="orderStatus != null">
  164. AND o.order_status = #{orderStatus}
  165. </if>
  166. <if test=" null != sortColumns">order by ${sortColumns}</if>
  167. </select>
  168. <select id="selectDetailOfCUser" parameterType="com.iformall.domain.po.WxOrder" resultMap="CVoResultMap">
  169. select
  170. <include refid="allCUserOrderDetailColumns"/>
  171. FROM wx_order o
  172. left join wx_coupon c ON o.product_id = c.id
  173. left join wx_coupon_order co on o.id = co.order_id
  174. where o.product_id = c.id
  175. <if test="cUserId != null">
  176. and o.c_user_id = #{cUserId}
  177. </if>
  178. <if test="tenantId != null">
  179. and o.tenant_id = #{tenantId}
  180. </if>
  181. <if test="id != null">
  182. and o.id = #{id}
  183. </if>
  184. </select>
  185. <select id="dayMicroPayAmountList" parameterType="map" resultType="map">
  186. select count(*) as count, IFNULL(sum(payment), 0) as total_price
  187. from wx_order
  188. inner join wx_merchant_b_user bu on bu.id = product_id
  189. inner join wx_merchant m on m.id = bu.merchant_id
  190. where `type` = 1 and `order_status` = 1
  191. <if test=" null != tenantId ">
  192. and `tenant_id` = #{tenantId}
  193. </if>
  194. <if test=" null != merchantId ">
  195. and bu.`merchant_id` = #{merchantId}
  196. </if>
  197. <if test=" null != cUserId ">
  198. and `c_user_id` = #{cUserId}
  199. </if>
  200. <if test=" null != bUserId ">
  201. and bu.`id` = #{bUserId}
  202. </if>
  203. <if test=" null != productId ">
  204. and `product_id` = #{productId}
  205. </if>
  206. <if test="startDate != null">
  207. AND create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  208. </if>
  209. <if test="endDate != null">
  210. AND create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  211. </if>
  212. </select>
  213. <resultMap id="PayVoResultMap" type="com.iformall.domain.vo.WxOrderPayVo">
  214. <id column="id" jdbcType="BIGINT" property="id"/>
  215. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  216. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  217. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  218. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  219. <result column="type" jdbcType="TINYINT" property="type"/>
  220. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  221. <result column="payment" jdbcType="INTEGER" property="payment"/>
  222. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  223. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  224. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  225. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  226. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  227. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  228. <result column="name" jdbcType="VARCHAR" property="bUserName" />
  229. <result column="bphone" jdbcType="VARCHAR" property="bUserPhone" />
  230. <result column="phone" jdbcType="VARCHAR" property="cUserPhone" />
  231. <result column="c_user_name" jdbcType="VARCHAR" property="cUserName" />
  232. </resultMap>
  233. <sql id="allPayOrderColumns">
  234. o.`id`,o.`order_number`,o.`tenant_id`,o.`c_user_id`,o.`product_id`,o.`type`,
  235. o.`payment_type`,o.`payment`,o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`,o.`detail`,
  236. m.name as merchant_name, bu.name, bu.phone as bphone, cu.phone,cu.c_user_name
  237. </sql>
  238. <select id="findListOfMicroPayOrderByDate" parameterType="map" resultMap="PayVoResultMap">
  239. select
  240. <include refid="allPayOrderColumns"/>
  241. from wx_order o
  242. inner join wx_merchant_b_user bu on bu.id = o.product_id
  243. inner join wx_merchant m on m.id = bu.merchant_id
  244. left join (
  245. select cu.id,cu.phone,(select cubi.`name` from wx_c_user_basic_info cubi
  246. where cubi.phone=cu.phone and cubi.`name` is not null limit 1) c_user_name
  247. from wx_c_user cu
  248. ) cu on cu.id = o.c_user_id
  249. where o.order_status = '1' and o.`type` = 1
  250. <if test=" null != tenantId ">
  251. and o.`tenant_id` = #{tenantId}
  252. </if>
  253. <if test=" null != merchantId ">
  254. and bu.`merchant_id` = #{merchantId}
  255. </if>
  256. <if test=" null != bUserId ">
  257. and bu.`id` = #{bUserId}
  258. </if>
  259. <if test="startDate != null">
  260. AND o.create_date &gt; #{startDate,jdbcType=TIMESTAMP}
  261. </if>
  262. <if test="endDate != null">
  263. AND o.create_date &lt; #{endDate,jdbcType=TIMESTAMP}
  264. </if>
  265. order by o.create_date desc
  266. </select>
  267. <select id="queryForSceneRepotyHistory" resultType="com.iformall.domain.vo.MarkingSceneDataVo" parameterType="hashmap">
  268. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime, count(o.id) triggerCount
  269. from wx_order o
  270. where o.`tenant_id` = #{tenantId} and o.`type` = #{type}
  271. <if test=" null != startTime and null != endTime">
  272. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  273. </if>
  274. group by xTime
  275. </select>
  276. <select id="listOrderReportByDate" resultType="com.iformall.domain.vo.WxOrderReportVo" parameterType="hashmap">
  277. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime, count(o.id) count, IFNULL (SUM(o.payment),0) amount
  278. from wx_order o
  279. where o.`tenant_id` = #{tenantId} and o.`type` = #{type}
  280. <if test=" null != startTime and null != endTime">
  281. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  282. </if>
  283. group by xTime
  284. </select>
  285. <select id="listMicroPayOrderReportByDateAndMerchant" resultType="com.iformall.domain.vo.WxOrderReportVo" parameterType="hashmap">
  286. select DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime, count(o.id) count, IFNULL (SUM(o.payment),0) amount
  287. from wx_order o
  288. inner join wx_merchant_b_user bu on bu.id = o.product_id
  289. inner join wx_merchant m on m.id = bu.merchant_id
  290. where m.`id` = #{merchantId} and o.`type` = 1
  291. <if test=" null != startTime and null != endTime">
  292. and o.`create_date` BETWEEN #{startTime} and #{endTime}
  293. </if>
  294. group by xTime
  295. </select>
  296. <resultMap id="WxMerchantMicroPayVo" type="com.iformall.domain.vo.WxMerchantMicroPayVo">
  297. <id column="id" jdbcType="BIGINT" property="id" />
  298. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  299. <result column="trade_amt" jdbcType="DECIMAL" property="tradeAmt" />
  300. <result column="report_date" jdbcType="VARCHAR" property="reportDate" />
  301. <result column="merchant_phone" jdbcType="VARCHAR" property="merchantPhone" />
  302. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
  303. </resultMap>
  304. <sql id="WxMerchantMicroPayColumnsVo">
  305. wm.id as id,
  306. wm.tenant_id as tenant_id,
  307. wm.name as merchant_name,
  308. wm.link_phone as merchant_phone,
  309. mo.xTime as report_date,
  310. (case when mo.amount > 0 then mo.amount else 0 end) trade_amt
  311. </sql>
  312. <select id="findListOfMerchantMicroPayOrderByDate" parameterType="map" resultMap="WxMerchantMicroPayVo">
  313. select
  314. <include refid="WxMerchantMicroPayColumnsVo"/>
  315. from wx_merchant wm
  316. left join
  317. (select m.id as mid, IFNULL(sum(o.payment),0) amount,DATE_FORMAT(o.create_date,'%Y-%m-%d') xTime
  318. from wx_merchant m, wx_order o, wx_merchant_b_user bu
  319. where bu.id = o.product_id
  320. and m.status = 1
  321. and m.id = bu.merchant_id
  322. and o.order_status = '1'
  323. and o.type = 1
  324. <if test="startTime != null">
  325. AND o.create_date &gt; #{startTime}
  326. </if>
  327. <if test="endTime != null">
  328. AND o.create_date &lt; #{endTime}
  329. </if>
  330. group by m.id,xTime) mo on mo.mid = wm.id
  331. where wm.status = 1
  332. <if test=" null != merchantName ">
  333. and wm.name like concat('%', #{merchantName},'%')
  334. </if>
  335. order by wm.create_date desc
  336. </select>
  337. <resultMap id="orderMap" type="com.iformall.domain.po.WxOrder">
  338. <id column="id" jdbcType="BIGINT" property="id"/>
  339. <result column="order_number" jdbcType="BIGINT" property="orderNumber"/>
  340. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  341. <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
  342. <result column="product_id" jdbcType="BIGINT" property="productId"/>
  343. <result column="type" jdbcType="TINYINT" property="type"/>
  344. <result column="payment_type" jdbcType="INTEGER" property="paymentType"/>
  345. <result column="payment" jdbcType="INTEGER" property="payment"/>
  346. <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime"/>
  347. <result column="order_status" jdbcType="INTEGER" property="orderStatus"/>
  348. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  349. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  350. <result column="detail" jdbcType="VARCHAR" property="detail"/>
  351. <result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
  352. <result column="c_user_name" jdbcType="VARCHAR" property="cUserName"/>
  353. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  354. </resultMap>
  355. <select id="findListOrder" resultMap="orderMap" parameterType="com.iformall.domain.vo.WxOrderQueryVo">
  356. select o.* from (
  357. select o.*,m.`name` merchant_name,cubi.`name` c_user_name,cubi.phone from (
  358. select o.*,cm.merchant_id from wx_order o
  359. left join wx_coupon_merchant cm on o.product_id=cm.product_id
  360. where type in (0,3)) o
  361. left join wx_merchant m on o.merchant_id=m.id
  362. left join wx_c_user_basic_info cubi on o.c_user_id=cubi.id
  363. union all
  364. select o.*,m.`name` merchantName,cubi.`name` c_user_name,cubi.phone from (
  365. select o.*,mbu.merchant_id from wx_order o
  366. left join wx_merchant_b_user mbu on o.product_id=mbu.id
  367. where type in (1,2)) o
  368. left join wx_merchant m on o.merchant_id=m.id
  369. left join wx_c_user_basic_info cubi on o.c_user_id=cubi.id
  370. ) o
  371. <where>
  372. <if test="tenantId!=null">
  373. and o.tenant_id =#{tenantId}
  374. </if>
  375. <if test="merchantName!=null">
  376. and o.`merchant_name` like concat('%',#{merchantName},'%')
  377. </if>
  378. <if test="startdate!=null and enddate!=null">
  379. and o.create_date between #{startdate} and #{enddate}
  380. </if>
  381. </where>
  382. order by o.id desc
  383. </select>
  384. <select id="queryOrderForMerchantCount" resultType="Long" parameterType="hashmap">
  385. select count(*) merchantCount from (
  386. select distinct merchant_id from (
  387. select o.*,m.`name` merchantName from (
  388. select o.*,cm.merchant_id from wx_order o
  389. left join wx_coupon_merchant cm on o.product_id=cm.product_id
  390. where type in (0,3)) o
  391. left join wx_merchant m on o.merchant_id=m.id
  392. union all
  393. select o.*,m.`name` merchantName from (
  394. select o.*,mbu.merchant_id from wx_order o
  395. left join wx_merchant_b_user mbu on o.product_id=mbu.id
  396. where type in (1,2)) o
  397. left join wx_merchant m on o.merchant_id=m.id
  398. ) o
  399. <where>
  400. <if test="tenantId!=null">
  401. and tenant_id =#{tenantId}
  402. </if>
  403. <if test="startdate!=null and enddate!=null">
  404. and create_date between #{startdate} and #{enddate}
  405. </if>
  406. </where>
  407. ) o
  408. </select>
  409. <select id="queryOrderForSum" resultType="Long" parameterType="hashmap">
  410. select ifnull(sum(payment),0) payment from (
  411. select o.*,m.`name` merchantName from (
  412. select o.*,cm.merchant_id from wx_order o
  413. left join wx_coupon_merchant cm on o.product_id=cm.product_id
  414. where type in (0,3)) o
  415. left join wx_merchant m on o.merchant_id=m.id
  416. union all
  417. select o.*,m.`name` merchantName from (
  418. select o.*,mbu.merchant_id from wx_order o
  419. left join wx_merchant_b_user mbu on o.product_id=mbu.id
  420. where type in (1,2)) o
  421. left join wx_merchant m on o.merchant_id=m.id
  422. ) o
  423. <where>
  424. <if test="tenantId!=null">
  425. and tenant_id =#{tenantId}
  426. </if>
  427. <if test="startdate!=null and enddate!=null">
  428. and create_date between #{startdate} and #{enddate}
  429. </if>
  430. </where>
  431. </select>
  432. </mapper>