TopDivideOrderMapper.xml 16 KB

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