Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. <?php
  2.  
  3. class ControllerVemaybayCronJobapp
  4. {
  5.  
  6.  
  7.  
  8. function index(){
  9. $connect = $this->connect();
  10. $query_routes_1 = $connect->query("SELECT * FROM **** where status = '0' GROUP BY routes ");
  11. for ($result = array();
  12. $row = $query_routes_1->fetch_assoc();
  13. $result[array_shift($row)] = $row);
  14.  
  15. foreach ($result as $i => $aaa){
  16. $routes = $aaa['routes'];
  17. $detail_routes_2 = $connect->query("SELECT * FROM **** where routes = '" . $routes . "' AND status = '0' ");
  18. for ($result2 = array();
  19. $row2 = $detail_routes_2 ->fetch_assoc();
  20. $result2[array_shift($row2)] = $row2);
  21.  
  22. foreach ($result2 as $t => $value1) {
  23.  
  24. $ngay = $value1['ngay'];
  25. $thang = $value1['thang'];
  26. $nam = $value1['nam'];
  27. $min = $value1['minPrice'];
  28. $max = $value1['maxPrice'];
  29. $providers = $value1['providers'];
  30. $startdate = $nam.$thang.'01';
  31. $enddate = $nam.$thang.'31';
  32.  
  33. $bien = $this->getlist_ticketsofdate($routes,$startdate,$enddate);
  34. foreach ($bien as $k => $value) {
  35. $moi2 = array();
  36. $moi = $value['c'];
  37. $moi2 = $value['f'];
  38. if($value['_id']['dim'] == $ngay ){
  39. if($min <= $value['c'] && $value['c'] <= $max && strpos($providers, $value['p']) !== false){
  40. $connect->query("UPDATE **** SET status='1' where customer_id = '" . $value1['customer_id'] . "' ");
  41. break;
  42. }else{
  43. foreach ($moi2 as $key => $value2) {
  44. if($min <= $value2['cp'] && $value2['cp'] <= $max && strpos($providers, $value2['p']) !== false){
  45. $connect->query("UPDATE **** SET status='1' where customer_id = '" . $value1['customer_id'] . "' ") ;
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55.  
  56.  
  57. function connect(){
  58. $servername = "****";
  59. $username = "****";
  60. $password = "****";
  61. $databasename = "****";
  62. $conn = new mysqli($servername, $username, $password,$databasename);
  63. if ($conn->connect_error) {
  64. die("Connection failed: " . $conn->connect_error);
  65. }
  66. return $conn;
  67. }
  68.  
  69.  
  70.  
  71. function getlist_ticketsofdate($diadiem,$startDate,$endDate){
  72.  
  73.  
  74. $url = '****';
  75.  
  76. $providers = array();
  77. $providers[0] = '****';
  78. $providers[1] = '****';
  79. $providers[2] = '****';
  80.  
  81. $routes = array();
  82. $routes[0] = $diadiem;
  83.  
  84. $headers = array();
  85. $headers[] = 'Content-Type: application/json';
  86. $headers[] = 'Connection:keep-alive';
  87.  
  88. $param = array(
  89. 'startDate' => $startDate,
  90. 'endDate' => $endDate,
  91. 'minPrice' => '0',
  92. 'maxPrice' => '700000',
  93. 'providers' => $providers,
  94. 'routes' => $routes,
  95. 'type' => 'date',
  96. );
  97.  
  98. $data_string = json_encode($param);
  99.  
  100. $ch = curl_init();
  101. curl_setopt($ch, CURLOPT_URL, $url);
  102. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  103. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  104. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  105.  
  106. $response = curl_exec($ch);
  107. $result_tickets = json_decode($response,true);
  108. return $result_tickets;
  109. }
  110. }
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement