main_new_version.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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. //为了调用,临时做一个登录动作
  19. $_POST['uname'] = "ra.admin";
  20. $_POST['psw'] = "abc123456789";
  21. login::getInstance()->do_login_auto();
  22. //验证路由权限
  23. common::securityCheckHandNew($action);
  24. if (_is_only_vgm()) {
  25. Header("Location:main.php?action=main");
  26. }
  27. error_log("--------------前端请求post参数---------------");
  28. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_POST)));
  29. error_log("--------------前端请求get参数---------------");
  30. error_log(utils::jsonFiltration("null", "\"\"", json_encode($_GET)));
  31. //Operation log 日志记录
  32. utils::operation_log_records();
  33. switch ($action) {
  34. case 'ocean_booking':
  35. ocean_booking::getInstance()->ocean_booking();
  36. break;
  37. case 'ocean_order':
  38. include ONLINE_ROOT . 'libs' . DS . 'ams_config.ini.php';
  39. ocean_order::getInstance()->ocean_order();
  40. break;
  41. case 'ajax':
  42. echo ajax::getInstance()->run();
  43. break;
  44. case 'opreation_log':
  45. echo operation_log::getInstance()->operation_log();
  46. break;
  47. /* display index page */
  48. case 'main':
  49. if (_isAdmin())
  50. $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)";
  51. elseif (_isNewUser())
  52. $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)";
  53. else
  54. $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)";
  55. $rs = common::excuteListSql($sql);
  56. if (empty($rs) && _isApexLogin()) {
  57. $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)";
  58. $rs = common::excuteListSql($sql);
  59. }
  60. $msg = "";
  61. foreach ($rs as $value) {
  62. $msg .= '<div class="menu_first with_second" id="' . $value['menu_id'] . '" class="' . $value['menu_id'] . '_section"><div class="menu_icon_left"><span class="icon iconfont ' . $value['menu_icon_font'] . '"></span></div><div class="menu_title"><span>&nbsp;' . $value['f_column'] . '</span></div><div class="menu_icon_right icon_right"><span class="icon iconfont icon-you"></span>
  63. </div></div><ul class="menu_second" >';
  64. if (_isAdmin())
  65. $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");
  66. elseif (_isNewUser())
  67. $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");
  68. else
  69. $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");
  70. if (empty($ll) && _isApexLogin()) {
  71. $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");
  72. }
  73. foreach ($ll as $v) {
  74. //非maria 帐号的全部移除Ocean Gross Profit Repor 权限
  75. if((strtolower(_getLoginName()) != "maria" && strtolower(_getLoginName()) != "doc.yuki") && $v["url_action"] == "ocean_gross_profit"){
  76. continue;
  77. }
  78. $msg .= '<li class="' . $v['sub_menu_id'] . '" onclick="commonRedirect(this, \'main_new_version.php?action=' . $v['url_action'] . '\', \'' . $v['sub_menu_id'] . '_section\')"><span class="menu_second_span">' . $v['s_column'] . '</span></li>';
  79. }
  80. $msg .= '</ul>';
  81. }
  82. //处理返回的格式
  83. $data = array();
  84. if (_isCustomerLogin()) {
  85. $data["isCustomerLogin"] = "yes";
  86. }
  87. $data["msg"] = $msg;
  88. $data["redirectTarget"] = $_SESSION['redirectTarget'];
  89. common::echo_json_encode("200",$data);
  90. break;
  91. case 'main_report':
  92. $type = $_REQUEST["r_type"];
  93. $container_type = $_REQUEST["container_type"];
  94. if (empty($_REQUEST["b_date"])) {
  95. $bdate = "null";
  96. } else {
  97. $bdate = $_REQUEST["b_date"];
  98. $bdate = "'$bdate'";
  99. }
  100. if (empty($_REQUEST["e_date"])) {
  101. $edate = "null";
  102. } else {
  103. $edate = $_REQUEST["e_date"];
  104. $edate = "'$edate'";
  105. }
  106. //Demo测试数据 日期全为空
  107. $edate = "null";
  108. $bdate = "null";
  109. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  110. $sqlWhere = common::check_input($sqlWhere);
  111. $sqlWhere = " " . $sqlWhere;
  112. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  113. . "r (c bigint, e integer, b integer, d text)");
  114. $key = "[";
  115. $value = "[";
  116. $totalValue = 0;
  117. foreach ($list as $vv) {
  118. if ($key != "[") {
  119. $key .= ",";
  120. $value .= ",";
  121. }
  122. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  123. $key .= '"' . $vv["d"] . '"';
  124. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  125. $totalValue = $totalValue + $vv["c"];
  126. } else {
  127. if ($vv["e"] == -1) {
  128. $key .= '"Over 80 Days"';
  129. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  130. } else {
  131. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  132. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  133. }
  134. $totalValue = $totalValue + $vv["c"];
  135. }
  136. }
  137. $key .= "]";
  138. $value .= "]";
  139. //$data = array($key, $value, $totalValue);
  140. //处理返回原表数据格式
  141. $data = common::mian_repot_do($value,$type,$totalValue);
  142. common::echo_json_encode(200, $data);
  143. exit();
  144. break;
  145. case 'main_report_kpi':
  146. $type = $_REQUEST["r_type"];
  147. $container_type = $_REQUEST["container_type"];
  148. if (empty($_REQUEST["b_date"])) {
  149. $bdate = "null";
  150. } else {
  151. $bdate = $_REQUEST["b_date"];
  152. $bdate = "'$bdate'";
  153. }
  154. if (empty($_REQUEST["e_date"])) {
  155. $edate = "null";
  156. } else {
  157. $edate = $_REQUEST["e_date"];
  158. $edate = "'$edate'";
  159. }
  160. //Demo测试数据 日期全为空
  161. $edate = "null";
  162. $bdate = "null";
  163. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  164. $sqlWhere = common::check_input($sqlWhere);
  165. $sqlWhere = " " . $sqlWhere;
  166. $list = common::excuteListSql("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  167. . "r (c bigint, d text)");
  168. error_log("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  169. . "r (c bigint, d text)");
  170. $key = "[";
  171. $value = "[";
  172. $totalValue = 0;
  173. foreach ($list as $vv) {
  174. if ($key != "[") {
  175. $key .= ",";
  176. $value .= ",";
  177. }
  178. if ($type == "ata_r3" || $type == "atd_r4" ) {
  179. $key .= '"' . $vv["d"] .'"';
  180. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] .'"}';
  181. $totalValue = $totalValue + $vv["c"];
  182. }
  183. }
  184. $key .= "]";
  185. $value .= "]";
  186. //处理返回原表数据格式
  187. $ETDList = array();
  188. $value_arr = json_decode($value,true);
  189. foreach($value_arr as $arr){
  190. $color = common::getItemStyle($type,$arr['name']);
  191. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  192. }
  193. if($type == 'atd_r4'){
  194. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)");
  195. }
  196. if($type == 'ata_r3'){
  197. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"(ATD-ETD)");
  198. }
  199. common::echo_json_encode(200, $data);
  200. exit();
  201. break;
  202. case 'main_report_container_bar':
  203. //新UI 要ALL 20 40 45 四份数据同时查询,且是柱状图,所以与r3 r4查询分开
  204. $container_type_arr = array("20","40","45");
  205. $container_type_param = $_REQUEST["container_type"];
  206. $ContainerCounSeries = array();
  207. foreach($container_type_arr as $_container_type){
  208. $container_type = $_container_type;
  209. $type = $_REQUEST["r_type"];
  210. if (empty($_REQUEST["b_date"])) {
  211. $bdate = "null";
  212. } else {
  213. $bdate = $_REQUEST["b_date"];
  214. $bdate = "'$bdate'";
  215. }
  216. if (empty($_REQUEST["e_date"])) {
  217. $edate = "null";
  218. } else {
  219. $edate = $_REQUEST["e_date"];
  220. $edate = "'$edate'";
  221. }
  222. //Demo测试数据 日期全为空
  223. $edate = "null";
  224. $bdate = "null";
  225. $list= array();
  226. //all 查询所有
  227. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  228. $sqlWhere = common::check_input($sqlWhere);
  229. $sqlWhere = " " . $sqlWhere;
  230. if(strtolower($container_type_param) == "all"){
  231. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  232. . "r (c bigint, e integer, b integer, d text)");
  233. }else{
  234. if($container_type_param == $_container_type){
  235. $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
  236. . "r (c bigint, e integer, b integer, d text)");
  237. }
  238. }
  239. $key = "[";
  240. $value = "[";
  241. $totalValue = 0;
  242. foreach ($list as $vv) {
  243. if ($key != "[") {
  244. $key .= ",";
  245. $value .= ",";
  246. }
  247. if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
  248. $key .= '"' . $vv["d"] . '"';
  249. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
  250. $totalValue = $totalValue + $vv["c"];
  251. } else {
  252. if ($vv["e"] == -1) {
  253. $key .= '"Over 80 Days"';
  254. $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
  255. } else {
  256. $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
  257. $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
  258. }
  259. $totalValue = $totalValue + $vv["c"];
  260. }
  261. }
  262. $key .= "]";
  263. $value .= "]";
  264. $key_arr = json_decode($key,true);
  265. $value_arr = json_decode($value,true);
  266. $data = array();
  267. $total = 0;
  268. $max = 0;
  269. foreach($value_arr as $arr){
  270. $data[] = intval($arr['value']);
  271. $total = $total + intval($arr['value']);
  272. $max = $max < intval($arr['value']) ? intval($arr['value']) : $max;
  273. }
  274. $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
  275. }
  276. //处理返回时数据格式
  277. $ContainerCounSeries_return = array();
  278. $ContainerCount_Title = $key_arr;
  279. $total = 0;
  280. $max_all = 0;
  281. foreach($ContainerCounSeries as $k =>$v){
  282. //这个type 是页面传过来的
  283. $color = common::getItemStyle($type,$k);
  284. $total = $total + $v['total'];
  285. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  286. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
  287. $max_all = $max_all + $v['max'];
  288. }
  289. //处理返回原表数据格式
  290. $interval = utils::calculateTicks(0,$max_all,5);
  291. if($interval == 0){
  292. //处理返回默认值
  293. $interval = 2;
  294. }
  295. $returnData = array("ContainerCount_Title"=>"Total: $total","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  296. "min" => 0,"Max" =>$interval*5,"interval" =>$interval);
  297. common::echo_json_encode(200, $returnData);
  298. exit();
  299. break;
  300. case 'main_report_co2e_bar':
  301. $returnData = common::getCo2eBar();
  302. common::echo_json_encode(200, $returnData);
  303. exit();
  304. break;
  305. case 'main_report_top10_bar':
  306. $returnData = common::getTopBar();
  307. common::echo_json_encode(200, $returnData);
  308. exit();
  309. break;
  310. case 'main_map':
  311. $uncode = $_POST["uncode"];
  312. $serial_no = $_POST["serial_no"];
  313. $unall = explode("|", $uncode);
  314. $sql = "";
  315. if (!empty($unall[0]) && $unall[0] != "''") {
  316. $sql .= "select lon as lng, lat as lat, uncode, 'Place of receipt: '||name1 as location_namewo, 'por' as type from vessel.vt_unlocode where "
  317. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  318. . "($unall[0])";
  319. }
  320. if (!empty($unall[1]) && $unall[1] != "''") {
  321. if (!empty($sql)) {
  322. $sql .= " union ";
  323. }
  324. $sql .= "select lon as lng, lat as lat, uncode, 'POL: '||name1 as location_namewo, 'pol' as type from vessel.vt_unlocode where "
  325. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  326. . "($unall[1])";
  327. }
  328. if (!empty($unall[2]) && $unall[2] != "''") {
  329. if (!empty($sql)) {
  330. $sql .= " union ";
  331. }
  332. $sql .= "select lon as lng, lat as lat, uncode, 'POD: '||name1 as location_namewo, 'pod' as type from vessel.vt_unlocode where "
  333. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  334. . "($unall[2])";
  335. }
  336. if (!empty($unall[3]) && $unall[3] != "''") {
  337. if (!empty($sql)) {
  338. $sql .= " union ";
  339. }
  340. $sql .= "select lon as lng, lat as lat, uncode, 'Place of delivery: '||name1 as location_namewo, 'poe' as type from vessel.vt_unlocode where "
  341. . "lon<>0 and lat<>0 and lon is not null and lat is not null and uncode in "
  342. . "($unall[3])";
  343. }
  344. $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,
  345. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  346. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  347. 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");
  348. foreach ($tkStatus as $vv) {
  349. $ll = explode(",", $vv["location"]);
  350. if ($vv["by_pickup"] == "t") {
  351. $pf = explode("\r\n", $vv["pickup_from_exp"]);
  352. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  353. $dt = explode("\r\n", $vv["consignee_exp"]);
  354. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  355. } else {
  356. $pf = explode("\r\n", $vv["consignee_exp"]);
  357. $pf = common::check_input($pf[0]) . "(" . $vv["ctnr"] . ")";
  358. $dt = explode("\r\n", $vv["deliveryto_exp"]);
  359. $dt = common::check_input($dt[0]) . "(" . $vv["ctnr"] . ")";
  360. }
  361. if ($vv["type"] == "26" && !empty($ll[1])) {
  362. if (!empty($sql)) {
  363. $sql .= " union ";
  364. }
  365. $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";
  366. } elseif ($vv["type"] == "25" && !empty($ll[1])) {
  367. if (!empty($sql)) {
  368. $sql .= " union ";
  369. }
  370. $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";
  371. }
  372. }
  373. if (!empty($sql)) {
  374. $gps = common::excuteListSql($sql . "");
  375. }
  376. if (!empty($serial_no)) {
  377. $all = explode(",", $serial_no);
  378. foreach ($all as $a) {
  379. $rs = common::excuteOneSql("select public.get_vessel_position('$a'::text)");
  380. if (!empty($rs)) {
  381. $rss = explode("|", $rs);
  382. $lng_lat = explode(",", $rss[1]);
  383. $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" => "");
  384. }
  385. }
  386. }
  387. $data = array("gps" => $gps);
  388. common::echo_json_encode("200", $data);
  389. exit();
  390. break;
  391. case 'main_map_new':
  392. $serial_no = $_POST["serial_no"];
  393. $sql = "with ss as (select '$serial_no' as sn)
  394. , aa as (
  395. 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 from public.online_ocean oo where serial_no=(select sn from ss) limit 1
  396. )
  397. , v1 as (select public.get_vessel_position(sn::text) bbb from ss)
  398. , t1 as (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, c.ctnr, split_part(g.deliveryto_exp,'\n',1) as deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id,
  399. to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime
  400. from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no
  401. 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)
  402. , vv as (select split_part(split_part(bbb, '|', 2), ',', 1)::numeric as lng, split_part(split_part(bbb, '|', 2), ',', 2)::numeric as lat, 'Vessel: '||split_part(bbb, '|', 3) as infor, 5 as sort, null::timestamp without time zone as stime, 'vessel'::text as ptype from v1 where bbb is not null and bbb<>'')
  403. , tt as (select split_part(location, ',', 2)::numeric as lng, split_part(location, ',', 1)::numeric as lat, (
  404. case when type='26' then ctnr||': Pick up: '||utime||', '||(case when by_pickup=true then pickup_from_exp else consignee_exp end)
  405. else ctnr||': Delivery: '||utime||', '||(case when by_pickup=true then consignee_exp else deliveryto_exp end)
  406. end
  407. ) as infor, 6 as sort, upload_time as stime, case when type='26' then 'pickup'::text else 'delivery'::text end as ptype from t1 where location is not null and location<>'')
  408. , rr as (
  409. select lon as lng, lat as lat, 'Place of receipt: '||place_of_receipt_exp as infor, 0 as sort, null::timestamp without time zone as stime, 'por'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_receipt_un
  410. union all
  411. select lon as lng, lat as lat, 'POL: '||port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype 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
  412. union all
  413. select lon as lng, lat as lat, 'POD: '||port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype 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
  414. union all
  415. select lon as lng, lat as lat, 'Place of delivery: '||place_of_delivery_exp as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_delivery_un
  416. union all
  417. select * from vv
  418. union all
  419. select * from tt
  420. )
  421. select * from rr order by sort, stime";
  422. $rss = common::excuteListSql($sql);
  423. common::echo_json_encode("200", $rss);
  424. exit();
  425. break;
  426. case 'main_welcome':
  427. $cp = common::check_input($_POST ['cp']); //current_page
  428. $ps = common::check_input($_POST ['ps']); //ps
  429. if (empty($ps))
  430. $ps = 10;
  431. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  432. //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天
  433. if(isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes"){
  434. $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
  435. }else{
  436. $date_type = common::check_input($_POST ['date_type']);
  437. if (isset($_POST['date_start']) && !empty($_POST['date_start']))
  438. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
  439. if (isset($_POST['date_end']) && !empty($_POST['date_end']))
  440. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
  441. }
  442. $rc = $_POST ['rc'];
  443. if ($rc == - 1) {
  444. $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere ." and last_status_315_update_time is not null";
  445. $rc = common::excuteOneSql($sql);
  446. error_log($sql);
  447. }
  448. $tp = ceil($rc / $ps);
  449. if ($rc > 0) {
  450. $sql = "SELECT serial_no,last_status_city, consignee, shipper, h_bol,
  451. to_char(etd, 'MM/DD/YYYY'::text) as etd, to_char(eta, 'MM/DD/YYYY'::text) AS eta,
  452. fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un, ctnrs, count_cntr, last_status_ctnr,booking_no,
  453. 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
  454. FROM public.online_ocean
  455. $sqlWhere and last_status_315_update_time is not null";
  456. if (_isDemo()) {
  457. $sql .= " ORDER BY eta DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  458. } else {
  459. $sql .= " ORDER BY last_status_315_update_time DESC limit " . $ps . " offset " . ($cp - 1) * $ps;
  460. }
  461. $rss = common::excuteListSql($sql);
  462. //RecentStatusList
  463. $RecentStatusList = array();
  464. foreach ($rss as $key => $value) {
  465. $Arrived = utils::outDisplayForMerge(common::getStatusDesc($value["last_status_315_code"]),common::_toString($value["last_status_loc"]),";");
  466. $RecentStatusList[] = array("Title"=>$value['h_bol'],
  467. "name"=>"MSC SHANVI III / HD433A",
  468. "bookingNumber" =>$value['booking_no'],
  469. "IsSubscribe" =>false,
  470. "shipperName"=>$value['shipper'],
  471. "consigneeName" =>$value['consignee'],
  472. "startStation"=>$value['fport_of_loading_un'],
  473. "endStation"=>$value['mport_of_discharge_un'],
  474. "ETD"=>$value['etd'],
  475. "ETA"=>$value['eta'],
  476. "type"=>"Completed",
  477. "Arrived"=>$Arrived,
  478. "Time"=>$value["last_status_315_date"],
  479. "a" =>common::deCode($value['serial_no'], 'E'));
  480. }
  481. $arrTmp = array('searchData' => $RecentStatusList,
  482. 'Management' => common::getManagement(),
  483. 'is_customer' =>_isCustomerLogin(),
  484. 'rc' => $rc,
  485. 'ps' => $ps,
  486. 'cp' => $cp,
  487. 'tp' => $tp);
  488. } else {
  489. $arrTmp = array('searchData' => array(),
  490. 'Management' => common::getManagement());
  491. }
  492. common::echo_json_encode(200,$arrTmp);
  493. exit();
  494. break;
  495. case 'save_layout':
  496. $management = json_encode($_POST["management"]);
  497. common::excuteUpdateSql("update public.ra_online_user set management = '$management' where lower(user_login) = '" . strtolower(_getLoginName()) . "'");
  498. $returnData = array("msg" => "success");
  499. common::echo_json_encode(200, $returnData);
  500. exit();
  501. break;
  502. default:
  503. $data = array(
  504. 'msg' => 'Page not found',
  505. );
  506. common::echo_json_encode(500, $data);
  507. }
  508. $db->Close();
  509. $db = null;
  510. if ($max_ec > 0)
  511. ini_set('max_execution_time', $max_ec); //recover old value
  512. if (!empty($memory_limit))
  513. ini_set('memory_limit', $memory_limit);
  514. ?>