Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

723 righe
40 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.WxBillAllMapper">
  4. <resultMap id="allVoResultMap" type="com.iformall.domain.vo.WxBillAllVo">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenantId" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="merchantId" jdbcType="INTEGER" property="merchantId" />
  8. <result column="shopId" jdbcType="INTEGER" property="shopId" />
  9. <result column="billTypeValue" jdbcType="INTEGER" property="billTypeValue"/>
  10. <result column="billType" jdbcType="VARCHAR" property="billType"/>
  11. <result column="needPay" jdbcType="BIGINT" property="needPay"/>
  12. <result column="merchantName" jdbcType="VARCHAR" property="merchantName" />
  13. <result column="rentShopType" jdbcType="INTEGER" property="rentShopType"/>
  14. <result column="receiveDate" jdbcType="TIMESTAMP" property="receiveDate" />
  15. <result column="expiredDay" jdbcType="INTEGER" property="expiredDay" />
  16. <result column="status" jdbcType="INTEGER" property="status" />
  17. <result column="receivePay" jdbcType="BIGINT" property="receivePay"/>
  18. <result column="owe" jdbcType="BIGINT" property="owe"/>
  19. <result column="pay" jdbcType="BIGINT" property="pay"/>
  20. <result column="payDate" jdbcType="TIMESTAMP" property="payDate" />
  21. <result column="starttime" jdbcType="TIMESTAMP" property="starttime" />
  22. <result column="endtime" jdbcType="TIMESTAMP" property="endtime" />
  23. <result column="shopNumber" jdbcType="VARCHAR" property="shopNumber"/>
  24. <result column="manager" jdbcType="VARCHAR" property="manager"/>
  25. <result column="managerPhone" jdbcType="VARCHAR" property="managerPhone"/>
  26. <result column="shopInfo" jdbcType="VARCHAR" property="shopInfo"/>
  27. <result column="name" jdbcType="VARCHAR" property="name"/>
  28. <result column="comments" property="comments"/>
  29. </resultMap>
  30. <select id="list" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  31. select
  32. bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId,
  33. bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  34. bill.receive_pay receivePay,bill.pay,
  35. case when bill.status=1 then bill.owe else 0 end owe
  36. ,bill.receive_date receiveDate,
  37. bill.pay_date payDate,expired_day expiredDay,bill.status,bill.starttime,
  38. bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName,
  39. s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info shopInfo,bill.comments
  40. from (
  41. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  42. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  43. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments
  44. from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0
  45. union all
  46. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  47. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  48. endtime,rent_shop_type,shop_info,NULL comments from wx_bill_rent_deposit where tenant_id=#{tenantId}
  49. union all
  50. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  51. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  52. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments
  53. from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0
  54. union all
  55. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  56. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  57. endtime,rent_shop_type,shop_info,NULL comments from wx_bill_property_deposit where tenant_id=#{tenantId}
  58. union all
  59. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  60. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  61. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as
  62. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  63. rent_shop_type,'[]' shop_info,price_detail as comments
  64. from wx_bill_daily where tenant_id=#{tenantId}
  65. union all
  66. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,concat('其他费用-',name) as bill_type,0 as
  67. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  68. rent_shop_type,'[]' shop_info,comments
  69. from wx_bill_other where tenant_id=#{tenantId}
  70. union all
  71. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  72. bill_type,0 as
  73. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  74. rent_shop_type,'[]' shop_info,comments
  75. from wx_bill_other_deposit where tenant_id=#{tenantId}
  76. ) bill
  77. left join wx_merchant m on bill.merchant_id=m.id
  78. left join wx_shop s on bill.shop_id=s.id
  79. where 1=1
  80. <if test=" null != tenantId ">
  81. and bill.tenant_id=#{tenantId}
  82. </if>
  83. <if test=" null != month and ''!=month">
  84. and date_format(bill.receive_date,'%Y-%m')=#{month}
  85. </if>
  86. <if test=" null != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
  87. <if test=" null != billTypeValue ">and bill.bill_type_value = #{billTypeValue}</if>
  88. <if test=" null != status ">and bill.`status` = #{status}</if>
  89. <if test=" null != rentShopType ">and bill.rent_shop_type = #{rentShopType}</if>
  90. <if test=" null != starttime and null!= endtime ">
  91. and bill.receive_date between #{starttime} and #{endtime}
  92. </if>
  93. <if test=" null != merchantId and ''!=merchantId">
  94. and bill.merchant_id=#{merchantId}
  95. </if>
  96. <if test=" null != statusList ">
  97. and bill.`status` in
  98. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  99. #{status}
  100. </foreach>
  101. </if>
  102. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  103. <if test=" null == sortColumns"> order by bill.receive_date,bill.id desc,bill.merchant_id,bill.status</if>
  104. </select>
  105. <select id="queryOweInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  106. select count(bill.id) owncount,IFNULL(sum(bill.owe),0) owe from (
  107. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  108. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
  109. union all
  110. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  111. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  112. wx_bill_rent_deposit
  113. union all
  114. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  115. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  116. wx_bill_property where is_preview = 0
  117. union all
  118. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  119. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  120. wx_bill_property_deposit
  121. union all
  122. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  123. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  124. type=1
  125. union all
  126. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  127. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  128. type=2
  129. union all
  130. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  131. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  132. type=3
  133. union all
  134. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  135. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  136. union all
  137. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  138. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  139. ) bill
  140. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  141. <if test=" null != starttime and null!= endtime ">
  142. and bill.receive_date between #{starttime} and #{endtime}
  143. </if>
  144. <if test=" null != month ">
  145. and date_format(bill.receive_date,'%Y-%m')=#{month}
  146. </if>
  147. <if test=" null != rentShopType ">
  148. and bill.rent_shop_type = #{rentShopType}
  149. </if>
  150. <if test=" null != billTypeList ">
  151. and bill.bill_type_value in
  152. <foreach collection="billTypeList" index="index" item="type" open="(" separator="," close=")">
  153. #{type}
  154. </foreach>
  155. </if>
  156. </select>
  157. <select id="queryPaidInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  158. select count(bill.id) paycount,IFNULL(sum(bill.pay),0) pay from (
  159. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  160. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_rent where is_preview = 0
  161. union all
  162. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  163. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  164. wx_bill_rent_deposit
  165. union all
  166. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  167. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  168. wx_bill_property where is_preview = 0
  169. union all
  170. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  171. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  172. wx_bill_property_deposit
  173. union all
  174. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  175. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  176. type=1
  177. union all
  178. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  179. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  180. type=2
  181. union all
  182. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  183. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  184. type=3
  185. union all
  186. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  187. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  188. union all
  189. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  190. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  191. ) bill
  192. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  193. <if test=" null != starttime and null!= endtime ">
  194. and bill.receive_date between #{starttime} and #{endtime}
  195. </if>
  196. <if test=" null != month ">
  197. and date_format(bill.receive_date,'%Y-%m')=#{month}
  198. </if>
  199. <if test=" null != rentShopType ">
  200. and bill.rent_shop_type = #{rentShopType}
  201. </if>
  202. </select>
  203. <select id="listData" resultType="hashmap" parameterType="com.iformall.domain.vo.WxBillAll">
  204. select bill.id,bill.merchant_id merchantId,bill.shop_id shopId,bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  205. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate,DATEDIFF(now(),bill.receive_date) expiredDay,bill.status,
  206. bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus,
  207. pb.pay_time_end tradeTime,pb.transaction_id transactionId,pb.pay_amount payAmount,bill.rent_shop_type
  208. rentShopType from (
  209. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  210. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  211. from wx_bill_rent where is_preview = 0 and tenant_id=#{tenantId} and rent_contract_id in (select id from
  212. wx_rent_contract where status in
  213. (2,3,4))
  214. union all
  215. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  216. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  217. from wx_bill_rent_deposit where tenant_id=#{tenantId} and rent_contract_id in (select id from wx_rent_contract
  218. where status in (2,3,4))
  219. union all
  220. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  221. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  222. from wx_bill_property where is_preview = 0 and tenant_id=#{tenantId} and property_contract_id in (select id from
  223. wx_property_contract
  224. where status in(2,3,4))
  225. union all
  226. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  227. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  228. from wx_bill_property_deposit where tenant_id=#{tenantId} and property_contract_id in (select id from
  229. wx_property_contract where status in
  230. (2,3,4))
  231. union all
  232. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  233. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  234. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type, 0 as need_pay,receive_pay,
  235. pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  236. from wx_bill_daily where tenant_id=#{tenantId}
  237. union all
  238. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_vaue,'其他费用' bill_type,0 as
  239. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  240. from wx_bill_other where tenant_id=#{tenantId}
  241. union all
  242. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,'其他押金' bill_type,0 as
  243. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  244. from wx_bill_other_deposit where tenant_id=#{tenantId}
  245. ) bill
  246. left join wx_merchant m on bill.merchant_id=m.id
  247. left join wx_shop s on bill.shop_id=s.id
  248. left join wx_pay_bill pb on bill.id=pb.bill_id
  249. where 1=1
  250. <if test=" null != id ">
  251. and bill.id=#{id}
  252. </if>
  253. <if test=" null != tenantId ">
  254. and bill.tenant_id=#{tenantId}
  255. </if>
  256. <if test=" null != merchantId ">
  257. and bill.merchant_id=#{merchantId}
  258. </if>
  259. <if test=" null != statusList ">
  260. and bill.`status` in
  261. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  262. #{status}
  263. </foreach>
  264. </if>
  265. <if test=" null != typeList ">
  266. and bill.`bill_type_value` in
  267. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  268. #{type}
  269. </foreach>
  270. </if>
  271. <if test="null!=starttime and null!=endtime">
  272. and DATE_FORMAT(bill.receive_date,'%Y-%m') between #{starttime} and #{endtime}
  273. </if>
  274. <if test=" null != status ">
  275. and bill.status=#{status}
  276. </if>
  277. <if test=" null != billTypeValue ">
  278. and bill.bill_type_value=#{billTypeValue}
  279. </if>
  280. <if test=" null != rentShopType ">
  281. and bill.rent_shop_type = #{rentShopType}
  282. </if>
  283. order by bill.merchant_id,bill.status,bill.receive_date desc
  284. </select>
  285. <select id="getWaitPayBill" resultType="hashmap">
  286. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  287. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType from (
  288. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  289. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  290. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  291. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  292. union all
  293. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  294. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  295. endtime,rent_shop_type from wx_bill_rent_deposit
  296. union all
  297. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  298. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  299. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  300. union all
  301. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  302. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  303. endtime,rent_shop_type from wx_bill_property_deposit
  304. union all
  305. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  306. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  307. from wx_bill_daily where type=1
  308. union all
  309. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  310. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  311. from wx_bill_daily where type=2
  312. union all
  313. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  314. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  315. from wx_bill_daily where type=3
  316. union all
  317. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  318. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  319. from wx_bill_other
  320. union all
  321. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  322. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  323. from wx_bill_other_deposit
  324. ) bill
  325. where bill.status not in(3,5,6)
  326. group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
  327. left join wx_merchant m on bill.merchant_id=m.id
  328. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  329. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  330. </select>
  331. <select id="getOweBill" resultType="hashmap">
  332. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.owe,m.link_phone linkPhone,app.appname from (
  333. select bill.tenant_id,bill.merchant_id,sum(owe) owe from (
  334. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  335. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  336. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  337. union all
  338. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  339. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  340. endtime,rent_shop_type from wx_bill_rent_deposit
  341. union all
  342. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  343. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  344. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  345. union all
  346. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  347. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  348. endtime,rent_shop_type from wx_bill_property_deposit
  349. union all
  350. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  351. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  352. from wx_bill_daily where type=1
  353. union all
  354. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  355. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  356. from wx_bill_daily where type=2
  357. union all
  358. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  359. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  360. from wx_bill_daily where type=3
  361. union all
  362. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  363. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  364. from wx_bill_other
  365. union all
  366. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  367. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  368. from wx_bill_other_deposit
  369. ) bill
  370. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  371. group by bill.tenant_id,bill.merchant_id) bill
  372. left join wx_merchant m on bill.merchant_id=m.id
  373. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  374. where m.status=1
  375. </select>
  376. <select id="getWaitPayBillForEmail" resultType="hashmap">
  377. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  378. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType,ws.manager,ws.manager_phone managerPhone from (
  379. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  380. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  381. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  382. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  383. union all
  384. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  385. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  386. endtime,rent_shop_type from wx_bill_rent_deposit
  387. union all
  388. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  389. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  390. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  391. union
  392. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  393. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  394. endtime,rent_shop_type from wx_bill_property_deposit
  395. union all
  396. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  397. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  398. from wx_bill_daily where type=1
  399. union all
  400. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  401. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  402. from wx_bill_daily where type=2
  403. union all
  404. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  405. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  406. from wx_bill_daily where type=3
  407. union all
  408. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  409. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  410. from wx_bill_other
  411. union all
  412. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  413. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  414. from wx_bill_other_deposit
  415. ) bill
  416. where bill.status not in(3,5,6)
  417. group by bill.tenant_id,bill.merchant_id,bill.receive_date,bill.bill_type
  418. ) bill
  419. left join wx_merchant m on bill.merchant_id=m.id
  420. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  421. left join wx_merchant_shop wms on wms.merchant_id = m.id
  422. left join wx_shop ws on wms.shop_id = ws.id
  423. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  424. </select>
  425. <select id="getOweBillForEmail" resultType="hashmap">
  426. select bill.tenant_id tenantId,bill.merchant_id merchantId,bill.bill_type billType,bill.owe owe,m.link_phone managerPhone,m.`link_person` manager,m.email,app.appname,bill.receive_date receiveDate
  427. ,DATEDIFF(now(),bill.receive_date) expiredDay from (
  428. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day from (
  429. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  430. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  431. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  432. union all
  433. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  434. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  435. endtime,rent_shop_type from wx_bill_rent_deposit
  436. union all
  437. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  438. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  439. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  440. union all
  441. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  442. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  443. endtime,rent_shop_type from wx_bill_property_deposit
  444. union all
  445. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  446. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  447. from wx_bill_daily where type=1
  448. union all
  449. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  450. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  451. from wx_bill_daily where type=2
  452. union all
  453. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  454. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  455. from wx_bill_daily where type=3
  456. union all
  457. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  458. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  459. from wx_bill_other
  460. union all
  461. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  462. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  463. from wx_bill_other_deposit
  464. ) bill
  465. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  466. group by bill.tenant_id,bill.merchant_id,bill.bill_type) bill
  467. left join wx_merchant m on bill.merchant_id=m.id
  468. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  469. where m.status=1
  470. </select>
  471. <sql id="getOweBillAsPageConditions">
  472. and status !=6
  473. <if test="null != status ">
  474. and status = #{status}
  475. </if>
  476. <if test=" null != month and ''!=month">
  477. and date_format(receive_date,'%Y-%m')=#{month}
  478. </if>
  479. <if test=" null != starttime and ''!=starttime">
  480. and receive_date >= #{starttime}
  481. </if>
  482. <if test=" null != endtime and ''!=endtime">
  483. and receive_date &lt;= #{endtime}
  484. </if>
  485. </sql>
  486. <select id="getOweBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  487. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.bill_type billType,
  488. m.link_phone managerPhone,m.`link_person` manager,m.email,
  489. bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay,
  490. round(bill.rentOwe/100,2) rentOwe,
  491. round(bill.propertyOwe/100,2) propertyOwe,
  492. round(bill.depositOwe/100,2) depositOwe,
  493. round(bill.otherOwe/100,2) otherOwe,
  494. round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe,
  495. <choose>
  496. <when test="1==filterHasPay">
  497. round((bill.rentReceivePay-bill.rentPay)/100,2) rentReceivePay,
  498. round((bill.propertyReceivePay-bill.propertyPay)/100,2) propertyReceivePay,
  499. round((bill.depositReceivePay-bill.depositPay)/100,2) depositReceivePay,
  500. round((bill.otherReceivePay-bill.otherPay)/100,2) otherReceivePay,
  501. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay
  502. -bill.rentPay-bill.propertyPay-bill.depositPay-bill.otherPay)/100,2) totalReceivePay
  503. </when>
  504. <otherwise>
  505. round(bill.rentReceivePay/100,2) rentReceivePay,
  506. round(bill.propertyReceivePay/100,2) propertyReceivePay,
  507. round(bill.depositReceivePay/100,2) depositReceivePay,
  508. round(bill.otherReceivePay/100,2) otherReceivePay,
  509. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay)/100,2) totalReceivePay
  510. </otherwise>
  511. </choose>
  512. from (
  513. select oweList.*,
  514. max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe,
  515. max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe,
  516. max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe,
  517. max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe,
  518. max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay,
  519. max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay,
  520. max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay,
  521. max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay,
  522. max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay,
  523. max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay,
  524. max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay,
  525. max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay
  526. from(
  527. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day,sum(bill.receive_pay) receive_pay,sum(bill.pay) pay from (
  528. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  529. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  530. endtime,rent_shop_type from wx_bill_rent where tenant_id = #{tenantId} and is_preview = 0
  531. <include refid="getOweBillAsPageConditions"/>
  532. union all
  533. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  534. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  535. endtime,rent_shop_type from wx_bill_property where tenant_id = #{tenantId} and is_preview = 0
  536. <include refid="getOweBillAsPageConditions"/>
  537. union all
  538. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  539. res.receive_pay,res.pay,res.owe owe,res.receive_date,res.pay_date,res.expired_day,res.status,res.starttime,res.endtime,res.rent_shop_type from(
  540. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,2 bill_type_value,'欠缴押金'
  541. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  542. endtime,rent_shop_type from wx_bill_rent_deposit where tenant_id = #{tenantId}
  543. <include refid="getOweBillAsPageConditions"/>
  544. union all
  545. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,4 bill_type_value,'欠缴押金'
  546. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  547. endtime,rent_shop_type from wx_bill_property_deposit where tenant_id = #{tenantId}
  548. <include refid="getOweBillAsPageConditions"/>
  549. union all
  550. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,8 bill_type_value,'欠缴押金' bill_type,0 as
  551. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  552. from wx_bill_other_deposit where tenant_id = #{tenantId}
  553. <include refid="getOweBillAsPageConditions"/>
  554. ) res
  555. union all
  556. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  557. res.receive_pay,res.pay,res.owe owe,res.receive_date,res.pay_date,res.expired_day,res.status,res.starttime,res.endtime,res.rent_shop_type from(
  558. select id,merchant_id,shop_id,tenant_id,'其他费用' name,5 bill_type_value,'其他费用' bill_type,0 as
  559. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  560. from wx_bill_daily where tenant_id = #{tenantId} and type in(1,2,3)
  561. <include refid="getOweBillAsPageConditions"/>
  562. union all
  563. select id,merchant_id,shop_id,tenant_id,'其他费用' name,7 bill_type_value,'其他费用' bill_type,0 as
  564. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  565. from wx_bill_other where tenant_id = #{tenantId}
  566. <include refid="getOweBillAsPageConditions"/>
  567. ) res
  568. ) bill
  569. where bill.status not in(3,5,6)
  570. group by bill.merchant_id,bill.bill_type
  571. ) oweList group by oweList.merchant_id
  572. ) bill
  573. left join wx_merchant m on bill.merchant_id=m.id
  574. where m.status=1 and m.tenant_id = #{tenantId}
  575. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  576. <if test=" null == sortColumns"> order by totalOwe desc </if>
  577. </select>
  578. <select id="getReceiveAndPayBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  579. select m.id,m.name,ws.shop_number shopNumber,ws.type,m.link_person linkPerson,m.link_line_phone linkPhone,
  580. round(
  581. (select sum(bill.receive_pay) from (
  582. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  583. union all
  584. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  585. union all
  586. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  587. union all
  588. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  589. union all
  590. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  591. union all
  592. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  593. union all
  594. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  595. ) bill where bill.merchant_id = m.id
  596. )/100,2) receivePay,
  597. round(
  598. (select sum(ss.money) from (
  599. select ms.subsidy money,mm.id
  600. from wx_merchant_subsidy ms
  601. left join wx_coupon_order co on co.id = ms.coupon_order_id
  602. left join wx_coupon c on c.id = co.coupon_id
  603. left join wx_merchant mm on mm.id = ms.merchant_id
  604. left join wx_card_spend cs on cs.order_id = ms.order_id
  605. left join wx_c_user cu on cu.id = cs.owner_id
  606. where ms.order_type in(3,0) and ms.status = 0
  607. union all
  608. select ms.subsidy money,mm.id
  609. from wx_merchant_subsidy ms
  610. left join wx_coupon_order co on co.id = ms.coupon_order_id
  611. left join wx_coupon c on c.id = co.coupon_id
  612. left join wx_merchant mm on mm.id = ms.merchant_id
  613. left join wx_card_spend cs on cs.order_id = ms.order_id
  614. left join wx_c_user cu on cu.id = cs.owner_id
  615. where ms.order_type in(3,0) and ms.status = 0
  616. union all
  617. select pay_amount money,mm.id from wx_profit_sharing_order pso
  618. left join wx_merchant mm on pso.merchant_id=mm.id
  619. where pso.sharing_status !=5
  620. )ss where ss.id = m.id
  621. )/100,2) payOut,
  622. (round(
  623. (select sum(bill.receive_pay) from (
  624. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  625. union all
  626. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  627. union all
  628. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  629. union all
  630. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  631. union all
  632. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  633. union all
  634. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  635. union all
  636. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  637. ) bill where bill.merchant_id = m.id
  638. )/100,2)-
  639. round(
  640. (select sum(ss.money) from (
  641. select ms.subsidy money,mm.id
  642. from wx_merchant_subsidy ms
  643. left join wx_coupon_order co on co.id = ms.coupon_order_id
  644. left join wx_coupon c on c.id = co.coupon_id
  645. left join wx_merchant mm on mm.id = ms.merchant_id
  646. left join wx_card_spend cs on cs.order_id = ms.order_id
  647. left join wx_c_user cu on cu.id = cs.owner_id
  648. where ms.order_type in(3,0) and ms.status = 0
  649. union all
  650. select ms.subsidy money,mm.id
  651. from wx_merchant_subsidy ms
  652. left join wx_coupon_order co on co.id = ms.coupon_order_id
  653. left join wx_coupon c on c.id = co.coupon_id
  654. left join wx_merchant mm on mm.id = ms.merchant_id
  655. left join wx_card_spend cs on cs.order_id = ms.order_id
  656. left join wx_c_user cu on cu.id = cs.owner_id
  657. where ms.order_type in(3,0) and ms.status = 0
  658. union all
  659. select pay_amount money,mm.id from wx_profit_sharing_order pso
  660. left join wx_merchant mm on pso.merchant_id=mm.id
  661. where pso.sharing_status !=5
  662. )ss where ss.id = m.id
  663. )/100,2)) balance
  664. from wx_merchant m left join wx_merchant_shop wms on wms.merchant_id = m.id left join wx_shop ws on wms.shop_id = ws.id
  665. where 1=1
  666. <if test=" null != tenantId"> and m.tenant_id = #{tenantId} </if>
  667. <if test=" null != merchantName"> and m.name like concat('%', #{merchantName},'%') </if>
  668. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  669. <if test=" null == sortColumns"> order by m.id desc </if>
  670. </select>
  671. </mapper>