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

850 wiersze
47 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. <result column="price_detail" property="priceDetail"/>
  30. <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
  31. <result column="freeze" property="freeze"/>
  32. </resultMap>
  33. <select id="list" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  34. select
  35. bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId,
  36. bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  37. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,
  38. bill.pay_date payDate,expired_day expiredDay,bill.status,bill.starttime,
  39. bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName,
  40. s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info
  41. shopInfo,bill.comments,bill.price_detail,updatetime,bill.freeze
  42. from (
  43. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  44. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  45. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  46. price_detail,updatetime,freeze
  47. from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0
  48. union all
  49. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_rent_deposit where
  52. tenant_id=#{tenantId}
  53. union all
  54. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  57. price_detail,updatetime,freeze
  58. from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0
  59. union all
  60. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  61. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  62. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_property_deposit where
  63. tenant_id=#{tenantId}
  64. union all
  65. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  66. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  67. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as
  68. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  69. rent_shop_type,'[]' shop_info, NULL comments,price_detail,updatetime,freeze
  70. from wx_bill_daily where tenant_id=#{tenantId}
  71. union all
  72. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,concat('其他费用-',name) as bill_type,0 as
  73. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  74. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze
  75. from wx_bill_other where tenant_id=#{tenantId}
  76. union all
  77. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  78. 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,comments,'' price_detail,updatetime,freeze
  81. from wx_bill_other_deposit where tenant_id=#{tenantId}
  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 and '' != starttime and ''!= 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 != typeList ">
  109. and bill.`bill_type_value` in
  110. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  111. #{type}
  112. </foreach>
  113. </if>
  114. <if test=" null != freeze ">and bill.freeze = #{freeze}</if>
  115. <if test=" null != id ">and bill.id = #{id}</if>
  116. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  117. <if test=" null == sortColumns"> order by bill.receive_date,bill.id desc,bill.merchant_id,bill.status</if>
  118. </select>
  119. <select id="queryOweInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  120. select count(bill.id) owncount,IFNULL(sum(bill.owe),0) owe from (
  121. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  122. 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
  123. union all
  124. select id,merchant_id,shop_id,tenant_id,2 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_rent_deposit
  127. union all
  128. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  129. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  130. wx_bill_property where is_preview = 0
  131. union all
  132. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  133. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  134. wx_bill_property_deposit
  135. union all
  136. select id,merchant_id,shop_id,tenant_id,5 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=1
  139. union all
  140. select id,merchant_id,shop_id,tenant_id,6 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_daily where
  142. type=2
  143. union all
  144. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  145. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  146. type=3
  147. union all
  148. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  149. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  150. union all
  151. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  152. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  153. ) bill
  154. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  155. <if test=" null != starttime and null!= endtime ">
  156. and bill.receive_date between #{starttime} and #{endtime}
  157. </if>
  158. <if test=" null != month ">
  159. and date_format(bill.receive_date,'%Y-%m')=#{month}
  160. </if>
  161. <if test=" null != rentShopType ">
  162. and bill.rent_shop_type = #{rentShopType}
  163. </if>
  164. <if test=" null != billTypeList ">
  165. and bill.bill_type_value in
  166. <foreach collection="billTypeList" index="index" item="type" open="(" separator="," close=")">
  167. #{type}
  168. </foreach>
  169. </if>
  170. </select>
  171. <select id="queryPaidInfo" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  172. select count(bill.id) paycount,IFNULL(sum(bill.pay),0) pay from (
  173. select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  174. 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
  175. union all
  176. select id,merchant_id,shop_id,tenant_id,2 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_rent_deposit
  179. union all
  180. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  181. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  182. wx_bill_property where is_preview = 0
  183. union all
  184. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  185. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  186. wx_bill_property_deposit
  187. union all
  188. select id,merchant_id,shop_id,tenant_id,5 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=1
  191. union all
  192. select id,merchant_id,shop_id,tenant_id,6 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_daily where
  194. type=2
  195. union all
  196. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  197. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  198. type=3
  199. union all
  200. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  201. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  202. union all
  203. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  204. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  205. ) bill
  206. where bill.tenant_id=#{tenantId} and bill.status=#{status}
  207. <if test=" null != starttime and null!= endtime ">
  208. and bill.receive_date between #{starttime} and #{endtime}
  209. </if>
  210. <if test=" null != month ">
  211. and date_format(bill.receive_date,'%Y-%m')=#{month}
  212. </if>
  213. <if test=" null != rentShopType ">
  214. and bill.rent_shop_type = #{rentShopType}
  215. </if>
  216. </select>
  217. <select id="listData" resultType="hashmap" parameterType="com.iformall.domain.vo.WxBillAll">
  218. select bill.settle_number,bill.id,bill.merchant_id merchantId,bill.shop_id shopId,bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  219. bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate,DATEDIFF(now(),bill.receive_date) expiredDay,bill.status,
  220. bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus,
  221. pb.pay_time_end tradeTime,pb.transaction_id transactionId,pb.pay_amount payAmount,bill.rent_shop_type
  222. rentShopType,bill.price_detail priceDetail,bill.freeze from (
  223. select '' settle_number,id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  224. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  225. price_detail,freeze
  226. from wx_bill_rent where is_preview = 0 and tenant_id=#{tenantId} and rent_contract_id in (select id from
  227. wx_rent_contract where status in
  228. (2,3,4))
  229. union all
  230. select '' settle_number,id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  231. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  232. price_detail,freeze
  233. from wx_bill_rent_deposit where tenant_id=#{tenantId} and rent_contract_id in (select id from wx_rent_contract
  234. where status in (2,3,4))
  235. union all
  236. select '' settle_number,id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  237. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  238. price_detail,freeze
  239. from wx_bill_property where is_preview = 0 and tenant_id=#{tenantId} and property_contract_id in (select id from
  240. wx_property_contract
  241. where status in(2,3,4))
  242. union all
  243. select '' settle_number,id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  244. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,''
  245. price_detail,freeze
  246. from wx_bill_property_deposit where tenant_id=#{tenantId} and property_contract_id in (select id from
  247. wx_property_contract where status in
  248. (2,3,4))
  249. union all
  250. select '' settle_number,id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  251. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  252. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type, 0 as need_pay,receive_pay,
  253. pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,rent_shop_type,price_detail,freeze
  254. from wx_bill_daily where tenant_id=#{tenantId}
  255. union all
  256. select '' settle_number,id,merchant_id,shop_id,tenant_id,name,7 bill_type_vaue,'其他费用' bill_type,0 as
  257. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type,''
  258. price_detail,freeze
  259. from wx_bill_other where tenant_id=#{tenantId}
  260. union all
  261. select '' settle_number,id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,'其他押金' bill_type,0 as
  262. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type,''
  263. price_detail,freeze
  264. from wx_bill_other_deposit where tenant_id=#{tenantId}
  265. union all
  266. select s.settle_number,s.id,s.merchant_id,'' shop_id,s.tenant_id,'结算单' name, 10 bill_type_value,'结算单' bill_type,0 need_pay,
  267. ((select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  268. (select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  269. 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
  270. union all
  271. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  272. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  273. wx_bill_rent_deposit
  274. union all
  275. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  276. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  277. wx_bill_property where is_preview = 0
  278. union all
  279. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  280. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  281. wx_bill_property_deposit
  282. union all
  283. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  284. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  285. type=1
  286. union all
  287. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  288. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  289. type=2
  290. union all
  291. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  292. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  293. type=3
  294. union all
  295. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  296. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  297. union all
  298. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  299. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  300. union all
  301. select id,id merchant_id,'' shop_id,tenant_id,10 bill_type_value,'补贴' bill_type,0 as
  302. need_pay,subsidy receive_pay,0 pay,0 owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
  303. ) bill
  304. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=0)
  305. -
  306. (select IFNULL(sum(bill.owe),0) from wx_bill_settle_bill bb left join
  307. (select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  308. 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
  309. union all
  310. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  311. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  312. wx_bill_rent_deposit
  313. union all
  314. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  315. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  316. wx_bill_property where is_preview = 0
  317. union all
  318. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  319. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  320. wx_bill_property_deposit
  321. union all
  322. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  323. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  324. type=1
  325. union all
  326. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  327. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  328. type=2
  329. union all
  330. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  331. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  332. type=3
  333. union all
  334. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  335. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  336. union all
  337. select id,merchant_id,shop_id,tenant_id,8 bill_type_value,'其他押金' bill_type,0 as
  338. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other_deposit
  339. union all
  340. select id,id merchant_id,'' shop_id,tenant_id,10 bill_type_value,'补贴' bill_type,0 as
  341. need_pay,subsidy receive_pay,0 pay,subsidy owe,'' receive_date,'' pay_date,'' expired_day,status,'' rent_shop_type from wx_merchant_subsidy
  342. ) bill
  343. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=1
  344. )
  345. ) receive_pay
  346. ,0 pay,0 owe,s.createtime receive_date,'' pay_date,0 expired_day,status,'' starttime,'' endtime,'' rent_shop_type,'' price_detail, 0 freeze
  347. from wx_bill_settle s where s.tenant_id=#{tenantId} and s.status >0
  348. ) bill
  349. left join wx_merchant m on bill.merchant_id=m.id
  350. left join wx_shop s on bill.shop_id=s.id
  351. left join wx_pay_bill pb on bill.id=pb.bill_id
  352. where 1=1
  353. <if test=" null != id ">
  354. and bill.id=#{id}
  355. </if>
  356. <if test=" null != tenantId ">
  357. and bill.tenant_id=#{tenantId}
  358. </if>
  359. <if test=" null != merchantId ">
  360. and bill.merchant_id=#{merchantId}
  361. </if>
  362. <if test=" null != statusList ">
  363. and bill.`status` in
  364. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  365. #{status}
  366. </foreach>
  367. </if>
  368. <if test=" null != typeList ">
  369. and bill.`bill_type_value` in
  370. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  371. #{type}
  372. </foreach>
  373. </if>
  374. <if test="null!=starttime and null!=endtime and ''!=starttime and ''!=endtime ">
  375. and DATE_FORMAT(bill.receive_date,'%Y-%m') between #{starttime} and #{endtime}
  376. </if>
  377. <if test=" null != status ">
  378. and bill.status=#{status}
  379. </if>
  380. <if test=" null != billTypeValue ">
  381. and bill.bill_type_value=#{billTypeValue}
  382. </if>
  383. <if test=" null != rentShopType ">
  384. and bill.rent_shop_type = #{rentShopType}
  385. </if>
  386. order by bill.merchant_id,bill.status desc,bill.receive_date desc
  387. </select>
  388. <select id="getWaitPayBill" resultType="hashmap">
  389. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  390. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType from (
  391. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  392. select id,merchant_id,shop_id,tenant_id,'租金' name,1 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 where is_preview = 0
  395. union all
  396. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_rent_deposit
  399. union all
  400. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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 where is_preview = 0
  403. union all
  404. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  405. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  406. endtime,rent_shop_type from wx_bill_property_deposit
  407. union all
  408. select id,merchant_id,shop_id,tenant_id,'水费' name,5 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=1
  411. union all
  412. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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=2
  415. union all
  416. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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_daily where type=3
  419. union all
  420. select id,merchant_id,shop_id,tenant_id,name,7 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
  423. union all
  424. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  425. 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
  426. from wx_bill_other_deposit
  427. ) bill
  428. where bill.status not in(3,5,6)
  429. group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
  430. left join wx_merchant m on bill.merchant_id=m.id
  431. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  432. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  433. </select>
  434. <select id="getOweBill" resultType="hashmap">
  435. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.owe,m.link_phone linkPhone,app.appname from (
  436. select bill.tenant_id,bill.merchant_id,sum(owe) owe 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 all
  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 all
  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 all
  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 all
  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 all
  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 all
  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 all
  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 all
  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
  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. <select id="getWaitPayBillForEmail" resultType="hashmap">
  480. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  481. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType,ws.manager,ws.manager_phone managerPhone from (
  482. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  483. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  484. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  485. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  486. union all
  487. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  488. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  489. endtime,rent_shop_type from wx_bill_rent_deposit
  490. union all
  491. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  492. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  493. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  494. union
  495. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  496. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  497. endtime,rent_shop_type from wx_bill_property_deposit
  498. union all
  499. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  500. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  501. from wx_bill_daily where type=1
  502. union all
  503. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  504. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  505. from wx_bill_daily where type=2
  506. union all
  507. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  508. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  509. from wx_bill_daily where type=3
  510. union all
  511. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  512. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  513. from wx_bill_other
  514. union all
  515. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  516. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  517. from wx_bill_other_deposit
  518. ) bill
  519. where bill.status not in(3,5,6)
  520. group by bill.tenant_id,bill.merchant_id,bill.receive_date,bill.bill_type
  521. ) bill
  522. left join wx_merchant m on bill.merchant_id=m.id
  523. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  524. left join wx_merchant_shop wms on wms.merchant_id = m.id
  525. left join wx_shop ws on wms.shop_id = ws.id
  526. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  527. </select>
  528. <select id="getOweBillForEmail" resultType="hashmap">
  529. 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
  530. ,DATEDIFF(now(),bill.receive_date) expiredDay from (
  531. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day from (
  532. select id,merchant_id,shop_id,tenant_id,'租金' name,1 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_rent where is_preview = 0
  535. union all
  536. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_deposit
  539. union all
  540. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  541. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  542. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  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
  547. union all
  548. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  549. 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
  550. from wx_bill_daily where type=1
  551. union all
  552. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  553. 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
  554. from wx_bill_daily where type=2
  555. union all
  556. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  557. 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
  558. from wx_bill_daily where type=3
  559. union all
  560. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  561. 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
  562. from wx_bill_other
  563. union all
  564. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  565. 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
  566. from wx_bill_other_deposit
  567. ) bill
  568. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  569. group by bill.tenant_id,bill.merchant_id,bill.bill_type) bill
  570. left join wx_merchant m on bill.merchant_id=m.id
  571. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  572. where m.status=1
  573. </select>
  574. <sql id="getOweBillAsPageConditions">
  575. and status !=6
  576. <if test="null != status ">
  577. and status = #{status}
  578. </if>
  579. <if test=" null != month and ''!=month">
  580. and date_format(receive_date,'%Y-%m')=#{month}
  581. </if>
  582. <if test=" null != starttime and ''!=starttime">
  583. and receive_date >= #{starttime}
  584. </if>
  585. <if test=" null != endtime and ''!=endtime">
  586. and receive_date &lt;= #{endtime}
  587. </if>
  588. </sql>
  589. <select id="getOweBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  590. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.bill_type billType,
  591. m.link_phone managerPhone,m.`link_person` manager,m.email,
  592. bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay,
  593. round(bill.rentOwe/100,2) rentOwe,
  594. round(bill.propertyOwe/100,2) propertyOwe,
  595. round(bill.depositOwe/100,2) depositOwe,
  596. round(bill.otherOwe/100,2) otherOwe,
  597. round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe,
  598. <choose>
  599. <when test="1==filterHasPay">
  600. round((bill.rentReceivePay-bill.rentPay)/100,2) rentReceivePay,
  601. round((bill.propertyReceivePay-bill.propertyPay)/100,2) propertyReceivePay,
  602. round((bill.depositReceivePay-bill.depositPay)/100,2) depositReceivePay,
  603. round((bill.otherReceivePay-bill.otherPay)/100,2) otherReceivePay,
  604. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay
  605. -bill.rentPay-bill.propertyPay-bill.depositPay-bill.otherPay)/100,2) totalReceivePay
  606. </when>
  607. <otherwise>
  608. round(bill.rentReceivePay/100,2) rentReceivePay,
  609. round(bill.propertyReceivePay/100,2) propertyReceivePay,
  610. round(bill.depositReceivePay/100,2) depositReceivePay,
  611. round(bill.otherReceivePay/100,2) otherReceivePay,
  612. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay)/100,2) totalReceivePay
  613. </otherwise>
  614. </choose>
  615. from (
  616. select oweList.*,
  617. max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe,
  618. max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe,
  619. max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe,
  620. max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe,
  621. max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay,
  622. max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay,
  623. max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay,
  624. max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay,
  625. max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay,
  626. max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay,
  627. max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay,
  628. max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay
  629. from(
  630. 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 (
  631. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  632. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  633. endtime,rent_shop_type from wx_bill_rent where tenant_id = #{tenantId} and is_preview = 0
  634. <include refid="getOweBillAsPageConditions"/>
  635. union all
  636. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  637. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  638. endtime,rent_shop_type from wx_bill_property where tenant_id = #{tenantId} and is_preview = 0
  639. <include refid="getOweBillAsPageConditions"/>
  640. union all
  641. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  642. 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(
  643. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,2 bill_type_value,'欠缴押金'
  644. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  645. endtime,rent_shop_type from wx_bill_rent_deposit where tenant_id = #{tenantId}
  646. <include refid="getOweBillAsPageConditions"/>
  647. union all
  648. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,4 bill_type_value,'欠缴押金'
  649. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  650. endtime,rent_shop_type from wx_bill_property_deposit where tenant_id = #{tenantId}
  651. <include refid="getOweBillAsPageConditions"/>
  652. union all
  653. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,8 bill_type_value,'欠缴押金' bill_type,0 as
  654. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  655. from wx_bill_other_deposit where tenant_id = #{tenantId}
  656. <include refid="getOweBillAsPageConditions"/>
  657. ) res
  658. union all
  659. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  660. 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(
  661. select id,merchant_id,shop_id,tenant_id,'其他费用' name,5 bill_type_value,'其他费用' bill_type,0 as
  662. 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
  663. from wx_bill_daily where tenant_id = #{tenantId} and type in(1,2,3)
  664. <include refid="getOweBillAsPageConditions"/>
  665. union all
  666. select id,merchant_id,shop_id,tenant_id,'其他费用' name,7 bill_type_value,'其他费用' bill_type,0 as
  667. 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
  668. from wx_bill_other where tenant_id = #{tenantId}
  669. <include refid="getOweBillAsPageConditions"/>
  670. ) res
  671. ) bill
  672. where bill.status not in(3,5,6)
  673. group by bill.merchant_id,bill.bill_type
  674. ) oweList group by oweList.merchant_id
  675. ) bill
  676. left join wx_merchant m on bill.merchant_id=m.id
  677. where m.tenant_id = #{tenantId}
  678. <if test=" null != merchantName and '' != merchantName">and m.name like concat('%', #{merchantName},'%')</if>
  679. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  680. <if test=" null == sortColumns"> order by totalOwe desc </if>
  681. </select>
  682. <select id="getReceiveAndPayBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  683. select tt.* from (
  684. select m.tenant_id,m.id,m.name,ws.shop_number shopNumber,ws.type,m.link_person linkPerson,m.link_phone linkPhone,
  685. xb.title business,rc.rental_start_date rentalStartDate,rc.rental_end_date rentalEndDate,rc.rent_shop_type,
  686. ifnull(round(
  687. (select sum(bill.receive_pay) from (
  688. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  689. union all
  690. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  691. union all
  692. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  693. union all
  694. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  695. union all
  696. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  697. union all
  698. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  699. union all
  700. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  701. ) bill where bill.merchant_id = m.id
  702. )/100,2),0) receivePay,
  703. ifnull(round(
  704. (select sum(ss.money) from (
  705. select ms.subsidy money,mm.id
  706. from wx_merchant_subsidy ms
  707. left join wx_coupon_order co on co.id = ms.coupon_order_id
  708. left join wx_coupon c on c.id = co.coupon_id
  709. left join wx_merchant mm on mm.id = ms.merchant_id
  710. left join wx_card_spend cs on cs.order_id = ms.order_id
  711. left join wx_c_user cu on cu.id = cs.owner_id
  712. where ms.order_type in(3,0) and ms.status = 0
  713. union all
  714. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  715. union all
  716. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  717. union all
  718. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  719. )ss where ss.id = m.id
  720. )/100,2),0) payOut,
  721. (ifnull(round(
  722. (select sum(bill.receive_pay) from (
  723. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  724. union all
  725. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  726. union all
  727. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  728. union all
  729. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  730. union all
  731. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  732. union all
  733. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  734. union all
  735. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  736. ) bill where bill.merchant_id = m.id
  737. )/100,2),0)-
  738. ifnull(round(
  739. (select sum(ss.money) from (
  740. select ms.subsidy money,mm.id
  741. from wx_merchant_subsidy ms
  742. left join wx_coupon_order co on co.id = ms.coupon_order_id
  743. left join wx_coupon c on c.id = co.coupon_id
  744. left join wx_merchant mm on mm.id = ms.merchant_id
  745. left join wx_card_spend cs on cs.order_id = ms.order_id
  746. left join wx_c_user cu on cu.id = cs.owner_id
  747. where ms.order_type in(3,0) and ms.status = 0
  748. union all
  749. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  750. union all
  751. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  752. union all
  753. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  754. )ss where ss.id = m.id
  755. )/100,2),0)) balance
  756. from wx_merchant m
  757. left join (select ms.merchant_id,s.type,GROUP_CONCAT(s.shop_number) as shop_number
  758. from wx_merchant_shop ms inner join wx_shop s on ms.shop_id=s.id where ms.is_del=0
  759. group by ms.merchant_id) ws on m.id=ws.merchant_id
  760. left join wx_business xb on(m.business_id = xb.id)
  761. left join wx_rent_contract rc on(rc.merchant_id = m.id)
  762. where m.status=1
  763. ) tt where 1=1
  764. <if test=" null != tenantId"> and tt.tenant_id = #{tenantId} </if>
  765. <if test=" null != merchantId"> and tt.id = #{merchantId} </if>
  766. <if test=" null != merchantName and ''!=merchantName">and tt.name like concat('%', #{merchantName},'%')</if>
  767. <if test=" null != rentShopType"> and tt.rent_shop_type = #{rentShopType} </if>
  768. and (receivePay >0 or payOut>0)
  769. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  770. <if test=" null == sortColumns"> order by tt.id desc </if>
  771. </select>
  772. <select id="allDepositList" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  773. select bill.*
  774. from (
  775. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  776. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  777. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_rent_deposit where
  778. tenant_id=#{tenantId}
  779. union all
  780. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  781. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  782. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_property_deposit where
  783. tenant_id=#{tenantId}
  784. union all
  785. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  786. bill_type,0 as
  787. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  788. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze
  789. from wx_bill_other_deposit where tenant_id=#{tenantId}
  790. ) bill
  791. where 1=1
  792. <if test=" null != freeze"> and bill.freeze = #{freeze} </if>
  793. <if test=" null != status"> and bill.status = #{status} </if>
  794. <if test=" null != merchantId">and bill.merchant_id=#{merchantId}</if>
  795. </select>
  796. </mapper>