Flatten nested repos
This commit is contained in:
61
test/vuex/one-sniper-tools/modules/Cities.php
Normal file
61
test/vuex/one-sniper-tools/modules/Cities.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
class Beranda extends MY_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onelite= $this->load->database("onelite",true);
|
||||
}
|
||||
function nearest() {
|
||||
$lat = $this->sys_input["lat"];
|
||||
$lng = $this->sys_input["lng"];
|
||||
$max = $this->sys_input["max"]?$this->sys_input["max"]:500;
|
||||
$sql = "select M_CityID,M_CityName, distance(?,?,M_BranchLat,M_BranchLng)/1000 distance
|
||||
from m_branch
|
||||
JOIN m_city ON M_BranchM_CityID = M_CityID
|
||||
having distance < ?
|
||||
order by distance ";
|
||||
$qry = $this->db_onelite->query($sql, array($lat,$lng,$max));
|
||||
echo $this->db_onelite->last_query();
|
||||
if (! $qry ) {
|
||||
//echo $this->db_onelite->last_query();
|
||||
echo json_encode( array(
|
||||
"status" => "ERR",
|
||||
"message" => print_r($this->db_onelite->last_query(),true)
|
||||
));
|
||||
return;
|
||||
}
|
||||
$rows = $qry->result_array();
|
||||
$sql = "select M_CityID as id, M_CityName as name
|
||||
from m_branch
|
||||
JOIN m_city ON M_BranchM_CityID = M_CityID
|
||||
GROUP BY M_BranchM_CityID";
|
||||
$qry = $this->db_onelite->query($sql);
|
||||
if (! $qry ) {
|
||||
|
||||
echo json_encode( array(
|
||||
"status" => "ERR",
|
||||
"message" => print_r($this->db_onelite->last_query(),true)
|
||||
));
|
||||
return;
|
||||
}
|
||||
$cities = $qry->result_array();
|
||||
$selected_city = array('id'=>'','name'=>'');
|
||||
if($rows){
|
||||
$selected_city['id'] = $rows[0]['M_CityID'];
|
||||
$selected_city['name'] = $rows[0]['M_CityName'];
|
||||
}else{
|
||||
$sql = "select M_CityID as id, M_CityName as name
|
||||
from m_branch
|
||||
JOIN m_city ON M_BranchM_CityID = M_CityID
|
||||
GROUP BY M_BranchM_CityID";
|
||||
$qry = $this->db_onelite->query($sql);
|
||||
$selected_city = $qry->row_array();
|
||||
}
|
||||
echo json_encode( array(
|
||||
"status" => "OK",
|
||||
"rows" => array('cities'=>$cities,'selected_city'=>$selected_city)
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user