No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

849 líneas
46 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. </resultMap>
  32. <select id="list" parameterType="com.iformall.domain.vo.WxBillAll" resultMap="allVoResultMap">
  33. select
  34. bill.id,bill.tenant_id tenantId,bill.merchant_id merchantId,bill.shop_id shopId,
  35. bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
  36. bill.receive_pay receivePay,bill.pay,
  37. case when bill.status=1 then bill.owe else 0 end owe
  38. ,bill.receive_date receiveDate,
  39. bill.pay_date payDate,expired_day expiredDay,bill.status,bill.starttime,
  40. bill.endtime,bill.name,bill.rent_shop_type rentShopType,m.name merchantName,
  41. s.shop_number shopNumber, s.manager, s.manager_phone managerPhone,bill.shop_info
  42. shopInfo,bill.comments,bill.price_detail,updatetime,bill.freeze
  43. from (
  44. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  45. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  46. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  47. price_detail,updatetime,freeze
  48. from wx_bill_rent where tenant_id=#{tenantId} and is_preview = 0
  49. union all
  50. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  51. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  52. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_rent_deposit where
  53. tenant_id=#{tenantId}
  54. union all
  55. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  56. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  57. endtime,rent_shop_type,case when shop_info is null then '[]' else shop_info end shop_info,comments,''
  58. price_detail,updatetime,freeze
  59. from wx_bill_property where tenant_id=#{tenantId} and is_preview = 0
  60. union all
  61. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  62. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,
  63. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime,freeze from wx_bill_property_deposit where
  64. tenant_id=#{tenantId}
  65. union all
  66. select id,merchant_id,shop_id,tenant_id,case when type=1 then '水费' when type=2 then '电费' else '空调费' end name,
  67. case when type=1 then 5 when type=2 then 6 else 9 end bill_type_value,
  68. case when type=1 then '水费' when type=2 then '电费' else '空调费' end bill_type,0 as
  69. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  70. rent_shop_type,'[]' shop_info, NULL comments,price_detail,updatetime,freeze
  71. from wx_bill_daily where tenant_id=#{tenantId}
  72. union all
  73. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,concat('其他费用-',name) as bill_type,0 as
  74. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  75. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze
  76. from wx_bill_other where tenant_id=#{tenantId}
  77. union all
  78. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  79. bill_type,0 as
  80. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime,
  81. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime,freeze
  82. from wx_bill_other_deposit where tenant_id=#{tenantId}
  83. ) bill
  84. left join wx_merchant m on bill.merchant_id=m.id
  85. left join wx_shop s on bill.shop_id=s.id
  86. where 1=1
  87. <if test=" null != tenantId ">
  88. and bill.tenant_id=#{tenantId}
  89. </if>
  90. <if test=" null != month and ''!=month">
  91. and date_format(bill.receive_date,'%Y-%m')=#{month}
  92. </if>
  93. <if test=" null != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
  94. <if test=" null != billTypeValue ">and bill.bill_type_value = #{billTypeValue}</if>
  95. <if test=" null != status ">and bill.`status` = #{status}</if>
  96. <if test=" null != rentShopType ">and bill.rent_shop_type = #{rentShopType}</if>
  97. <if test=" null != starttime and null!= endtime and '' != starttime and ''!= endtime ">
  98. and bill.receive_date between #{starttime} and #{endtime}
  99. </if>
  100. <if test=" null != merchantId and ''!=merchantId">
  101. and bill.merchant_id=#{merchantId}
  102. </if>
  103. <if test=" null != statusList ">
  104. and bill.`status` in
  105. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  106. #{status}
  107. </foreach>
  108. </if>
  109. <if test=" null != typeList ">
  110. and bill.`bill_type_value` in
  111. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  112. #{type}
  113. </foreach>
  114. </if>
  115. <if test=" null != freeze ">and bill.freeze = #{freeze}</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 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
  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
  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
  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
  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
  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
  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
  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.receive_pay),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. ) bill
  301. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=0)
  302. -
  303. (select IFNULL(sum(bill.receive_pay),0) from wx_bill_settle_bill bb left join
  304. (select id,merchant_id,shop_id,tenant_id,1 bill_type_value,'租金'
  305. 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
  306. union all
  307. select id,merchant_id,shop_id,tenant_id,2 bill_type_value,'租赁押金'
  308. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  309. wx_bill_rent_deposit
  310. union all
  311. select id,merchant_id,shop_id,tenant_id,3 bill_type_value,'物业费'
  312. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  313. wx_bill_property where is_preview = 0
  314. union all
  315. select id,merchant_id,shop_id,tenant_id,4 bill_type_value,'物业押金'
  316. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from
  317. wx_bill_property_deposit
  318. union all
  319. select id,merchant_id,shop_id,tenant_id,5 bill_type_value,'水费' bill_type,0 as
  320. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  321. type=1
  322. union all
  323. select id,merchant_id,shop_id,tenant_id,6 bill_type_value,'电费' bill_type,0 as
  324. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  325. type=2
  326. union all
  327. select id,merchant_id,shop_id,tenant_id,9 bill_type_value,'空调费' bill_type,0 as
  328. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_daily where
  329. type=3
  330. union all
  331. select id,merchant_id,shop_id,tenant_id,7 bill_type_value,'其他费用' bill_type,0 as
  332. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,rent_shop_type from wx_bill_other
  333. union all
  334. select id,merchant_id,shop_id,tenant_id,8 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_deposit
  336. ) bill
  337. on(bb.bill_id=bill.id) where bb.settle_id = s.id and bb.type=1
  338. )
  339. -
  340. (select IFNULL(sum(settle_money),0) from wx_bill_settle_record where settle_id = s.id)
  341. ) receive_pay
  342. ,0 pay,0 owe,s.createtime receive_date,'' pay_date,0 expired_day,status,'' starttime,'' endtime,'' rent_shop_type,'' price_detail
  343. from wx_bill_settle s where s.tenant_id=#{tenantId} and s.status >0
  344. ) bill
  345. left join wx_merchant m on bill.merchant_id=m.id
  346. left join wx_shop s on bill.shop_id=s.id
  347. left join wx_pay_bill pb on bill.id=pb.bill_id
  348. where 1=1
  349. <if test=" null != id ">
  350. and bill.id=#{id}
  351. </if>
  352. <if test=" null != tenantId ">
  353. and bill.tenant_id=#{tenantId}
  354. </if>
  355. <if test=" null != merchantId ">
  356. and bill.merchant_id=#{merchantId}
  357. </if>
  358. <if test=" null != statusList ">
  359. and bill.`status` in
  360. <foreach collection="statusList" index="index" item="status" open="(" separator="," close=")">
  361. #{status}
  362. </foreach>
  363. </if>
  364. <if test=" null != typeList ">
  365. and bill.`bill_type_value` in
  366. <foreach collection="typeList" index="index" item="type" open="(" separator="," close=")">
  367. #{type}
  368. </foreach>
  369. </if>
  370. <if test="null!=starttime and null!=endtime and ''!=starttime and ''!=endtime ">
  371. and DATE_FORMAT(bill.receive_date,'%Y-%m') between #{starttime} and #{endtime}
  372. </if>
  373. <if test=" null != status ">
  374. and bill.status=#{status}
  375. </if>
  376. <if test=" null != billTypeValue ">
  377. and bill.bill_type_value=#{billTypeValue}
  378. </if>
  379. <if test=" null != rentShopType ">
  380. and bill.rent_shop_type = #{rentShopType}
  381. </if>
  382. order by bill.merchant_id,bill.status,bill.receive_date desc
  383. </select>
  384. <select id="getWaitPayBill" resultType="hashmap">
  385. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  386. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType from (
  387. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  388. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  389. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  390. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  391. union all
  392. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  393. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  394. endtime,rent_shop_type from wx_bill_rent_deposit
  395. union all
  396. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  397. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  398. endtime,rent_shop_type from wx_bill_property where is_preview = 0
  399. union all
  400. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  401. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  402. endtime,rent_shop_type from wx_bill_property_deposit
  403. union all
  404. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  405. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  406. from wx_bill_daily where type=1
  407. union all
  408. select id,merchant_id,shop_id,tenant_id,'电费' name,6 bill_type_value,'电费' bill_type,0 as
  409. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  410. from wx_bill_daily where type=2
  411. union all
  412. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 bill_type_value,'空调费' bill_type,0 as
  413. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  414. from wx_bill_daily where type=3
  415. union all
  416. select id,merchant_id,shop_id,tenant_id,name,7 bill_type_value,'其他费用' bill_type,0 as
  417. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  418. from wx_bill_other
  419. union all
  420. select id,merchant_id,shop_id,tenant_id,name,8 bill_type_value,'其他押金' bill_type,0 as
  421. need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,'' endtime,rent_shop_type
  422. from wx_bill_other_deposit
  423. ) bill
  424. where bill.status not in(3,5,6)
  425. group by bill.tenant_id,bill.merchant_id,bill.receive_date) bill
  426. left join wx_merchant m on bill.merchant_id=m.id
  427. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  428. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  429. </select>
  430. <select id="getOweBill" resultType="hashmap">
  431. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.owe,m.link_phone linkPhone,app.appname from (
  432. select bill.tenant_id,bill.merchant_id,sum(owe) owe from (
  433. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  434. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  435. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  436. union all
  437. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_deposit
  440. union all
  441. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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_property where is_preview = 0
  444. union all
  445. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 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_deposit
  448. union all
  449. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  450. 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
  451. from wx_bill_daily where type=1
  452. union all
  453. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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=2
  456. union all
  457. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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=3
  460. union all
  461. select id,merchant_id,shop_id,tenant_id,name,7 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_other
  464. union all
  465. select id,merchant_id,shop_id,tenant_id,name,8 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_deposit
  468. ) bill
  469. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  470. group by bill.tenant_id,bill.merchant_id) bill
  471. left join wx_merchant m on bill.merchant_id=m.id
  472. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  473. where m.status=1
  474. </select>
  475. <select id="getWaitPayBillForEmail" resultType="hashmap">
  476. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.receive_date receiveDate,
  477. bill.need_pay needPay,m.link_phone linkPhone,app.appname,m.email,bill.bill_type billType,ws.manager,ws.manager_phone managerPhone from (
  478. select bill.bill_type,bill.tenant_id,bill.merchant_id,bill.receive_date,ifnull(sum(need_pay),0) need_pay from (
  479. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  480. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  481. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  482. union all
  483. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_deposit
  486. union all
  487. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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_property where is_preview = 0
  490. union
  491. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 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_deposit
  494. union all
  495. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  496. 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
  497. from wx_bill_daily where type=1
  498. union all
  499. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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=2
  502. union all
  503. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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=3
  506. union all
  507. select id,merchant_id,shop_id,tenant_id,name,7 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_other
  510. union all
  511. select id,merchant_id,shop_id,tenant_id,name,8 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_deposit
  514. ) bill
  515. where bill.status not in(3,5,6)
  516. group by bill.tenant_id,bill.merchant_id,bill.receive_date,bill.bill_type
  517. ) bill
  518. left join wx_merchant m on bill.merchant_id=m.id
  519. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  520. left join wx_merchant_shop wms on wms.merchant_id = m.id
  521. left join wx_shop ws on wms.shop_id = ws.id
  522. where m.status=1 and DATEDIFF(bill.receive_date,now())=m.bill_setting
  523. </select>
  524. <select id="getOweBillForEmail" resultType="hashmap">
  525. 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
  526. ,DATEDIFF(now(),bill.receive_date) expiredDay from (
  527. select bill.tenant_id,bill.merchant_id,bill.bill_type,sum(owe) owe,bill.receive_date,bill.expired_day from (
  528. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  529. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  530. endtime,rent_shop_type from wx_bill_rent where is_preview = 0
  531. union all
  532. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 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_deposit
  535. union all
  536. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 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_property where is_preview = 0
  539. union all
  540. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 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_deposit
  543. union all
  544. select id,merchant_id,shop_id,tenant_id,'水费' name,5 bill_type_value,'水费' bill_type,0 as
  545. 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
  546. from wx_bill_daily where type=1
  547. union all
  548. select id,merchant_id,shop_id,tenant_id,'电费' name,6 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=2
  551. union all
  552. select id,merchant_id,shop_id,tenant_id,'空调费' name,9 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=3
  555. union all
  556. select id,merchant_id,shop_id,tenant_id,name,7 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_other
  559. union all
  560. select id,merchant_id,shop_id,tenant_id,name,8 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_deposit
  563. ) bill
  564. where DATEDIFF(bill.receive_date,now())&lt;0 and bill.status not in(3,5,6)
  565. group by bill.tenant_id,bill.merchant_id,bill.bill_type) bill
  566. left join wx_merchant m on bill.merchant_id=m.id
  567. left join (select tenant_id,`name` appname from wx_appinfo app where type=1) app on bill.tenant_id=app.tenant_id
  568. where m.status=1
  569. </select>
  570. <sql id="getOweBillAsPageConditions">
  571. and status !=6
  572. <if test="null != status ">
  573. and status = #{status}
  574. </if>
  575. <if test=" null != month and ''!=month">
  576. and date_format(receive_date,'%Y-%m')=#{month}
  577. </if>
  578. <if test=" null != starttime and ''!=starttime">
  579. and receive_date >= #{starttime}
  580. </if>
  581. <if test=" null != endtime and ''!=endtime">
  582. and receive_date &lt;= #{endtime}
  583. </if>
  584. </sql>
  585. <select id="getOweBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  586. select bill.tenant_id tenantId,bill.merchant_id merchantId,m.name merchantName,bill.bill_type billType,
  587. m.link_phone managerPhone,m.`link_person` manager,m.email,
  588. bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay,
  589. round(bill.rentOwe/100,2) rentOwe,
  590. round(bill.propertyOwe/100,2) propertyOwe,
  591. round(bill.depositOwe/100,2) depositOwe,
  592. round(bill.otherOwe/100,2) otherOwe,
  593. round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe,
  594. <choose>
  595. <when test="1==filterHasPay">
  596. round((bill.rentReceivePay-bill.rentPay)/100,2) rentReceivePay,
  597. round((bill.propertyReceivePay-bill.propertyPay)/100,2) propertyReceivePay,
  598. round((bill.depositReceivePay-bill.depositPay)/100,2) depositReceivePay,
  599. round((bill.otherReceivePay-bill.otherPay)/100,2) otherReceivePay,
  600. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay
  601. -bill.rentPay-bill.propertyPay-bill.depositPay-bill.otherPay)/100,2) totalReceivePay
  602. </when>
  603. <otherwise>
  604. round(bill.rentReceivePay/100,2) rentReceivePay,
  605. round(bill.propertyReceivePay/100,2) propertyReceivePay,
  606. round(bill.depositReceivePay/100,2) depositReceivePay,
  607. round(bill.otherReceivePay/100,2) otherReceivePay,
  608. round((bill.rentReceivePay+bill.propertyReceivePay+bill.depositReceivePay+bill.otherReceivePay)/100,2) totalReceivePay
  609. </otherwise>
  610. </choose>
  611. from (
  612. select oweList.*,
  613. max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe,
  614. max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe,
  615. max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe,
  616. max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe,
  617. max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay,
  618. max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay,
  619. max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay,
  620. max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay,
  621. max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay,
  622. max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay,
  623. max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay,
  624. max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay
  625. from(
  626. 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 (
  627. select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金'
  628. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  629. endtime,rent_shop_type from wx_bill_rent where tenant_id = #{tenantId} and is_preview = 0
  630. <include refid="getOweBillAsPageConditions"/>
  631. union all
  632. select id,merchant_id,shop_id,tenant_id,'物业费' name,3 bill_type_value,'物业费'
  633. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  634. endtime,rent_shop_type from wx_bill_property where tenant_id = #{tenantId} and is_preview = 0
  635. <include refid="getOweBillAsPageConditions"/>
  636. union all
  637. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  638. 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(
  639. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,2 bill_type_value,'欠缴押金'
  640. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  641. endtime,rent_shop_type from wx_bill_rent_deposit where tenant_id = #{tenantId}
  642. <include refid="getOweBillAsPageConditions"/>
  643. union all
  644. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,4 bill_type_value,'欠缴押金'
  645. bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''
  646. endtime,rent_shop_type from wx_bill_property_deposit where tenant_id = #{tenantId}
  647. <include refid="getOweBillAsPageConditions"/>
  648. union all
  649. select id,merchant_id,shop_id,tenant_id,'欠缴押金' name,8 bill_type_value,'欠缴押金' bill_type,0 as
  650. 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
  651. from wx_bill_other_deposit where tenant_id = #{tenantId}
  652. <include refid="getOweBillAsPageConditions"/>
  653. ) res
  654. union all
  655. select res.id,res.merchant_id,res.shop_id,res.tenant_id,res.name,res.bill_type_value,res.bill_type,res.need_pay,
  656. 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(
  657. select id,merchant_id,shop_id,tenant_id,'其他费用' name,5 bill_type_value,'其他费用' bill_type,0 as
  658. 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
  659. from wx_bill_daily where tenant_id = #{tenantId} and type in(1,2,3)
  660. <include refid="getOweBillAsPageConditions"/>
  661. union all
  662. select id,merchant_id,shop_id,tenant_id,'其他费用' name,7 bill_type_value,'其他费用' bill_type,0 as
  663. 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
  664. from wx_bill_other where tenant_id = #{tenantId}
  665. <include refid="getOweBillAsPageConditions"/>
  666. ) res
  667. ) bill
  668. where bill.status not in(3,5,6)
  669. group by bill.merchant_id,bill.bill_type
  670. ) oweList group by oweList.merchant_id
  671. ) bill
  672. left join wx_merchant m on bill.merchant_id=m.id
  673. where m.status=1 and m.tenant_id = #{tenantId}
  674. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  675. <if test=" null == sortColumns"> order by totalOwe desc </if>
  676. </select>
  677. <!--union all
  678. select pay_amount money,mm.id from wx_profit_sharing_order pso
  679. left join wx_merchant mm on pso.merchant_id=mm.id
  680. where pso.sharing_status !=5
  681. -->
  682. <select id="getReceiveAndPayBillAsPage" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  683. select m.id,m.name,ws.shop_number shopNumber,ws.type,m.link_person linkPerson,m.link_phone linkPhone,
  684. xb.title business,rc.rental_start_date rentalStartDate,rc.rental_end_date rentalEndDate,
  685. round(
  686. (select sum(bill.receive_pay) from (
  687. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  688. union all
  689. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  690. union all
  691. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  692. union all
  693. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  694. union all
  695. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  696. union all
  697. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  698. union all
  699. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  700. ) bill where bill.merchant_id = m.id
  701. )/100,2) receivePay,
  702. round(
  703. (select sum(ss.money) from (
  704. select ms.subsidy money,mm.id
  705. from wx_merchant_subsidy ms
  706. left join wx_coupon_order co on co.id = ms.coupon_order_id
  707. left join wx_coupon c on c.id = co.coupon_id
  708. left join wx_merchant mm on mm.id = ms.merchant_id
  709. left join wx_card_spend cs on cs.order_id = ms.order_id
  710. left join wx_c_user cu on cu.id = cs.owner_id
  711. where ms.order_type in(3,0) and ms.status = 0
  712. union all
  713. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  714. union all
  715. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  716. union all
  717. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  718. )ss where ss.id = m.id
  719. )/100,2) payOut,
  720. (round(
  721. (select sum(bill.receive_pay) from (
  722. select merchant_id,receive_pay from wx_bill_rent where is_preview = 0 and status not in(3,6)
  723. union all
  724. select merchant_id,receive_pay from wx_bill_rent_deposit where status not in(3,6)
  725. union all
  726. select merchant_id,receive_pay from wx_bill_property where is_preview = 0 and status not in(3,6)
  727. union all
  728. select merchant_id,receive_pay from wx_bill_property_deposit where status not in(3,6)
  729. union all
  730. select merchant_id,receive_pay from wx_bill_daily where type in(1,2,3) and status not in(3,6)
  731. union all
  732. select merchant_id,receive_pay from wx_bill_other where status not in(3,6)
  733. union all
  734. select merchant_id,receive_pay from wx_bill_other_deposit where status not in(3,6)
  735. ) bill where bill.merchant_id = m.id
  736. )/100,2)-
  737. round(
  738. (select sum(ss.money) from (
  739. select ms.subsidy money,mm.id
  740. from wx_merchant_subsidy ms
  741. left join wx_coupon_order co on co.id = ms.coupon_order_id
  742. left join wx_coupon c on c.id = co.coupon_id
  743. left join wx_merchant mm on mm.id = ms.merchant_id
  744. left join wx_card_spend cs on cs.order_id = ms.order_id
  745. left join wx_c_user cu on cu.id = cs.owner_id
  746. where ms.order_type in(3,0) and ms.status = 0
  747. union all
  748. select receive_pay money,merchant_id id from wx_bill_rent_deposit where status = 3
  749. union all
  750. select receive_pay money,merchant_id id from wx_bill_property_deposit where status = 3
  751. union all
  752. select receive_pay money,merchant_id id from wx_bill_other_deposit where status = 3
  753. )ss where ss.id = m.id
  754. )/100,2)) balance
  755. from wx_merchant m left join wx_merchant_shop wms on wms.merchant_id = m.id left join wx_shop ws on wms.shop_id = ws.id
  756. left join wx_business xb on(m.business_id = xb.id)
  757. left join wx_rent_contract rc on(rc.merchant_id = m.id)
  758. where 1=1
  759. <if test=" null != tenantId"> and m.tenant_id = #{tenantId} </if>
  760. <if test=" null != merchantId"> and m.id = #{merchantId} </if>
  761. <if test=" null != merchantName"> and m.name like concat('%', #{merchantName},'%') </if>
  762. <if test=" null != rentShopType"> and rc.rent_shop_type = #{rentShopType} </if>
  763. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  764. <if test=" null == sortColumns"> order by m.id desc </if>
  765. </select>
  766. <select id="allDepositList" parameterType="com.iformall.domain.vo.WxBillAll" resultType="hashmap">
  767. select bill.*
  768. from (
  769. select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金'
  770. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  771. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime from wx_bill_rent_deposit where
  772. tenant_id=#{tenantId}
  773. union all
  774. select id,merchant_id,shop_id,tenant_id,'物业押金' name,4 bill_type_value,'物业押金'
  775. bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,''
  776. endtime,rent_shop_type,shop_info,NULL comments,'' price_detail,updatetime from wx_bill_property_deposit where
  777. tenant_id=#{tenantId}
  778. union all
  779. select id,merchant_id,shop_id,tenant_id,comments as name,8 bill_type_value,concat('其他押金-',comments) as
  780. bill_type,0 as
  781. need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,'' starttime,'' endtime,
  782. rent_shop_type,'[]' shop_info,comments,'' price_detail,updatetime
  783. from wx_bill_other_deposit where tenant_id=#{tenantId}
  784. ) bill
  785. where 1=1
  786. <if test=" null != status"> and bill.status = #{status} </if>
  787. <if test=" null != merchantId">and bill.merchant_id=#{merchantId}</if>
  788. </select>
  789. </mapper>