$_SESSION['SESSION_TIMEOUT']) { exit(json_encode("session_time_out")); } else { $_SESSION["LAST_OPERATE_TIME"] = time(); } $operate = utils::_get('operate'); $operate = strtolower($operate); switch ($operate) { case 'save_setting_display': $this->save_setting_display(); break; case 'autody': return json_encode($this->autody()); break; case 'autoport': return json_encode($this->autoPort()); break; default : break; } } public function save_setting_display() { $ids = $_POST['ids']; if(!empty($ids)){ $ss = utils::implode(",", $_POST['ids']); column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']); $data = array( 'msg' => 'success' ); common::echo_json_encode(200,$data); }else{ $data = array( 'msg' => 'data error' ); common::echo_json_encode(500,$data); } } //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全 public function autody(){ $term = $_POST['term']; $type = $_POST['type']; $search_field = $_POST['search_field']; $search_mode = $_POST['search_mode']; $term = trim($term); if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales" || strtolower($type) == "vessel") { if($search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); }elseif($search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); } $search_field_mapping = array("Origin Agent"=>"origin as code", "Destination Agent"=>"agent as code", "Shipper Name"=>"shipper as code", "Consignee Name"=>"consignee as code", "Sales"=>"sales_rep as code", "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2", "Vessel_booking"=>"f_vessel as code,m_vessel as code_2", "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2", "Vessel_tracking"=>"vessel as code,f_vessel as code_2"); $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '" . common::check_input($term) . "%')", "Destination Agent"=>" and (agent ilike '" . common::check_input($term) . "%')", "Shipper Name"=>" and (shipper ilike '" . common::check_input($term) . "%')", "Consignee Name"=>" and (consignee ilike '" . common::check_input($term) . "%')", "Sales"=>" and (sales_rep ilike '" . common::check_input($term) . "%')", "Voyage/Flight_booking"=>" and (f_voyage ilike '" . common::check_input($term) . "%' or m_voyage ilike '" . common::check_input($term) . "%')", "Vessel_booking"=>" and (f_vessel ilike '" . common::check_input($term) . "%' or m_vessel ilike '" . common::check_input($term) . "%')", "Voyage/Flight_tracking"=>" and (voyage ilike '" . common::check_input($term) . "%' or f_voyage ilike '" . common::check_input($term) . "%')", "Vessel_tracking"=>" and (vessel ilike '" . common::check_input($term) . "%' or f_vessel ilike '" . common::check_input($term) . "%')"); //特殊处理一下合并Voyage和Vessel if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){ $_str = $search_mode == "tracking" ? "tracking" : "booking"; $search_field = $search_field ."_".$_str; } $str = $search_field_mapping[$search_field]; $sql_where = $sql_where_mapping[$search_field]; $table = $search_mode == "tracking" ? "public.online_ocean " : "public.online_booking "; $sql = "select $str from $table $sqlWhere $sql_where "; $sql .= " order by id limit 20"; $rs = common::excuteListSql($sql); } $rs = common::excuteListSql($sql); $array = array(); foreach($rs as $v){ if(!empty($v['code'])){ $array[] = $v['code']; } if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){ $array[] = $v['code_2']; } } $array = utils::removeDuplicateArray($array); common::echo_json_encode(200,$array); exit(); } public function autoPort() { $cp = common::check_input($_POST ['cp']); //current_page $ps = common::check_input($_POST ['ps']); //ps if (empty($ps)) $ps = 20; $term = $_POST['term']; $term = trim($term); $search_field = $_POST['search_field']; $search_mode = $_POST['search_mode']; $in_sql = $this->getPortsUncity($search_field,$search_mode); $rc = $_POST ['rc']; if ($rc == - 1) { $sql = "SELECT count(1) from public.ports where (isoname ilike '" . common::check_input($term) . "%' or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%') and $in_sql"; $rc = common::excuteOneSql($sql); } $tp = ceil($rc / $ps); if ($rc > 0) { $sql = "SELECT isoname as country, uncity as city,uncode from public.ports where (isoname ilike '" . common::check_input($term) . "%' or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%') and $in_sql"; $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps; $rs = common::excuteListSql($sql); //前端要加上id 从1开始 $retData = array(); foreach($rs as $key => $val){ if(!empty($val['country'])){ $val["id"] = $key +1; $retData[] = $val; } } $arrTmp = array('searchData' => $retData, 'rc' => $rc, 'ps' => $ps, 'cp' => $cp, 'tp' => $tp); common::echo_json_encode(200,$arrTmp); exit(); }else{ $arrTmp = array('searchData' => array(), 'rc' => 0); common::echo_json_encode(200, $arrTmp); exit(); } } public function autoPort_old() { $cp = common::check_input($_POST ['cp']); //current_page $ps = common::check_input($_POST ['ps']); //ps if (empty($ps)) $ps = 20; $term = $_POST['term']; $term = trim($term); $_curr_schemas = $_POST['model']; if (empty($_curr_schemas)) { $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas']; if (empty($_curr_schemas)) { $_curr_schemas = "public"; } } $rc = $_POST ['rc']; if ($rc == - 1) { $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%' or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')"; $rc = common::excuteOneSql($sql); } $tp = ceil($rc / $ps); if ($rc > 0) { $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%' or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')"; $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps; $rs = common::excuteListSql($sql); //前端要加上id 从1开始 $retData = array(); foreach($rs as $key => $val){ if(!empty($val['country'])){ $val["id"] = $key +1; $retData[] = $val; } } $arrTmp = array('searchData' => $retData, 'rc' => $rc, 'ps' => $ps, 'cp' => $cp, 'tp' => $tp); common::echo_json_encode(200,$arrTmp); exit(); }else{ $arrTmp = array('searchData' => array()); common::echo_json_encode(200, $arrTmp); exit(); } } public function autody_old() { $term = $_POST['term']; $type = $_POST['type']; $term = trim($term); if (strtolower($type) == "apex") { $_curr_schemas = $_POST['model']; if (empty($_curr_schemas)) { $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas']; if (empty($_curr_schemas)) { $_curr_schemas = "public"; } } if ($_curr_schemas == "public") { $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))" . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) " . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')"; } else { $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))" . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) " . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')"; } $sql .= " order by contact_id limit 20"; $rs = common::excuteListSql($sql); } //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并 if (strtolower($type) == "contanct") { $sql = "SELECT company as code from contact_v where active = true and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')"; $sql .= " order by contact_id limit 20"; $rs = common::excuteListSql($sql); } if (strtolower($type) == "sales") { $_curr_schemas = $_POST['model']; if (empty($_curr_schemas)) { $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas']; if (empty($_curr_schemas)) { $_curr_schemas = "public"; } } $sql = "SELECT salesopcode as code from $_curr_schemas.employee where salesopcode is not null and salesopcode !='' and (salesopcode ilike '" . common::check_input($term) . "%' or employee_id ilike '" . common::check_input($term) . "%')"; $sql .= " order by salesopcode limit 20"; } if (strtolower($type) == "vessel") { $vessel = $_POST['vessel']; $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'"; $sql .= " order by vessel limit 20"; } $rs = common::excuteListSql($sql); $array = array(); foreach($rs as $v){ if(!empty($v['code'])){ $array[] = $v['code']; } } common::echo_json_encode(200,$array); exit(); } public function getTrackingSearchWhere(){ $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]); $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search"); if (!empty($_REQUEST["_reportRef"])) { $_reportType = $_REQUEST["_reportType"]; $_reportRef = $_REQUEST["_reportRef"]; if ($_reportType == "r3") { if ($_reportRef == "Previous 7 Days") { $sqlWhere .= " and eta>(current_date-interval '7 days') and eta "1<>1"){ $sqlWhere .= " and ($more_sql)"; } } return $sqlWhere; } public function getBookingSearchWhere(){ $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]); $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search"); //新版要排除type2情况,总数才会对的上 $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))"; //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No. if (!empty($_POST["_textSearch"])) { $textSearch_arr = $_POST['_textSearch']; if(!is_array($textSearch_arr)){ $textSearch_arr = array($textSearch_arr); } $more_sql = "1<>1"; foreach($textSearch_arr as $tsv){ $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'"; $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'"; $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'"; $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'"; } if ($more_sql <> "1<>1"){ $sqlWhere .= " and ($more_sql)"; } } return $sqlWhere; } PUBLIC function getPortsUncity($search_field,$search_mode){ $uncity = array(); if($search_field == "Origin" && $search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); $sql = "select shipper_city from public.online_booking $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['shipper_city'])){ $uncity[] = $city['shipper_city']; } } } if($search_field == "Destination" && $search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); $sql = "select consignee_city from public.online_booking $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['consignee_city'])){ $uncity[] = $city['consignee_city']; } } } if($search_field == "Place of Receipt" && $search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); $sql = "select place_of_receipt_exp from public.online_booking $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['place_of_receipt_exp'])){ $uncity[] = $city['place_of_receipt_exp']; } } } if($search_field == "Port of Loading" && $search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); $sql = "select fport_of_loading_exp from public.online_booking $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['fport_of_loading_exp'])){ $uncity[] = $city['fport_of_loading_exp']; } } } if($search_field == "Place of delivery" && $search_mode == "booking"){ $sqlWhere = $this->getBookingSearchWhere(); $sql = "select place_of_delivery_exp from public.online_booking $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['place_of_delivery_exp'])){ $uncity[] = $city['place_of_delivery_exp']; } } } //tracking if($search_field == "Origin" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select shipper_city,consignee_city from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['shipper_city'])){ $uncity[] = $city['shipper_city']; } if(!empty($city['consignee_city'])){ $uncity[] = $city['consignee_city']; } } } if($search_field == "Destination" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select final_desination_exp from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['final_desination_exp'])){ $uncity[] = $city['final_desination_exp']; } } } if($search_field == "Place of Receipt" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select place_of_receipt_exp from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['place_of_receipt_exp'])){ $uncity[] = $city['place_of_receipt_exp']; } } } if($search_field == "Port of Loading" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select port_of_loading from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['port_of_loading'])){ $uncity[] = $city['port_of_loading']; } } } if($search_field == "Place of Discharge" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select port_of_discharge from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['port_of_discharge'])){ $uncity[] = $city['port_of_discharge']; } } } if($search_field == "Place of delivery" && $search_mode == "tracking"){ $sqlWhere = $this->getTrackingSearchWhere(); $sql = "select place_of_delivery_exp from public.online_ocean $sqlWhere"; $city_temp = common::excuteListSql($sql); foreach($city_temp as $city){ if(!empty($city['place_of_delivery_exp'])){ $uncity[] = $city['place_of_delivery_exp']; } } } $uncity = utils::removeDuplicateArray($uncity); $in_sql = utils::getInSql(utils::implode(';', $uncity)); if(!empty($uncity)){ $in_sql = " lower(uncity) ".$in_sql; } return $in_sql; } } ?>