main_new_version.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. <?php
  2. $max_ec = ini_get('max_execution_time'); //set max_excution_time
  3. ini_set('max_execution_time', '600');
  4. $memory_limit = "";
  5. $action = "";
  6. if (isset($_GET['action']))
  7. $action = strtolower($_GET['action']);
  8. if (isset($_POST['action']))
  9. $action = strtolower($_POST['action']);
  10. include "include.ini.php";
  11. include 'service/ocean_booking.class.php';
  12. include 'service/ocean_order.class.php';
  13. include 'service/operation_log.class.php';
  14. include 'service/search.class.php';
  15. include 'service/column.class.php';
  16. include 'service/ajax.class.php';
  17. include 'service/login.class.php';
  18. include 'service/tools.class.php';
  19. //为了调用,临时做一个登录动作 如果是正式版 要注释掉菜单System Settings
  20. //$_POST['uname'] = "ra.admin";
  21. //$_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = 'ra.admin'");
  22. // $name =strpos(common::ip(), "192.168.0.158") !== false || strpos(common::ip(), "192.168.0.161s") !== false ? "dddde" : 'ra.admin';
  23. // $_POST['uname'] = $name;
  24. // $_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = '".$name."'");
  25. // login::getInstance()->do_login_auto();
  26. //验证路由权限
  27. common::securityCheckHandNew($action);
  28. if (_is_only_vgm()) {
  29. Header("Location:main.php?action=main");
  30. }
  31. error_log("--------------前端请求post参数---------------");
  32. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_POST)));
  33. error_log("--------------前端请求get参数---------------");
  34. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_GET)));
  35. //Operation log 日志记录
  36. utils::operation_log_records();
  37. switch ($action) {
  38. case 'ocean_booking':
  39. ocean_booking::getInstance()->ocean_booking();
  40. break;
  41. case 'ocean_order':
  42. ocean_order::getInstance()->ocean_order();
  43. break;
  44. case 'ajax':
  45. echo ajax::getInstance()->run();
  46. break;
  47. case 'opreation_log':
  48. echo operation_log::getInstance()->operation_log();
  49. break;
  50. case 'main':
  51. //如果在没有登录前,没有登录信息,指定用户
  52. if(!isset($_SESSION['ONLINE_USER'])){
  53. $menuList = array();
  54. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  55. $menuList[] = array("index"=>'2',"label"=>"Booking","icon"=>"icon_booking__fill_b","path"=>"/booking");
  56. $menuList[] = array("index"=>'3',"label"=>"Tracking","icon"=>"icon_tracking__fill_b","path"=>"/tracking");
  57. } else {
  58. //d登录后,根据配置的权限,是否显示
  59. if (_isAdmin())
  60. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true group by f_column order by min(order_by)";
  61. elseif (_isNewUser())
  62. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and customer_check = true group by f_column ORDER BY min(order_by)";
  63. else
  64. $sql = "select p.f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_user_permission up left join public.ra_online_permission p on up.p_id = p.id where has_new_version=true and lower(user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' group by p.f_column ORDER BY min(p.order_by)";
  65. $rs = common::excuteListSql($sql);
  66. if (empty($rs) && _isApexLogin()) {
  67. $sql = "select f_column, min(menu_id) as menu_id, max(menu_icon_font) as menu_icon_font from public.ra_online_permission where has_new_version=true and default_check = true group by f_column ORDER BY min(order_by)";
  68. $rs = common::excuteListSql($sql);
  69. }
  70. $menuSetting = array("Ocean Booking" => array("label"=>"Booking","path"=>"/booking","icon"=>"icon_booking__fill_b"),
  71. "Ocean B/L Info." => array("label"=>"Tracking","path"=>"/tracking","icon"=>"icon_tracking__fill_b"));
  72. $menuList = array();
  73. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  74. $index = 2;
  75. foreach ($rs as $value) {
  76. if ($value['f_column'] == "Shipment Info."){
  77. if (_isAdmin())
  78. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  79. elseif (_isNewUser())
  80. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and customer_check = true and f_column = '" . common::check_input($value['f_column']) . "' ORDER BY order_by");
  81. else
  82. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission p left join public.ra_online_user_permission gp on gp.p_id = p.id where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and lower(gp.user_name) = '" . common::check_input(strtolower(_getLoginName())) . "' ORDER BY p.order_by");
  83. if (empty($ll) && _isApexLogin()) {
  84. $ll = common::excuteListSql("select s_column, url_action, sub_menu_id from public.ra_online_permission where has_new_version=true and f_column = '" . common::check_input($value['f_column']) . "' and default_check = true ORDER BY order_by");
  85. }
  86. //单独拼接URL
  87. foreach ($ll as $v) {
  88. if($v['s_column'] =="Ocean Booking" || $v['s_column'] =="Ocean B/L Info."){
  89. $urlData = $menuSetting[$v['s_column']];
  90. $menuList[] = array("index"=>"$index","label"=>$urlData['label'],"icon"=>$urlData['icon'],"path"=>$urlData['path']);
  91. $index = $index + 1;
  92. }
  93. }
  94. }
  95. }
  96. // $menuList[] = array("index"=>$index,"label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list",
  97. // "children"=>array(array("index" =>$index.'-1',"label" =>"Operation Log","path"=>"/Operationlog")));
  98. $systemManagement = array("index"=>"$index","label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list");
  99. $children = array();
  100. $children[] = array("index" =>$index.'-1',"label" =>"System Message","path"=>"/system-message");
  101. $children[] = array("index" =>$index.'-2',"label" =>"System Settings","path"=>"/SystemSettings");
  102. //只有chud的账户可以看日志记录
  103. if(_getLoginName() == "chud" || _getLoginName() == "IT.Andywu" || _getLoginName() == "ra.admin"){
  104. $children[] = array("index" =>$index.'-3',"label" =>"Operation Log","path"=>"/Operationlog");
  105. }
  106. $systemManagement["children"] = $children;
  107. if (!empty($children)){
  108. $menuList[] = $systemManagement;
  109. }
  110. }
  111. common::echo_json_encode(200, $menuList);
  112. exit();
  113. break;
  114. case 'main_filter':
  115. $data = common::getManagement();
  116. common::echo_json_encode(200, $data['dashboard_filter']);
  117. exit();
  118. break;
  119. case 'main_report':
  120. //分担查询
  121. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  122. //这里只剩下r3,r4的查询
  123. $type = $_REQUEST["r_type"];
  124. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  125. $sqlWhere = " " . $sqlWhere;
  126. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  127. $sqlWhere = common::check_input($sqlWhere);
  128. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
  129. // . "r (c bigint, e integer, b integer, d text)");
  130. $sql = "select * from public.online_order_status_date_kln_pending('$type'::text, '$sqlWhere'::text) "
  131. . "r (c bigint, e integer, b integer, d text)";
  132. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  133. $key = "[";
  134. $value = "[";
  135. $totalValue = 0;
  136. foreach ($list as $vv) {
  137. if ($key != "[") {
  138. $key .= ",";
  139. $value .= ",";
  140. }
  141. if ($type == "r2" || $type == "r3" || $type == "r4") {
  142. $key .= '"' . $vv["d"] . '"';
  143. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  144. $totalValue = $totalValue + $vv["c"];
  145. } else {
  146. if ($vv["e"] == -1) {
  147. $key .= '"Over 80 Days"';
  148. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  149. } else {
  150. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  151. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  152. }
  153. $totalValue = $totalValue + $vv["c"];
  154. }
  155. }
  156. $key .= "]";
  157. $value .= "]";
  158. //处理返回原表数据格式 r1 r3 r4的数据返回
  159. $data = common::mian_repot_do($value,$type,$totalValue);
  160. common::echo_json_encode(200, $data);
  161. exit();
  162. break;
  163. case 'main_report_etd':
  164. //分担查询
  165. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  166. //这里只有r1查询
  167. $type = "r1";
  168. $container_type = "";
  169. $date_type = strtolower($_REQUEST["date_type"]);
  170. if (empty($_REQUEST["date_start"])) {
  171. $bdate = "null";
  172. } else {
  173. $bdate = $_REQUEST["date_start"];
  174. $bdate = "'$bdate'";
  175. }
  176. if (empty($_REQUEST["date_end"])) {
  177. $edate = "null";
  178. } else {
  179. $edate = $_REQUEST["date_end"];
  180. $edate = "'$edate'";
  181. }
  182. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  183. $sqlWhere = " " . $sqlWhere;
  184. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  185. $sqlWhere = common::check_input($sqlWhere);
  186. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$date_type'::text) "
  187. // . "r (c bigint, e integer, b integer, d text)");
  188. $sql = "select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$date_type'::text) "
  189. . "r (c bigint, e integer, b integer, d text)";
  190. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  191. $key = "[";
  192. $value = "[";
  193. $totalValue = 0;
  194. foreach ($list as $vv) {
  195. if ($key != "[") {
  196. $key .= ",";
  197. $value .= ",";
  198. }
  199. if ($type == "r2" || $type == "r3" || $type == "r4") {
  200. $key .= '"' . $vv["d"] . '"';
  201. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  202. $totalValue = $totalValue + $vv["c"];
  203. } else {
  204. if ($vv["e"] == -1) {
  205. $key .= '"Over 80 Days"';
  206. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  207. } else {
  208. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  209. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  210. }
  211. $totalValue = $totalValue + $vv["c"];
  212. }
  213. }
  214. $key .= "]";
  215. $value .= "]";
  216. //处理返回原表数据格式 r1 r3 r4的数据返回
  217. $data = common::mian_repot_do($value,$type,$totalValue);
  218. common::echo_json_encode(200, $data);
  219. exit();
  220. break;
  221. case 'main_report_kpi':
  222. //分担查询
  223. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  224. $type = $_REQUEST["r_type"];
  225. $sqlWhere = ' and ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  226. $sqlWhere = " " . $sqlWhere;
  227. $sqlWhere = $sqlWhere . common::getDashboardTransportationSqlWhere();
  228. $sqlWhere = common::check_input($sqlWhere);
  229. $date_type = strtolower($_REQUEST["date_type"]);
  230. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  231. $sqlWhere .= " and $date_type >= ''" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00''";
  232. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  233. $sqlWhere .= " and $date_type <= ''" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59''";
  234. // $list = common::excuteListSql("select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
  235. // . "r (c bigint, d text)");
  236. $sql = "select * from public.online_order_status_date_kln_kpi('$type'::text,'$sqlWhere'::text) "
  237. . "r (c bigint, d text)";
  238. $list = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  239. $key = "[";
  240. $value = "[";
  241. $totalValue = 0;
  242. foreach ($list as $vv) {
  243. if ($key != "[") {
  244. $key .= ",";
  245. $value .= ",";
  246. }
  247. if ($type == "ata_r3" || $type == "atd_r4" ) {
  248. $key .= '"' . $vv["d"] .'"';
  249. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  250. $totalValue = $totalValue + $vv["c"];
  251. }
  252. }
  253. $key .= "]";
  254. $value .= "]";
  255. //处理返回原表数据格式
  256. $ETDList = array();
  257. $value_arr = json_decode($value,true);
  258. foreach($value_arr as $arr){
  259. $color = common::getItemStyle($type,$arr['name']);
  260. if($arr['name'] == "0 Day"){
  261. $arr['name'] = "≤1 Day";
  262. }
  263. if($arr['name'] == "7 Days"){
  264. $arr['name'] = "≥7 Days";
  265. }
  266. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  267. }
  268. // 排序依据的键数组(这里我们用一个数字数组来表示)
  269. $order = ["≤1 Day", "1-2 Days", "3-6 Days","≥7 Days"];
  270. $ETDList = utils::arrayOrderBykeys($order,$ETDList,"name");
  271. if($type == 'atd_r4'){
  272. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)","download_name" => "KPI Departure");
  273. }
  274. if($type == 'ata_r3'){
  275. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATA-ETA)","download_name" => "KPI Arrival");
  276. }
  277. common::echo_json_encode(200, $data);
  278. exit();
  279. break;
  280. case 'main_report_container_bar':
  281. //新UI 20 40 45 3份数据同时查询,且是柱状图,所以与r3 r4查询分开
  282. $container_type ='';
  283. $ContainerCounSeries = array();
  284. $date_type = strtolower($_REQUEST["date_type"]);
  285. $type = $_REQUEST["r_type"];
  286. if (empty($_REQUEST["date_start"])) {
  287. $bdate = "null";
  288. } else {
  289. $bdate = $_REQUEST["date_start"];
  290. $bdate = "'$bdate'";
  291. }
  292. if (empty($_REQUEST["date_end"])) {
  293. $edate = "null";
  294. } else {
  295. $edate = $_REQUEST["date_end"];
  296. $edate = "'$edate'";
  297. }
  298. $list= array();
  299. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  300. $sqlWhere = common::check_input($sqlWhere);
  301. $sqlWhere = " " . $sqlWhere;
  302. //这个20 40 45都查询出来。否则值查询都对应的size,其他的不查询
  303. $value_arr = common::excuteListSql("select * from public.online_order_status_date_kln_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$date_type'::text) "
  304. . "r (month_group text, _20_rc numeric, _40_rc numeric, _45_rc numeric)");
  305. $key_arr = array();
  306. $container_type_arr = array("20","40","45");
  307. foreach($container_type_arr as $_container_type){
  308. $data = array();
  309. //每一个size 的所有月份总计
  310. $total = 0;
  311. //每一个size 对应的最大值
  312. $max = 0;
  313. foreach($value_arr as $arr){
  314. $data[] = intval($arr['_'.$_container_type.'_rc']);
  315. $total = $total + intval($arr['_'.$_container_type.'_rc']);
  316. $max = $max < intval($arr['_'.$_container_type.'_rc']) ? intval($arr['_'.$_container_type.'_rc']) : $max;
  317. if ($_container_type == '20'){
  318. $key_arr[] = $arr['month_group'];
  319. }
  320. }
  321. $ContainerCounSeries[$_container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  322. }
  323. //处理返回时数据格式
  324. $ContainerCounSeries_return = array();
  325. //横坐标栏位
  326. $ContainerCount_Title = $key_arr;
  327. //所查的所有模式计算总和
  328. $total = 0;
  329. //所有size下的最大值,方便标注计算最长的Y坐标
  330. $max_all = 0;
  331. foreach($ContainerCounSeries as $k =>$v){
  332. //这个type 是页面传过来的。这个固定r2
  333. $color = common::getItemStyle($type,$k);
  334. $total = $total + $v['total'];
  335. $ContainerCounSeries_return[] = array("name"=>strval($k),"type"=>"bar","emphasis" => array("focus" =>"none"),
  336. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  337. $max_all = $max_all + $v['max'];
  338. }
  339. //计算Y坐标的间隔
  340. $interval = utils::calculateTicks(0,$max_all,5);
  341. if($interval == 0){
  342. //处理返回默认值
  343. $interval = 2;
  344. }
  345. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  346. "min" => 0,"Max" =>$interval*5,"interval" =>$interval,"download_name" => "Container Count");
  347. //demo
  348. // $json = '{"code":200,"data":{"ContainerCount_Title":"Total: 463518","ContainerCountList":["OCT,23","NOV,23","DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24"],"ContainerCounSeries":[{"name":"20","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[4400,8600,8804,9271,8961,8793,8534,9476,9530,10277,10081,8997,5784],"itemStyle":{"color":"#FF7500"}},{"name":"40","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[13652,28021,30422,30136,26320,27035,23979,26494,28406,33318,32318,30962,16369],"itemStyle":{"color":"#FFAC66"}},{"name":"45","type":"bar","emphasis":{"focus":"none"},"stack":"\u603b\u8ba1","data":[189,337,415,437,439,321,250,320,324,603,328,415,200],"itemStyle":{"color":"#FFE3CC"}}],"min":0,"Max":45000,"interval":9000}}';
  349. // $returnData = json_decode($json,true);
  350. // echo json_encode($returnData);
  351. // exit();
  352. common::echo_json_encode(200, $returnData);
  353. exit();
  354. break;
  355. case 'main_report_co2e_bar':
  356. $returnData = common::getCo2eBar();
  357. common::echo_json_encode(200, $returnData);
  358. exit();
  359. break;
  360. case 'main_report_top10_bar':
  361. $returnData = common::getTopBar();
  362. common::echo_json_encode(200, $returnData);
  363. exit();
  364. break;
  365. case 'main_report_revenue':
  366. $returnData = common::getRevenue();
  367. common::echo_json_encode(200, $returnData);
  368. exit();
  369. break;
  370. case 'main_map':
  371. $uncode = $_POST["uncode"];
  372. $serial_no = $_POST["serial_no"];
  373. $unall = explode("|", $uncode);
  374. $sql = "";
  375. if (!empty($unall[0]) && $unall[0] != "''") {
  376. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  377. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  378. . "($unall[0])";
  379. }
  380. if (!empty($unall[1]) && $unall[1] != "''") {
  381. if (!empty($sql)) {
  382. $sql .= " union ";
  383. }
  384. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  385. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  386. . "($unall[1])";
  387. }
  388. if (!empty($unall[2]) && $unall[2] != "''") {
  389. if (!empty($sql)) {
  390. $sql .= " union ";
  391. }
  392. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  393. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  394. . "($unall[2])";
  395. }
  396. if (!empty($unall[3]) && $unall[3] != "''") {
  397. if (!empty($sql)) {
  398. $sql .= " union ";
  399. }
  400. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' as type from vessel.vt_unlocode where "
  401. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  402. . "($unall[3])";
  403. }
  404. $tkStatus = common::excuteListSql("select tl.by_pickup, g.consignee_exp, g.pickup_from_exp, c.ctnr, g.deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id,
  405. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  406. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  407. where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no='$serial_no') order by tl.order_id");
  408. foreach ($tkStatus as $vv) {
  409. $ll = explode(",", $vv["location"]);
  410. if ($vv["by_pickup"] == "t") {
  411. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  412. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  413. $dt = explode("\r\n", $vv["consignee_exp"]);
  414. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  415. } else {
  416. $pf = explode("\r\n", $vv["consignee_exp"]);
  417. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  418. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  419. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  420. }
  421. if ($vv["type"] == "26" && !empty($ll[1])) {
  422. if (!empty($sql)) {
  423. $sql .= " union ";
  424. }
  425. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Pick up: " . $vv["utime"] . "<br>'||'" . $pf . "' as location_namewo, 'pickup' as type";
  426. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  427. if (!empty($sql)) {
  428. $sql .= " union ";
  429. }
  430. $sql .= "select '" . $ll[1] . "' as lng, '" . $ll[0] . "' as lat, '" . $vv["ctnr"] . "' as uncode, 'Delivery: " . $vv["utime"] . "<br>'||'" . $dt . "' as location_namewo, 'delivery' as type";
  431. }
  432. }
  433. if (!empty($sql)) {
  434. $gps = common::excuteListSql($sql . "");
  435. }
  436. if (!empty($serial_no)) {
  437. $all = explode(",", $serial_no);
  438. foreach ($all as $a) {
  439. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  440. if (!empty($rs)) {
  441. $rss = explode("|", $rs);
  442. $lng_lat = explode(",", $rss[1]);
  443. $gps[] = array("lng" => $lng_lat[0], "lat" => $lng_lat[1], "uncode" => "", "location_namewo" => "", "type" => "vessel", "vessel_name" => $rss[2], "m_shipname" => "", "mmsi" => "", "imo" => "", "m_shipstate" => "", "m_shiptype" => "", "m_dest" => "", "m_newshiparrive" => "", "m_newlasttime" => "", "lasttime" => "", "sub" => "");
  444. }
  445. }
  446. }
  447. $data = array("gps" => $gps);
  448. common::echo_json_encode("200", $data);
  449. exit();
  450. break;
  451. case 'main_map_new':
  452. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  453. //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
  454. $serial_no = $_REQUEST["serial_no"];
  455. $_schemas = $_REQUEST['_schemas'];
  456. if(empty($_schemas)){
  457. $_schemas ="public";
  458. }
  459. //$serial_no = "F41E6016-1A97-4C93-8198-53D8B3B26220";
  460. $transport_mode = common::excuteOneSql("SELECT transport_mode FROM public.kln_ocean ko
  461. WHERE ko.serial_no = '$serial_no' and order_from = '$_schemas'");
  462. if($transport_mode == "sea"){
  463. $sql = "with ss as (select '$serial_no' as sn)
  464. , aa as (
  465. select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp,dd.*
  466. from public.kln_ocean oo
  467. left join LATERAL (
  468. select (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un,
  469. port_of_transshipment_name
  470. from $_schemas.ocean o where o.serial_no=oo.serial_no order by id desc limit 1
  471. ) dd on true
  472. where serial_no=(select sn from ss) limit 1
  473. )
  474. , rr as (
  475. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  476. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  477. union all
  478. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  479. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  480. union all
  481. select lon as lng, lat as lat, 'Transfer' as label, port_of_transshipment_name as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype
  482. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=port_of_transshipment_un
  483. )
  484. select * from rr order by sort, stime";
  485. } elseif ($transport_mode == "air"){
  486. $sql = "with ss as (select '$serial_no' as sn)
  487. , aa as (
  488. select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp
  489. from public.kln_ocean oo
  490. where serial_no=(select sn from ss) limit 1
  491. )
  492. , rr as (
  493. select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype
  494. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=fport_of_loading_un
  495. union all
  496. select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype
  497. from vessel.vt_unlocode, aa where (lat<=90 and lat>=-90) and (lon<=180 and lon>=-180) and lon is not null and lat is not null and uncode=mport_of_discharge_un
  498. )
  499. select * from rr order by sort, stime";
  500. }
  501. $rss = common::excuteListSql($sql);
  502. //$rss = $mapdb->GetAll($sql);
  503. //先固定死
  504. // $json = '[{"lng":"100.78594000","lat":"13.68521000","label":"Origin","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},
  505. // {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
  506. // {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
  507. //$rss = json_decode($json,true);
  508. ///global $mapdb;
  509. //查询线(包含所有的线) 空运不查询航线
  510. if ($transport_mode == "air"){
  511. $Line =array();
  512. }else{
  513. error_log("select * from get_track_data('$serial_no',true)");
  514. $map_sql = "select * from get_track_data('$serial_no',true)";
  515. $Line = $mapdb->GetAll($map_sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $map_sql), 0));
  516. }
  517. $solidLine = array();
  518. $dottedLine = array();
  519. $rangePoint = array();
  520. foreach($Line as $line){
  521. if($line['tp'] == "1"){
  522. $solidLine[] = $line;
  523. }elseif($line['tp'] == "0"){
  524. $dottedLine[] = $line;
  525. }else{
  526. $rangePoint[] = $line;
  527. }
  528. }
  529. //如果没有虚线,这这个范围点也是异常的,不需要显示
  530. if(empty($dottedLine)){
  531. $rangePoint = array();
  532. }
  533. $data = array("point"=>$rss,"solidLine"=>$solidLine,"dottedLine"=>$dottedLine,"rangePoint"=>$rangePoint);
  534. common::echo_json_encode(200, $data);
  535. //common::echo_json_encode(200, $rss);
  536. exit();
  537. break;
  538. case 'main_welcome':
  539. $cp = common::check_input($_POST ['cp']); //current_page
  540. $ps = common::check_input($_POST ['ps']); //ps
  541. if (empty($ps))
  542. $ps = 10;
  543. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  544. $sqlWhere .= common::getDashboardTransportationSqlWhere();
  545. // test dome
  546. // $_POST['is_default'] = "no";
  547. // $_POST['date_start'] =null;
  548. // $_POST['date_end'] = null;
  549. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个默认条件已经废除,前端不会这样传参数
  550. if (isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes" && false){
  551. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  552. } else {
  553. $date_type = strtolower(common::check_input($_POST ['date_type']));
  554. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  555. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  556. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  557. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  558. }
  559. if (isset($_POST['customer']) && !empty($_POST['customer'])){
  560. $sqlWhere .= " and (shipper ilike '%".common::check_input($_POST['customer'])."%' or shipper_id ilike '%".common::check_input($_POST['customer'])."%'
  561. or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
  562. }
  563. $rc = $_POST ['rc'];
  564. if ($rc == - 1) {
  565. $sql = "SELECT count(1) from public.kln_ocean" . $sqlWhere;
  566. $rc = common::excuteOneSql($sql);
  567. }
  568. $tp = ceil($rc / $ps);
  569. if ($rc > 0) {
  570. $sql = "SELECT order_from as _schemas,serial_no, consignee, shipper, h_bol,final_desination_uncode, transport_mode,
  571. to_char(etd, 'MM/DD/YYYY'::text) as etd,
  572. to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  573. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, booking_no,
  574. f_vessel,f_voyage,origin,
  575. CASE
  576. WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
  577. WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
  578. WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departure'::text
  579. WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
  580. WHEN (m_iffdel is not null) THEN 'Completed'::text
  581. ELSE 'Created'::text
  582. END AS new_status
  583. FROM public.kln_ocean $sqlWhere";
  584. //$sqlWhere and last_status_315_update_time is not null";
  585. $sql .= " ORDER BY eta desc,id DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  586. //$sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  587. $rss = common::excuteListSql($sql);
  588. //RecentStatusList
  589. $RecentStatusList = array();
  590. foreach ($rss as $key => $value) {
  591. $serial_no = $value["serial_no"];
  592. $_schemas_bk = $value['_schemas'];
  593. $_schemas = $value['_schemas'];
  594. if($_schemas == "public"){
  595. $_schemas = "ocean";
  596. }
  597. //单独取查询milestone信息
  598. if ($value['transport_mode'] == "sea"){
  599. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  600. a.code as dd_code
  601. from public.ocean_milestone a
  602. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  603. where a.serial_no='$serial_no'
  604. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFDEL', ','))
  605. and a.act_date is not null
  606. order by sn.sno desc limit 1";
  607. } elseif ($value['transport_mode'] == "air"){
  608. //air milestone 的Departed实际描述要替换: IFFDEP =》 IFFONB
  609. $milestone_sql = "select a.act_date,a.act_time,sn.description,a.timezone,
  610. case when a.code = 'IFFONB' then 'IFFDEP'
  611. else a.code
  612. end as dd_code
  613. from $_schemas_bk.air_milestone a
  614. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  615. where a.serial_no='$serial_no'
  616. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFONB,IFFARR,IFFDEL', ','))
  617. and a.act_date is not null
  618. order by sn.sno desc limit 1";
  619. }
  620. $milestone = common::excuteObjectSql($milestone_sql);
  621. $value["act_date"] = $milestone["act_date"];
  622. $value["act_time"] = $milestone["act_time"];
  623. $value["description"] = $milestone["description"];
  624. $value["timezone"] = $milestone["timezone"];
  625. $value["dd_code"] = $milestone["dd_code"];
  626. $timezone = "";
  627. //按照最新execl Timezone From 来自于origin
  628. if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
  629. $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(c.country, 2) || COALESCE(c.city_code,'')) as timezone
  630. FROM $_schemas.contacts c WHERE c.contact_id = '".$value['origin']."'";
  631. $timezone = common::excuteOneSql($sql);
  632. }
  633. //按照最新execl Timezone From 来自于final_destination
  634. if($value['dd_code'] == "IFFDEL"){
  635. $sql = "select time_zone from public.city_timezone where uncode = '".$value['final_desination_uncode']."'";
  636. $timezone = common::excuteOneSql($sql);
  637. }
  638. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR"){
  639. $EDI315Time = array();
  640. if ($value['transport_mode'] == "sea"){
  641. //Timezone From 来自于EDI315
  642. $EDI315Time = common::getEDI315Time($serial_no,$value['_schemas']);
  643. }
  644. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
  645. //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
  646. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  647. if(empty($timezone)){
  648. if($value['dd_code'] == "IFFREC"){
  649. $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'";
  650. }else{
  651. $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
  652. }
  653. $timezone = common::excuteOneSql($sql);
  654. }
  655. }
  656. if($value['dd_code'] == "IFFARR"){
  657. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  658. if(empty($timezone)){
  659. $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
  660. $timezone = common::excuteOneSql($sql);
  661. }
  662. }
  663. // 根据IFFDEL这个milestone来判断是否转变为completed
  664. // if($value['dd_code'] == "IFFAFD"){
  665. // $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  666. // if(empty($timezone)){
  667. // $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_delivery_un']."'";
  668. // $timezone = common::excuteOneSql($sql);
  669. // }
  670. // }
  671. }
  672. $Arrived = $value['description'];
  673. $startStation=$value['fport_of_loading_un'];
  674. $endStation=$value['mport_of_discharge_un'];
  675. if ($value['transport_mode'] == "sea"){
  676. $startStation=$value['place_of_receipt_un'];
  677. $endStation=$value['place_of_delivery_un'];
  678. }
  679. if ($value['transport_mode'] == "air"){
  680. $startStation=!empty($ocean['place_of_receipt_un'])? $ocean['place_of_receipt_un'] : $ocean['fport_of_loading_un'];
  681. $endStation=!empty($ocean['place_of_delivery_un']) ? $ocean['place_of_delivery_un'] : $ocean['mport_of_discharge_un'];
  682. }
  683. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  684. "name"=>utils::outDisplayForMerge($value['f_vessel'],$value['f_voyage']),
  685. "bookingNumber" =>$value['booking_no'],
  686. "IsSubscribe" =>false,
  687. "shipperName"=>$value['shipper'],
  688. "consigneeName" =>$value['consignee'],
  689. "startStation"=>$startStation,
  690. "endStation"=>$endStation,
  691. "ETD"=>$value['etd'],
  692. "ETA"=>$value['eta'],
  693. "type"=>$value['new_status'],
  694. "Arrived"=>$Arrived,
  695. "Time"=>$value["act_date"],
  696. "act_time" =>$value["act_time"],
  697. "timezone"=>$timezone,
  698. "_schemas"=>$value["_schemas"],
  699. "transport_mode"=>$value["transport_mode"],
  700. 'is_subscribe' =>common::checkedSubscribe($value['serial_no']),
  701. "a" =>common::deCode($value['serial_no'], 'E'));
  702. }
  703. $data = common::getManagement();
  704. $arrTmp = array('searchData' => $RecentStatusList,
  705. 'Management' => $data['Management'],
  706. 'dashboard_filter' => $data['dashboard_filter'],
  707. 'is_customer' =>_isCustomerLogin(),
  708. 'rc' => $rc,
  709. 'ps' => $ps,
  710. 'cp' => $cp,
  711. 'tp' => $tp);
  712. } else {
  713. $data = common::getManagement();
  714. $arrTmp = array('searchData' => array(),
  715. 'Management' => $data['Management'],
  716. 'dashboard_filter' => $data['dashboard_filter']);
  717. }
  718. common::echo_json_encode(200,$arrTmp);
  719. exit();
  720. break;
  721. case 'save_layout':
  722. $management = json_encode($_POST["management"]);
  723. $dashboard_filter = json_encode($_POST["dashboardObj"]);
  724. $_param = "";
  725. if(!empty($_POST["management"])){
  726. $_param .= " management = '$management' ";
  727. }
  728. if(isset($_POST["dashboardObj"]) && !empty($dashboard_filter)){
  729. $_param .= ",dashboard_filter = '$dashboard_filter' ";
  730. }
  731. if(!empty($_param)){
  732. common::excuteUpdateSql("update public.ra_online_user set $_param where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  733. }
  734. $returnData = array("msg" => "success");
  735. common::echo_json_encode(200, $returnData);
  736. exit();
  737. break;
  738. case 'password':
  739. tools::getInstance()->updatePassword();
  740. break;
  741. case 'tools':
  742. tools::getInstance()->markSystem();
  743. break;
  744. case 'system_setting':
  745. tools::getInstance()->user_system_setting();
  746. break;
  747. case 'monitoring_setting':
  748. tools::getInstance()->user_monitoring_setting();
  749. break;
  750. case 'notifications_rules':
  751. tools::getInstance()->notifications_rules();
  752. break;
  753. case 'user_guide':
  754. $rootPath = realpath(dirname(__FILE__)) . DS;
  755. //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");
  756. // PDF文件在服务器上的位置
  757. $filename = $rootPath."userFile". DS."KLN_Online_User_Guide_24.11.26.pdf";
  758. $display_name = "KLN_Online_User_Guide_24_11_26.pdf";
  759. // Header content type
  760. header("Content-type: application/pdf");
  761. header("Content-Length: " . filesize($filename));
  762. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  763. // 将文件发送到浏览器。
  764. readfile($filename);
  765. break;
  766. case 'feature_update':
  767. $id = $_REQUEST["id"];
  768. $rootPath = realpath(dirname(__FILE__)) . DS;
  769. //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");
  770. // PDF文件在服务器上的位置
  771. $filename = $rootPath."upload". DS."feature_update_".$id.".pdf";
  772. $display_name = "feature_update.pdf";
  773. // Header content type
  774. header("Content-type: application/pdf");
  775. header("Content-Length: " . filesize($filename));
  776. header("Content-Disposition:inline;filename=\"" . $display_name . "\"");
  777. // 将文件发送到浏览器。
  778. readfile($filename);
  779. break;
  780. default:
  781. $data = array(
  782. 'msg' => 'Page not found',
  783. );
  784. common::echo_json_encode(500, $data);
  785. }
  786. $db->Close();
  787. $db = null;
  788. if ($max_ec > 0)
  789. ini_set('max_execution_time', $max_ec); //recover old value
  790. if (!empty($memory_limit))
  791. ini_set('memory_limit', $memory_limit);
  792. ?>