No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

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