ajax.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of auto
  7. *
  8. * @author Administrator
  9. */
  10. class ajax {
  11. private static $_ajax;
  12. public static function getInstance() {
  13. if (!self::$_ajax) {
  14. $c = __CLASS__;
  15. self::$_ajax = new $c;
  16. }
  17. return self::$_ajax;
  18. }
  19. public function run() {
  20. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  21. if ($time > $_SESSION['SESSION_TIMEOUT']) {
  22. exit(json_encode("session_time_out"));
  23. } else {
  24. $_SESSION["LAST_OPERATE_TIME"] = time();
  25. }
  26. $operate = utils::_get('operate');
  27. $operate = strtolower($operate);
  28. switch ($operate) {
  29. case 'save_setting_display':
  30. $this->save_setting_display();
  31. break;
  32. case 'autody':
  33. return json_encode($this->autody());
  34. break;
  35. case 'autoport':
  36. return json_encode($this->autoPort());
  37. break;
  38. default :
  39. break;
  40. }
  41. }
  42. public function save_setting_display() {
  43. $ids = $_POST['ids'];
  44. if(!empty($ids)){
  45. $ss = utils::implode(",", $_POST['ids']);
  46. column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']);
  47. $data = array(
  48. 'msg' => 'success'
  49. );
  50. common::echo_json_encode(200,$data);
  51. }else{
  52. $data = array(
  53. 'msg' => 'data error'
  54. );
  55. common::echo_json_encode(500,$data);
  56. }
  57. }
  58. //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全
  59. public function autody(){
  60. //分担查询
  61. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  62. $term = $_POST['term'];
  63. $type = $_POST['type'];
  64. $search_field = $_POST['search_field'];
  65. $search_mode = $_POST['search_mode'];
  66. $term = trim($term);
  67. if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales"
  68. || strtolower($type) == "vessel" || strtolower($type) == "voyage") {
  69. if($search_mode == "tracking"){
  70. $sqlWhere = $this->getTrackingSearchWhere();
  71. }elseif($search_mode == "booking"){
  72. $sqlWhere = $this->getBookingSearchWhere();
  73. }
  74. //Notify Party Bill to Destination Operator 是tracking里的,但booking没有,所以不影响
  75. $search_field_mapping = array("Origin Agent"=>"origin as code",
  76. "Destination Agent"=>"agent as code",
  77. "Shipper Name"=>"shipper as code",
  78. "Consignee Name"=>"consignee as code",
  79. "Notify Party" =>"notify_party as code",
  80. "Bill to" =>"billto as code",
  81. "Destination Operator"=>"dest_op as code",
  82. "Sales"=>"sales_rep as code",
  83. "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2",
  84. "Vessel_booking"=>"f_vessel as code,m_vessel as code_2",
  85. "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2",
  86. "Vessel_tracking"=>"vessel as code,f_vessel as code_2");
  87. $search_field_group_mapping = array("Origin Agent"=>"group by origin",
  88. "Destination Agent"=>"group by agent",
  89. "Shipper Name"=>"group by shipper",
  90. "Consignee Name"=>"group by consignee",
  91. "Notify Party" =>"group by notify_party",
  92. "Bill to" =>"group by billto",
  93. "Destination Operator"=>"group by dest_op",
  94. "Sales"=>"group by sales_rep",
  95. "Voyage/Flight_booking"=>"group by f_voyage,m_voyage",
  96. "Vessel_booking"=>"group by f_vessel,m_vessel",
  97. "Voyage/Flight_tracking"=>"group by voyage,f_voyage",
  98. "Vessel_tracking"=>"group by vessel,f_vessel");
  99. $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '%" . common::check_input($term) . "%')",
  100. "Destination Agent"=>" and (agent ilike '%" . common::check_input($term) . "%')",
  101. "Shipper Name"=>" and (shipper ilike '%" . common::check_input($term) . "%')",
  102. "Consignee Name"=>" and (consignee ilike '%" . common::check_input($term) . "%')",
  103. "Notify Party"=>" and (notify_party ilike 'v" . common::check_input($term) . "%')",
  104. "Bill to"=>" and (billto ilike '%" . common::check_input($term) . "%')",
  105. "Destination Operator"=>" and (dest_op ilike '%" . common::check_input($term) . "%')",
  106. "Sales"=>" and (sales_rep ilike '%" . common::check_input($term) . "%')",
  107. "Voyage/Flight_booking"=>" and (f_voyage ilike '%" . common::check_input($term) . "%' or m_voyage ilike '%" . common::check_input($term) . "%')",
  108. "Vessel_booking"=>" and (f_vessel ilike '%" . common::check_input($term) . "%' or m_vessel ilike '%" . common::check_input($term) . "%')",
  109. "Voyage/Flight_tracking"=>" and (voyage ilike '%" . common::check_input($term) . "%' or f_voyage ilike '%" . common::check_input($term) . "%')",
  110. "Vessel_tracking"=>" and (vessel ilike '%" . common::check_input($term) . "%' or f_vessel ilike '%" . common::check_input($term) . "%')");
  111. //特殊处理一下合并Voyage和Vessel
  112. $_search_field = $search_field;
  113. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  114. $_str = $search_mode == "tracking" ? "tracking" : "booking";
  115. $_search_field = $search_field ."_".$_str;
  116. }
  117. $str = $search_field_mapping[$_search_field];
  118. $sql_where = $sql_where_mapping[$_search_field];
  119. $group_by = $search_field_group_mapping[$_search_field];
  120. $table = $search_mode == "tracking" ? "public.kln_ocean " : "public.kln_booking ";
  121. // if($search_mode == "booking"){
  122. // $order_by = " f_etd desc";
  123. // }else{
  124. // $order_by = " etd desc";
  125. // if (_isCustomerLogin()) {
  126. // $order_by = " eta desc";
  127. // }
  128. // }
  129. //$sql = "select DISTINCT * from (select $str from $table $sqlWhere $sql_where order by $order_by ) as temp";
  130. //$sql .= " order by code limit 20";
  131. if($search_mode == "booking"){
  132. $order_by = " max(f_etd) desc";
  133. }else{
  134. $order_by = " max(etd) desc";
  135. if (_isCustomerLogin()) {
  136. $order_by = " max(eta) desc";
  137. }
  138. }
  139. $sql = "select $str from $table $sqlWhere $sql_where $group_by order by $order_by";
  140. $sql .= " limit 20";
  141. }
  142. if(!empty($sql)){
  143. //$rs = common::excuteListSql($sql);
  144. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  145. error_log($sql);
  146. }
  147. $array = array();
  148. foreach($rs as $v){
  149. if(!empty($v['code'])){
  150. $array[] = $v['code'];
  151. }
  152. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  153. $array[] = $v['code_2'];
  154. }
  155. }
  156. $array = utils::removeDuplicateArray($array);
  157. common::echo_json_encode(200,$array);
  158. exit();
  159. }
  160. public function autoPort() {
  161. //分担查询
  162. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  163. $cp = common::check_input($_POST ['cp']); //current_page
  164. $ps = common::check_input($_POST ['ps']); //ps
  165. if (empty($ps))
  166. $ps = 20;
  167. $term = $_POST['term'];
  168. $term = trim($term);
  169. $search_field = $_POST['search_field'];
  170. $search_mode = $_POST['search_mode'];
  171. $_sql_arr = $this->getPortsUncity($search_field,$search_mode,$term);
  172. $rc = $_POST ['rc'];
  173. if ($rc == - 1) {
  174. $sql = $_sql_arr['count_sql'];
  175. //$rc = common::excuteOneSql($sql);
  176. $rc = $mapdb->GetOne($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  177. error_log($sql);
  178. }
  179. $tp = ceil($rc / $ps);
  180. if ($rc > 0) {
  181. $sql = $_sql_arr['sql'];
  182. $sql = "select DISTINCT ON (city) country, city,uncode from ($sql) as temp ";
  183. $sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  184. //$rs = common::excuteListSql($sql);
  185. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  186. error_log($sql);
  187. //前端要加上id 从1开始
  188. $retData = array();
  189. $i = 0;
  190. foreach($rs as $key => $val){
  191. if($search_field == "Port of Loading"){
  192. if(!empty($val['uncode'])){
  193. $val["id"] = $i +1;
  194. $retData[] = $val;
  195. $i = $i +1;
  196. }
  197. }else{
  198. if(!empty($val['city'])){
  199. $val["id"] = $i +1;
  200. $retData[] = $val;
  201. $i = $i +1;
  202. }
  203. }
  204. }
  205. $arrTmp = array('searchData' => $retData,
  206. 'rc' => $rc,
  207. 'ps' => $ps,
  208. 'cp' => $cp,
  209. 'tp' => $tp);
  210. common::echo_json_encode(200,$arrTmp);
  211. exit();
  212. }else{
  213. $arrTmp = array('searchData' => array(), 'rc' => 0);
  214. common::echo_json_encode(200, $arrTmp);
  215. exit();
  216. }
  217. }
  218. public function autoPort_old() {
  219. $cp = common::check_input($_POST ['cp']); //current_page
  220. $ps = common::check_input($_POST ['ps']); //ps
  221. if (empty($ps))
  222. $ps = 20;
  223. $term = $_POST['term'];
  224. $term = trim($term);
  225. $_curr_schemas = $_POST['model'];
  226. if (empty($_curr_schemas)) {
  227. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  228. if (empty($_curr_schemas)) {
  229. $_curr_schemas = "public";
  230. }
  231. }
  232. $rc = $_POST ['rc'];
  233. if ($rc == - 1) {
  234. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  235. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  236. $rc = common::excuteOneSql($sql);
  237. }
  238. $tp = ceil($rc / $ps);
  239. if ($rc > 0) {
  240. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  241. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  242. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  243. $rs = common::excuteListSql($sql);
  244. //前端要加上id 从1开始
  245. $retData = array();
  246. foreach($rs as $key => $val){
  247. if(!empty($val['country'])){
  248. $val["id"] = $key +1;
  249. $retData[] = $val;
  250. }
  251. }
  252. $arrTmp = array('searchData' => $retData,
  253. 'rc' => $rc,
  254. 'ps' => $ps,
  255. 'cp' => $cp,
  256. 'tp' => $tp);
  257. common::echo_json_encode(200,$arrTmp);
  258. exit();
  259. }else{
  260. $arrTmp = array('searchData' => array());
  261. common::echo_json_encode(200, $arrTmp);
  262. exit();
  263. }
  264. }
  265. public function autody_old() {
  266. $term = $_POST['term'];
  267. $type = $_POST['type'];
  268. $term = trim($term);
  269. if (strtolower($type) == "apex") {
  270. $_curr_schemas = $_POST['model'];
  271. if (empty($_curr_schemas)) {
  272. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  273. if (empty($_curr_schemas)) {
  274. $_curr_schemas = "public";
  275. }
  276. }
  277. if ($_curr_schemas == "public") {
  278. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  279. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  280. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  281. } else {
  282. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  283. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  284. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  285. }
  286. $sql .= " order by contact_id limit 20";
  287. $rs = common::excuteListSql($sql);
  288. }
  289. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  290. if (strtolower($type) == "contanct") {
  291. $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) . "%')";
  292. $sql .= " order by contact_id limit 20";
  293. $rs = common::excuteListSql($sql);
  294. }
  295. if (strtolower($type) == "sales") {
  296. $_curr_schemas = $_POST['model'];
  297. if (empty($_curr_schemas)) {
  298. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  299. if (empty($_curr_schemas)) {
  300. $_curr_schemas = "public";
  301. }
  302. }
  303. $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) . "%')";
  304. $sql .= " order by salesopcode limit 20";
  305. }
  306. if (strtolower($type) == "vessel") {
  307. $vessel = $_POST['vessel'];
  308. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  309. $sql .= " order by vessel limit 20";
  310. }
  311. $rs = common::excuteListSql($sql);
  312. $array = array();
  313. foreach($rs as $v){
  314. if(!empty($v['code'])){
  315. $array[] = $v['code'];
  316. }
  317. }
  318. common::echo_json_encode(200,$array);
  319. exit();
  320. }
  321. public function getTrackingSearchWhere(){
  322. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  323. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  324. if (!empty($_REQUEST["_reportRef"])) {
  325. $_reportType = $_REQUEST["_reportType"];
  326. $_reportRef = $_REQUEST["_reportRef"];
  327. if ($_reportType == "r3") {
  328. if ($_reportRef == "Previous 7 Days") {
  329. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  330. } else if ($_reportRef == "0 Day") {
  331. $sqlWhere .= " and eta=current_date";
  332. } else if ($_reportRef == "1-2 Days") {
  333. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  334. } else if ($_reportRef == "3-6 Days") {
  335. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  336. } else if ($_reportRef == "7 Days") {
  337. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  338. } else {
  339. $sqlWhere .= " and 1<>1";
  340. }
  341. } else if ($_reportType == "r4") {
  342. if ($_reportRef == "Previous 7 Days") {
  343. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  344. } else if ($_reportRef == "0 Day") {
  345. $sqlWhere .= " and etd=current_date";
  346. } else if ($_reportRef == "1-2 Days") {
  347. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  348. } else if ($_reportRef == "3-6 Days") {
  349. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  350. } else if ($_reportRef == "7 Days") {
  351. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  352. } else {
  353. $sqlWhere .= " and 1<>1";
  354. }
  355. } else if ($_reportType == "ata_r3") {
  356. if ($_reportRef == "0 Day") {
  357. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  358. } else if ($_reportRef == "1-2 Days") {
  359. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  360. } else if ($_reportRef == "3-6 Days") {
  361. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  362. } else if ($_reportRef == "7 Days") {
  363. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  364. } else {
  365. $sqlWhere .= " and 1<>1";
  366. }
  367. } else if ($_reportType == "atd_r4") {
  368. if ($_reportRef == "0 Day") {
  369. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  370. } else if ($_reportRef == "1-2 Days") {
  371. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  372. } else if ($_reportRef == "3-6 Days") {
  373. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  374. } else if ($_reportRef == "7 Days") {
  375. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  376. } else {
  377. $sqlWhere .= " and 1<>1";
  378. }
  379. } else if ($_reportType == "top") {
  380. if (!empty($_reportRef)) {
  381. $_reportStationType = $_REQUEST["_reportStationType"];
  382. if($_reportStationType == 'shippr_uncode'){
  383. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  384. }
  385. if($_reportStationType == 'fport_of_loading_un'){
  386. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  387. }
  388. if($_reportStationType == 'consignee_uncode'){
  389. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  390. }
  391. if($_reportStationType == 'mport_of_discharge_un'){
  392. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  393. }
  394. } else {
  395. $sqlWhere .= " and 1<>1";
  396. }
  397. } else if ($_reportType == "co2e") {
  398. $_reportDataType = $_REQUEST["_reportDataType"];
  399. //查询sea 其他的为空
  400. if (!empty($_reportRef) && $_reportDataType == "sea") {
  401. $_reportStationType = $_REQUEST["_reportStationType"];
  402. if($_reportStationType == 'origin'){
  403. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  404. }else{
  405. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  406. }
  407. } else {
  408. $sqlWhere .= " and 1<>1";
  409. }
  410. } else {
  411. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  412. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  413. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  414. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  415. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  416. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  417. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  418. $sqlWhere .= " and (eta-etd)>80";
  419. } else {
  420. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  421. }
  422. }
  423. }
  424. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  425. if (!empty($_POST["_textSearch"])) {
  426. $textSearch_arr = $_POST['_textSearch'];
  427. if(!is_array($textSearch_arr)){
  428. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  429. $textSearch_arr = array($textSearch_arr);
  430. }
  431. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  432. //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
  433. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
  434. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
  435. or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  436. }
  437. return $sqlWhere;
  438. }
  439. public function getBookingSearchWhere(){
  440. $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
  441. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  442. //移除掉全文检索 但保留代码
  443. // if (!empty($_POST["_textSearch"])) {
  444. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  445. // }
  446. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  447. if (!empty($_POST["_textSearch"])) {
  448. $textSearch_arr = $_POST['_textSearch'];
  449. if(!is_array($textSearch_arr)){
  450. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  451. $textSearch_arr = array($textSearch_arr);
  452. }
  453. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  454. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
  455. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  456. }
  457. return $sqlWhere;
  458. }
  459. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  460. //uncode 前两位便是 isoname,不用模糊查询这个了
  461. if($search_field == "Origin" && $search_mode == "booking"){
  462. $sqlWhere = $this->getBookingSearchWhere();
  463. $count_sql = "select COUNT(DISTINCT shipper_city)
  464. from public.kln_booking $sqlWhere
  465. and COALESCE(shippr_uncode,'')<>''
  466. and (shipper_city ilike '%" . common::check_input($term) . "%'
  467. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  468. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  469. from public.kln_booking $sqlWhere
  470. and COALESCE(shippr_uncode,'')<>''
  471. and (shipper_city ilike '%" . common::check_input($term) . "%'
  472. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  473. return array("count_sql"=>$count_sql,"sql"=>$sql);
  474. }
  475. if($search_field == "Destination" && $search_mode == "booking"){
  476. $sqlWhere = $this->getBookingSearchWhere();
  477. $count_sql = "select count(DISTINCT consignee_city)
  478. from public.kln_booking $sqlWhere
  479. and COALESCE(consignee_uncode,'')<>''
  480. and (consignee_city ilike '%" . common::check_input($term) . "%'
  481. or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
  482. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  483. from public.kln_booking $sqlWhere
  484. and COALESCE(consignee_uncode,'')<>''
  485. and (consignee_city ilike '%" . common::check_input($term) . "%'
  486. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  487. return array("count_sql"=>$count_sql,"sql"=>$sql);
  488. }
  489. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  490. $sqlWhere = $this->getBookingSearchWhere();
  491. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  492. from public.kln_booking $sqlWhere
  493. and COALESCE(place_of_receipt_uncode,'')<>''
  494. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  495. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  496. $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  497. from public.kln_booking $sqlWhere
  498. and COALESCE(place_of_receipt_uncode,'')<>''
  499. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  500. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  501. return array("count_sql"=>$count_sql,"sql"=>$sql);
  502. }
  503. if($search_field == "Port of Loading" && $search_mode == "booking"){
  504. $sqlWhere = $this->getBookingSearchWhere();
  505. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  506. from public.kln_booking $sqlWhere
  507. and COALESCE(fport_of_loading_uncode,'')<>''
  508. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  509. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  510. $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  511. from public.kln_booking $sqlWhere
  512. and COALESCE(fport_of_loading_uncode,'')<>''
  513. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  514. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  515. return array("count_sql"=>$count_sql,"sql"=>$sql);
  516. }
  517. if($search_field == "Place of delivery" && $search_mode == "booking"){
  518. $sqlWhere = $this->getBookingSearchWhere();
  519. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  520. from public.kln_booking $sqlWhere
  521. and COALESCE(place_of_delivery_uncode,'')<>''
  522. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  523. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  524. $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  525. from public.kln_booking $sqlWhere
  526. and COALESCE(place_of_delivery_uncode,'')<>''
  527. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  528. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  529. return array("count_sql"=>$count_sql,"sql"=>$sql);
  530. }
  531. //tracking
  532. $order_by = " etd desc";
  533. if (_isCustomerLogin()) {
  534. $order_by = " eta desc";
  535. }
  536. if($search_field == "Origin" && $search_mode == "tracking"){
  537. $sqlWhere = $this->getTrackingSearchWhere();
  538. $count_sql = "select COUNT(DISTINCT shipper_city)
  539. from public.kln_ocean $sqlWhere
  540. and COALESCE(shippr_uncode,'')<>''
  541. and (shipper_city ilike '%" . common::check_input($term) . "%'
  542. or shippr_uncode ilike '%" . common::check_input($term) . "%')";
  543. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  544. from public.kln_ocean $sqlWhere
  545. and COALESCE(shippr_uncode,'')<>''
  546. and (shipper_city ilike '%" . common::check_input($term) . "%'
  547. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  548. return array("count_sql"=>$count_sql,"sql"=>$sql);
  549. }
  550. if($search_field == "Destination" && $search_mode == "tracking"){
  551. $sqlWhere = $this->getTrackingSearchWhere();
  552. $count_sql = "select COUNT(DISTINCT consignee_city)
  553. from public.kln_ocean $sqlWhere
  554. and COALESCE(consignee_uncode,'')<>''
  555. and (consignee_city ilike '%" . common::check_input($term) . "%'
  556. or consignee_uncode ilike '%" . common::check_input($term) . "%')";
  557. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  558. from public.kln_ocean $sqlWhere
  559. and COALESCE(consignee_uncode,'')<>''
  560. and (consignee_city ilike '%" . common::check_input($term) . "%'
  561. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  562. return array("count_sql"=>$count_sql,"sql"=>$sql);
  563. }
  564. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  565. $sqlWhere = $this->getTrackingSearchWhere();
  566. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  567. from public.kln_ocean $sqlWhere
  568. and COALESCE(place_of_receipt_un,'')<>''
  569. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  570. or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
  571. $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  572. from public.kln_ocean $sqlWhere
  573. and COALESCE(place_of_receipt_un,'')<>''
  574. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  575. or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  576. return array("count_sql"=>$count_sql,"sql"=>$sql);
  577. }
  578. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  579. $sqlWhere = $this->getTrackingSearchWhere();
  580. $count_sql = "select COUNT(DISTINCT port_of_loading)
  581. from public.kln_ocean $sqlWhere
  582. and COALESCE(fport_of_loading_un,'')<>''
  583. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  584. or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
  585. $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  586. from public.kln_ocean $sqlWhere
  587. and COALESCE(fport_of_loading_un,'')<>''
  588. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  589. or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  590. return array("count_sql"=>$count_sql,"sql"=>$sql);
  591. }
  592. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  593. $sqlWhere = $this->getTrackingSearchWhere();
  594. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  595. from public.kln_ocean $sqlWhere
  596. and COALESCE(mport_of_discharge_un,'')<>''
  597. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  598. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
  599. $sql = "select left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  600. from public.kln_ocean $sqlWhere
  601. and COALESCE(mport_of_discharge_un,'')<>''
  602. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  603. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  604. return array("count_sql"=>$count_sql,"sql"=>$sql);
  605. }
  606. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  607. $sqlWhere = $this->getTrackingSearchWhere();
  608. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  609. from public.kln_ocean $sqlWhere
  610. and COALESCE(place_of_delivery_un,'')<>''
  611. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  612. or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
  613. $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  614. from public.kln_ocean $sqlWhere
  615. and COALESCE(place_of_delivery_un,'')<>''
  616. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  617. or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  618. return array("count_sql"=>$count_sql,"sql"=>$sql);
  619. }
  620. }
  621. }
  622. ?>