Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2008
    Posts
    303
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help with including a minimum price

    The php web video script that Iím using calculates the cost of the video. Any uploaded video is priced at what the Admin has set in admin panel, (but after the upload the uploader can change the price). All that works successfully. However, Iíd like to add the function that the price set by Admin is the minimum price, so uploader canít price it below that (currently an uploader can change to any price - from his logged-in account). The admin-panel code pertaining to that is this:

    Code:
    <div class="form-line">
    <input type="number" name="video_play_price" class="form-control" value="{{CONFIG video_play_price}}">
    <label class="form-label">Cost Video</label>
    </div>

    And I believe this php code(below) is where the added function code needs to go? Possibly around line 20(in Bold)? Any help will be appreciated.

    Code:
    <?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";
    }
    Last edited by chrisjchrisj; Jan 20th, 2019 at 06:28 PM.

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,955
    Thanks
    36
    Thanked 1,064 Times in 1,060 Posts
    You can set minimum value (as well as the maximum) for a <input type="number" min="PUT VALUE HERE" ...>. I would also make value="..." the same value.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •