<?php
include "control/activity.php";
$dd = new activity();

$runing = $_REQUEST['runing'];
$rcvdAmount = $_REQUEST['rcvdAmount'];
$rcvdBet = $_REQUEST['rcvdBet'];
$userKey = $_REQUEST['userKey'];

if($runing == "" || $rcvdAmount == "" || $rcvdBet=="" || $userKey == "")
{
     print_r(json_encode(array("status" => "failed","remark" => "All field are Required..!!")));
}
else{
   
   $table = "userdetails";
   $condition = " where userKey='$userKey'";
   $getUserDetails = $dd->check($table,$condition);
   if($getUserDetails['status'] == "success")
   {
       $daily_task = $getUserDetails['data']['daily_task'];
       if($rcvdBet > $daily_task)
       {
            $table = " userdetails";
            $value = "wallet=wallet+$rcvdBet,daily_task=daily_task+$rcvdBet";
            $condition = " userKey='$userKey' AND daily_task < $rcvdBet";
            $result = $dd->updateData($table,$value,$condition);
            if($result){
                $ref = mt_rand(1111111111,9999999999);
                $date = date("h:i d/m/Y");
              $table = "account_history";
              $value ="(`userKey`, `amount`, `tax`, `action_date`, `lossorprofit`, `refrence`,`game_name`) 
              SELECT '$userKey','$rcvdBet','0','$date','0','$ref','bet' FROM userdetails WHERE userKey='$userKey'";
              $result = $dd->insertData($table,$value);
              if($result){
                  print_r(json_encode(array("status" => "success","remark" => "Payment Recievd successfully..!!"))); 
              }
               
           }
       }else{
          print_r(json_encode(array("status" => "failed","remark" => "Somthing is wrong..!!"))); 
       }
   }else{
       print_r(json_encode(array("status" => "failed","remark" => "User Details not match..!!"))); 
       
   }
   
   
   
}

?>