TopDivideOrderMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zhongzheng.modules.top.financial.mapper.TopDivideOrderMapper">
  6. <resultMap type="com.zhongzheng.modules.top.financial.domain.TopDivideOrder" id="TopDivideOrderResult">
  7. <result property="id" column="id"/>
  8. <result property="divideLogId" column="divide_log_id"/>
  9. <result property="orderSn" column="order_sn"/>
  10. <result property="orderType" column="order_type"/>
  11. <result property="status" column="status"/>
  12. <result property="createTime" column="create_time"/>
  13. <result property="updateTime" column="update_time"/>
  14. </resultMap>
  15. <select id="getFinishList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  16. SELECT
  17. tdo.*,
  18. st.tenant_name ,
  19. cl.check_status,
  20. dl.pay_status,
  21. dl.divide_type,
  22. oo.accomplish_time as order_time,
  23. oo.remark,
  24. oo.divide_company_money,
  25. oo.divide_seller_money,
  26. oo.brokerage,
  27. oo.pretax_brokerage,
  28. oo.order_price,
  29. oo.order_from,
  30. oo.create_time as order_create_time,
  31. r.role_name,
  32. r.role_id,
  33. oo.create_username,
  34. oo.create_no
  35. FROM
  36. top_divide_order tdo
  37. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  38. LEFT JOIN sys_tenant st ON dl.tenant_id = st.tenant_id
  39. LEFT JOIN v_top_order oo ON tdo.order_sn = oo.order_sn
  40. LEFT JOIN
  41. top_old_order_check_log cl ON (dl.divide_type+1) = cl.check_from AND cl.check_sign = 1 AND tdo.order_sn = cl.order_sn
  42. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  43. WHERE
  44. tdo.order_type = 1
  45. AND tdo.divide_log_id = #{divideLogId}
  46. <if test="startPrice != null and startPrice != ''">
  47. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ >= ]]> #{startPrice}
  48. </if>
  49. <if test="endPrice != null and endPrice != ''">
  50. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ <= ]]> #{endPrice}
  51. </if>
  52. <if test="orderSn != null and orderSn != ''">
  53. AND oo.order_sn = #{orderSn}
  54. </if>
  55. <if test="accomplishStartTime != null ">
  56. AND oo.accomplish_time <![CDATA[ >= ]]> #{accomplishStartTime}
  57. </if>
  58. <if test="accomplishEndTime != null ">
  59. AND oo.accomplish_time <![CDATA[ <= ]]> #{accomplishEndTime}
  60. </if>
  61. <if test="checkStatus != null and checkStatus == 0">
  62. AND cl.check_status <![CDATA[ <= ]]> 0
  63. </if>
  64. <if test="checkStatus != null and checkStatus == 1">
  65. AND cl.check_status <![CDATA[ >= ]]> 1
  66. </if>
  67. </select>
  68. <select id="getFinishCount" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  69. SELECT
  70. SUM(oo.order_price) as order_price,
  71. SUM(oo.divide_company_money) as divide_company_money,
  72. SUM(oo.divide_seller_money) as divide_seller_money,
  73. SUM(oo.pretax_brokerage) as pretax_brokerage
  74. FROM
  75. top_divide_order tdo
  76. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  77. LEFT JOIN sys_tenant st ON dl.tenant_id = st.tenant_id
  78. LEFT JOIN v_top_order oo ON tdo.order_sn = oo.order_sn
  79. LEFT JOIN
  80. top_old_order_check_log cl ON (dl.divide_type+1) = cl.check_from AND cl.check_sign = 1 AND tdo.order_sn = cl.order_sn
  81. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  82. WHERE
  83. tdo.order_type = 1
  84. AND tdo.divide_log_id = #{divideLogId}
  85. <if test="startPrice != null and startPrice != ''">
  86. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ >= ]]> #{startPrice}
  87. </if>
  88. <if test="endPrice != null and endPrice != ''">
  89. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ <= ]]> #{endPrice}
  90. </if>
  91. <if test="orderSn != null and orderSn != ''">
  92. AND oo.order_sn = #{orderSn}
  93. </if>
  94. <if test="accomplishStartTime != null ">
  95. AND oo.accomplish_time <![CDATA[ >= ]]> #{accomplishStartTime}
  96. </if>
  97. <if test="accomplishEndTime != null ">
  98. AND oo.accomplish_time <![CDATA[ <= ]]> #{accomplishEndTime}
  99. </if>
  100. <if test="checkStatus != null and checkStatus == 0">
  101. AND cl.check_status <![CDATA[ <= ]]> 0
  102. </if>
  103. <if test="checkStatus != null and checkStatus == 1">
  104. AND cl.check_status <![CDATA[ >= ]]> 1
  105. </if>
  106. </select>
  107. <select id="getRefundList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  108. SELECT
  109. tdo.*,
  110. st.tenant_name,
  111. dl.pay_status,
  112. dl.divide_type,
  113. oo.remark,
  114. oo.order_price,
  115. oo.brokerage,
  116. oo.pretax_brokerage,
  117. tor.divide_money,
  118. tor.refund_time as order_time,
  119. oo.create_time as order_create_time
  120. FROM
  121. top_divide_order tdo
  122. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  123. LEFT JOIN sys_tenant st ON dl.tenant_id = st.tenant_id
  124. LEFT JOIN v_top_order oo ON tdo.order_sn = oo.order_sn
  125. LEFT JOIN top_old_order_refund tor ON tdo.order_sn = tor.order_sn
  126. WHERE
  127. tdo.order_type = 2
  128. AND tdo.divide_log_id = #{divideLogId}
  129. <if test="startPrice != null and startPrice != ''">
  130. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ >= ]]> #{startPrice}
  131. </if>
  132. <if test="endPrice != null and endPrice != ''">
  133. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ <= ]]> #{endPrice}
  134. </if>
  135. <if test="orderSn != null and orderSn != ''">
  136. AND oo.order_sn = #{orderSn}
  137. </if>
  138. <if test="accomplishStartTime != null ">
  139. AND tor.refund_time <![CDATA[ >= ]]> #{accomplishStartTime}
  140. </if>
  141. <if test="accomplishEndTime != null ">
  142. AND tor.refund_time <![CDATA[ <= ]]> #{accomplishEndTime}
  143. </if>
  144. <if test="checkStatus != null and checkStatus == 0">
  145. AND 1=0
  146. </if>
  147. </select>
  148. <select id="getRefundCount" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  149. SELECT
  150. SUM(tor.divide_money) as divide_money
  151. FROM
  152. top_divide_order tdo
  153. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  154. LEFT JOIN sys_tenant st ON dl.tenant_id = st.tenant_id
  155. LEFT JOIN v_top_order oo ON tdo.order_sn = oo.order_sn
  156. LEFT JOIN top_old_order_refund tor ON tdo.order_sn = tor.order_sn
  157. WHERE
  158. tdo.order_type = 2
  159. AND tdo.divide_log_id = #{divideLogId}
  160. <if test="startPrice != null and startPrice != ''">
  161. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ >= ]]> #{startPrice}
  162. </if>
  163. <if test="endPrice != null and endPrice != ''">
  164. AND (oo.order_price - oo.pretax_brokerage) <![CDATA[ <= ]]> #{endPrice}
  165. </if>
  166. <if test="orderSn != null and orderSn != ''">
  167. AND oo.order_sn = #{orderSn}
  168. </if>
  169. <if test="accomplishStartTime != null ">
  170. AND tor.refund_time <![CDATA[ >= ]]> #{accomplishStartTime}
  171. </if>
  172. <if test="accomplishEndTime != null ">
  173. AND tor.refund_time <![CDATA[ <= ]]> #{accomplishEndTime}
  174. </if>
  175. <if test="checkStatus != null and checkStatus == 0">
  176. AND 1=0
  177. </if>
  178. </select>
  179. <select id="getBusinessList" parameterType="String" resultType="String">
  180. SELECT
  181. business_name
  182. FROM
  183. v_top_order_business
  184. WHERE
  185. order_sn = #{orderSn}
  186. GROUP BY
  187. business_name
  188. </select>
  189. <select id="getMonthFinishAllTenant" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="String">
  190. SELECT
  191. v.tenant_id
  192. FROM
  193. v_top_order v
  194. WHERE
  195. 1 = 1
  196. AND v.finish_status = 1
  197. <if test="divideModel != null and divideModel != ''">
  198. AND v.divide_model = #{divideModel}
  199. </if>
  200. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  201. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  202. </if>
  203. <if test="tenantId != null and tenantId != ''">
  204. AND v.tenant_id = #{tenantId}
  205. </if>
  206. GROUP BY v.tenant_id
  207. </select>
  208. <select id="getMonthFinishList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  209. SELECT
  210. v.order_sn,
  211. v.divide_company_money,
  212. v.divide_seller_money,
  213. v.tenant_id,
  214. v.create_no,
  215. v.create_username,
  216. v.brokerage
  217. FROM
  218. v_top_order v
  219. WHERE
  220. 1 = 1
  221. AND v.finish_status = 1
  222. <if test="divideModel != null and divideModel != ''">
  223. AND v.divide_model = #{divideModel}
  224. </if>
  225. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  226. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  227. </if>
  228. <if test="tenantId != null and tenantId != ''">
  229. AND v.tenant_id = #{tenantId}
  230. </if>
  231. <if test="createNo != null and createNo != ''">
  232. AND v.create_no = #{createNo}
  233. </if>
  234. <if test="createSysUserId != null and createSysUserId != ''">
  235. AND v.create_sys_user_id = #{createSysUserId}
  236. </if>
  237. <if test="createSysUserId == 0">
  238. AND (v.create_sys_user_id is null or v.create_sys_user_id = 0)
  239. </if>
  240. </select>
  241. <select id="getMonthCreditList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  242. SELECT
  243. v.order_sn,
  244. v.create_time,
  245. v.purchase_org,
  246. v.divide_company_money,
  247. v.divide_seller_money,
  248. v.tenant_id,
  249. v.create_no,
  250. v.create_username,
  251. v.brokerage,
  252. v.brokerage_type,
  253. v.brokerage_bank_account,
  254. v.brokerage_bank_name,
  255. v.brokerage_bank,
  256. v.order_price,
  257. st.tenant_name,
  258. v.pretax_brokerage,
  259. r.role_name,
  260. r.role_id,
  261. cl.check_status,
  262. v.pretax,
  263. bp.pay_type,
  264. bp.to_bank_acount,
  265. bp.to_bank_name,
  266. bp.to_bank_type_name,
  267. bp.create_time as pay_time,
  268. (SELECT
  269. ocl.check_reason
  270. FROM
  271. top_old_order_check_log ocl
  272. WHERE
  273. ocl.check_from = 4
  274. AND ocl.order_sn = v.order_sn
  275. AND ocl.check_status = -1
  276. ORDER BY ocl.check_sort
  277. LIMIT 1) as check_reason
  278. FROM
  279. top_old_order v
  280. LEFT JOIN sys_tenant st ON v.tenant_id = st.tenant_id
  281. LEFT JOIN
  282. top_old_order_check_log cl ON cl.check_from = 4 AND cl.check_sign = 1 AND v.order_sn = cl.order_sn
  283. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  284. LEFT JOIN top_order_bank_pay bp ON bp.type = 4 AND bp.order_sn = v.order_sn AND bp.result_status = 1
  285. WHERE
  286. 1 = 1
  287. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  288. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  289. </if>
  290. <if test="buyStartTime != null and buyStartTime != ''">
  291. AND v.create_time BETWEEN #{buyStartTime} and #{buyEndTime}
  292. </if>
  293. <if test="tenantId != null and tenantId != ''">
  294. AND v.tenant_id = #{tenantId}
  295. </if>
  296. <if test="checkStatus != null and checkStatus.size()!=0">
  297. AND cl.check_status in
  298. <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">
  299. #{item}
  300. </foreach>
  301. </if>
  302. <if test="tenantIds != null and tenantIds.size()!=0">
  303. AND v.tenant_id in
  304. <foreach collection="tenantIds" item="item" index="index" open="(" close=")" separator=",">
  305. #{item}
  306. </foreach>
  307. </if>
  308. <if test="createNo != null and createNo != ''">
  309. AND (v.create_no = #{createNo} or v.create_username like concat('%', #{createNo}, '%'))
  310. </if>
  311. <if test="orderSn != null and orderSn != ''">
  312. AND v.order_sn = #{orderSn}
  313. </if>
  314. AND v.finish_status = 1
  315. AND v.brokerage > 0
  316. <if test="reCheckStatus == 1">
  317. AND (SELECT
  318. count(*)
  319. FROM
  320. top_old_order_check_log bcl
  321. WHERE
  322. bcl.check_from = 4
  323. AND bcl.check_status = 0
  324. AND bcl.check_sign = 1
  325. <if test="roleIds != null and roleIds.size()!=0">
  326. AND bcl.role_id in
  327. <foreach collection="roleIds" item="item" index="index" open="(" close=")" separator=",">
  328. #{item}
  329. </foreach>
  330. </if>
  331. AND bcl.order_sn = v.order_sn)>0
  332. </if>
  333. <if test="reCheckStatus == 2">
  334. AND (SELECT
  335. count(*)
  336. FROM
  337. top_old_order_check_log bcl
  338. WHERE
  339. bcl.check_from = 4
  340. AND bcl.check_status = 0
  341. AND bcl.check_sign = 1
  342. <if test="roleIds != null and roleIds.size()!=0">
  343. AND bcl.role_id not in
  344. <foreach collection="roleIds" item="item" index="index" open="(" close=")" separator=",">
  345. #{item}
  346. </foreach>
  347. </if>
  348. AND bcl.order_sn = v.order_sn)>0
  349. </if>
  350. order by v.create_time
  351. </select>
  352. <select id="getMonthCreditWaitCount" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="Long">
  353. SELECT
  354. count(*)
  355. FROM
  356. top_old_order v
  357. LEFT JOIN sys_tenant st ON v.tenant_id = st.tenant_id
  358. LEFT JOIN
  359. top_old_order_check_log cl ON cl.check_from = 4 AND cl.check_sign = 1 AND v.order_sn = cl.order_sn
  360. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  361. LEFT JOIN top_order_bank_pay bp ON bp.type = 4 AND bp.order_sn = v.order_sn AND bp.result_status = 1
  362. WHERE
  363. 1 = 1
  364. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  365. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  366. </if>
  367. <if test="tenantId != null and tenantId != ''">
  368. AND v.tenant_id = #{tenantId}
  369. </if>
  370. <if test="createNo != null and createNo != ''">
  371. AND (v.create_no = #{createNo} or v.create_username like concat('%', #{createNo}, '%'))
  372. </if>
  373. <if test="orderSn != null and orderSn != ''">
  374. AND v.order_sn = #{orderSn}
  375. </if>
  376. AND v.finish_status = 1
  377. AND v.brokerage > 0
  378. AND (SELECT
  379. count(*)
  380. FROM
  381. top_old_order_check_log bcl
  382. WHERE
  383. bcl.check_from = 4
  384. AND bcl.check_status = 0
  385. AND bcl.check_sign = 1
  386. <if test="roleIds != null and roleIds.size()!=0">
  387. AND bcl.role_id in
  388. <foreach collection="roleIds" item="item" index="index" open="(" close=")" separator=",">
  389. #{item}
  390. </foreach>
  391. </if>
  392. AND bcl.order_sn = v.order_sn)>0
  393. </select>
  394. <select id="getMonthRefundList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  395. SELECT
  396. tor.order_sn,
  397. tor.divide_money,
  398. tor.tenant_id,
  399. tor.refund_sn,
  400. v.create_no,
  401. v.create_username
  402. FROM
  403. top_old_order_refund tor
  404. LEFT JOIN v_top_order v on tor.order_sn = v.order_sn
  405. WHERE
  406. 1 = 1
  407. AND tor.period_status = 3
  408. <if test="divideModel != null and divideModel != ''">
  409. AND tor.divide_model = #{divideModel}
  410. </if>
  411. <if test="refundTimeStartTime != null and refundTimeStartTime != ''">
  412. AND tor.refund_time BETWEEN #{refundTimeStartTime} and #{refundTimeEndTime}
  413. </if>
  414. <if test="tenantId != null and tenantId != ''">
  415. AND tor.tenant_id = #{tenantId}
  416. </if>
  417. <if test="createNo != null and createNo != ''">
  418. AND v.create_no = #{createNo}
  419. </if>
  420. <if test="createSysUserId != null and createSysUserId != ''">
  421. AND v.create_sys_user_id = #{createSysUserId}
  422. </if>
  423. <if test="createSysUserId == 0">
  424. AND (v.create_sys_user_id is null or v.create_sys_user_id = 0)
  425. </if>
  426. </select>
  427. <select id="getMonthBadSum" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="BigDecimal">
  428. SELECT
  429. IFNULL(SUM(too.order_uncollected),0)
  430. FROM
  431. top_old_order too
  432. WHERE
  433. too.status=1
  434. AND too.check_status = 1
  435. <if test="buyStartTime != null and buyStartTime != ''">
  436. AND too.check_time <![CDATA[ >= ]]> #{buyStartTime}
  437. </if>
  438. <if test="buyEndTime != null and buyEndTime != ''">
  439. AND too.check_time <![CDATA[ <= ]]> #{buyEndTime}
  440. </if>
  441. <if test="tenantId != null and tenantId != ''">
  442. AND too.tenant_id = #{tenantId}
  443. </if>
  444. </select>
  445. <select id="getMonthFinishAllSeller" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopCreateUserVo">
  446. SELECT
  447. v.create_sys_user_id,
  448. any_value (v.create_username) create_username,
  449. v.tenant_id
  450. FROM
  451. v_top_order v
  452. WHERE
  453. 1 = 1
  454. AND v.finish_status = 1
  455. <if test="divideModel != null and divideModel != ''">
  456. AND v.divide_model = #{divideModel}
  457. </if>
  458. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  459. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  460. </if>
  461. <if test="tenantId != null and tenantId != ''">
  462. AND v.tenant_id = #{tenantId}
  463. </if>
  464. <if test="createNo != null and createNo != ''">
  465. AND v.create_no = #{createNo}
  466. </if>
  467. GROUP BY v.create_sys_user_id,v.tenant_id
  468. </select>
  469. <select id="getByOrderSn" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  470. SELECT
  471. tdo.*
  472. FROM
  473. top_divide_order tdo
  474. LEFT JOIN top_divide_log dl on tdo.divide_log_id = dl.id
  475. WHERE
  476. 1 = 1
  477. AND tdo.order_type = 1
  478. <if test="divideType != null and divideType != ''">
  479. AND dl.divide_type = #{divideType}
  480. </if>
  481. <if test="orderSn != null and orderSn != ''">
  482. AND tdo.order_sn = #{orderSn}
  483. </if>
  484. LIMIT 1
  485. </select>
  486. <update id="updateCheckStatusById" parameterType="com.zhongzheng.modules.top.order.domain.TopOrderBankPay" >
  487. UPDATE top_divide_order tdo
  488. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  489. LEFT JOIN top_old_order_check_log cl ON ( dl.divide_type + 1 ) = cl.check_from
  490. AND cl.check_sign = 1
  491. AND tdo.order_sn = cl.order_sn
  492. <set>
  493. cl.check_status = 3
  494. </set>
  495. where
  496. tdo.order_type = 1
  497. AND tdo.divide_log_id = #{divideLogId}
  498. AND cl.check_status = 2
  499. </update>
  500. </mapper>