TopDivideOrderMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. </select>
  235. <select id="getMonthCreditList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  236. SELECT
  237. v.order_sn,
  238. v.create_time,
  239. v.purchase_org,
  240. v.divide_company_money,
  241. v.divide_seller_money,
  242. v.tenant_id,
  243. v.create_no,
  244. v.create_username,
  245. v.brokerage,
  246. v.order_price,
  247. st.tenant_name,
  248. v.pretax_brokerage,
  249. r.role_name,
  250. r.role_id,
  251. cl.check_status,
  252. v.pretax,
  253. bp.pay_type,
  254. bp.to_bank_acount,
  255. bp.to_bank_name,
  256. bp.to_bank_type_name,
  257. bp.create_time as pay_time,
  258. (SELECT
  259. ocl.check_reason
  260. FROM
  261. top_old_order_check_log ocl
  262. WHERE
  263. ocl.check_from = 4
  264. AND ocl.order_sn = v.order_sn
  265. AND ocl.check_status = -1
  266. ORDER BY ocl.check_sort
  267. LIMIT 1) as check_reason
  268. FROM
  269. top_old_order v
  270. LEFT JOIN sys_tenant st ON v.tenant_id = st.tenant_id
  271. LEFT JOIN
  272. top_old_order_check_log cl ON cl.check_from = 4 AND cl.check_sign = 1 AND v.order_sn = cl.order_sn
  273. LEFT JOIN top_sys_role r ON cl.role_id = r.role_id
  274. LEFT JOIN top_order_bank_pay bp ON bp.type = 4 AND bp.order_sn = v.order_sn AND bp.result_status = 1
  275. WHERE
  276. 1 = 1
  277. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  278. AND v.credit_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  279. </if>
  280. <if test="tenantId != null and tenantId != ''">
  281. AND v.tenant_id = #{tenantId}
  282. </if>
  283. <if test="createNo != null and createNo != ''">
  284. AND (v.create_no = #{createNo} or v.create_username like concat('%', #{createNo}, '%'))
  285. </if>
  286. <if test="orderSn != null and orderSn != ''">
  287. AND v.order_sn = #{orderSn}
  288. </if>
  289. AND v.credit_time > 0
  290. </select>
  291. <select id="getMonthRefundList" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  292. SELECT
  293. tor.order_sn,
  294. tor.divide_money,
  295. tor.tenant_id,
  296. tor.refund_sn,
  297. v.create_no,
  298. v.create_username
  299. FROM
  300. top_old_order_refund tor
  301. LEFT JOIN v_top_order v on tor.order_sn = v.order_sn
  302. WHERE
  303. 1 = 1
  304. AND tor.period_status = 3
  305. <if test="divideModel != null and divideModel != ''">
  306. AND tor.divide_model = #{divideModel}
  307. </if>
  308. <if test="refundTimeStartTime != null and refundTimeStartTime != ''">
  309. AND tor.refund_time BETWEEN #{refundTimeStartTime} and #{refundTimeEndTime}
  310. </if>
  311. <if test="tenantId != null and tenantId != ''">
  312. AND tor.tenant_id = #{tenantId}
  313. </if>
  314. <if test="createNo != null and createNo != ''">
  315. AND v.create_no = #{createNo}
  316. </if>
  317. </select>
  318. <select id="getMonthBadSum" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="BigDecimal">
  319. SELECT
  320. IFNULL(SUM(too.order_uncollected),0)
  321. FROM
  322. top_old_order too
  323. WHERE
  324. too.status=1
  325. AND too.check_status = 1
  326. <if test="buyStartTime != null and buyStartTime != ''">
  327. AND too.check_time <![CDATA[ >= ]]> #{buyStartTime}
  328. </if>
  329. <if test="buyEndTime != null and buyEndTime != ''">
  330. AND too.check_time <![CDATA[ <= ]]> #{buyEndTime}
  331. </if>
  332. <if test="tenantId != null and tenantId != ''">
  333. AND too.tenant_id = #{tenantId}
  334. </if>
  335. </select>
  336. <select id="getMonthFinishAllSeller" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopCreateUserVo">
  337. SELECT
  338. v.create_no,
  339. v.create_username,
  340. v.tenant_id
  341. FROM
  342. v_top_order v
  343. WHERE
  344. 1 = 1
  345. AND v.finish_status = 1
  346. <if test="divideModel != null and divideModel != ''">
  347. AND v.divide_model = #{divideModel}
  348. </if>
  349. <if test="accomplishStartTime != null and accomplishStartTime != ''">
  350. AND v.accomplish_time BETWEEN #{accomplishStartTime} and #{accomplishEndTime}
  351. </if>
  352. <if test="tenantId != null and tenantId != ''">
  353. AND v.tenant_id = #{tenantId}
  354. </if>
  355. <if test="createNo != null and createNo != ''">
  356. AND v.create_no = #{createNo}
  357. </if>
  358. GROUP BY v.create_no,v.create_username,v.tenant_id
  359. </select>
  360. <select id="getByOrderSn" parameterType="com.zhongzheng.modules.top.financial.bo.TopDivideOrderQueryBo" resultType="com.zhongzheng.modules.top.financial.vo.TopDivideOrderVo">
  361. SELECT
  362. tdo.*
  363. FROM
  364. top_divide_order tdo
  365. LEFT JOIN top_divide_log dl on tdo.divide_log_id = dl.id
  366. WHERE
  367. 1 = 1
  368. AND tdo.order_type = 1
  369. <if test="divideType != null and divideType != ''">
  370. AND dl.divide_type = #{divideType}
  371. </if>
  372. <if test="orderSn != null and orderSn != ''">
  373. AND tdo.order_sn = #{orderSn}
  374. </if>
  375. LIMIT 1
  376. </select>
  377. <update id="updateCheckStatusById" parameterType="com.zhongzheng.modules.top.order.domain.TopOrderBankPay" >
  378. UPDATE top_divide_order tdo
  379. LEFT JOIN top_divide_log dl ON tdo.divide_log_id = dl.id
  380. LEFT JOIN top_old_order_check_log cl ON ( dl.divide_type + 1 ) = cl.check_from
  381. AND cl.check_sign = 1
  382. AND tdo.order_sn = cl.order_sn
  383. <set>
  384. cl.check_status = 3
  385. </set>
  386. where
  387. tdo.order_type = 1
  388. AND tdo.divide_log_id = #{divideLogId}
  389. AND cl.check_status = 2
  390. </update>
  391. </mapper>