選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

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