Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

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