This php web video script that I’m using calculates the cost of the video, and then upon a purchase inserts the amount of the price into the video/owner/users’ ‘wallet’ account (the column in the users table titled ‘wallet"). I believe this file code (below) performs that function. I’d like help with modifying it so that instead of the purchase amount going into the video/owner/users’ ‘wallet’, the price is inserted into the video/owner/users’ ‘balance’ account (the column in the users table titled ‘balance’). I believe that function starts at around line 60 (marked below). I look forward to your suggestions/assistance.
<?php
ob_start();
if (IS_LOGGED == false) {
$data = array('status' => 400, 'error' => 'Not logged in');
echo json_encode($data);
exit();
}
if (!empty($_POST['id'])) {
if (!is_array($_POST['id'])) {
$id_array[] = $_POST['id'];
} else {
$id_array = $_POST['id'];
}
// get cost video
$db->where('name', 'video_play_price');
$db_cost = $db->getOne('config');
$video_cost = (float)$db_cost->value;
$count_video = count($id_array);
$user_id = $user->id;
$wallet = (float)str_replace(',', '', $user->wallet);
$amout = 0;
foreach ($id_array as $id) {
$video_id = (int)PT_Secure($id);
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
$amout += $video->video_play_price?$video->video_play_price:$video_cost;
}
// $amout = $video_cost * $count_video;
$charge = ( $video_cost *0.50 );
if ($wallet >= $amout) {
$new_wallet = (string)($wallet - $amout);
$db->startTransaction();
$inserted_records = 0;
foreach ($id_array as $id) {
$video_id = (int)PT_Secure($id);
// $uploader_amount = $video_cost - $charge; //100 - 20% = 80
// get video data
$video = $db->where('id', $id)->getOne(T_VIDEOS);
**$video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost;**
$uploader_amount = ( $video_cost_new *0.50 );
// add data to paid table
$insert_buy = $db->insert('u_paid_videos', [
'id_user' => $user_id,
'id_video' => $video_id,
'session_key' => $_SESSION['session_key'],
'video_play_price' => (string)$video_cost,
'video_title' => $video->title,
'user_id_uploaded' => $video->user_id,
//'up_credit'=>$video_cost,
'up_credit'=>$uploader_amount,
]);
if ($insert_buy) { $inserted_records++; }
//add wallet users' video
$userwallet = $db->where('id', $video->user_id)->getOne(T_USERS);
//$videouserwallet = $userwallet->wallet+$video_cost;
$videouserwallet = $userwallet->wallet+$uploader_amount;
$db->where('id', $video->user_id);
$update_wallet = $db->update(T_USERS, [
// 'wallet' => $videouserwallet,
'wallet' => number_format($videouserwallet, 2, '.', ''),
]);
}
$db->where('id', $user_id);
$update_wallet = $db->update(T_USERS, [
'wallet' => $new_wallet,
]);
if (($inserted_records == $count_video) && $update_wallet) {
$db->commit();
echo json_encode([
'status' => 200
]);
exit();
} else {
$db->rollback();
echo json_encode([
'status' => 400,
'error' => 'Buy process error'
]);
exit();
}
} else {
echo json_encode([
'status' => 400,
'error_num' => 1,
'error' => 'Not enough money'
]);
exit();
}
} else {
echo json_encode([
'status' => 400,
'error' => 'Bad Request, Invalid or missing parameter'
]);
exit();
echo('$video_play_price: '.$video_play_price.PHP_EOL);
echo('$charge: '.$charge.PHP_EOL);
echo('$amout: '.$amout.PHP_EOL);
$uploader_amount = $video_play_price - $charge;
$uploader_amount = $amout - $charge;
exit;
echo "$uploader_amount";
}