Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 

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