main_new_version.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. //为了调用,临时做一个登录动作
  20. // $_POST['uname'] = "ra.admin";
  21. // $_POST['psw'] = "abc123456789";
  22. // login::getInstance()->do_login_auto();
  23. //验证路由权限
  24. common::securityCheckHandNew($action);
  25. if (_is_only_vgm()) {
  26. Header("Location:main.php?action=main");
  27. }
  28. error_log("--------------前端请求post参数---------------");
  29. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_POST)));
  30. error_log("--------------前端请求get参数---------------");
  31. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_GET)));
  32. //Operation log 日志记录
  33. utils::operation_log_records();
  34. switch ($action) {
  35. case 'ocean_booking':
  36. ocean_booking::getInstance()->ocean_booking();
  37. break;
  38. case 'ocean_order':
  39. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  40. ocean_order::getInstance()->ocean_order();
  41. break;
  42. case 'ajax':
  43. echo ajax::getInstance()->run();
  44. break;
  45. case 'opreation_log':
  46. echo operation_log::getInstance()->operation_log();
  47. break;
  48. case 'main':
  49. $menuList = array();
  50. $menuList[] = array("index"=>'1',"label"=>"Dashboard","icon"=>"icon_data_fill_b","path"=>"/dashboard");
  51. $menuList[] = array("index"=>'3',"label"=>"Booking","icon"=>"icon_booking__fill_b","path"=>"/booking");
  52. $menuList[] = array("index"=>'4',"label"=>"Tracking","icon"=>"icon_tracking__fill_b","path"=>"/tracking");
  53. if(_isApexLogin()){
  54. $menuList[] = array("index"=>'6',"label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list",
  55. "children"=>array(array("index" =>'5-4',"label" =>"Operation Log","path"=>"/Operationlog")));
  56. }
  57. common::echo_json_encode(200, $menuList);
  58. exit();
  59. break;
  60. case 'main_filter':
  61. $data = common::getManagement();
  62. common::echo_json_encode(200, $data['dashboard_filter']);
  63. exit();
  64. break;
  65. case 'main_report':
  66. $type = $_REQUEST["r_type"];
  67. $container_type = $_REQUEST["container_type"];
  68. if (empty($_REQUEST["b_date"])) {
  69. $bdate = "null";
  70. } else {
  71. $bdate = $_REQUEST["b_date"];
  72. $bdate = "'$bdate'";
  73. }
  74. if (empty($_REQUEST["e_date"])) {
  75. $edate = "null";
  76. } else {
  77. $edate = $_REQUEST["e_date"];
  78. $edate = "'$edate'";
  79. }
  80. //Demo测试数据 日期全为空 :前端是由日期过来来的
  81. //$edate = "null";
  82. //$bdate = "null";
  83. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  84. $sqlWhere = common::check_input($sqlWhere);
  85. $sqlWhere = " " . $sqlWhere;
  86. //online_order_status_date_new 与本地的区分,发布上去这去掉new
  87. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  88. . "r (c bigint, e integer, b integer, d text)");
  89. $key = "[";
  90. $value = "[";
  91. $totalValue = 0;
  92. foreach ($list as $vv) {
  93. if ($key != "[") {
  94. $key .= ",";
  95. $value .= ",";
  96. }
  97. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  98. $key .= '"' . $vv["d"] . '"';
  99. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  100. $totalValue = $totalValue + $vv["c"];
  101. } else {
  102. if ($vv["e"] == -1) {
  103. $key .= '"Over 80 Days"';
  104. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  105. } else {
  106. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  107. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  108. }
  109. $totalValue = $totalValue + $vv["c"];
  110. }
  111. }
  112. $key .= "]";
  113. $value .= "]";
  114. //处理返回原表数据格式
  115. $data = common::mian_repot_do($value,$type,$totalValue);
  116. common::echo_json_encode(200, $data);
  117. exit();
  118. break;
  119. case 'main_report_etd':
  120. //这里只有r1查询
  121. $type = "r1";
  122. $container_type = "";
  123. $date_type = strtolower($_REQUEST["date_type"]);
  124. if (empty($_REQUEST["date_start"])) {
  125. $bdate = "null";
  126. } else {
  127. $bdate = $_REQUEST["date_start"];
  128. $bdate = "'$bdate'";
  129. }
  130. if (empty($_REQUEST["date_end"])) {
  131. $edate = "null";
  132. } else {
  133. $edate = $_REQUEST["date_end"];
  134. $edate = "'$edate'";
  135. }
  136. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  137. $sqlWhere = common::check_input($sqlWhere);
  138. $sqlWhere = " " . $sqlWhere;
  139. $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$data_type'::text) "
  140. . "r (c bigint, e integer, b integer, d text)");
  141. $key = "[";
  142. $value = "[";
  143. $totalValue = 0;
  144. foreach ($list as $vv) {
  145. if ($key != "[") {
  146. $key .= ",";
  147. $value .= ",";
  148. }
  149. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  150. $key .= '"' . $vv["d"] . '"';
  151. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  152. $totalValue = $totalValue + $vv["c"];
  153. } else {
  154. if ($vv["e"] == -1) {
  155. $key .= '"Over 80 Days"';
  156. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  157. } else {
  158. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  159. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  160. }
  161. $totalValue = $totalValue + $vv["c"];
  162. }
  163. }
  164. $key .= "]";
  165. $value .= "]";
  166. //处理返回原表数据格式
  167. $data = common::mian_repot_do($value,$type,$totalValue);
  168. common::echo_json_encode(200, $data);
  169. exit();
  170. break;
  171. case 'main_report_kpi':
  172. $type = $_REQUEST["r_type"];
  173. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  174. $sqlWhere = common::check_input($sqlWhere);
  175. $sqlWhere = " " . $sqlWhere;
  176. $date_type = strtolower($_REQUEST["date_type"]);
  177. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  178. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  179. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  180. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  181. $transportation = strtolower($_REQUEST["transportation"]);
  182. if(!is_array($transportation)){
  183. $transportation = array($transportation);
  184. }
  185. if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  186. }else{
  187. //这里不用处理,只有sea的数据
  188. }
  189. $list = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere'::text) "
  190. . "r (c bigint, d text)");
  191. $key = "[";
  192. $value = "[";
  193. $totalValue = 0;
  194. foreach ($list as $vv) {
  195. if ($key != "[") {
  196. $key .= ",";
  197. $value .= ",";
  198. }
  199. if ($type == "ata_r3" || $type == "atd_r4" ) {
  200. $key .= '"' . $vv["d"] .'"';
  201. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  202. $totalValue = $totalValue + $vv["c"];
  203. }
  204. }
  205. $key .= "]";
  206. $value .= "]";
  207. //处理返回原表数据格式
  208. $ETDList = array();
  209. $value_arr = json_decode($value,true);
  210. foreach($value_arr as $arr){
  211. $color = common::getItemStyle($type,$arr['name']);
  212. if($arr['name'] == "0 Day"){
  213. $arr['name'] = "≤1 Day";
  214. }
  215. if($arr['name'] == "7 Days"){
  216. $arr['name'] = "≥7 Days";
  217. }
  218. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  219. }
  220. if($type == 'atd_r4'){
  221. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)","download_name" => "KPI Departure");
  222. }
  223. if($type == 'ata_r3'){
  224. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATA-ETA)","download_name" => "KPI Arrival");
  225. }
  226. common::echo_json_encode(200, $data);
  227. exit();
  228. break;
  229. case 'main_report_container_bar':
  230. //新UI 要ALL 20 40 45 四份数据同时查询,且是柱状图,所以与r3 r4查询分开
  231. $container_type_arr = array("20","40","45");
  232. $container_type_param = $_REQUEST["container_type"];
  233. $ContainerCounSeries = array();
  234. foreach($container_type_arr as $_container_type){
  235. $container_type = $_container_type;
  236. $date_type = strtolower($_REQUEST["date_type"]);
  237. $type = $_REQUEST["r_type"];
  238. if (empty($_REQUEST["date_start"])) {
  239. $bdate = "null";
  240. } else {
  241. $bdate = $_REQUEST["date_start"];
  242. $bdate = "'$bdate'";
  243. }
  244. if (empty($_REQUEST["date_end"])) {
  245. $edate = "null";
  246. } else {
  247. $edate = $_REQUEST["date_end"];
  248. $edate = "'$edate'";
  249. }
  250. $list= array();
  251. //all 查询所有
  252. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  253. $sqlWhere = common::check_input($sqlWhere);
  254. $sqlWhere = " " . $sqlWhere;
  255. //如果页面查询的是ALL 这个20 40 45都查询出来。否则值查询都对应的size,其他的不查询
  256. if(strtolower($container_type_param) == "all"){
  257. $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$data_type'::text) "
  258. . "r (c bigint, e integer, b integer, d text)");
  259. }else{
  260. if($container_type_param == $_container_type){
  261. $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$data_type'::text) "
  262. . "r (c bigint, e integer, b integer, d text)");
  263. }
  264. }
  265. $key = "[";
  266. $value = "[";
  267. $totalValue = 0;
  268. foreach ($list as $vv) {
  269. if ($key != "[") {
  270. $key .= ",";
  271. $value .= ",";
  272. }
  273. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  274. $key .= '"' . $vv["d"] . '"';
  275. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  276. $totalValue = $totalValue + $vv["c"];
  277. } else {
  278. if ($vv["e"] == -1) {
  279. $key .= '"Over 80 Days"';
  280. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  281. } else {
  282. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  283. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  284. }
  285. $totalValue = $totalValue + $vv["c"];
  286. }
  287. }
  288. $key .= "]";
  289. $value .= "]";
  290. $key_arr = json_decode($key,true);
  291. $value_arr = json_decode($value,true);
  292. $data = array();
  293. //每一个size 的所有月份总计
  294. $total = 0;
  295. //每一个size 对应的最大值
  296. $max = 0;
  297. foreach($value_arr as $arr){
  298. $data[] = intval($arr['value']);
  299. $total = $total + intval($arr['value']);
  300. $max = $max < intval($arr['value']) ? intval($arr['value']) : $max;
  301. }
  302. $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  303. }
  304. //处理返回时数据格式
  305. $ContainerCounSeries_return = array();
  306. //横坐标栏位
  307. $ContainerCount_Title = $key_arr;
  308. //所查的所有模式计算总和
  309. $total = 0;
  310. //所有size下的最大值,方便标注计算最长的Y坐标
  311. $max_all = 0;
  312. foreach($ContainerCounSeries as $k =>$v){
  313. //这个type 是页面传过来的。这个固定r2
  314. $color = common::getItemStyle($type,$k);
  315. $total = $total + $v['total'];
  316. $ContainerCounSeries_return[] = array("name"=>strval($k),"type"=>"bar","emphasis" => array("focus" =>"none"),
  317. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  318. $max_all = $max_all + $v['max'];
  319. }
  320. //计算Y坐标的间隔
  321. $interval = utils::calculateTicks(0,$max_all,5);
  322. if($interval == 0){
  323. //处理返回默认值
  324. $interval = 2;
  325. }
  326. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  327. "min" => 0,"Max" =>$interval*5,"interval" =>$interval,"download_name" => "Container Count");
  328. //demo
  329. // $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}}';
  330. // $returnData = json_decode($json,true);
  331. // echo json_encode($returnData);
  332. // exit();
  333. common::echo_json_encode(200, $returnData);
  334. exit();
  335. break;
  336. case 'main_report_co2e_bar':
  337. $returnData = common::getCo2eBar();
  338. common::echo_json_encode(200, $returnData);
  339. exit();
  340. break;
  341. case 'main_report_top10_bar':
  342. $returnData = common::getTopBar();
  343. common::echo_json_encode(200, $returnData);
  344. exit();
  345. break;
  346. case 'main_map':
  347. $uncode = $_POST["uncode"];
  348. $serial_no = $_POST["serial_no"];
  349. $unall = explode("|", $uncode);
  350. $sql = "";
  351. if (!empty($unall[0]) && $unall[0] != "''") {
  352. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  353. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  354. . "($unall[0])";
  355. }
  356. if (!empty($unall[1]) && $unall[1] != "''") {
  357. if (!empty($sql)) {
  358. $sql .= " union ";
  359. }
  360. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  361. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  362. . "($unall[1])";
  363. }
  364. if (!empty($unall[2]) && $unall[2] != "''") {
  365. if (!empty($sql)) {
  366. $sql .= " union ";
  367. }
  368. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  369. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  370. . "($unall[2])";
  371. }
  372. if (!empty($unall[3]) && $unall[3] != "''") {
  373. if (!empty($sql)) {
  374. $sql .= " union ";
  375. }
  376. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' 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[3])";
  379. }
  380. $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,
  381. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  382. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  383. 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");
  384. foreach ($tkStatus as $vv) {
  385. $ll = explode(",", $vv["location"]);
  386. if ($vv["by_pickup"] == "t") {
  387. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  388. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  389. $dt = explode("\r\n", $vv["consignee_exp"]);
  390. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  391. } else {
  392. $pf = explode("\r\n", $vv["consignee_exp"]);
  393. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  394. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  395. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  396. }
  397. if ($vv["type"] == "26" && !empty($ll[1])) {
  398. if (!empty($sql)) {
  399. $sql .= " union ";
  400. }
  401. $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";
  402. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  403. if (!empty($sql)) {
  404. $sql .= " union ";
  405. }
  406. $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";
  407. }
  408. }
  409. if (!empty($sql)) {
  410. $gps = common::excuteListSql($sql . "");
  411. }
  412. if (!empty($serial_no)) {
  413. $all = explode(",", $serial_no);
  414. foreach ($all as $a) {
  415. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  416. if (!empty($rs)) {
  417. $rss = explode("|", $rs);
  418. $lng_lat = explode(",", $rss[1]);
  419. $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" => "");
  420. }
  421. }
  422. }
  423. $data = array("gps" => $gps);
  424. common::echo_json_encode("200", $data);
  425. exit();
  426. break;
  427. case 'main_map_new':
  428. //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
  429. $serial_no = $_REQUEST["serial_no"];
  430. $sql = "with ss as (select '$serial_no' as sn)
  431. , aa as (
  432. 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.*
  433. from public.online_ocean oo
  434. left join LATERAL (
  435. select (select uncode from ports where code = o.port_of_transshipment) as port_of_transshipment_un,
  436. port_of_transshipment_name
  437. from ocean o where o.serial_no=oo.serial_no order by id desc limit 1
  438. ) dd on true
  439. where serial_no=(select sn from ss) limit 1
  440. )
  441. , v1 as (select public.get_vessel_position(sn::text) bbb from ss)
  442. , t1 as (
  443. select tl.upload_time, tl.by_pickup, split_part(g.consignee_exp,'\n',1) as consignee_exp, split_part(g.pickup_from_exp,'\n',1) as pickup_from_exp,
  444. c.ctnr, split_part(g.deliveryto_exp,'\n',1) as deliveryto_exp,g.serial_no, tl.location, tl.type, tl.id,
  445. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  446. from public.tk_general g, public.tk_commodity c
  447. left join public.tk_location tl on c.serial_no=tl.serial_no
  448. where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no=(select sn from ss)) order by tl.order_id)
  449. , rr as (
  450. 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
  451. from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=fport_of_loading_un
  452. union all
  453. 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
  454. from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=mport_of_discharge_un
  455. union all
  456. 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
  457. from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=port_of_transshipment_un
  458. )
  459. select * from rr order by sort, stime";
  460. $rss = common::excuteListSql($sql);
  461. //先固定死
  462. // $json = '[{"lng":"100.78594000","lat":"13.68521000","label":"Origin","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},
  463. // {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
  464. // {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
  465. //$rss = json_decode($json,true);
  466. common::echo_json_encode(200, $rss);
  467. exit();
  468. break;
  469. case 'main_welcome':
  470. $cp = common::check_input($_POST ['cp']); //current_page
  471. $ps = common::check_input($_POST ['ps']); //ps
  472. if (empty($ps))
  473. $ps = 10;
  474. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  475. // test dome
  476. // $_POST['is_default'] = "no";
  477. // $_POST['date_start'] =null;
  478. // $_POST['date_end'] = null;
  479. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个默认条件已经废除,前端不会这样传参数
  480. if (isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes" && false){
  481. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  482. } else {
  483. $date_type = strtolower(common::check_input($_POST ['date_type']));
  484. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  485. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  486. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  487. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  488. }
  489. if (isset($_POST['customer']) && !empty($_POST['customer'])){
  490. $sqlWhere .= " and (shipper ilike '%".common::check_input($_POST['customer'])."%' or shipper_id ilike '%".common::check_input($_POST['customer'])."%'
  491. or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
  492. }
  493. $rc = $_POST ['rc'];
  494. if ($rc == - 1) {
  495. $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere ." and last_status_315_update_time is not null";
  496. $rc = common::excuteOneSql($sql);
  497. //error_log($sql);
  498. }
  499. $tp = ceil($rc / $ps);
  500. if ($rc > 0) {
  501. $sql = "SELECT order_from as _schemas,serial_no,last_status_city, consignee, shipper, h_bol,
  502. to_char(etd, 'MM/DD/YYYY'::text) as etd, to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  503. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, ctnrs, count_cntr, last_status_ctnr,booking_no,
  504. to_char(last_status_315_date, 'MM/DD/YYYY'::text) as last_status_315_date,last_status_315_code, last_status_loc, last_status_city, order_from,
  505. f_vessel,f_voyage,
  506. CASE
  507. WHEN dd.status is null THEN 'Created'::text
  508. ELSE dd.status::text
  509. END AS new_status,
  510. dd.act_date,dd.act_time,dd.description,
  511. dd.timezone,dd.code as dd_code
  512. FROM public.online_ocean
  513. left join LATERAL (select case when a.code='IFFBCF' then 'Created'
  514. when a.code='IFFCPU' then 'Cargo Received'
  515. when a.code='IFFREC' then 'Cargo Received'
  516. when a.code='IFFDEP' then 'Departure'
  517. when a.code='IFFARR' then 'Arrived'
  518. when a.code='IFFAFD' then 'Completed'
  519. else 'Created' END as status,
  520. act_date,act_time,
  521. _dd.description as description,
  522. timezone,code
  523. from ocean_milestone a
  524. left join LATERAL (select sno,description from milestone where code=a.code and project_no = '*' order by sno limit 1) _dd on true
  525. where a.serial_no=online_ocean.serial_no
  526. and a.code in (select regexp_split_to_table('IFFBCF,IFFCPU,IFFREC,IFFDEP,IFFARR,IFFAFD', ','))
  527. and a.act_date is not null
  528. order by id desc limit 1) dd on true
  529. $sqlWhere and last_status_315_update_time is not null";
  530. if (_isDemo()) {
  531. $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  532. } else {
  533. $sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  534. }
  535. $rss = common::excuteListSql($sql);
  536. //RecentStatusList
  537. $RecentStatusList = array();
  538. foreach ($rss as $key => $value) {
  539. $_schemas = $value['_schemas'];
  540. if($_schemas == "public"){
  541. $_schemas = "ocean";
  542. }
  543. $timezone = "";
  544. //按照最新execl Timezone From 来自于origin
  545. if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
  546. $sql = "SELECT (select time_zone from public.city_timezone where uncode = LEFT(country, 2) || COALESCE(city_code,'')) as timezone
  547. FROM $_schemas.contacts c WHERE c.contact_id = '".$value['origin']."'";
  548. $timezone = common::excuteOneSql($sql);
  549. }
  550. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR" || $value['dd_code'] == "IFFAFD"){
  551. //Timezone From 来自于EDI315
  552. $serial_no = $value["serial_no"];
  553. $EDI315Time = common::getEDI315Time($serial_no);
  554. if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
  555. //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
  556. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  557. if(empty($timezone)){
  558. if($value['dd_code'] == "IFFREC"){
  559. $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'";
  560. }else{
  561. $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
  562. }
  563. $timezone = common::excuteOneSql($sql);
  564. }
  565. }
  566. if($value['dd_code'] == "IFFARR"){
  567. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  568. if(empty($timezone)){
  569. $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
  570. $timezone = common::excuteOneSql($sql);
  571. }
  572. }
  573. if($value['dd_code'] == "IFFAFD"){
  574. $timezone = $EDI315Time[$value['dd_code']]['timezone'];
  575. if(empty($timezone)){
  576. $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_delivery_un']."'";
  577. $timezone = common::excuteOneSql($sql);
  578. }
  579. }
  580. }
  581. $Arrived = $value['description'];
  582. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  583. "name"=>utils::outDisplayForMerge($value['f_vessel'],$value['f_voyage']),
  584. "bookingNumber" =>$value['booking_no'],
  585. "IsSubscribe" =>false,
  586. "shipperName"=>$value['shipper'],
  587. "consigneeName" =>$value['consignee'],
  588. "startStation"=>$value['fport_of_loading_un'],
  589. "endStation"=>$value['mport_of_discharge_un'],
  590. "ETD"=>$value['etd'],
  591. "ETA"=>$value['eta'],
  592. "type"=>$value['new_status'],
  593. "Arrived"=>$Arrived,
  594. "Time"=>$value["act_date"],
  595. "act_time" =>$value["act_time"],
  596. "timezone"=>$timezone,
  597. "_schemas"=>$value["_schemas"],
  598. "a" =>common::deCode($value['serial_no'], 'E'));
  599. }
  600. $data = common::getManagement();
  601. $arrTmp = array('searchData' => $RecentStatusList,
  602. 'Management' => $data['Management'],
  603. 'dashboard_filter' => $data['dashboard_filter'],
  604. 'is_customer' =>_isCustomerLogin(),
  605. 'rc' => $rc,
  606. 'ps' => $ps,
  607. 'cp' => $cp,
  608. 'tp' => $tp);
  609. } else {
  610. $data = common::getManagement();
  611. $arrTmp = array('searchData' => array(),
  612. 'Management' => $data['Management'],
  613. 'dashboard_filter' => $data['dashboard_filter']);
  614. }
  615. common::echo_json_encode(200,$arrTmp);
  616. exit();
  617. break;
  618. case 'save_layout':
  619. $management = json_encode($_POST["management"]);
  620. $dashboard_filter = json_encode($_POST["dashboardObj"]);
  621. $_param = "";
  622. if(!empty($_POST["management"])){
  623. $_param .= " management = '$management' ";
  624. }
  625. if(!empty($dashboard_filter)){
  626. $_param .= ",dashboard_filter = '$dashboard_filter' ";
  627. }
  628. if(!empty($_param)){
  629. common::excuteUpdateSql("update public.ra_online_user set $_param where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  630. }
  631. $returnData = array("msg" => "success");
  632. common::echo_json_encode(200, $returnData);
  633. exit();
  634. break;
  635. case 'password':
  636. tools::getInstance()->updatePassword();
  637. break;
  638. case 'tools':
  639. tools::getInstance()->markSystem();
  640. break;
  641. default:
  642. $data = array(
  643. 'msg' => 'Page not found',
  644. );
  645. common::echo_json_encode(500, $data);
  646. }
  647. $db->Close();
  648. $db = null;
  649. if ($max_ec > 0)
  650. ini_set('max_execution_time', $max_ec); //recover old value
  651. if (!empty($memory_limit))
  652. ini_set('memory_limit', $memory_limit);
  653. ?>