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

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