`id`,`tenant_id`,`parent_tenant_id`,`rent_contract_id`,`receive_pay`,`pay`,`receive_date`,`pay_date`,`create_by`,`create_by_name`,`update_by`,`update_by_name`,
`createtime`,`expired_day`,`status`,`is_del`,`contract_need_pay`,`rent_price_info`,`need_pay`,`bussiness_manage_fee_need_pay`,`operating_manage_fee_need_pay`,
`merchant_id`,`user_id`,`shop_id`,`updatetime`,`rent_shop_type`,`apply_status`,`apply_pay_img`,`apply_update_time`,`last_owe_call_time`,
`revenue`,`late_pay_ratio`,`late_pay_time`,`late_pay_price`,`period`,`is_preview`,`shop_info`,`last_owe_call_user`,`set_off`,`advance_id`,
`pay_way`,`late_pay_status`,`comments`,starttime,endtime,bus_discount_ratio,freeze,join_rent_price,service_charge_pay,`energy_fees_id`
where 1=1
and `id` = #{id}
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
and `rent_contract_id` = #{rentContractId}and `energy_fees_id` = #{energyFeesId}and `advance_id` = #{advanceId}and `receive_pay` = #{receivePay}and `pay` = #{pay}and `receive_date` = #{receiveDate}and `pay_date` = #{payDate}and `createtime` = #{createtime}and `expired_day` = #{expiredDay}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 `starttime` = #{starttime}and `endtime` = #{endtime}
and endtime >= #{endtimeBegin}
and endtime < #{endtimeEnd}
and (`last_owe_call_time` is not null and `receive_pay` - `pay` - `set_off > 0 and status not in (3,6,7) )
and status in
#{stItem}
and id in
#{idItem}
order by ${sortColumns}
br.is_preview = 0
and br.`id` = #{id} and br.`tenant_id` = #{tenantId}and br.`parent_tenant_id` = #{parentTenantId}and br.`freeze` = #{freeze}and br.`rent_shop_type` = #{rentShopType}and br.`status` = #{status}and br.`apply_status` = #{applyStatus}and br.`id` = #{id}and br.`merchant_id` = #{merchantId}and br.`advance_id` = #{advanceId}and br.`is_del` = #{isDel}and br.`rent_contract_id` = #{rentContractId}and br.`energy_fees_id` = #{energyFeesId}and br.`pay_way` = #{payWay}and br.`late_pay_status` = #{latePayStatus}and br.`starttime` <= #{starttime}and br.`endtime` >= #{endtime}
and date_format(br.starttime,'%Y-%m') <= #{month} and date_format(br.endtime,'%Y-%m') >= #{month}
and (br.`starttime` <= #{oweBillLastTime} and br.`receive_pay` - br.`pay` - br.`set_off` > 0 and br.status not in (3,6,7))
and (br.`starttime` > #{oweBillLastTime} and br.`starttime` <= #{nearBillLastTime} and br.`receive_pay` - br.`pay` - br.`set_off` > 0 and br.status not in (3,6,7))
and (br.`starttime` <= #{needPayStartDay} and br.`receive_pay` - br.`pay` - br.`set_off` > 0 and br.status not in (3,6,7))
and (br.`last_owe_call_time` is not null and br.`receive_pay` - br.`pay`- br.`set_off` > 0 and br.status not in (3,6,7) )
and br.`rent_contract_id` in
#{ridItem}
and br.`merchant_id` in
#{midItem}
and br.`status` in
#{stItem}
update wx_bill_rent 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_rent set status=#{waitPay} where id in(
select a.id from (select br.id,rc.receive_period,br.rent_contract_id,br.receive_date from wx_bill_rent br
left join wx_rent_contract rc on br.rent_contract_id=rc.id
where br.status!=#{paid}
and br.`tenant_id` = #{tenantId}
and br.`parent_tenant_id` = #{parentTenantId}
and br.status!=6 and now() < br.receive_date
and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a)
update wx_bill_rent set status = 6 where rent_contract_id = #{rentContractId}
and status != 3
delete from wx_bill_rent where rent_contract_id = #{id}
delete from wx_bill_rent where rent_contract_id = #{rentContractId}
and is_preview = #{isPreview}
update wx_bill_rent set updatetime = now()
,receive_pay = #{receivePay},comments = #{comments},receive_date = #{receiveDate},status = 3,pay_date=now()
where id = #{id}
update wx_bill_rent set is_preview = #{isPreview},merchant_id = #{merchantId},need_pay = receive_pay
where rent_contract_id = #{rentContractId}
INSERT INTO wx_bill_rent (id,tenant_id,parent_tenant_id,
rent_contract_id, receive_pay, pay, receive_date, pay_date, createtime, expired_day,create_by,create_by_name,update_by,update_by_name,
status, is_del, contract_need_pay,rent_price_info,need_pay,bussiness_manage_fee_need_pay,operating_manage_fee_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,energy_fees_id,advance_id)
VALUES
(
#{item.id},#{item.tenantId},#{item.parentTenantId},
#{item.rentContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime},#{item.expiredDay},#{item.createBy},#{item.createByName},#{item.updateBy},#{item.updateByName},
#{item.status},#{item.isDel},#{item.contractNeedPay},#{item.rentPriceInfo},#{item.needPay},#{item.bussinessManageFeeNeedPay},#{item.operatingManageFeeNeedPay},#{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},#{item.energyFeesId},#{item.advanceId}
)
update wx_bill_rent
updatetime = now(),receive_pay = #{item.receivePay},comments = #{item.comments},receive_date = #{item.receiveDate},status = 3,pay_date=now()
where id = #{item.id}
delete from wx_bill_rent where id = #{id} and tenant_id = #{tenantId}