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.
 
 
 
 
 

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