`id`,`tenant_id`,`parent_tenant_id`,`property_contract_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,
`createtime`,`expired_day`,`tenant_id`,`owe`,`status`,`is_del`,`need_pay`,
`merchant_id`,`user_id`,`shop_id`,`updatetime`,`rent_shop_type`,`apply_status`,`apply_pay_img`,`apply_update_time`,
`revenue`,`late_pay_ratio`,`late_pay_time`,`late_pay_price`,`period`,`is_preview`,`shop_info`,
`pay_way`,`late_pay_status`,`comments`,starttime,endtime,freeze,service_charge_pay
where 1=1
and `id` = #{id}
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
and `property_contract_id` = #{propertyContractId}and `receive_pay` = #{receivePay}and `pay` = #{pay}and `receive_date` = #{receiveDate}and `pay_date` = #{payDate}and `createtime` = #{createtime}and `expired_day` = #{expiredDay}and `owe` = #{owe}and `status` = #{status}and `apply_status` = #{applyStatus}and `is_del` = #{isDel}and `need_pay` = #{needPay}and `merchant_id` = #{merchantId}and `user_id` = #{userId}and `shop_id` = #{shopId}and `updatetime` = #{updatetime}and `rent_shop_type` = #{rentShopType}and is_preview = #{isPreview}and `pay_way` = #{payWay}and `late_pay_status` = #{latePayStatus}
and id in
#{idItem}
order by ${sortColumns}
update wx_bill_property b set b.status=#{notPaid},b.expired_day=
DATEDIFF(now(), b.receive_date)
where b.status!=#{paid} and b.status!=6
and DATEDIFF(now(), b.receive_date) >0
and b.`tenant_id` = #{tenantId}
and b.`parent_tenant_id` = #{parentTenantId}
update wx_bill_property set status=#{waitPay} where id in(
select a.id from (
select br.id,rc.receive_period,br.property_contract_id,br.receive_date
from wx_bill_property br
left join wx_property_contract rc on br.property_contract_id=rc.id
where 1=1
and br.`tenant_id` = #{tenantId}
and br.`parent_tenant_id` = #{parentTenantId}
and br.status!=#{paid} and br.status != 6 and now() < br.receive_date
and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a)
update wx_bill_property set status = 6 where property_contract_id = #{propertyContractId}
and status in(4,2)
update wx_bill_property set status = 6 where property_contract_id in
(select id from wx_property_contract where rent_contract_id = #{id})
and status != 3
delete from wx_bill_property where property_contract_id = #{id}
update wx_bill_property set updatetime = now()
,receive_pay = #{receivePay},owe=#{receivePay},comments = #{comments},receive_date = #{receiveDate},status = 3,pay_date=now()
where id = #{id}
update wx_bill_property set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay,
owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
where property_contract_id = #{propertyContractId}
INSERT INTO wx_bill_property (id,property_contract_id, receive_pay, pay, receive_date, pay_date, createtime,
expired_day,
tenant_id, parent_tenant_id, owe, status, is_del, need_pay, merchant_id, user_id, shop_id, updatetime, starttime,
endtime,
rent_shop_type, revenue, late_pay_ratio, late_pay_time, late_pay_price, period, is_preview, shop_info,
pay_way, late_pay_status, comments,service_charge_pay)
VALUES
(
#{item.id},#{item.propertyContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},
#{item.expiredDay},#{item.tenantId},#{item.parentTenantId},
#{item.owe},#{item.status},#{item.isDel},#{item.needPay},#{item.merchantId},
#{item.userId},#{item.shopId},#{item.updatetime},#{item.starttime},#{item.endtime},#{item.rentShopType},#{item.revenue},
#{item.latePayRatio},#{item.latePayTime},#{item.latePayPrice},#{item.period},#{item.isPreview},#{item.shopInfo},
#{item.payWay},#{item.latePayStatus},#{item.comments},#{item.serviceChargePay}
)
update wx_bill_property
updatetime = now(),receive_pay = #{item.receivePay},comments = #{item.comments},receive_date = #{item.receiveDate},status = 3,pay_date=now()
where id = #{item.id}
insert into wx_bill_action(id,user_name,`action`,bill_id,details,tenant_id,parent_tenant_id)
select
(select unix_timestamp(now()) + CEILING(RAND()*90000+10000) + CEILING(RAND()*90000+10000) + CEILING(RAND()*90000+10000)) id
,'系统端' user_name,7 `action`,b.id bill_id,
CONCAT('系统计入',
if(b.late_pay_price is null,
round(
b.owe * c.late_pay_ratio * DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) /10000
,2)
,
round(
b.owe * (c.late_pay_ratio) /10000
,2)
)
,'元') details,b.tenant_id,b.parent_tenant_id
from wx_bill_property b left join wx_property_contract c on(b.`property_contract_id`=c.id)
where c.late_pay_ratio >0
and DATEDIFF(now(), date_add(b.receive_date,interval(c.late_pay_day) day)) >0
and b.status!=3 and b.status!=6
update wx_bill_property b set b.late_pay_price =
if(b.late_pay_price is null,
round(
b.owe * (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`)
* DATEDIFF(now(), date_add(b.receive_date,interval(select late_pay_day from wx_property_contract where id = b.`property_contract_id`) day)) /100
,2)
,
b.late_pay_price +
round(
b.owe * (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`) /100
,2)
)
where b.status!=3 and b.status!=6
and (select late_pay_ratio from wx_property_contract where id = b.`property_contract_id`) > 0
and DATEDIFF(now(), date_add(b.receive_date,interval(select late_pay_day from wx_property_contract where id = b.`property_contract_id`) day)) >0;
update wx_bill_property
set service_charge_pay=round(receive_pay*#{serviceChargeRate}/10000),owe=receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
where service_charge_pay=0 and status in(1,2,4)
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
update wx_bill_property
set owe = receive_pay + service_charge_pay + ifnull(late_pay_price,0) - pay
where status in (1,2,4)