Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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