我有这样的代码,当用户收到资金时,我需要运行该代码,现在它是仅在满足其他条件时才触发代码的功能的一部分。此代码仅在付款有争议(即使从资金中扣除并反映在余额值中)并退款时才将佣金值添加到用户余额中,但是当他收到任何资金时,我需要在列表中的用户余额中添加佣金:>
$payer_of_commission = get_post_meta( $bid_id_accepted, 'payer_of_commission', true );
if( $payer_of_commission != 'project_owner' ) {
$bid = get_post($bid_id_accepted);
$commission_fee = get_post_meta($bid_id_accepted, 'commission_fee', true);
$fre_available = FRE_Credit_Users()->getUserWallet($bid->post_author);
if(!empty($fre_available->balance)){
$new_balance = intval($fre_available->balance) - intval($commission_fee);
}else{
$new_balance = 0 - intval($commission_fee);
}
FRE_Credit_Users()->updateUserBalance($bid->post_author,$new_balance);
$args_commission = array(
'post_title' => __('Paid',ET_DOMAIN),
'post_author' => $bid->post_author,
'history_type' => 'charge',
'status' => 'completed',
'amount' => $commission_fee,
'project_accept' => $bid->post_parent,
'currency' => fre_credit_get_payment_currency(),
'is_commission' => 1,
);
FRE_Credit_History()->saveHistory($args_commission);
所有功能:
public function refundEscrow($project_id, $bid_id_accepted){
$pay_key = get_post_meta($bid_id_accepted, 'fre_paykey', true);
$re = FRE_Credit_Users()->refund($pay_key, $project_id, $bid_id_accepted);
if( $re['success'] ){
$order = get_post_meta($bid_id_accepted, 'fre_bid_order', true);
if ($order) {
wp_update_post(array(
'ID' => $order,
'post_status' => 'refund'
));
}
wp_update_post(array(
'ID' => $project_id,
'post_status' => 'disputed'
));
wp_update_post(array(
'ID' => $bid_id_accepted,
'post_status' => 'disputed'
));
//update charge to cancelled from ver 1.8.2
update_post_meta($pay_key,'history_status','cancelled');
// update transfer of freelancer to cancelled
$list_transfer = get_posts(array(
'post_type' => 'fre_credit_history',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'history_type',
'value' => 'transfer'
),
array(
'key' => 'history_status',
'value' => 'pending'
),
array(
'key' => 'payment',
'value' => $project_id
)
),
) );
if($list_transfer){
foreach ($list_transfer as $tr){
update_post_meta($tr->ID,'history_status','cancelled');
}
}
$payer_of_commission = get_post_meta( $bid_id_accepted, 'payer_of_commission', true );
if( $payer_of_commission != 'project_owner' ) {
$bid = get_post($bid_id_accepted);
$commission_fee = get_post_meta($bid_id_accepted, 'commission_fee', true);
$fre_available = FRE_Credit_Users()->getUserWallet($bid->post_author);
if(!empty($fre_available->balance)){
$new_balance = intval($fre_available->balance) - intval($commission_fee);
}else{
$new_balance = 0 - intval($commission_fee);
}
FRE_Credit_Users()->updateUserBalance($bid->post_author,$new_balance);
$args_commission = array(
'post_title' => __('Paid',ET_DOMAIN),
'post_author' => $bid->post_author,
'history_type' => 'charge',
'status' => 'completed',
'amount' => $commission_fee,
'project_accept' => $bid->post_parent,
'currency' => fre_credit_get_payment_currency(),
'is_commission' => 1,
);
FRE_Credit_History()->saveHistory($args_commission);
}
// update meta when admin arbitrate
if(isset($_REQUEST['comment']) && isset($_REQUEST['winner'])){
$comment = $_REQUEST['comment'];
$winner = $_REQUEST['winner'];
update_post_meta($project_id, 'comment_of_admin', $comment);
update_post_meta($project_id, 'winner_of_arbitrate', $winner);
}
//send mail
$mail = Fre_Mailing::get_instance();
$mail->refund($project_id, $bid_id_accepted);
do_action('fre_resolve_project_notification', $project_id);
// // send json back
wp_send_json(array(
'success' => true,
'msg' => __("Send payment successful.", ET_DOMAIN) ,
'data' =>__('Success', ET_DOMAIN)
));
} else {
wp_send_json($re);
}
}