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

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