You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

623 lines
35 KiB

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.iformall.mapper.WxBillAllMapper">
  4. <resultMap id="allVoResultMap" type="com.iformall.domain.vo.WxBillAllVo">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenantId" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="merchantId" jdbcType="INTEGER" property="merchantId" />
  8. <result column="shopId" jdbcType="INTEGER" property="shopId" />
  9. <result column="billTypeValue" jdbcType="INTEGER" property="billTypeValue"/>
  10. <result column="billType" jdbcType="VARCHAR" property="billType"/>
  11. <result column="needPay" jdbcType="BIGINT" property="needPay"/>
  12. <result column="merchantName" jdbcType="VARCHAR" property="merchantName" />
  13. <result column="rentShopType" jdbcType="INTEGER" property="rentShopType"/>
  14. <result column="receiveDate" jdbcType="TIMESTAMP" property="receiveDate" />
  15. <result column="expiredDay" jdbcType="INTEGER" property="expiredDay" />
  16. <result column="status" jdbcType="INTEGER" property="status" />
  17. <result column="receivePay" jdbcType="BIGINT" property="receivePay"/>
  18. <result column="owe" jdbcType="BIGINT" property="owe"/>
  19. <result column="pay" jdbcType="BIGINT" property="pay"/>
  20. <result column="payDate" jdbcType="TIMESTAMP" property="payDate" />
  21. <result column="starttime" jdbcType="TIMESTAMP" property="starttime" />
  22. <result column="endtime" jdbcType="TIMESTAMP" property="endtime" />
  23. <result column="shopNumber" jdbcType="VARCHAR" property="shopNumber"/>
  24. <result column="manager" jdbcType="VARCHAR" property="manager"/>
  25. <result column="managerPhone" jdbcType="VARCHAR" property="managerPhone"/>
  26. <result column="shopInfo" jdbcType="VARCHAR" property="shopInfo"/>
  27. <result column="name" jdbcType="VARCHAR" property="name"/>
  28. <result column="comments" property="comments"/>
  29. </resultMap>
  30. <select id="list" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  31. select
  32. bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId,
  33. bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  34. bill.receive_pay receivePay,bill.pay,
  35. case when bill.status=1 then bill.owe else 0 end owe
  36. ,bill.receive_date receiveDate,
  37. bill.pay_date payDate,DATEDIFF(now(),bill.receive_date) expiredDay,bill.status,bill.starttime,
  38. bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName,
  39. s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info shopInfo,bill.comments
  40. from (
  41. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  42. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  43. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments
  44. from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0
  45. union all
  46. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  47. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  48. endtime,rent_shop_type,shop_info,NULL comments from wx_bill_rent_deposit where tenant_id=#{tenantId}
  49. union all
  50. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  51. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  52. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments
  53. from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0
  54. union all
  55. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  56. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  57. endtime,rent_shop_type,shop_info,NULL comments from wx_bill_property_deposit where tenant_id=#{tenantId}
  58. union all
  59. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  60. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  61. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as
  62. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  63. rent_shop_type,'[]' shop_info,NULL comments
  64. from wx_bill_daily where tenant_id=#{tenantId}
  65. union all
  66. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as
  67. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  68. rent_shop_type,'[]' shop_info,comments
  69. from wx_bill_other where tenant_id=#{tenantId}
  70. union all
  71. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,'其他押金' bill_type,0 as
  72. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  73. rent_shop_type,'[]' shop_info,comments
  74. from wx_bill_other_deposit where tenant_id=#{tenantId}
  75. ) bill
  76. left join wx_merchant m on bill.merchant_id=m.id
  77. left join wx_shop s on bill.shop_id=s.id
  78. where 1=1
  79. <if test=" null != tenantId ">
  80. and bill.tenant_id=#{tenantId}
  81. </if>
  82. <if test=" null != month and ''!=month">
  83. and date_format(bill.receive_date,'%Y-%m')=#{month}
  84. </if>
  85. <if test=" null != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
  86. <if test=" null != billTypeValue ">and bill.bill_type_value = #{billTypeValue}</if>
  87. <if test=" null != status ">and bill.`status` = #{status}</if>
  88. <if test=" null != rentShopType ">and bill.rent_shop_type = #{rentShopType}</if>
  89. <if test=" null != starttime and null!= endtime ">
  90. and bill.receive_date between #{starttime} and #{endtime}
  91. </if>
  92. <if test=" null != merchantId and ''!=merchantId">
  93. and bill.merchant_id=#{merchantId}
  94. </if>
  95. <if test=" null != statusList ">
  96. and bill.`status` in
  97. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  98. #{status}
  99. </foreach>
  100. </if>
  101. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  102. <if test=" null == sortColumns"> order by bill.receive_date,bill.id desc,bill.merchant_id,bill.status</if>
  103. </select>
  104. <select id="queryOweInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  105. select count(bill.id) owncount,IFNULL(sum(bill.owe),0) owe from (
  106. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  107. 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
  108. union all
  109. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  110. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  111. wx_bill_rent_deposit
  112. union all
  113. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  114. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  115. wx_bill_property where is_preview = 0
  116. union all
  117. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  118. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  119. wx_bill_property_deposit
  120. union all
  121. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  122. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  123. type=1
  124. union all
  125. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  126. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  127. type=2
  128. union all
  129. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  130. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  131. type=3
  132. union all
  133. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,0 as
  134. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  135. union all
  136. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  137. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  138. ) bill
  139. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  140. <if test=" null != starttime and null!= endtime ">
  141. and bill.receive_date between #{starttime} and #{endtime}
  142. </if>
  143. <if test=" null != month ">
  144. and date_format(bill.receive_date,'%Y-%m')=#{month}
  145. </if>
  146. <if test=" null != rentShopType ">
  147. and bill.rent_shop_type = #{rentShopType}
  148. </if>
  149. <if test=" null != billTypeList ">
  150. and bill.bill_type_value in
  151. <foreach collection="billTypeList" index="index" item="type" open="(" separator="," close=")">
  152. #{type}
  153. </foreach>
  154. </if>
  155. </select>
  156. <select id="queryPaidInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  157. select count(bill.id) paycount,IFNULL(sum(bill.pay),0) pay from (
  158. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  159. 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
  160. union all
  161. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  162. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  163. wx_bill_rent_deposit
  164. union all
  165. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  166. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  167. wx_bill_property where is_preview = 0
  168. union all
  169. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  170. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  171. wx_bill_property_deposit
  172. union all
  173. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  174. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  175. type=1
  176. union all
  177. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  178. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  179. type=2
  180. union all
  181. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  182. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  183. type=3
  184. union all
  185. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他' bill_type,0 as
  186. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  187. union all
  188. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  189. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  190. ) bill
  191. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  192. <if test=" null != starttime and null!= endtime ">
  193. and bill.receive_date between #{starttime} and #{endtime}
  194. </if>
  195. <if test=" null != month ">
  196. and date_format(bill.receive_date,'%Y-%m')=#{month}
  197. </if>
  198. <if test=" null != rentShopType ">
  199. and bill.rent_shop_type = #{rentShopType}
  200. </if>
  201. </select>
  202. <select id="listData" resultType="hashmap" parameterType="com.iformall.domain.vo.WxBillAll">
  203. select bill.id,bill.merchant_id merchantId,bill.shop_id shopId,bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  204. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate,DATEDIFF(now(),bill.receive_date) expiredDay,bill.status,
  205. bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus,
  206. pb.pay_time_end tradeTime,pb.transaction_id transactionId,pb.pay_amount payAmount,bill.rent_shop_type
  207. rentShopType from (
  208. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  209. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  210. from wx_bill_rent where is_preview = 0 and tenant_id=#{tenantId} and rent_contract_id in (select id from
  211. wx_rent_contract where status in
  212. (2,3,4))
  213. union all
  214. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  215. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  216. from wx_bill_rent_deposit where tenant_id=#{tenantId} and rent_contract_id in (select id from wx_rent_contract
  217. where status in (2,3,4))
  218. union all
  219. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  220. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  221. from wx_bill_property where is_preview = 0 and tenant_id=#{tenantId} and property_contract_id in (select id from
  222. wx_property_contract
  223. where status in(2,3,4))
  224. union all
  225. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  226. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type
  227. from wx_bill_property_deposit where tenant_id=#{tenantId} and property_contract_id in (select id from
  228. wx_property_contract where status in
  229. (2,3,4))
  230. union all
  231. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  232. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  233. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type, 0 as need_pay,receive_pay,
  234. pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  235. from wx_bill_daily where tenant_id=#{tenantId}
  236. union all
  237. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_vaue,'其他' bill_type,0 as
  238. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  239. from wx_bill_other where tenant_id=#{tenantId}
  240. union all
  241. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,'其他押金' bill_type,0 as
  242. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  243. from wx_bill_other_deposit where tenant_id=#{tenantId}
  244. ) bill
  245. left join wx_merchant m on bill.merchant_id=m.id
  246. left join wx_shop s on bill.shop_id=s.id
  247. left join wx_pay_bill pb on bill.id=pb.bill_id
  248. where 1=1
  249. <if test=" null != id ">
  250. and bill.id=#{id}
  251. </if>
  252. <if test=" null != tenantId ">
  253. and bill.tenant_id=#{tenantId}
  254. </if>
  255. <if test=" null != merchantId ">
  256. and bill.merchant_id=#{merchantId}
  257. </if>
  258. <if test=" null != statusList ">
  259. and bill.`status` in
  260. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  261. #{status}
  262. </foreach>
  263. </if>
  264. <if test=" null != typeList ">
  265. and bill.`bill_type_value` in
  266. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  267. #{type}
  268. </foreach>
  269. </if>
  270. <if test="null!=starttime and null!=endtime">
  271. and DATE_FORMAT(bill.receive_date,'%Y-%m') between #{starttime} and #{endtime}
  272. </if>
  273. <if test=" null != status ">
  274. and bill.status=#{status}
  275. </if>
  276. <if test=" null != billTypeValue ">
  277. and bill.bill_type_value=#{billTypeValue}
  278. </if>
  279. <if test=" null != rentShopType ">
  280. and bill.rent_shop_type = #{rentShopType}
  281. </if>
  282. order by bill.merchant_id,bill.status,bill.receive_date desc
  283. </select>
  284. <select id="getWaitPayBill" resultType="hashmap">
  285. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  286. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType from (
  287. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  288. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  289. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  290. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  291. union all
  292. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  293. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  294. endtime,rent_shop_type from wx_bill_rent_deposit
  295. union all
  296. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  297. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  298. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  299. union all
  300. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  301. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  302. endtime,rent_shop_type from wx_bill_property_deposit
  303. union all
  304. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  305. 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
  306. from wx_bill_daily where type=1
  307. union all
  308. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  309. 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
  310. from wx_bill_daily where type=2
  311. union all
  312. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  313. 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
  314. from wx_bill_daily where type=3
  315. union all
  316. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as
  317. 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
  318. from wx_bill_other
  319. union all
  320. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  321. 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
  322. from wx_bill_other_deposit
  323. ) bill
  324. where bill.status not in(3,5,6)
  325. group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
  326. left join wx_merchant m on bill.merchant_id=m.id
  327. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  328. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  329. </select>
  330. <select id="getOweBill" resultType="hashmap">
  331. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.owe,m.link_phone linkPhone,app.appname from (
  332. select bill.tenant_id,bill.merchant_id,sum(owe) owe from (
  333. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  334. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  335. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  336. union all
  337. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  338. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  339. endtime,rent_shop_type from wx_bill_rent_deposit
  340. union all
  341. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  342. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  343. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  344. union all
  345. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  346. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  347. endtime,rent_shop_type from wx_bill_property_deposit
  348. union all
  349. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  350. 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
  351. from wx_bill_daily where type=1
  352. union all
  353. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  354. 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
  355. from wx_bill_daily where type=2
  356. union all
  357. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  358. 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
  359. from wx_bill_daily where type=3
  360. union all
  361. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as
  362. 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
  363. from wx_bill_other
  364. union all
  365. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  366. 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
  367. from wx_bill_other_deposit
  368. ) bill
  369. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  370. group by bill.tenant_id,bill.merchant_id) bill
  371. left join wx_merchant m on bill.merchant_id=m.id
  372. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  373. where m.status=1
  374. </select>
  375. <select id="getWaitPayBillForEmail" resultType="hashmap">
  376. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  377. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType,ws.manager,ws.manager_phone managerPhone from (
  378. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  379. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  380. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  381. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  382. union all
  383. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  384. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  385. endtime,rent_shop_type from wx_bill_rent_deposit
  386. union all
  387. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  388. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  389. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  390. union
  391. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  392. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  393. endtime,rent_shop_type from wx_bill_property_deposit
  394. union all
  395. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  396. 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
  397. from wx_bill_daily where type=1
  398. union all
  399. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  400. 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
  401. from wx_bill_daily where type=2
  402. union all
  403. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  404. 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
  405. from wx_bill_daily where type=3
  406. union all
  407. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as
  408. 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
  409. from wx_bill_other
  410. union all
  411. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  412. 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
  413. from wx_bill_other_deposit
  414. ) bill
  415. where bill.status not in(3,5,6)
  416. group by bill.tenant_id,bill.merchant_id,bill.receive_date,bill.bill_type
  417. ) bill
  418. left join wx_merchant m on bill.merchant_id=m.id
  419. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  420. left join wx_merchant_shop wms on wms.merchant_id = m.id
  421. left join wx_shop ws on wms.shop_id = ws.id
  422. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  423. </select>
  424. <select id="getOweBillForEmail" resultType="hashmap">
  425. select bill.tenant_id tenantId,bill.merchant_id merchantId,bill.bill_type billType,bill.owe owe,m.link_phone managerPhone,m.`link_person` manager,m.email,app.appname,bill.receive_date receiveDate
  426. ,DATEDIFF(now(),bill.receive_date) expiredDay from (
  427. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day from (
  428. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  429. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  430. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  431. union all
  432. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  433. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  434. endtime,rent_shop_type from wx_bill_rent_deposit
  435. union all
  436. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  437. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  438. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  439. union all
  440. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  441. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  442. endtime,rent_shop_type from wx_bill_property_deposit
  443. union all
  444. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  445. 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
  446. from wx_bill_daily where type=1
  447. union all
  448. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  449. 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
  450. from wx_bill_daily where type=2
  451. union all
  452. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  453. 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
  454. from wx_bill_daily where type=3
  455. union all
  456. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他' bill_type,0 as
  457. 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
  458. from wx_bill_other
  459. union all
  460. select id,merchant_id,shop_id,tenant_id,name,8 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_other_deposit
  463. ) bill
  464. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  465. group by bill.tenant_id,bill.merchant_id,bill.bill_type) bill
  466. left join wx_merchant m on bill.merchant_id=m.id
  467. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  468. where m.status=1
  469. </select>
  470. <sql id="getOweBillAsPageConditions">
  471. and status !=6
  472. <if test="null != status ">
  473. and status = #{status}
  474. </if>
  475. <if test=" null != month and ''!=month">
  476. and date_format(receive_date,'%Y-%m')=#{month}
  477. </if>
  478. <if test=" null != starttime and ''!=starttime">
  479. and receive_date >= #{starttime}
  480. </if>
  481. <if test=" null != endtime and ''!=endtime">
  482. and receive_date &lt;= #{endtime}
  483. </if>
  484. </sql>
  485. <select id="getOweBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  486. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.bill_type billType,
  487. m.link_phone managerPhone,m.`link_person` manager,m.email,
  488. bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay,
  489. round(bill.rentOwe/100,2) rentOwe,
  490. round(bill.propertyOwe/100,2) propertyOwe,
  491. round(bill.depositOwe/100,2) depositOwe,
  492. round(bill.otherOwe/100,2) otherOwe,
  493. round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe,
  494. <choose>
  495. <when test="1==filterHasPay">
  496. round((bill.rentReceivePay-bill.rentPay)/100,2) rentReceivePay,
  497. round((bill.propertyReceivePay-bill.propertyPay)/100,2) propertyReceivePay,
  498. round((bill.depositReceivePay-bill.depositPay)/100,2) depositReceivePay,
  499. round((bill.otherReceivePay-bill.otherPay)/100,2) otherReceivePay,
  500. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay
  501. -bill.rentPay-bill.propertyPay-bill.depositPay-bill.otherPay)/100,2) totalReceivePay
  502. </when>
  503. <otherwise>
  504. round(bill.rentReceivePay/100,2) rentReceivePay,
  505. round(bill.propertyReceivePay/100,2) propertyReceivePay,
  506. round(bill.depositReceivePay/100,2) depositReceivePay,
  507. round(bill.otherReceivePay/100,2) otherReceivePay,
  508. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay)/100,2) totalReceivePay
  509. </otherwise>
  510. </choose>
  511. from (
  512. select oweList.*,
  513. max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe,
  514. max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe,
  515. max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe,
  516. max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe,
  517. max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay,
  518. max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay,
  519. max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay,
  520. max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay,
  521. max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay,
  522. max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay,
  523. max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay,
  524. max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay
  525. from(
  526. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day,sum(bill.receive_pay) receive_pay,sum(bill.pay) pay from (
  527. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  528. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  529. endtime,rent_shop_type from wx_bill_rent where is_preview = 0 and tenant_id = #{tenantId}
  530. <include refid="getOweBillAsPageConditions"/>
  531. union all
  532. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  533. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  534. endtime,rent_shop_type from wx_bill_property where is_preview = 0 and tenant_id = #{tenantId}
  535. <include refid="getOweBillAsPageConditions"/>
  536. union all
  537. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  538. res.receive_pay,res.pay,res.owe owe,res.receive_date,res.pay_date,res.expired_day,res.status,res.starttime,res.endtime,res.rent_shop_type from(
  539. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,2 bill_type_value,'欠缴押金'
  540. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  541. endtime,rent_shop_type from wx_bill_rent_deposit where tenant_id = #{tenantId}
  542. <include refid="getOweBillAsPageConditions"/>
  543. union all
  544. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,4 bill_type_value,'欠缴押金'
  545. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  546. endtime,rent_shop_type from wx_bill_property_deposit where tenant_id = #{tenantId}
  547. <include refid="getOweBillAsPageConditions"/>
  548. union all
  549. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,8 bill_type_value,'欠缴押金' bill_type,0 as
  550. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  551. from wx_bill_other_deposit where tenant_id = #{tenantId}
  552. <include refid="getOweBillAsPageConditions"/>
  553. ) res
  554. union all
  555. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  556. res.receive_pay,res.pay,res.owe owe,res.receive_date,res.pay_date,res.expired_day,res.status,res.starttime,res.endtime,res.rent_shop_type from(
  557. select id,merchant_id,shop_id,tenant_id,'其他费用' name,5 bill_type_value,'其他费用' bill_type,0 as
  558. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  559. from wx_bill_daily where type in(1,2,3) and tenant_id = #{tenantId}
  560. <include refid="getOweBillAsPageConditions"/>
  561. union all
  562. select id,merchant_id,shop_id,tenant_id,'其他费用' name,7 bill_type_value,'其他费用' bill_type,0 as
  563. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  564. from wx_bill_other where tenant_id = #{tenantId}
  565. <include refid="getOweBillAsPageConditions"/>
  566. ) res
  567. ) bill
  568. where bill.status not in(3,5,6)
  569. group by bill.merchant_id,bill.bill_type
  570. ) oweList group by oweList.merchant_id
  571. ) bill
  572. left join wx_merchant m on bill.merchant_id=m.id
  573. where m.status=1 and m.tenant_id = #{tenantId}
  574. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  575. <if test=" null == sortColumns"> order by totalOwe desc </if>
  576. </select>
  577. </mapper>