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.
 
 
 
 
 

912 wiersze
51 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. <result column="price_detail" property="priceDetail"/>
  30. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
  31. <result column="freeze" property="freeze"/>
  32. <result column="late_pay_price" property="latePayPrice"/>
  33. </resultMap>
  34. <select id="list" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  35. select
  36. bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId,
  37. bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  38. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,
  39. bill.pay_date payDate,expired_day expiredDay,bill.status,bill.starttime,
  40. bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName,
  41. s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info
  42. shopInfo,bill.comments,bill.price_detail,updatetime,bill.freeze,bill.late_pay_price
  43. from (
  44. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  45. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  46. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  47. price_detail,updatetime,freeze,late_pay_price
  48. from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0
  49. union all
  50. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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,shop_info,NULL comments,'' price_detail,updatetime,freeze,'' late_pay_price from wx_bill_rent_deposit where
  53. tenant_id=#{tenantId}
  54. union all
  55. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  58. price_detail,updatetime,freeze,late_pay_price
  59. from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0
  60. union all
  61. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  62. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  63. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze,'' late_pay_price from wx_bill_property_deposit where
  64. tenant_id=#{tenantId}
  65. union all
  66. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  67. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  68. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as
  69. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  70. rent_shop_type,'[]' shop_info, NULL comments,price_detail,updatetime,freeze,'' late_pay_price
  71. from wx_bill_daily where tenant_id=#{tenantId}
  72. union all
  73. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,concat('其他费用-',name) as bill_type,0 as
  74. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  75. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze,'' late_pay_price
  76. from wx_bill_other where tenant_id=#{tenantId}
  77. union all
  78. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  79. bill_type,0 as
  80. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  81. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze,'' late_pay_price
  82. from wx_bill_other_deposit where tenant_id=#{tenantId}
  83. ) bill
  84. left join wx_merchant m on bill.merchant_id=m.id
  85. left join wx_shop s on bill.shop_id=s.id
  86. where 1=1
  87. <if test=" null != tenantId ">
  88. and bill.tenant_id=#{tenantId}
  89. </if>
  90. <if test=" null != month and ''!=month">
  91. and date_format(bill.receive_date,'%Y-%m')=#{month}
  92. </if>
  93. <if test=" null != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
  94. <if test=" null != billTypeValue ">and bill.bill_type_value = #{billTypeValue}</if>
  95. <if test=" null != status ">and bill.`status` = #{status}</if>
  96. <if test=" null != rentShopType ">and bill.rent_shop_type = #{rentShopType}</if>
  97. <if test=" null != starttime and null!= endtime and '' != starttime and ''!= endtime ">
  98. and bill.receive_date between #{starttime} and #{endtime}
  99. </if>
  100. <if test=" null != merchantId and ''!=merchantId">
  101. and bill.merchant_id=#{merchantId}
  102. </if>
  103. <if test=" null != statusList ">
  104. and bill.`status` in
  105. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  106. #{status}
  107. </foreach>
  108. </if>
  109. <if test=" null != typeList ">
  110. and bill.`bill_type_value` in
  111. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  112. #{type}
  113. </foreach>
  114. </if>
  115. <if test=" null != freeze ">and bill.freeze = #{freeze}</if>
  116. <if test=" null != id ">and bill.id = #{id}</if>
  117. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  118. <if test=" null == sortColumns"> order by bill.receive_date,bill.id desc,bill.merchant_id,bill.status</if>
  119. </select>
  120. <select id="queryOweInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  121. select count(bill.id) owncount,IFNULL(sum(bill.owe),0) owe from (
  122. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  123. 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
  124. union all
  125. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  126. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  127. wx_bill_rent_deposit
  128. union all
  129. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  130. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  131. wx_bill_property where is_preview = 0
  132. union all
  133. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  134. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  135. wx_bill_property_deposit
  136. union all
  137. select id,merchant_id,shop_id,tenant_id,5 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_daily where
  139. type=1
  140. union all
  141. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  142. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  143. type=2
  144. union all
  145. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  146. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  147. type=3
  148. union all
  149. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  150. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  151. union all
  152. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  153. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  154. ) bill
  155. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  156. <if test=" null != starttime and null!= endtime ">
  157. and bill.receive_date between #{starttime} and #{endtime}
  158. </if>
  159. <if test=" null != month ">
  160. and date_format(bill.receive_date,'%Y-%m')=#{month}
  161. </if>
  162. <if test=" null != rentShopType ">
  163. and bill.rent_shop_type = #{rentShopType}
  164. </if>
  165. <if test=" null != billTypeList ">
  166. and bill.bill_type_value in
  167. <foreach collection="billTypeList" index="index" item="type" open="(" separator="," close=")">
  168. #{type}
  169. </foreach>
  170. </if>
  171. </select>
  172. <select id="queryPaidInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  173. select count(bill.id) paycount,IFNULL(sum(bill.pay),0) pay from (
  174. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  175. 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
  176. union all
  177. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  178. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  179. wx_bill_rent_deposit
  180. union all
  181. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  182. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  183. wx_bill_property where is_preview = 0
  184. union all
  185. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  186. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  187. wx_bill_property_deposit
  188. union all
  189. select id,merchant_id,shop_id,tenant_id,5 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_daily where
  191. type=1
  192. union all
  193. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  194. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  195. type=2
  196. union all
  197. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  198. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  199. type=3
  200. union all
  201. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  202. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  203. union all
  204. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  205. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  206. ) bill
  207. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  208. <if test=" null != starttime and null!= endtime ">
  209. and bill.receive_date between #{starttime} and #{endtime}
  210. </if>
  211. <if test=" null != month ">
  212. and date_format(bill.receive_date,'%Y-%m')=#{month}
  213. </if>
  214. <if test=" null != rentShopType ">
  215. and bill.rent_shop_type = #{rentShopType}
  216. </if>
  217. </select>
  218. <select id="listData" resultType="hashmap" parameterType="com.iformall.domain.vo.WxBillAll">
  219. select bill.settle_number,bill.id,bill.merchant_id merchantId,bill.shop_id shopId,bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  220. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate,DATEDIFF(now(),bill.receive_date) expiredDay,bill.status,
  221. bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus,
  222. pb.pay_time_end tradeTime,pb.transaction_id transactionId,pb.pay_amount payAmount,bill.rent_shop_type
  223. rentShopType,bill.price_detail priceDetail,bill.freeze from (
  224. select '' settle_number,id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  225. bill_type,need_pay,receive_pay,pay,(receive_pay+service_charge_pay+ifnull(late_pay_price,0)-pay)
  226. owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  227. price_detail,freeze
  228. from wx_bill_rent where is_preview = 0 and tenant_id=#{tenantId} and rent_contract_id in (select id from
  229. wx_rent_contract where status in
  230. (2,3,4))
  231. union all
  232. select '' settle_number,id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  233. bill_type,need_pay,receive_pay,pay,(receive_pay+service_charge_pay-pay)
  234. owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  235. price_detail,freeze
  236. from wx_bill_rent_deposit where tenant_id=#{tenantId} and rent_contract_id in (select id from wx_rent_contract
  237. where status in (2,3,4))
  238. union all
  239. select '' settle_number,id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  240. bill_type,need_pay,receive_pay,pay,(receive_pay+service_charge_pay+ifnull(late_pay_price,0)-pay)
  241. owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  242. price_detail,freeze
  243. from wx_bill_property where is_preview = 0 and tenant_id=#{tenantId} and property_contract_id in (select id from
  244. wx_property_contract
  245. where status in(2,3,4))
  246. union all
  247. select '' settle_number,id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  248. bill_type,need_pay,receive_pay,pay,(receive_pay+service_charge_pay-pay)
  249. owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  250. price_detail,freeze
  251. from wx_bill_property_deposit where tenant_id=#{tenantId} and property_contract_id in (select id from
  252. wx_property_contract where status in
  253. (2,3,4))
  254. union all
  255. select '' settle_number,id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  256. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  257. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type, 0 as need_pay,receive_pay,
  258. pay,(receive_pay+service_charge_pay-pay)
  259. owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,price_detail,freeze
  260. from wx_bill_daily where tenant_id=#{tenantId}
  261. union all
  262. select '' settle_number,id,merchant_id,shop_id,tenant_id,name,7 bill_type_vaue,'其他费用' bill_type,0 as
  263. need_pay,receive_pay,pay,(receive_pay+service_charge_pay-pay) owe,receive_date,pay_date,expired_day,status,''
  264. starttime,'' endtime,rent_shop_type,''
  265. price_detail,freeze
  266. from wx_bill_other where tenant_id=#{tenantId}
  267. union all
  268. select '' settle_number,id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,'其他押金' bill_type,0 as
  269. need_pay,receive_pay,pay,(receive_pay+service_charge_pay-pay) owe,receive_date,pay_date,expired_day,status,''
  270. starttime,'' endtime,rent_shop_type,''
  271. price_detail,freeze
  272. from wx_bill_other_deposit where tenant_id=#{tenantId}
  273. union all
  274. select s.settle_number,s.id,s.merchant_id,'' shop_id,s.tenant_id,'结算单' name, 10 bill_type_value,'结算单' bill_type,0 need_pay,
  275. ((select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  276. (select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  277. 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
  278. union all
  279. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  280. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  281. wx_bill_rent_deposit
  282. union all
  283. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  284. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  285. wx_bill_property where is_preview = 0
  286. union all
  287. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  288. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  289. wx_bill_property_deposit
  290. union all
  291. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  292. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  293. type=1
  294. union all
  295. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  296. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  297. type=2
  298. union all
  299. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  300. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  301. type=3
  302. union all
  303. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  304. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  305. union all
  306. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  307. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  308. union all
  309. select id,id merchant_id,'' shop_id,tenant_id,10 bill_type_value,'补贴' bill_type,0 as
  310. need_pay,subsidy receive_pay,0 pay,0 owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
  311. ) bill
  312. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=0)
  313. -
  314. (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  315. (select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  316. 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
  317. union all
  318. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  319. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  320. wx_bill_rent_deposit
  321. union all
  322. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  323. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  324. wx_bill_property where is_preview = 0
  325. union all
  326. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  327. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  328. wx_bill_property_deposit
  329. union all
  330. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  331. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  332. type=1
  333. union all
  334. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  335. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  336. type=2
  337. union all
  338. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  339. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  340. type=3
  341. union all
  342. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  343. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  344. union all
  345. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  346. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  347. union all
  348. select id,id merchant_id,'' shop_id,tenant_id,10 bill_type_value,'补贴' bill_type,0 as
  349. need_pay,subsidy receive_pay,0 pay,subsidy owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
  350. ) bill
  351. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=1
  352. )
  353. ) receive_pay
  354. ,0 pay,0 owe,s.createtime receive_date,'' pay_date,0 expired_day,status,'' starttime,'' endtime,'' rent_shop_type,'' price_detail, 0 freeze
  355. from wx_bill_settle s where s.tenant_id=#{tenantId} and s.status >0
  356. ) bill
  357. left join wx_merchant m on bill.merchant_id=m.id
  358. left join wx_shop s on bill.shop_id=s.id
  359. left join wx_pay_bill pb on bill.id=pb.bill_id
  360. where 1=1
  361. <if test=" null != id ">
  362. and bill.id=#{id}
  363. </if>
  364. <if test=" null != tenantId ">
  365. and bill.tenant_id=#{tenantId}
  366. </if>
  367. <if test=" null != merchantId ">
  368. and bill.merchant_id=#{merchantId}
  369. </if>
  370. <if test=" null != statusList ">
  371. and bill.`status` in
  372. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  373. #{status}
  374. </foreach>
  375. </if>
  376. <if test=" null != typeList ">
  377. and bill.`bill_type_value` in
  378. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  379. #{type}
  380. </foreach>
  381. </if>
  382. <if test="null!=starttime and null!=endtime and ''!=starttime and ''!=endtime ">
  383. and DATE_FORMAT(bill.receive_date,'%Y-%m') between #{starttime} and #{endtime}
  384. </if>
  385. <if test=" null != status ">
  386. and bill.status=#{status}
  387. </if>
  388. <if test=" null != billTypeValue ">
  389. and bill.bill_type_value=#{billTypeValue}
  390. </if>
  391. <if test=" null != rentShopType ">
  392. and bill.rent_shop_type = #{rentShopType}
  393. </if>
  394. order by bill.merchant_id,bill.status desc,bill.receive_date desc
  395. </select>
  396. <select id="getWaitPayBill" resultType="hashmap">
  397. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  398. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType from (
  399. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  400. select id,merchant_id,shop_id,tenant_id,'租金' name,1 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_rent where is_preview = 0
  403. union all
  404. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_rent_deposit
  407. union all
  408. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  409. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  410. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  411. union all
  412. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  413. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  414. endtime,rent_shop_type from wx_bill_property_deposit
  415. union all
  416. select id,merchant_id,shop_id,tenant_id,'水费' name,5 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=1
  419. union all
  420. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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_daily where type=2
  423. union all
  424. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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_daily where type=3
  427. union all
  428. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  429. 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
  430. from wx_bill_other
  431. union all
  432. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  433. 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
  434. from wx_bill_other_deposit
  435. ) bill
  436. where bill.status not in(3,5,6)
  437. group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
  438. left join wx_merchant m on bill.merchant_id=m.id
  439. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  440. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  441. </select>
  442. <select id="getOweBill" resultType="hashmap">
  443. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.owe,m.link_phone linkPhone,app.appname from (
  444. select bill.tenant_id,bill.merchant_id,sum(owe) owe from (
  445. select id,merchant_id,shop_id,tenant_id,'租金' name,1 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 where is_preview = 0
  448. union all
  449. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_rent_deposit
  452. union all
  453. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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 where is_preview = 0
  456. union all
  457. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  458. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  459. endtime,rent_shop_type from wx_bill_property_deposit
  460. union all
  461. select id,merchant_id,shop_id,tenant_id,'水费' name,5 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=1
  464. union all
  465. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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=2
  468. union all
  469. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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_daily where type=3
  472. union all
  473. select id,merchant_id,shop_id,tenant_id,name,7 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
  476. union all
  477. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  478. 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
  479. from wx_bill_other_deposit
  480. ) bill
  481. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  482. group by bill.tenant_id,bill.merchant_id) bill
  483. left join wx_merchant m on bill.merchant_id=m.id
  484. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  485. where m.status=1
  486. </select>
  487. <select id="getWaitPayBillForEmail" resultType="hashmap">
  488. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  489. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType,ws.manager,ws.manager_phone managerPhone from (
  490. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  491. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  492. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  493. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  494. union all
  495. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  496. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  497. endtime,rent_shop_type from wx_bill_rent_deposit
  498. union all
  499. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  500. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  501. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  502. union
  503. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  504. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  505. endtime,rent_shop_type from wx_bill_property_deposit
  506. union all
  507. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  508. 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
  509. from wx_bill_daily where type=1
  510. union all
  511. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  512. 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
  513. from wx_bill_daily where type=2
  514. union all
  515. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  516. 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
  517. from wx_bill_daily where type=3
  518. union all
  519. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  520. 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
  521. from wx_bill_other
  522. union all
  523. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  524. 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
  525. from wx_bill_other_deposit
  526. ) bill
  527. where bill.status not in(3,5,6)
  528. group by bill.tenant_id,bill.merchant_id,bill.receive_date,bill.bill_type
  529. ) bill
  530. left join wx_merchant m on bill.merchant_id=m.id
  531. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  532. left join wx_merchant_shop wms on wms.merchant_id = m.id
  533. left join wx_shop ws on wms.shop_id = ws.id
  534. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  535. </select>
  536. <select id="getOweBillForEmail" resultType="hashmap">
  537. 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
  538. ,DATEDIFF(now(),bill.receive_date) expiredDay from (
  539. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day 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 is_preview = 0
  543. union all
  544. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  545. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  546. endtime,rent_shop_type from wx_bill_rent_deposit
  547. union all
  548. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  549. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  550. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  551. union all
  552. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 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_property_deposit
  555. union all
  556. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  557. 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
  558. from wx_bill_daily where type=1
  559. union all
  560. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  561. 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
  562. from wx_bill_daily where type=2
  563. union all
  564. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  565. 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
  566. from wx_bill_daily where type=3
  567. union all
  568. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  569. 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
  570. from wx_bill_other
  571. union all
  572. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  573. 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
  574. from wx_bill_other_deposit
  575. ) bill
  576. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  577. group by bill.tenant_id,bill.merchant_id,bill.bill_type) bill
  578. left join wx_merchant m on bill.merchant_id=m.id
  579. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  580. where m.status=1
  581. </select>
  582. <sql id="getOweBillAsPageConditions">
  583. and status !=6
  584. <if test="null != status ">
  585. and status = #{status}
  586. </if>
  587. <if test=" null != month and ''!=month">
  588. and date_format(receive_date,'%Y-%m')=#{month}
  589. </if>
  590. <if test=" null != starttime and ''!=starttime">
  591. and receive_date >= #{starttime}
  592. </if>
  593. <if test=" null != endtime and ''!=endtime">
  594. and receive_date &lt;= #{endtime}
  595. </if>
  596. </sql>
  597. <select id="getOweBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  598. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.bill_type billType,
  599. m.link_phone managerPhone,m.`link_person` manager,m.email,
  600. bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay,
  601. round(bill.rentOwe/100,2) rentOwe,
  602. round(bill.propertyOwe/100,2) propertyOwe,
  603. round(bill.depositOwe/100,2) depositOwe,
  604. round(bill.otherOwe/100,2) otherOwe,
  605. round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe,
  606. <choose>
  607. <when test="1==filterHasPay">
  608. round((bill.rentReceivePay+bill.rentLatePay+bill.rentServiceChargePay-bill.rentPay)/100,2)
  609. rentReceivePay,
  610. round((bill.propertyReceivePay+bill.propertyLatePay+bill.propertyServiceChargePay-bill.propertyPay)/100,2)
  611. propertyReceivePay,
  612. round((bill.depositReceivePay+bill.depositLatePay+bill.depositServiceChargePay-bill.depositPay)/100,2)
  613. depositReceivePay,
  614. round((bill.otherReceivePay+bill.otherLatePay+bill.otherServiceChargePay-bill.otherPay)/100,2)
  615. otherReceivePay,
  616. round((bill.rentReceivePay+bill.rentLatePay+bill.rentServiceChargePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay
  617. +bill.rentLatePay+bill.propertyLatePay+bill.depositLatePay+bill.otherLatePay+bill.rentSeviceChargePay+bill.propertySeviceChargePay
  618. +bill.depositSeviceChargePay+bill.otherSeviceChargePay
  619. -bill.rentPay-bill.propertyPay-bill.depositPay-bill.otherPay)/100,2) totalReceivePay
  620. </when>
  621. <otherwise>
  622. round((bill.rentReceivePay+bill.rentLatePay+bill.rentServiceChargePay)/100,2) rentReceivePay,
  623. round((bill.propertyReceivePay+bill.propertyLatePay+bill.propertyServiceChargePay)/100,2)
  624. propertyReceivePay,
  625. round((bill.depositReceivePay+bill.depositLatePay+bill.depositServiceChargePay)/100,2)
  626. depositReceivePay,
  627. round((bill.otherReceivePay+bill.otherLatePay+bill.otherServiceChargePay)/100,2) otherReceivePay,
  628. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay
  629. +bill.otherReceivePay+bill.rentLatePay+bill.propertyLatePay+bill.depositLatePay
  630. +bill.otherLatePay+bill.rentSeviceChargePay+bill.propertySeviceChargePay+bill.depositSeviceChargePay+bill.otherSeviceChargePay)/100,2)
  631. totalReceivePay
  632. </otherwise>
  633. </choose>
  634. from (
  635. select oweList.*,
  636. max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe,
  637. max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe,
  638. max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe,
  639. max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe,
  640. max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay,
  641. max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay,
  642. max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay,
  643. max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay,
  644. max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay,
  645. max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay,
  646. max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay,
  647. max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay,
  648. max(case oweList.bill_type when '租金' then oweList.latePayPrice else 0 end) rentLatePay,
  649. max(case oweList.bill_type when '物业费' then oweList.latePayPrice else 0 end) propertyLatePay,
  650. max(case oweList.bill_type when '欠缴押金' then oweList.latePayPrice else 0 end) depositLatePay,
  651. max(case oweList.bill_type when '其他费用' then oweList.latePayPrice else 0 end) otherLatePay,
  652. max(case oweList.bill_type when '租金' then oweList.serviceChargePay else 0 end) rentServiceChargePay,
  653. max(case oweList.bill_type when '物业费' then oweList.serviceChargePay else 0 end) propertyServiceChargePay,
  654. max(case oweList.bill_type when '欠缴押金' then oweList.serviceChargePay else 0 end) depositServiceChargePay,
  655. max(case oweList.bill_type when '其他费用' then oweList.serviceChargePay else 0 end) otherServiceChargePay
  656. from(
  657. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe)
  658. owe,bill.receive_date,bill.expired_day,sum(bill.receive_pay) receive_pay,sum(bill.pay)
  659. pay,sum(bill.late_pay_price) latePayPrice,sum(bill.service_charge_pay) serviceChargePay from (
  660. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  661. bill_type,need_pay,receive_pay,pay,(receive_pay+) owe,DATE_FORMAT(receive_date,'%Y-%m-%d')
  662. receive_date,pay_date,expired_day,status,'' starttime,''
  663. endtime,rent_shop_type,late_pay_price,service_charge_pay from wx_bill_rent where tenant_id = #{tenantId} and
  664. is_preview = 0
  665. <include refid="getOweBillAsPageConditions"/>
  666. union all
  667. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  668. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  669. endtime,rent_shop_type,late_pay_price,service_charge_pay from wx_bill_property where tenant_id = #{tenantId} and
  670. is_preview = 0
  671. <include refid="getOweBillAsPageConditions"/>
  672. union all
  673. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  674. 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,0 late_pay_price from(
  675. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,2 bill_type_value,'欠缴押金'
  676. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  677. endtime,rent_shop_type,service_charge_pay from wx_bill_rent_deposit where tenant_id = #{tenantId}
  678. <include refid="getOweBillAsPageConditions"/>
  679. union all
  680. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,4 bill_type_value,'欠缴押金'
  681. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  682. endtime,rent_shop_type,service_charge_pay from wx_bill_property_deposit where tenant_id = #{tenantId}
  683. <include refid="getOweBillAsPageConditions"/>
  684. union all
  685. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,8 bill_type_value,'欠缴押金' bill_type,0 as
  686. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,
  687. pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type,service_charge_pay
  688. from wx_bill_other_deposit where tenant_id = #{tenantId}
  689. <include refid="getOweBillAsPageConditions"/>
  690. ) res
  691. union all
  692. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  693. 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,0 late_pay_price from(
  694. select id,merchant_id,shop_id,tenant_id,'其他费用' name,5 bill_type_value,'其他费用' bill_type,0 as
  695. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,
  696. expired_day,status,'' starttime,'' endtime,rent_shop_type,service_charge_pay
  697. from wx_bill_daily where tenant_id = #{tenantId} and type in(1,2,3)
  698. <include refid="getOweBillAsPageConditions"/>
  699. union all
  700. select id,merchant_id,shop_id,tenant_id,'其他费用' name,7 bill_type_value,'其他费用' bill_type,0 as
  701. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,
  702. expired_day,status,'' starttime,'' endtime,rent_shop_type,service_charge_pay
  703. from wx_bill_other where tenant_id = #{tenantId}
  704. <include refid="getOweBillAsPageConditions"/>
  705. ) res
  706. ) bill
  707. where bill.status not in(3,5,6)
  708. group by bill.merchant_id,bill.bill_type
  709. ) oweList group by oweList.merchant_id
  710. ) bill
  711. left join wx_merchant m on bill.merchant_id=m.id
  712. where m.tenant_id = #{tenantId}
  713. <if test=" null != merchantName and '' != merchantName">and m.name like concat('%', #{merchantName},'%')</if>
  714. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  715. <if test=" null == sortColumns"> order by totalOwe desc </if>
  716. </select>
  717. <select id="getReceiveAndPayBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  718. select tt.* from (
  719. select m.tenant_id,m.id,m.name,ws.shop_number shopNumber,ws.type,m.link_person linkPerson,m.link_phone linkPhone,
  720. xb.title business,rc.rental_start_date rentalStartDate,rc.rental_end_date rentalEndDate,rc.rent_shop_type,
  721. ifnull(round(
  722. (select sum(bill.receive_pay)+sum(bill.late_pay_price)+bill.receivePay from (
  723. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay,late_pay_price from
  724. wx_bill_rent where is_preview = 0 and status not in(3,6)
  725. union all
  726. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  727. wx_bill_rent_deposit where status not in(3,6)
  728. union all
  729. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,late_pay_price from
  730. wx_bill_property where is_preview = 0 and status not in(3,6)
  731. union all
  732. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  733. wx_bill_property_deposit where status not in(3,6)
  734. union all
  735. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  736. wx_bill_daily where type in(1,2,3) and status not in(3,6)
  737. union all
  738. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  739. wx_bill_other where status not in(3,6)
  740. union all
  741. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  742. wx_bill_other_deposit where status not in(3,6)
  743. ) bill where bill.merchant_id = m.id
  744. )/100,2),0) receivePay,
  745. ifnull(round(
  746. (select sum(ss.money) from (
  747. select ms.subsidy money,mm.id
  748. from wx_merchant_subsidy ms
  749. left join wx_coupon_order co on co.id = ms.coupon_order_id
  750. left join wx_coupon c on c.id = co.coupon_id
  751. left join wx_merchant mm on mm.id = ms.merchant_id
  752. left join wx_card_spend cs on cs.order_id = ms.order_id
  753. left join wx_c_user cu on cu.id = cs.owner_id
  754. where ms.order_type in(3,0) and ms.status = 0
  755. union all
  756. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  757. union all
  758. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  759. union all
  760. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  761. )ss where ss.id = m.id
  762. )/100,2),0) payOut,
  763. (ifnull(round(
  764. (select sum(bill.receive_pay)+sum(bill.late_pay_price)+bill.receivePay from (
  765. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,late_pay_price from
  766. wx_bill_rent
  767. where is_preview = 0 and status not in(3,6)
  768. union all
  769. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  770. wx_bill_rent_deposit where status not in(3,6)
  771. union all
  772. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,late_pay_price from
  773. wx_bill_property where is_preview = 0 and status not in(3,6)
  774. union all
  775. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  776. wx_bill_property_deposit where status not in(3,6)
  777. union all
  778. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  779. wx_bill_daily where type in(1,2,3) and status not in(3,6)
  780. union all
  781. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  782. wx_bill_other where status not in(3,6)
  783. union all
  784. select merchant_id,receive_pay,ifnull(service_charge_pay,0) receivePay, receivePay,0 late_pay_price from
  785. wx_bill_other_deposit where status not in(3,6)
  786. ) bill where bill.merchant_id = m.id
  787. )/100,2),0)-
  788. ifnull(round(
  789. (select sum(ss.money) from (
  790. select ms.subsidy money,mm.id
  791. from wx_merchant_subsidy ms
  792. left join wx_coupon_order co on co.id = ms.coupon_order_id
  793. left join wx_coupon c on c.id = co.coupon_id
  794. left join wx_merchant mm on mm.id = ms.merchant_id
  795. left join wx_card_spend cs on cs.order_id = ms.order_id
  796. left join wx_c_user cu on cu.id = cs.owner_id
  797. where ms.order_type in(3,0) and ms.status = 0
  798. union all
  799. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  800. union all
  801. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  802. union all
  803. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  804. )ss where ss.id = m.id
  805. )/100,2),0)) balance
  806. from wx_merchant m
  807. left join (select ms.merchant_id,s.type,GROUP_CONCAT(s.shop_number) as shop_number
  808. from wx_merchant_shop ms inner join wx_shop s on ms.shop_id=s.id where ms.is_del=0
  809. group by ms.merchant_id) ws on m.id=ws.merchant_id
  810. left join wx_business xb on(m.business_id = xb.id)
  811. left join wx_rent_contract rc on(rc.merchant_id = m.id)
  812. where m.status=1
  813. ) tt where 1=1
  814. <if test=" null != tenantId"> and tt.tenant_id = #{tenantId} </if>
  815. <if test=" null != merchantId"> and tt.id = #{merchantId} </if>
  816. <if test=" null != merchantName and ''!=merchantName">and tt.name like concat('%', #{merchantName},'%')</if>
  817. <if test=" null != rentShopType"> and tt.rent_shop_type = #{rentShopType} </if>
  818. and (receivePay >0 or payOut>0)
  819. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  820. <if test=" null == sortColumns"> order by tt.id desc </if>
  821. <if test="null != limitStart and null != limitEnd">
  822. limit #{limitStart},#{limitEnd}
  823. </if>
  824. </select>
  825. <select id="allDepositList" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  826. select bill.*
  827. from (
  828. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  829. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  830. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_rent_deposit where
  831. tenant_id=#{tenantId}
  832. union all
  833. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  834. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  835. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_property_deposit where
  836. tenant_id=#{tenantId}
  837. union all
  838. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  839. bill_type,0 as
  840. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  841. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze
  842. from wx_bill_other_deposit where tenant_id=#{tenantId}
  843. ) bill
  844. where 1=1
  845. <if test=" null != freeze"> and bill.freeze = #{freeze} </if>
  846. <if test=" null != status"> and bill.status = #{status} </if>
  847. <if test=" null != merchantId">and bill.merchant_id=#{merchantId}</if>
  848. </select>
  849. </mapper>