Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1.     <?php
  2.     $db_host = 'localhost';
  3.     $db_name = "dados";
  4.     $mysql_charset = "utf8";
  5.     $db_username = "root";
  6.     $db_password = "";
  7.  
  8.  
  9.     //  Initiate curl
  10.     $ch = curl_init();
  11.     // Disable SSL verification
  12.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  13.     // Will return the response, if false it print the response
  14.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15.     // Set the url
  16.     curl_setopt($ch, CURLOPT_URL, "http://graph.facebook.com/?id=https://gamaia.com.br/");
  17.     // Execute
  18.     $result = curl_exec($ch);
  19.     // Closing
  20.     curl_close($ch);
  21.  
  22.     // Will dump a beauty json :3
  23.     var_dump(json_decode($result, true));
  24.  
  25.     $json = json_decode($result, true);
  26.  
  27.     echo " <br />Compartilhamento Atual:".$json["share"]["share_count"];
  28.  
  29.         //conexão com o host
  30.         try{
  31.             $PDO = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset='.$mysql_charset, $db_username, $db_password);
  32.         }catch(PDOException $e){
  33.             echo($e->getMessage());
  34.         }
  35.  
  36.         //selecionar tabela
  37.         $stmt = $PDO->prepare("SELECT * FROM tab_produtos_promo WHERE idpromo = 1");
  38.         $stmt->execute();
  39.         $row = $stmt->fetch(PDO::FETCH_ASSOC);
  40.         ################################################################
  41.  
  42.  
  43.             #REDIRECIONAMENTO
  44.             $url = $row['cmp_codigo'];
  45.             header("location: http://localhost/gamaia_test/detalhes".$row['url']);
  46.  
  47.             $shared = $row['shared'];
  48.  
  49.                 echo "<br ><br >Compartilhamento até o inicio: ".$shared;
  50.  
  51.                 $atual = $json["share"]["share_count"] - $shared;
  52.                 echo "<br ><br >Atual da Pagina:".$atual;
  53.  
  54.                     // Preços
  55.  
  56.                 $preco = $row['cmp_preco_de'];
  57.                 $precoMin = $row['promo'];
  58.                 $desconto = $row['desconto'];
  59.  
  60.                     //  formula de calculo
  61.  
  62.                 $precoAtual = $preco - ( $desconto * $atual );
  63.  
  64.  
  65.                 echo "<br ><br >".$preco." -> ".$precoAtual;
  66.  
  67.             if($precoAtual <= $precoMin){
  68.  
  69.                 //If para remover o item após ultrapassar o preço minimo
  70.                 $stmt = $PDO->prepare("UPDATE tab_produtos SET cmp_estoque = 0");
  71.                 $stmt->execute();
  72.                 $row = $stmt->fetch(PDO::FETCH_ASSOC);
  73.  
  74.                 echo "<br>Remover</br>";
  75.             }
  76.             else {
  77.                 $stmt = $PDO->prepare("UPDATE tab_produtos SET cmp_preco_por = :preco2");
  78.                         $stmt->bindParam(':preco2', $precoAtual);
  79.                                 $stmt->execute();
  80.                             }
  81.  
  82.  
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement