Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

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