Просмотр файла api/finishMission/index.php

Размер файла: 1.15Kb
  1. <?php
  2.  
  3. include '../../bot/config.php';
  4. include '../../bot/functions.php';
  5.  
  6. $MySQLi = new mysqli('localhost',$DB['username'],$DB['password'],$DB['dbname']);
  7. $MySQLi->query("SET NAMES 'utf8'");
  8. $MySQLi->set_charset('utf8mb4');
  9. if ($MySQLi->connect_error) die;
  10. function ToDie($MySQLi){
  11. $MySQLi->close();
  12. die;
  13. }
  14.  
  15.  
  16. session_start();
  17. $app_hash = $_SESSION['app_hash'];
  18.  
  19. $get_user = mysqli_fetch_assoc(mysqli_query($MySQLi, "SELECT * FROM `users` WHERE `hash` = '{$app_hash}' LIMIT 1"));
  20.  
  21. if(!$get_user){
  22. http_response_code(300);
  23. echo json_encode(['ok' => false, 'message' => 'user not found'], JSON_PRETTY_PRINT);
  24. $MySQLi->close();
  25. die;
  26. }
  27.  
  28.  
  29. $missionId = json_decode(file_get_contents('php://input'), true)['missionId'];
  30.  
  31.  
  32. $MySQLi->query("UPDATE `user_missions` SET `status` = '2' WHERE `mission_id` = '{$missionId}' AND `user_id` = '{$get_user['id']}' LIMIT 1");
  33.  
  34. $reward = (int) mysqli_fetch_assoc(mysqli_query($MySQLi, "SELECT * FROM `missions` WHERE `id` = '{$missionId}' LIMIT 1"))['reward'];
  35.  
  36. $MySQLi->query("UPDATE `users` SET `balance` = `balance` + '{$reward}' WHERE `hash` = '{$app_hash}' LIMIT 1");
  37.  
  38.  
  39.  
  40.  
  41. $MySQLi->close();