select pay_bill_id, bill_id, currency, product_amount, redline_amount, cost_amount, pay_total, belong_saler, belong_saler_code, settlement_man, settlement_man_code, create_by, create_time, update_by, update_time from prc_pay_bill insert into prc_pay_bill ( pay_bill_id, bill_id, currency, product_amount, redline_amount, cost_amount, pay_total, belong_saler, belong_saler_code, settlement_man, settlement_man_code, create_by, create_time ) values ( #{payBillId}, #{billId}, #{currency}, #{productAmount}, #{redlineAmount}, #{costAmount}, #{payTotal}, #{belongSaler}, #{belongSalerCode}, #{settlementMan}, #{settlementManCode}, #{createBy}, sysdate() ) update prc_pay_bill set currency = #{currency}, product_amount = #{productAmount}, redline_amount = #{redlineAmount}, cost_amount = #{costAmount}, pay_total = #{payTotal}, belong_saler = #{belongSaler}, belong_saler_code = #{belongSalerCode}, settlement_man = #{settlementMan}, settlement_man_code = #{settlementManCode}, update_by = #{updateBy}, update_time = sysdate() where bill_id = #{billId} insert into prc_pay_bill ( pay_bill_id, bill_id, currency, product_amount, redline_amount, cost_amount, pay_total, belong_saler, belong_saler_code, settlement_man, settlement_man_code, create_by, create_time ) values ( #{payBillId}, #{billId}, #{currency}, #{productAmount}, #{redlineAmount}, #{costAmount}, #{payTotal}, #{belongSaler}, #{belongSalerCode}, #{settlementMan}, #{settlementManCode}, #{createBy}, sysdate() ) on duplicate key update currency = values(currency), product_amount = values(product_amount), redline_amount = values(redline_amount), cost_amount = values(cost_amount), pay_total = values(pay_total), belong_saler = values(belong_saler), belong_saler_code = values(belong_saler_code), settlement_man = values(settlement_man), settlement_man_code = values(settlement_man_code), update_by = values(update_by), update_time = sysdate() insert into prc_pay_bill ( pay_bill_id, bill_id, currency, pay_total, belong_saler, belong_saler_code, settlement_man, settlement_man_code, create_by, create_time, update_by, update_time ) select replace(uuid(), '-', ''), o.bill_id, ifnull(nullif(o.currency, ''), 'CNY'), 0, o.belong_saler, o.belong_saler_code, o.settlement_man, o.settlement_man_code, #{operator}, sysdate(), #{operator}, sysdate() from prc_order_bill o where o.bill_id in #{billId} and not exists ( select 1 from prc_pay_bill b where b.bill_id = o.bill_id ) update prc_pay_bill b left join ( select bill_id, ifnull(sum(amount), 0) as total from prc_pay_bill_fee where ifnull(is_deleted, '0') = '0' and bill_id in #{billId} group by bill_id ) s on s.bill_id = b.bill_id set b.pay_total = ifnull(s.total, 0), b.update_time = sysdate() where b.bill_id in #{billId} update prc_pay_bill set pay_calc_status = #{status}, pay_calc_msg = #{message}, update_by = #{operator}, update_time = sysdate() where bill_id = #{billId} delete from prc_pay_bill where bill_id = #{billId}