common.class.php 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of common
  7. *
  8. * @author Administrator
  9. */
  10. class common {
  11. /*
  12. * mysql check input
  13. */
  14. public static function check_input($value, $boolean = FALSE, $toupper = FALSE) {
  15. if ($boolean !== FALSE) {
  16. if ($value == "t")
  17. return "'t'";
  18. else
  19. return "'f'";
  20. }
  21. $value = trim($value);
  22. if ($toupper !== FALSE)
  23. $value = mb_strtoupper($value);
  24. if (!is_numeric($value)) {
  25. $value = pg_escape_string($value);
  26. }
  27. return $value;
  28. }
  29. public static function excuteOneSql($sql, $exception = FALSE) {
  30. if ($exception) {
  31. global $db;
  32. $result = $db->GetOne($sql);
  33. return $result === FALSE ? null : $result;
  34. } else {
  35. if (empty($sql))
  36. exit(json_encode("Program encountered an error."));
  37. global $db;
  38. $result = $db->GetOne($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  39. return $result === FALSE ? null : $result;
  40. }
  41. }
  42. public static function excuteObjectSql($sql) {
  43. if (empty($sql))
  44. exit(json_encode("Program encountered an error."));
  45. global $db;
  46. $result = $db->GetRow($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  47. return $result === FALSE ? null : $result;
  48. }
  49. public static function excuteUpdateSql($sql, $req_id = FALSE) {
  50. if (empty($sql))
  51. exit(json_encode("Program encountered an error."));
  52. global $db;
  53. $rs = $db->Execute($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  54. if ($rs && $req_id !== FALSE)
  55. return $db->PO_Insert_ID();
  56. else
  57. return $rs;
  58. }
  59. public static function excuteListSql($sql, $exception = FALSE) {
  60. if ($exception) {
  61. global $db;
  62. $result = $db->GetAll($sql);
  63. return $result === FALSE ? null : $result;
  64. } else {
  65. if (empty($sql))
  66. exit(json_encode("Program encountered an error."));
  67. global $db;
  68. $result = $db->GetAll($sql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $sql), 0));
  69. return $result === FALSE ? null : $result;
  70. }
  71. }
  72. /*
  73. * Database log output
  74. */
  75. public static function dbLog($db, $sql) {
  76. $backMsg = $db->errorMsg() . ' sql=' . $sql;
  77. return $backMsg;
  78. }
  79. /*
  80. * get IP
  81. */
  82. public static function ip() {
  83. if (getenv("HTTP_X_FORWARDED_FOR"))
  84. return getenv("HTTP_X_FORWARDED_FOR");
  85. if (getenv("HTTP_CLIENT_IP"))
  86. return getenv("HTTP_CLIENT_IP");
  87. if (getenv("REMOTE_ADDR"))
  88. return getenv("REMOTE_ADDR");
  89. if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
  90. return $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
  91. if ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
  92. return $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
  93. if ($HTTP_SERVER_VARS["REMOTE_ADDR"])
  94. return $HTTP_SERVER_VARS["REMOTE_ADDR"];
  95. return "Unknown";
  96. }
  97. public static function getDBUuid() {
  98. global $db;
  99. $sql = "select uuid_generate_v1()";
  100. $uuid = $db->GetOne($sql);
  101. return $uuid;
  102. }
  103. public static function securityCheckHandNew($action) {
  104. if (strpos($action, "handset") === 0) {
  105. } elseif (strpos($action, "hand") === 0) {
  106. } else {
  107. common::sessionVerify();
  108. $httpAccept = $_SERVER['HTTP_ACCEPT']; // ajax request,is json or html
  109. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER
  110. ['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; // is ajax request?
  111. //暂时这么写,放开action = main的查询是为了在没有登录时获取信息。
  112. //tools是为了避免查询的用户,没有配置tools权限,但是新版mark_save需要进入
  113. if($action == "main" || $action == "tools" || $action == "save_layout"){
  114. return;
  115. }
  116. if (!isset($_SESSION['ONLINE_USER'])) {
  117. self::timeoutPrintInfor($httpAccept, $ajax, 'no');
  118. } else {
  119. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  120. $set_session_timeout = $_SESSION['SESSION_TIMEOUT'];
  121. if (_getLoginName() == "ra.admin") {
  122. $set_session_timeout = 4 * 3600;
  123. }
  124. if ($time > $set_session_timeout) {
  125. self::timeoutPrintInfor($httpAccept, $ajax, 'yes');
  126. } else {
  127. $_SESSION["LAST_OPERATE_TIME"] = time();
  128. if (!_isAdmin() && $_GET["action"] != "linkcrm") {
  129. if (!utils::checkExist($_SESSION['ONLINE_USER']['permission'], $action)
  130. && !(stripos($action, "main") === 0)
  131. && !(stripos($action, "user_guide") === 0)
  132. && !(stripos($action, "ajax") === 0)
  133. && !(stripos($action, "opreation_log") === 0)) {
  134. $data = array("msg"=>"Permission Denied");
  135. common::echo_json_encode(500, $data);
  136. exit();
  137. }
  138. }
  139. }
  140. }
  141. session_write_close();
  142. }
  143. }
  144. public static function getCompanySearch() {
  145. $sc_list = _get_schemas();
  146. if (count($sc_list) == 1) {
  147. return "";
  148. }
  149. if (_isCustomerLogin()) {
  150. $msg = '<input type="hidden" name="_apex_or_sfs" value=""/>';
  151. } else {
  152. $msg = '<div class="modules">Apex/SFS/Kerry :&nbsp;<select name="_apex_or_sfs" class="sl"><option value="">All</option>';
  153. if ($_SESSION['ONLINE_USER']['main_schemas'] == "public") {
  154. $msg .= '<option value="public">Apex</option>';
  155. } else {
  156. $msg .= '<option value="public">Apex</option>';
  157. }
  158. if ($_SESSION['ONLINE_USER']['main_schemas'] == "sfs") {
  159. $msg .= '<option value="sfs">SFS</option>';
  160. } else {
  161. $msg .= '<option value="sfs">SFS</option>';
  162. }
  163. if ($_SESSION['ONLINE_USER']['main_schemas'] == "kyiff") {
  164. $msg .= '<option value="kyiff">Kerry</option>';
  165. } else {
  166. $msg .= '<option value="kyiff">Kerry</option>';
  167. }
  168. $msg .= '</select></div>';
  169. }
  170. return $msg;
  171. }
  172. public static function sessionVerify() {
  173. if (!isset($_SESSION['user_agent'])) {
  174. $_SESSION['user_agent'] = MD5($_SERVER['REMOTE_ADDR']
  175. . $_SERVER['HTTP_USER_AGENT']);
  176. } elseif ($_SESSION['user_agent'] != MD5($_SERVER['REMOTE_ADDR']
  177. . $_SERVER['HTTP_USER_AGENT'])) {
  178. session_regenerate_id();
  179. }
  180. }
  181. public static function searchExtendHandNew($type, $user, $company_name = "station_name") {
  182. if (_isAdminHandNew($user)) {
  183. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  184. {
  185. return "1=1";
  186. }
  187. //return " (schem_not_display is null or schem_not_display=false)";
  188. return " (COALESCE(schem_not_display,false) = false)";
  189. }
  190. if (_isDocAdmin($user["user_login"])) {
  191. if(strtolower($type) == "air_booking" ) //|| strtolower($type) == "air"
  192. {
  193. return "1=1";
  194. }
  195. //return ' (schem_not_display is null or schem_not_display=false)';
  196. return ' (COALESCE(schem_not_display,false) = false)';
  197. }
  198. if (strtolower($type) != "ocean" && strtolower($type) != "booking" && strtolower($type) != "air_booking"&& strtolower($type) != "air") {
  199. return " 1<>1";
  200. }
  201. if (empty($user["schemas_list"])) {
  202. $user["schemas_list"] = $_SESSION["schemas_list"];
  203. }
  204. $schemas_list = $user["schemas_list"];
  205. if ($user["is_kerry_shipment"] == "t") {
  206. $sqlWhere = " is_kerry_shipment is not null and is_kerry_shipment=true";
  207. } else if ($user["is_kerry_shipment"] == "f") {
  208. //$sqlWhere = " (is_kerry_shipment is null or is_kerry_shipment=false)";
  209. $sqlWhere = " (COALESCE(is_kerry_shipment,false) = false)";
  210. } else {
  211. $sqlWhere = " 1=1";
  212. }
  213. if (!empty($_POST["_apex_or_sfs"])) {
  214. $sqlWhere .= " and order_from='" . $_POST["_apex_or_sfs"] . "'";
  215. }
  216. if (count($schemas_list) == 1) {
  217. $schames = $schemas_list[0]["schemas_name"];
  218. if(strtolower($type) == "air_booking" ||strtolower($type) == "air")
  219. {
  220. }
  221. else
  222. $sqlWhere .= " and order_from='$schames'";
  223. if ($schames == "sfs" && empty($user["sfs_ONLINE_USER"])) {
  224. $user = $_SESSION["sfs_ONLINE_USER"];
  225. }
  226. if (strtolower($type) == "ocean") {
  227. $sqlWhere .= self::_oceanHandNew($user, $schames);
  228. if ($company_name == "doc") {
  229. if (empty($user["view_file_format"])) {
  230. if (strtolower($user["user_type"]) == "customer") {
  231. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  232. } else {
  233. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  234. }
  235. } else {
  236. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  237. }
  238. }
  239. }
  240. if (strtolower($type) == "booking") {
  241. $sqlWhere .= self::_bookingHandNew($user, $schames);
  242. }
  243. if (strtolower($type) == "air_booking") {
  244. $sqlWhere .= self::_airHandNew($user, $schames);
  245. }
  246. if (strtolower($type) == "air") {
  247. $sqlWhere .= self::_airHandNew($user, $schames);
  248. if ($company_name == "doc") {
  249. if (empty($user["view_file_format"])) {
  250. if (strtolower($user["user_type"]) == "customer") {
  251. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true and client_display = true)";
  252. } else {
  253. $sqlWhere .= " and serial_no in (SELECT serial_no from $schames.ra_online_file_format where active = true)";
  254. }
  255. } else {
  256. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  257. }
  258. }
  259. }
  260. } elseif (count($schemas_list) == 2) {
  261. if(strtolower($type) == "air_booking" )//|| strtolower($type) == "air"
  262. {
  263. // $sqlWhere .= " and 1=1";
  264. }
  265. else{
  266. //$sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  267. $sqlWhere .= " and (COALESCE(schem_not_display,false) = false)";
  268. }
  269. if (strtolower($type) == "ocean") {
  270. $sqlWhere .= " and ((order_from='public' ";
  271. $sqlWhere .= self::_oceanHandNew($user, "public");
  272. if ($company_name == "doc") {
  273. if (empty($user["view_file_format"])) {
  274. if (strtolower($user["user_type"]) == "customer") {
  275. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  276. } else {
  277. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  278. }
  279. } else {
  280. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  281. }
  282. }
  283. $sqlWhere .= ") or (order_from='sfs' ";
  284. if (empty($user["sfs_ONLINE_USER"])) {
  285. $user = $_SESSION["sfs_ONLINE_USER"];
  286. }
  287. $sqlWhere .= self::_oceanHandNew($user, "sfs");
  288. if ($company_name == "doc") {
  289. if (empty($user["view_file_format"])) {
  290. if (strtolower($user["user_type"]) == "customer") {
  291. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  292. } else {
  293. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  294. }
  295. } else {
  296. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  297. }
  298. }
  299. $sqlWhere .= ") )";
  300. }
  301. if (strtolower($type) == "booking") {
  302. $sqlWhere .= " and ((order_from='public' ";
  303. $sqlWhere .= self::_bookingHandNew($user, "public");
  304. $sqlWhere .= ") or (order_from='sfs' ";
  305. if (empty($user["sfs_ONLINE_USER"])) {
  306. $user = $_SESSION["sfs_ONLINE_USER"];
  307. }
  308. $sqlWhere .= self::_bookingHandNew($user, "sfs");
  309. $sqlWhere .= "))";
  310. }
  311. if (strtolower($type) == "air_booking") {
  312. $sqlWhere .= " and ((order_from='public' ";
  313. $sqlWhere .= self::_airHandNew($user, "public");
  314. $sqlWhere .= ") or (order_from='sfs' ";
  315. if (empty($user["sfs_ONLINE_USER"])) {
  316. $user = $_SESSION["sfs_ONLINE_USER"];
  317. }
  318. $sqlWhere .= self::_airHandNew($user, "sfs");
  319. $sqlWhere .= "))";
  320. // $sqlWhere .= self::_airHandNew($user, $schames);
  321. }
  322. if (strtolower($type) == "air") {
  323. $sqlWhere .= " and ((order_from='public' ";
  324. $sqlWhere .= self::_airHandNew($user, "public");
  325. if ($company_name == "doc") {
  326. if (empty($user["view_file_format"])) {
  327. if (strtolower($user["user_type"]) == "customer") {
  328. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true and client_display = true)";
  329. } else {
  330. $sqlWhere .= " and serial_no in (SELECT serial_no from public.ra_online_file_format where active = true)";
  331. }
  332. } else {
  333. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  334. }
  335. }
  336. $sqlWhere .= ") or (order_from='sfs' ";
  337. if (empty($user["sfs_ONLINE_USER"])) {
  338. $user = $_SESSION["sfs_ONLINE_USER"];
  339. }
  340. $sqlWhere .= self::_airHandNew($user, "sfs");
  341. if ($company_name == "doc") {
  342. if (empty($user["view_file_format"])) {
  343. if (strtolower($user["user_type"]) == "customer") {
  344. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true and client_display = true)";
  345. } else {
  346. $sqlWhere .= " and serial_no in (SELECT serial_no from sfs.ra_online_file_format where active = true)";
  347. }
  348. } else {
  349. $sqlWhere .= " and serial_no in (SELECT regexp_split_to_table('" . $user["view_file_format"] . "',';'))";
  350. }
  351. }
  352. $sqlWhere .= ") )";
  353. }
  354. } else {
  355. $sqlWhere = " 1<>1";
  356. }
  357. return $sqlWhere;
  358. }
  359. public static function getStatusStage($status) {
  360. if ($status == "EE" || $status == "I") {
  361. return 0;
  362. }
  363. if ($status == "AE" || $status == "VD" || $status == "VA_RELAY" || $status == "UV_RELAY" || $status == "AE_RELAY" || $status == "VD_RELAY") {
  364. return 1;
  365. }
  366. if ($status == "VA" || $status == "UV" || $status == "AL" || $status == "AR" || $status == "CU" || $status == "CT" || $status == "CR" || $status == "OA") {
  367. return 2;
  368. }
  369. if ($status == "AV" || $status == "D" || $status == "RD") {
  370. return 3;
  371. }
  372. return -1;
  373. }
  374. public static function getInNotInSql($contact_id, $type = 'in') {
  375. if (empty($contact_id))
  376. return " =''";
  377. $contact_id = trim($contact_id);
  378. $contact_id = trim($contact_id, ";");
  379. $contact_id = trim($contact_id);
  380. $contact_id = strtolower($contact_id);
  381. if ($type == 'in') {
  382. if (utils::checkExist($contact_id, ";")) {
  383. $ss = "";
  384. $aa = explode(";", $contact_id);
  385. foreach ($aa as $k => $v) {
  386. $v = trim($v);
  387. if (empty($ss))
  388. $ss = "'" . common::check_input($v) . "'";
  389. else
  390. $ss .= ",'" . common::check_input($v) . "'";
  391. }
  392. return " in (" . $ss . ")";
  393. } else {
  394. return " = '" . common::check_input($contact_id) . "'";
  395. }
  396. } else {
  397. if (utils::checkExist($contact_id, ";")) {
  398. $ss = "";
  399. $aa = explode(";", $contact_id);
  400. foreach ($aa as $k => $v) {
  401. $v = trim($v);
  402. if (empty($ss))
  403. $ss = "'" . common::check_input($v) . "'";
  404. else
  405. $ss .= ",'" . common::check_input($v) . "'";
  406. }
  407. return " in (" . $ss . ")";
  408. } else {
  409. return " != '" . common::check_input($contact_id) . "'";
  410. }
  411. }
  412. }
  413. public static function getInNotInSqlForSearch($contact_id, $type = 'in') {
  414. if (empty($contact_id))
  415. return " =''";
  416. $contact_id = trim($contact_id);
  417. $contact_id = trim($contact_id, ";");
  418. $contact_id = trim($contact_id);
  419. $contact_id = strtolower($contact_id);
  420. if ($type == 'in') {
  421. if (utils::checkExist($contact_id, ";")) {
  422. $ss = "";
  423. $aa = explode(";", $contact_id);
  424. foreach ($aa as $k => $v) {
  425. $v = trim($v);
  426. if (empty($ss))
  427. $ss = "'" . common::check_input($v) . "'";
  428. else
  429. $ss .= ",'" . common::check_input($v) . "'";
  430. }
  431. return $ss;
  432. } else {
  433. return "'" . common::check_input($contact_id) . "'";
  434. }
  435. }
  436. }
  437. /*
  438. * Encrypt a SQL query statement used to be passed as a parameter to get excel output
  439. encode :DeCode('str','E');
  440. decode :DeCode('enstr','D');
  441. */
  442. public static function deCode($string, $operation = "E") {
  443. $key = md5("uls_webwms");
  444. $key_length = strlen($key);
  445. if ($operation == "D")
  446. $string = rawurldecode($string);
  447. $string = $operation == 'D' ? base64_decode($string) : substr(md5($string . $key), 0, 8) . $string;
  448. $string_length = strlen($string);
  449. $rndkey = $box = array();
  450. $result = '';
  451. for ($i = 0; $i <= 255; $i++) {
  452. $rndkey [$i] = ord($key [$i % $key_length]);
  453. $box [$i] = $i;
  454. }
  455. for ($j = $i = 0; $i < 256; $i++) {
  456. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  457. $tmp = $box [$i];
  458. $box [$i] = $box [$j];
  459. $box [$j] = $tmp;
  460. }
  461. for ($a = $j = $i = 0; $i < $string_length; $i++) {
  462. $a = ($a + 1) % 256;
  463. $j = ($j + $box [$a]) % 256;
  464. $tmp = $box [$a];
  465. $box [$a] = $box [$j];
  466. $box [$j] = $tmp;
  467. $result .= chr(ord($string [$i]) ^ ($box [($box [$a] + $box [$j]) % 256]));
  468. }
  469. if ($operation == 'D') {
  470. if (substr($result, 0, 8) == substr(md5(substr($result, 8) . $key), 0, 8)) {
  471. return substr($result, 8);
  472. } else {
  473. return '';
  474. }
  475. } else {
  476. return rawurlencode(str_replace('=', '', base64_encode($result)));
  477. }
  478. }
  479. public static function getStatusDesc($code) {
  480. if (strtoupper($code) == "EE") {
  481. return "Empty Equipment Dispatched";
  482. }
  483. if (strtoupper($code) == "I") {
  484. return "Gate in full for a booking";
  485. }
  486. if (strtoupper($code) == "AE") {
  487. return "Container loaded on vessel";
  488. }
  489. if (strtoupper($code) == "VD") {
  490. return "Vessel Departure";
  491. }
  492. if (strtoupper($code) == "VA_RELAY") {
  493. return "Arrive Relay Port";
  494. }
  495. if (strtoupper($code) == "VD_RELAY") {
  496. return "Depart Relay Port";
  497. }
  498. if (strtoupper($code) == "AE_RELAY") {
  499. return "Loaded at Relay Port";
  500. }
  501. if (strtoupper($code) == "UV_RELAY") {
  502. return "Unloaded at Relay Port";
  503. }
  504. if (strtoupper($code) == "VA") {
  505. return "Vessel Arrival";
  506. }
  507. if (strtoupper($code) == "UV") {
  508. return "Unloaded From Vessel";
  509. }
  510. if (strtoupper($code) == "AL") {
  511. return "Container loaded on Rail";
  512. }
  513. if (strtoupper($code) == "AR") {
  514. return "Container unloaded from Rail";
  515. }
  516. if (strtoupper($code) == "CU") {
  517. return "Carrier and Customs Release";
  518. }
  519. if (strtoupper($code) == "CT") {
  520. return "Customs release";
  521. }
  522. if (strtoupper($code) == "CR") {
  523. return "Carrier release";
  524. }
  525. if (strtoupper($code) == "OA") {
  526. return "Gate out full from final discharge port";
  527. }
  528. if (strtoupper($code) == "AV") {
  529. return "Shipment available for pickup or delivery";
  530. }
  531. if (strtoupper($code) == "RD") {
  532. return "Container returned empty";
  533. }
  534. if (strtoupper($code) == "D") {
  535. return "Gate out for delivery to customer";
  536. }
  537. }
  538. public static function _toString($msg) {
  539. if ($msg == "" || $msg == NULL) {
  540. return "";
  541. }
  542. return $msg . "";
  543. }
  544. /*
  545. * timeout output
  546. */
  547. public static function timeoutPrintInfor($httpAccept, $ajax, $login) {
  548. //记录系统因session过期 退出登录
  549. $data = array("msg"=>"session_time_out");
  550. self::echo_json_encode(403,$data);
  551. exit();
  552. }
  553. private static function _oceanHandNew($user, $schemas = "public") {
  554. $o = $user['ocean_station'];
  555. $o_or = $user['ocean_station_or'];
  556. $d = $user['ocean_agent'];
  557. $d_or = $user['ocean_agent_or'];
  558. $sales = $user['ocean_sales'];
  559. $sales_or = $user['ocean_sales_or'];
  560. $op = $user['ocean_dest_op'];
  561. $op_or = $user['ocean_dest_op_or'];
  562. $follow = $user['ocean_following_sales'];
  563. $follow_or = $user['ocean_following_sales_or'];
  564. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all" || strtolower($op_or) == "all") {
  565. return " and 1=1";
  566. }
  567. $sqlWhere = "";
  568. if (_isCustomerLoginHandNew($user)) {
  569. //error_log("_oceanHandNew".$schemas);
  570. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schemas);
  571. } else {
  572. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  573. return " and 1<>1";
  574. }
  575. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  576. } else {
  577. $sql = "1=1";
  578. if (!empty($o) && strtolower($o) != 'all') {
  579. $sql .= " and lower(origin)";
  580. $sql .= utils::getInSql($o);
  581. }
  582. if (!empty($d) && strtolower($d) != 'all') {
  583. $sql .= " and lower(agent)";
  584. $sql .= utils::getInSql($d);
  585. }
  586. $sqlWhere .= " and (" . $sql . ")";
  587. }
  588. if (strtolower($sales) == 'all' || empty($sales)) {
  589. } else {
  590. if (utils::checkExist($sales, ";")) {
  591. $sql = "1!=1";
  592. $tt = explode(";", $sales);
  593. foreach ($tt as $t) {
  594. $t = trim($t);
  595. if (!empty($t))
  596. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  597. }
  598. $sqlWhere .= " and ($sql)";
  599. } else
  600. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  601. }
  602. if (strtolower($op) == 'all' || empty($op)) {
  603. } else {
  604. $sqlWhere .= " and lower(dest_op) " . utils::getInSql($op);
  605. }
  606. if (strtolower($follow) == 'all' || empty($follow)) {
  607. } else {
  608. if (utils::checkExist($follow, ";")) {
  609. $sql = "1!=1";
  610. $tt = explode(";", $follow);
  611. foreach ($tt as $t) {
  612. $t = trim($t);
  613. if (!empty($t))
  614. $sql .= " or following_sales ilike '" . $t . "'";
  615. }
  616. $sqlWhere .= " and ($sql)";
  617. } else
  618. $sqlWhere .= " and following_sales ilike '" . $follow . "'";
  619. }
  620. $sqlWhere = " (1=1 $sqlWhere)";
  621. if (!empty($o_or)) {
  622. $sqlWhere .= " or lower(origin)";
  623. $sqlWhere .= utils::getInSql($o_or);
  624. }
  625. if (!empty($d_or)) {
  626. $sqlWhere .= " or lower(agent)";
  627. $sqlWhere .= utils::getInSql($d_or);
  628. }
  629. if (!empty($sales_or)) {
  630. if (utils::checkExist($sales_or, ";")) {
  631. $sql = "1!=1";
  632. $tt = explode(";", $sales_or);
  633. foreach ($tt as $t) {
  634. $t = trim($t);
  635. if (!empty($t))
  636. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  637. }
  638. $sqlWhere .= " or ($sql)";
  639. } else
  640. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  641. }
  642. if (!empty($op_or)) {
  643. $sqlWhere .= " or lower(dest_op) " . utils::getInSql($op_or);
  644. }
  645. if (!empty($follow_or)) {
  646. if (utils::checkExist($follow_or, ";")) {
  647. $sql = "1!=1";
  648. $tt = explode(";", $follow_or);
  649. foreach ($tt as $t) {
  650. $t = trim($t);
  651. if (!empty($t))
  652. $sql .= " or following_sales ilike '" . $t . "'";
  653. }
  654. $sqlWhere .= " or ($sql)";
  655. }else {
  656. $sqlWhere .= " or following_sales ilike '" . $follow_or . "'";
  657. }
  658. }
  659. $sqlWhere = " and ($sqlWhere)";
  660. }
  661. return $sqlWhere;
  662. }
  663. private static function _bookingHandNew($user, $schames) {
  664. // if (_isDemo())
  665. // return " serial_no = 'D4DD1D79-83F4-4E65-9773-CF5277D72738'";
  666. $o = $user['ocean_station'];
  667. $o_or = $user['ocean_station_or'];
  668. $d = $user['ocean_agent'];
  669. $d_or = $user['ocean_agent_or'];
  670. $sales = $user['ocean_sales'];
  671. $sales_or = $user['ocean_sales_or'];
  672. $op = $user['ocean_dest_op'];
  673. $op_or = $user['ocean_dest_op_or'];
  674. $follow = $user['ocean_following_sales'];
  675. $follow_or = $user['ocean_following_sales_or'];
  676. if (strtolower($o_or) == "all" || strtolower($d_or) == "all" || strtolower($sales_or) == "all") {
  677. return " and 1=1";
  678. }
  679. // $sc_list = $user['schemas_list'];
  680. // if (empty($sc_list)) {
  681. // $sc_list = $_SESSION["schemas_list"];
  682. // }
  683. // if (empty($sc_list)) {
  684. // return " and 1<>1";
  685. // }
  686. // $sqlWhere = " and 1=1";
  687. // if ($user["is_kerry_shipment"] == "t") {
  688. // $sqlWhere = " and and is_kerry_shipment is not null and is_kerry_shipment=true";
  689. // } else if ($user["is_kerry_shipment"] == "f") {
  690. // $sqlWhere = " and (is_kerry_shipment is null or is_kerry_shipment=false)";
  691. // }
  692. // if (count($sc_list) == 1) {
  693. // $sch = $sc_list[0]['schemas_name'];
  694. // $sqlWhere .= " and order_from='$sch'";
  695. // } else {
  696. // $sqlWhere .= " and (schem_not_display is null or schem_not_display=false)";
  697. // }
  698. $sqlWhere = "";
  699. if (_isCustomerLoginHandNew($user)) {
  700. $sqlWhere .= " and " . _customerFilerSearchHandNew($user, $schames);
  701. } else {
  702. if (empty($o) && empty($d) && empty($sales) && empty($op) && empty($follow)) {
  703. return " and 1<>1";
  704. }
  705. if ((strtolower($o) == 'all' || empty($o)) && (strtolower($d) == "all" || empty($d))) {
  706. } else {
  707. $sql = "1=1";
  708. if (!empty($o) && strtolower($o) != 'all') {
  709. $sql .= " and lower(origin)";
  710. $sql .= utils::getInSql($o);
  711. }
  712. if (!empty($d) && strtolower($d) != 'all') {
  713. $sql .= " and lower(agent)";
  714. $sql .= utils::getInSql($d);
  715. }
  716. $sqlWhere .= " and (" . $sql . ")";
  717. }
  718. if (strtolower($sales) == 'all' || empty($sales)) {
  719. } else {
  720. if (utils::checkExist($sales, ";")) {
  721. $sql = "1!=1";
  722. $tt = explode(";", $sales);
  723. foreach ($tt as $t) {
  724. $t = trim($t);
  725. if (!empty($t))
  726. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  727. }
  728. $sqlWhere .= " and ($sql)";
  729. } else
  730. $sqlWhere .= " and lower(sales_rep)='" . strtolower($sales) . "'";
  731. }
  732. if (strtolower($follow) == 'all' || empty($follow)) {
  733. } else {
  734. if (utils::checkExist($follow, ";")) {
  735. $sql = "1!=1";
  736. $tt = explode(";", $follow);
  737. foreach ($tt as $t) {
  738. $t = trim($t);
  739. if (!empty($t))
  740. $sql .= " or following_sales ilike '" . $t . "%'";
  741. }
  742. $sqlWhere .= " and ($sql)";
  743. } else
  744. $sqlWhere .= " and following_sales ilike '" . $follow . "%'";
  745. }
  746. $sqlWhere = " (1=1 $sqlWhere)";
  747. if (!empty($o_or)) {
  748. $sqlWhere .= " or lower(origin)";
  749. $sqlWhere .= utils::getInSql($o_or);
  750. }
  751. if (!empty($d_or)) {
  752. $sqlWhere .= " or lower(agent)";
  753. $sqlWhere .= utils::getInSql($d_or);
  754. }
  755. if (!empty($sales_or)) {
  756. if (utils::checkExist($sales_or, ";")) {
  757. $sql = "1!=1";
  758. $tt = explode(";", $sales_or);
  759. foreach ($tt as $t) {
  760. $t = trim($t);
  761. if (!empty($t))
  762. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  763. }
  764. $sqlWhere .= " or ($sql)";
  765. } else
  766. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "%'";
  767. }
  768. if (!empty($follow_or)) {
  769. if (utils::checkExist($follow_or, ";")) {
  770. $sql = "1!=1";
  771. $tt = explode(";", $follow_or);
  772. foreach ($tt as $t) {
  773. $t = trim($t);
  774. if (!empty($t))
  775. $sql .= " or following_sales ilike '" . $t . "%'";
  776. }
  777. $sqlWhere .= " or ($sql)";
  778. } else
  779. $sqlWhere .= " or following_sales ilike '" . $follow_or . "%'";
  780. }
  781. $sqlWhere = " and ($sqlWhere)";
  782. }
  783. return $sqlWhere;
  784. }
  785. private static function _airHandNew($user, $schemas = "public")
  786. {
  787. if($schemas=="public")
  788. {
  789. $station = $user['air_station'];
  790. $station_or = $user['air_station_or'];
  791. $sales = $user['air_sales'];
  792. $sales_or = $user['air_sales_or'];
  793. }
  794. else
  795. {
  796. $station = $user[$schemas."_ONLINE_USER"]['air_station'];
  797. $station_or = $user[$schemas."_ONLINE_USER"]['air_station_or'];
  798. $sales = $user[$schemas."_ONLINE_USER"]['air_sales'];
  799. $sales_or = $user[$schemas."_ONLINE_USER"]['air_sales_or'];
  800. }
  801. if (strtolower($station_or) == "all" || strtolower($sales_or) == "all" ) //|| strtolower($d_or) == "all"|| strtolower($op_or) == "all"|| strtolower($follow_or) == "all"
  802. {
  803. return " and 1=1";
  804. }
  805. $sqlWhere = "";
  806. if (_isCustomerLoginHandNew($user)) {
  807. //error_log("_oceanHandNew".$schemas);
  808. $sqlWhere .= " and " . _customerFilerSearchHandNew_Air($user, $schemas);
  809. }
  810. else
  811. {
  812. if (empty($station) && empty($sales) ) //&& empty($d)&& empty($op) && empty($follow)
  813. {
  814. return " and 1<>1";
  815. }
  816. if ((strtolower($station) == 'all' || empty($station)) ) //&& (strtolower($d) == "all" || empty($d))
  817. {
  818. }
  819. else
  820. {
  821. $sql = "1=1";
  822. if (!empty($station) && strtolower($station) != 'all') {
  823. $sql .= " and (lower(origin)";
  824. $sql .= utils::getInSql($station);
  825. $sql .= " or lower(destination_station)";
  826. $sql .= utils::getInSql($station);
  827. $sql .= ")";
  828. }
  829. $sqlWhere .= " and (" . $sql . ")";
  830. }
  831. if (strtolower($sales) == 'all' || empty($sales)) {
  832. } else
  833. {
  834. if (utils::checkExist($sales, ";")) {
  835. $sql = "1!=1";
  836. $tt = explode(";", $sales);
  837. foreach ($tt as $t) {
  838. $t = trim($t);
  839. if (!empty($t))
  840. {
  841. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  842. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  843. }
  844. }
  845. $sqlWhere .= " and ($sql)";
  846. } else
  847. {
  848. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales) . "'";
  849. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales) . "'";
  850. }
  851. }
  852. $sqlWhere = " (1=1 $sqlWhere)";
  853. if (!empty($station_or)) {
  854. $sqlWhere .= " or lower(origin)";
  855. $sqlWhere .= utils::getInSql($station_or);
  856. $sqlWhere .= " or lower(destination_station)";
  857. $sqlWhere .= utils::getInSql($station_or);
  858. }
  859. if (!empty($sales_or)) {
  860. if (utils::checkExist($sales_or, ";")) {
  861. $sql = "1!=1";
  862. $tt = explode(";", $sales_or);
  863. foreach ($tt as $t) {
  864. $t = trim($t);
  865. if (!empty($t))
  866. {
  867. $sql .= " or lower(sales_rep)='" . strtolower($t) . "'";
  868. $sql .= " or lower(following_sales)='" . strtolower($t) . "'";
  869. }
  870. }
  871. $sqlWhere .= " or ($sql)";
  872. } else
  873. {
  874. $sqlWhere .= " or lower(sales_rep)='" . strtolower($sales_or) . "'";
  875. $sqlWhere .= " or lower(following_sales)='" . strtolower($sales_or) . "'";
  876. }
  877. }
  878. $sqlWhere = " and ($sqlWhere)";
  879. }
  880. return $sqlWhere;
  881. }
  882. public static function isNewVersion() {
  883. if (utils::checkExist($_SERVER['PHP_SELF'], "main_new_version.php")) {
  884. return "_new";
  885. }
  886. return "";
  887. }
  888. public static function removeTopOceanOldVersionSpecialField($rss){
  889. $rss_bk = $rss;
  890. $new_arr = array();
  891. foreach ($rss_bk as $k => $v) {
  892. if (utils::startWith($v['database_column_name'], "__") || utils::startWith($v['database_column_name'], "___")){
  893. //unset($rss[$k]);
  894. }else{
  895. $new_arr[] = $v;
  896. }
  897. }
  898. return $new_arr;
  899. }
  900. public static function echo_json_encode($code,$data){
  901. $resData = array();
  902. $resData["code"] = $code;
  903. $resData["data"] =$data;
  904. //echo utils::jsonFiltration("null", "\"\"", json_encode($resData));
  905. echo json_encode($resData);
  906. }
  907. /*
  908. * MM/DD/YYYY To YYYY-MM-DD
  909. */
  910. public static function usDate2sqlDate($timestr) {
  911. if (empty($timestr))
  912. return '';
  913. $datearray = explode("/", $timestr);
  914. $m = $datearray [0];
  915. $d = $datearray [1];
  916. $y = $datearray [2];
  917. return $y . "-" . $m . "-" . $d;
  918. }
  919. public static function uuid() {
  920. return md5(uniqid("", TRUE) . mt_rand());
  921. }
  922. /*
  923. * YYYYMMDD To MM/DD/YYYY
  924. */
  925. public static function date2usdate($datestr) {
  926. if (empty($datestr))
  927. return '';
  928. $y = substr($datestr, 0, 4);
  929. $m = substr($datestr, 4, 2);
  930. $d = substr($datestr, 6, 2);
  931. return $m . "/" . $d . "/" . $y;
  932. }
  933. /*
  934. * date add some days
  935. */
  936. public static function addDays($date, $days) {
  937. $time = strtotime($date) + $days * 24 * 3600;
  938. return date('m/d/Y', $time);
  939. }
  940. /*
  941. * download file from file system
  942. */
  943. public static function download_file($filename, $display_name = null, $delete = FALSE, $files = NULL) {
  944. $filename = str_replace("/", DIRECTORY_SEPARATOR, $filename);
  945. $filename = str_replace("\\", DIRECTORY_SEPARATOR, $filename);
  946. if (!file_exists($filename))
  947. exit('File Not Exist');
  948. if (empty($display_name))
  949. $display_name = basename($filename);
  950. //$file = fopen($filename, "r");
  951. header_remove("Content-type");
  952. header("Content-type:" . self::getContentType($filename));
  953. header("Expires: 0");
  954. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  955. header("Pragma: can-cache");
  956. header("Accept-ranges:bytes");
  957. header("Accept-length:" . filesize($filename));
  958. header("Content-Disposition:attachment;filename=\"" . $display_name . "\"");
  959. //echo fread($file, filesize($filename));
  960. //fclose($file);
  961. //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
  962. $read_buffer = 4096;
  963. $handle = fopen($filename, 'rb');
  964. //总的缓冲的字节数
  965. $sum_buffer = 0;
  966. $filesize = filesize($filename);
  967. //只要没到文件尾,就一直读取
  968. while (!feof($handle) && $sum_buffer < $filesize) {
  969. echo fread($handle, $read_buffer);
  970. $sum_buffer += $read_buffer;
  971. }
  972. //关闭句柄
  973. fclose($handle);
  974. if ($delete !== FALSE) {
  975. unlink($filename);
  976. }
  977. if (!empty($files)) {
  978. foreach ($files as $f) {
  979. unlink($f);
  980. }
  981. }
  982. }
  983. public static function getContentType($filename) {
  984. $extend = self::getExtendFilename($filename);
  985. $filetype = array(
  986. 'xls' => 'application/vnd.ms-excel',
  987. 'doc' => 'application/msword',
  988. 'gif' => 'image/gif',
  989. 'jpg' => 'image/jpeg',
  990. 'jpeg' => 'image/jpeg',
  991. 'jpe' => 'image/jpeg',
  992. 'bmp' => 'image/bmp',
  993. 'png' => 'image/png',
  994. 'tif' => 'image/tiff',
  995. 'pdf' => 'application/pdf',
  996. 'zip' => 'application/zip'
  997. );
  998. return $filetype[$extend];
  999. }
  1000. /*
  1001. * Get the file extension
  1002. */
  1003. public static function getExtendFilename($file_name) {
  1004. $extend = pathinfo($file_name);
  1005. $extend = strtolower($extend["extension"]);
  1006. return $extend;
  1007. }
  1008. public static function getManagement(){
  1009. //Management 自己配置需要创建表保存
  1010. $user_management_data = common::excuteObjectSql("select management,dashboard_filter from ra_online_user where user_login = '"._getLoginName()."'");
  1011. //为空,配置使用默认值
  1012. $user_management = $user_management_data['management'];
  1013. if(empty($user_management)){
  1014. $Management = common::getdefaultManagement();
  1015. }else{
  1016. $Management = json_decode($user_management,true);
  1017. foreach($Management as $key =>$val){
  1018. $Management[$key]['id'] = intval($val['id']);
  1019. $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
  1020. }
  1021. }
  1022. $user_dashboard_filter = $user_management_data['dashboard_filter'];
  1023. $dashboard_filter =array();
  1024. if(!empty($user_dashboard_filter)){
  1025. $dashboard_filter = json_decode($user_dashboard_filter,true);
  1026. }else{
  1027. $threeMonthsAgoTimestamp = strtotime('-3 months');
  1028. $date_start = date('Y-m-d', $threeMonthsAgoTimestamp);
  1029. $date_end = date('Y-m-d');
  1030. $date_start_two = date('m/d/Y', $threeMonthsAgoTimestamp);
  1031. $date_end_two = date('m/d/Y');
  1032. //ETD
  1033. $_12MonthsAgoTimestamp = strtotime('-11 months');
  1034. $etd_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  1035. $etd_date_end = date('Y-m');
  1036. $etd_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  1037. $etd_date_end_two = date('m/Y');
  1038. //柜子
  1039. $ctnr_date_start = date('Y-m', $_12MonthsAgoTimestamp);
  1040. $ctnr_date_end = date('Y-m');
  1041. $ctnr_date_start_two = date('m/Y', $_12MonthsAgoTimestamp);
  1042. $ctnr_date_end_two = date('m/Y');
  1043. //Top
  1044. $top_date_start = date('Y-m-d', $_12MonthsAgoTimestamp);
  1045. $top_date_end = date('Y-m-d');
  1046. $top_date_start_two = date('m/d/Y', $_12MonthsAgoTimestamp);
  1047. $top_date_end_two = date('m/d/Y');
  1048. //KPIDefaulteData
  1049. $dashboard_filter['KPIDefaulteData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  1050. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  1051. //PendingDefaultData
  1052. $dashboard_filter['PendingDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>"","date_start_two"=>"",
  1053. "date_end"=>"","date_end_two"=>"");
  1054. //RecentDefaultData
  1055. $dashboard_filter['RecentDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start_two,"date_start_two"=>$date_start,
  1056. "date_end"=>$date_end_two,"date_end_two"=>$date_end);
  1057. //ETDDefaultData
  1058. $dashboard_filter['ETDDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$etd_date_start_two,"date_start_two"=>$etd_date_start,
  1059. "date_end"=>$etd_date_end_two,"date_end_two"=>$etd_date_end);
  1060. //ContainerefaultData
  1061. $dashboard_filter['ContainerefaultData'] = array("transportation" =>array('Sea'),"date_type"=>"ETA","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  1062. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  1063. //RevenueDefaultData
  1064. if(_isRevenueDisplay()){
  1065. $dashboard_filter['RevenueDefaultData'] = array("transportation" =>array('All'),"date_type"=>"Invoice Issue Date","date_start"=>$ctnr_date_start_two,"date_start_two"=>$ctnr_date_start,
  1066. "date_end"=>$ctnr_date_end_two,"date_end_two"=>$ctnr_date_end);
  1067. }
  1068. //Top10faultData
  1069. $dashboard_filter['Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1070. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1071. //OriginCo2Top10faultData
  1072. $dashboard_filter['OriginCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1073. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1074. //DestinationCo2Top10faultData
  1075. $dashboard_filter['DestinationCo2Top10faultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$top_date_start_two,"date_start_two"=>$top_date_start,
  1076. "date_end"=>$top_date_end_two,"date_end_two"=>$top_date_end);
  1077. }
  1078. return array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
  1079. }
  1080. public static function getItemStyle($type,$code){
  1081. if($type == 'r1'){
  1082. $data = array("0-20 Days" =>"#ffc594",
  1083. "20-40 Days" =>"#ff9e4c",
  1084. "40-60 Days" =>"#ff7500",
  1085. "60-80 Days" =>"#ff3d00",
  1086. "Over 80 Days" =>"#d50000");
  1087. return $data[$code];
  1088. }
  1089. if($type == 'r4' || $type == 'r3' || $type == 'atd_r4' || $type == 'ata_r3'){
  1090. $data = array("0 Day" =>"#ffc594",
  1091. "Today" =>"#ffc594",
  1092. "1-2 Days" =>"#ff9e4c",
  1093. "3-6 Days" =>"#ff7500",
  1094. "7 Days" =>"#ff3d00");
  1095. return $data[$code];
  1096. }
  1097. if($type == 'r2' || utils::startWith($type,"co2e")){
  1098. $data = array("45" =>"#FFE3CC",
  1099. "40" =>"#FFAC66",
  1100. "20" =>"#FF7500",
  1101. "air" =>"#FFE3CC",
  1102. "sea" =>"#FFAC66",
  1103. "road" =>"#FF7500");
  1104. return $data[$code];
  1105. }
  1106. if($type == "top"){
  1107. $data = array("1" =>"#FF7500",
  1108. "2" =>"#ff9033",
  1109. "3" =>"#ff9e4d",
  1110. "4" =>"#ffac66",
  1111. "5" =>"#ffba80",
  1112. "6" =>"#ffc899",
  1113. "7" =>"#ffd6b3",
  1114. "8" =>"#ffe3cc",
  1115. "9" =>"#fff1e6",
  1116. "10" =>"#fff1e6");
  1117. return $data[$code];
  1118. }
  1119. }
  1120. //处理返回原表数据格式
  1121. public static function mian_repot_do($value,$type,$totalValue){
  1122. $data = array();
  1123. $value_arr = json_decode($value,true);
  1124. //r1 是 ETD to ETA (Days)圆形图表数据结构返回
  1125. if($type == 'r1'){
  1126. $ETDList = array();
  1127. foreach($value_arr as $arr){
  1128. $color = common::getItemStyle($type,$arr['name']);
  1129. $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
  1130. }
  1131. $ETDList = array_reverse($ETDList);
  1132. $ETD_Title = "Total: $totalValue";
  1133. $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('50%','80%'),"ETD_Title" =>$ETD_Title,"download_name" => "ETD to ETA (Days)");
  1134. }
  1135. if($type == 'r4' || $type == 'r3'){
  1136. //重新整理一下数据,给UI一致
  1137. $data_kd = array();
  1138. foreach($value_arr as $arr){
  1139. if(stripos("Today", $arr['name']) !== false){
  1140. $color = common::getItemStyle($type,"Today");
  1141. if(empty($data_kd["0"])){
  1142. $data_kd["0"] = array("value" =>intval($arr['value']),"name" =>"≤1 Day","itemStyle" =>array("color" =>$color));
  1143. }else{
  1144. $data_kd["0"]["value"] = $data_kd["0"]["value"] + intval($arr['value']);
  1145. }
  1146. }
  1147. if(stripos("+1 Days/+2 Days", $arr['name']) !== false){
  1148. $color = common::getItemStyle($type,"1-2 Days");
  1149. if(empty($data_kd["1"])){
  1150. $data_kd["1"] = array("value" =>intval($arr['value']),"name" =>"1-2 Days","itemStyle" =>array("color" =>$color));
  1151. }else{
  1152. $data_kd["1"]["value"] = $data_kd["1"]["value"] + intval($arr['value']);
  1153. }
  1154. }
  1155. if(stripos("+3 Days/+4 Days/+5 Days/+6 Days", $arr['name']) !== false){
  1156. $color = common::getItemStyle($type,"3-6 Days");
  1157. if(empty($data_kd["2"])){
  1158. $data_kd["2"] = array("value" =>intval($arr['value']),"name" =>"3-6 Days","itemStyle" =>array("color" =>$color));
  1159. }else{
  1160. $data_kd["2"]["value"] = $data_kd["2"]["value"] + intval($arr['value']);
  1161. }
  1162. }
  1163. if(stripos("+7 Days/Over 7 Days", $arr['name']) !== false){
  1164. $color = common::getItemStyle($type,"7 Days");
  1165. if(empty($data_kd["3"])){
  1166. $data_kd["3"] = array("value" =>intval($arr['value']),"name" =>"≥7 Days","itemStyle" =>array("color" =>$color));
  1167. }else{
  1168. $data_kd["3"]["value"] = $data_kd["3"]["value"] + intval($arr['value']);
  1169. }
  1170. }
  1171. }
  1172. if($type == 'r4'){
  1173. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"","download_name" => "Pending Departure");
  1174. }
  1175. if($type == 'r3'){
  1176. $data = array("ETDList" =>$data_kd,"ETD_Radius"=>array('30%','50%'),"title1" =>"Arrival","title2" =>"","download_name" => "Pending Arrival");
  1177. }
  1178. }
  1179. return $data;
  1180. }
  1181. //单独处理co2e bar
  1182. public static function getCo2eBar(){
  1183. //新UI air sea road 目前只有sea
  1184. $type = $_REQUEST["r_type"];
  1185. $shipment_mode_arr = array("air","sea","road");
  1186. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1187. $sqlWhere = " " . $sqlWhere;
  1188. $date_type = strtolower($_REQUEST["date_type"]);
  1189. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1190. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1191. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1192. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1193. $ContainerCount_Title = array();
  1194. //先查询总的排放量sea air road,确定排名后,在分别查询对应的sea air road
  1195. //这里的问题跟 top 一样 。总的排放量查询有问题。目前是总的排放量 暂时等于 sea的排放量
  1196. if ($type == "co2e_orgin"){
  1197. $co2e_shippr_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
  1198. shippr_uncode as station from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by shippr_uncode order by catnum desc limit 10";
  1199. $co2e_aLL = common::excuteListSql($co2e_shippr_sql);
  1200. }
  1201. if ($type == "co2e_destination"){
  1202. $co2e_consignee_sql = "select SUM(COALESCE(carbon_emission,0)) as catnum ,
  1203. consignee_uncode as station from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' and carbon_emission is not null $sqlWhere group by consignee_uncode order by catnum desc limit 10";
  1204. $co2e_aLL = common::excuteListSql($co2e_consignee_sql);
  1205. }
  1206. //最大Y值
  1207. $maxY = 0;
  1208. $stations = array();
  1209. foreach($co2e_aLL as $val){
  1210. $ContainerCount_Title[] = $val['station'];
  1211. $maxY = $maxY > $val['catnum'] ? $maxY : $val['catnum'];
  1212. if(!empty($val['station'])){
  1213. $stations[] = $val['station'];
  1214. }
  1215. }
  1216. $station_str = utils::implode(',',$stations);
  1217. $ContainerCounSeries = array();
  1218. foreach($shipment_mode_arr as $_shipment_mode){
  1219. //类型有 sea air road,目前之类只查询sea的,其他为空
  1220. $shipment_mode = $_shipment_mode;
  1221. $co2e = array();
  1222. if ($type == "co2e_orgin"){
  1223. $co2e_shippr_sql_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1224. if(!empty($co2e_shippr_sql_union)){
  1225. $co2e = common::excuteListSql($co2e_shippr_sql_union);
  1226. }
  1227. $download_name = "CO2e Emission by Origin (Top 10)";
  1228. }
  1229. if ($type == "co2e_destination"){
  1230. $co2e_consignee_union = utils::_getSql($station_str,$type,$shipment_mode,$sqlWhere);
  1231. if(!empty($co2e_consignee_union)){
  1232. $co2e = common::excuteListSql($co2e_consignee_union);
  1233. }
  1234. $download_name = "CO2e Emission by Destination (Top 10)";
  1235. }
  1236. $total = 0;
  1237. $max = 0;
  1238. $data = array();
  1239. foreach($co2e as $val){
  1240. $data[] = empty($val['catnum'])? 0 : round($val['catnum'], 4);
  1241. $total = $total + $val['catnum'];
  1242. $max = $max < $val['catnum'] ? $val['catnum'] : $max;
  1243. }
  1244. $transportation = $_REQUEST["transportation"];
  1245. if(!is_array($transportation)){
  1246. $transportation = array($transportation);
  1247. }
  1248. if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1249. }else{
  1250. //这里不用处理,只有sea的数据
  1251. if (!in_array("Sea", $transportation)){
  1252. $data = array_fill_keys(array_keys($data), 0);
  1253. $total = 0;
  1254. $max = 0;
  1255. }
  1256. }
  1257. $ContainerCounSeries[$shipment_mode] = array("data"=>$data,"total"=>$total,"max"=>$max);
  1258. }
  1259. //处理返回时数据格式 其实不太需要计算最大值,在最开始总量查询的时候以及查询出来
  1260. $ContainerCounSeries_return = array();
  1261. foreach($ContainerCounSeries as $k =>$v){
  1262. $color = common::getItemStyle($type,$k);
  1263. $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
  1264. "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color),'barWidth'=>'40');
  1265. }
  1266. //处理返回原表数据格式
  1267. //计算刻度值 最小值是0,最大值是3000,刻度是500 interval
  1268. $interval = utils::calculateTicks(0,$maxY,10);
  1269. if($interval == 0){
  1270. //处理返回默认值
  1271. $interval = 1;
  1272. }
  1273. $returnData = array("ContainerCount_Title"=>"","ContainerCountList" =>$ContainerCount_Title,"ContainerCounSeries" =>$ContainerCounSeries_return,
  1274. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,"download_name" => $download_name);
  1275. return $returnData;
  1276. }
  1277. public static function getTopBar(){
  1278. $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  1279. $sqlWhere = " " . $sqlWhere;
  1280. $date_type = strtolower($_REQUEST["date_type"]);
  1281. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start']))
  1282. $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_REQUEST['date_start']) . " 00:00:00'";
  1283. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end']))
  1284. $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_REQUEST['date_end']) . " 23:59:59'";
  1285. $toporiginType = "shippr_uncode";
  1286. $shippr_uncode_10_sql ="with aa as (select count(shippr_uncode) as num,shippr_uncode,
  1287. (array_agg(shipper_city))[1] AS shipper_city from online_ocean
  1288. where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
  1289. select aa.*,dd.* from aa
  1290. left join LATERAL ( select lon as lng, lat as lat,
  1291. '' as label, '' as infor, 3 as sort,
  1292. null::timestamp without time zone as stime,''::text as ptype
  1293. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
  1294. //todo 这里预写个大概
  1295. //common::getTopBarSQL($toporiginType,$_REQUEST["transportation"]);
  1296. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1297. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1298. if(count($shippr_uncode_10) == 1 && empty($shippr_uncode_10[0]["shippr_uncode"])){
  1299. $toporiginType = "fport_of_loading_un";
  1300. $shippr_uncode_10_sql = "with aa as (select count(fport_of_loading_un) as num,fport_of_loading_un as shippr_uncode
  1301. from online_ocean where 1=1 and COALESCE(fport_of_loading_un,'')<>'' $sqlWhere group by fport_of_loading_un order by num desc limit 10)
  1302. select aa.*,dd.* from aa
  1303. left join LATERAL ( select lon as lng, lat as lat,
  1304. '' as label, '' as infor, 3 as sort,
  1305. null::timestamp without time zone as stime,''::text as ptype
  1306. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.fport_of_loading_un ) dd on true";
  1307. $shippr_uncode_10 = common::excuteListSql($shippr_uncode_10_sql);
  1308. }
  1309. //$toporiginType = "fport_of_loading_un";
  1310. $topdestinationinType = "consignee_uncode";
  1311. $consignee_uncode_10_sql = "with aa as (select count(consignee_uncode) as num,consignee_uncode,
  1312. (array_agg(consignee_city))[1] AS consignee_city
  1313. from online_ocean where 1=1 and COALESCE(consignee_uncode,'')<>'' $sqlWhere group by consignee_uncode order by num desc limit 10)
  1314. select aa.*,dd.* from aa
  1315. left join LATERAL ( select lon as lng, lat as lat,
  1316. '' as label, '' as infor, 3 as sort,
  1317. null::timestamp without time zone as stime,''::text as ptype
  1318. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.consignee_uncode ) dd on true";
  1319. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1320. //如果值没有:客户地址-->站点地址-->Port地址(POL/POD)
  1321. if(count($consignee_uncode_10) == 1 && empty($consignee_uncode_10[0]["consignee_uncode"])){
  1322. $topdestinationinType = "mport_of_discharge_un";
  1323. $consignee_uncode_10_sql = "with aa as (select count(mport_of_discharge_un) as num,mport_of_discharge_un as consignee_uncode from online_ocean where 1=1 and COALESCE(mport_of_discharge_un,'')<>'' $sqlWhere group by mport_of_discharge_un order by num desc limit 10)
  1324. select aa.*,dd.* from aa
  1325. left join LATERAL ( select lon as lng, lat as lat,
  1326. '' as label, '' as infor, 3 as sort,
  1327. null::timestamp without time zone as stime,''::text as ptype
  1328. from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.mport_of_discharge_un ) dd on true";
  1329. $consignee_uncode_10 = common::excuteListSql($consignee_uncode_10_sql);
  1330. }
  1331. //Top查询有点问题,暂时这样查询: 理论上查询air sea road 所有数据的top 10,在更加这个top的站点,分别去查询对于mode的数据计总。
  1332. //但是目前只有sea, 所有模式计总 = sea计总(以后这里是要改的)
  1333. $transportation = $_REQUEST["transportation"];
  1334. if(!is_array($transportation)){
  1335. $transportation = array($transportation);
  1336. }
  1337. if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1338. }else{
  1339. //这里不用处理,只有sea的数据
  1340. if (!in_array("Sea", $transportation)){
  1341. $shippr_uncode_10 = array();
  1342. $consignee_uncode_10 = array();
  1343. }
  1344. }
  1345. $toporigin = array();
  1346. $toporiginMap = array();
  1347. $i = 0;
  1348. $origiNunMax = 0;
  1349. foreach($shippr_uncode_10 as $orgin){
  1350. $i = $i + 1;
  1351. $map = array();
  1352. if(!empty($orgin['lat'])&&!empty($orgin['lng'])){
  1353. $map = array("lat" =>$orgin['lat'],"lng" =>$orgin['lng']);
  1354. }
  1355. //$json = '{"lng":121.8525,"lat":29.926545,"label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1356. //$map = json_decode($json,true);
  1357. if(!empty($map)){
  1358. $toporiginMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1359. "divIcon" => array("iconSize"=>0),
  1360. "name" =>$orgin['shippr_uncode'],
  1361. "color" =>common::getItemStyle("top",$i),
  1362. "value" =>$orgin['num'],
  1363. "textcolor" =>"#FFF");
  1364. }
  1365. //查询uncode,对应的city
  1366. $city = "";
  1367. if($toporiginType == "shippr_uncode"){
  1368. $city = $orgin['shipper_city'];
  1369. }
  1370. //$city 做假数据
  1371. $toporigin[] = array("name"=>$orgin['shippr_uncode'],"city_name"=>$city,"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i));
  1372. $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
  1373. }
  1374. $topdestination = array();
  1375. $topdestinationinMap = array();
  1376. $i = 0;
  1377. $agentiNunMax = 0;
  1378. foreach($consignee_uncode_10 as $agent){
  1379. $i = $i + 1;
  1380. $map = array();
  1381. if(!empty($agent['lat'])&&!empty($agent['lng'])){
  1382. $map = array("lat" =>$agent['lat'],"lng" =>$agent['lng']);
  1383. }
  1384. // $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
  1385. // $map = json_decode($json,true);
  1386. if(!empty($map)){
  1387. $topdestinationinMap[] = array("qandl"=>array(floatval($map['lat']),floatval($map['lng'])),
  1388. "divIcon" => array("iconSize"=>0),
  1389. "name" =>$agent['consignee_uncode'],
  1390. "color" =>common::getItemStyle("top",$i),
  1391. "value" =>$agent['num'],
  1392. "textcolor" =>"#FFF");
  1393. }
  1394. //查询uncode,对应的city
  1395. $city = "";
  1396. if($topdestinationinType == "consignee_uncode"){
  1397. $city = $agent['consignee_city'];
  1398. }
  1399. //$city 做假数据
  1400. $topdestination[] = array("name"=>$agent['consignee_uncode'],"city_name"=>$city,"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i));
  1401. $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
  1402. }
  1403. //处理返回原表数据格式
  1404. $interval = utils::calculateTicks(0,$origiNunMax,10);
  1405. if($interval == 0){
  1406. //处理返回默认值
  1407. $interval = 1;
  1408. }
  1409. $dest_interval = utils::calculateTicks(0,$agentiNunMax,10);
  1410. if($dest_interval == 0){
  1411. //处理返回默认值
  1412. $dest_interval = 1;
  1413. }
  1414. $returnData = array("seller_data_list_origin"=>$toporigin,"toporiginMap"=>array_reverse($toporiginMap),"toporiginType"=>$toporiginType,
  1415. "seller_data_list_destination"=>$topdestination,"topdestinationinMap"=>array_reverse($topdestinationinMap),"topdestinationinType"=>$topdestinationinType,
  1416. "min" => 0,"Max" =>$interval*10,"interval" =>$interval,
  1417. "dest_min" => 0,"dest_Max" =>$dest_interval*10,"dest_interval" =>$dest_interval);
  1418. return $returnData;
  1419. }
  1420. public static function getRevenue(){
  1421. $data = '{"bar_title":"Total: 0","barList":["DEC,23","JAN,24","FEB,24","MAR,24","APR,24","MAY,24","JUN,24","JUL,24","AUG,24","SEP,24","OCT,24","NOV,24"],"barSeries":[{"name":"USD","type":"bar","data":[1,1,1,1,1,1,1,1,1,1,1,1],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FF7500","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"THB","type":"bar","data":[2,2,2,2,2,2,2,2,2,2,2,2],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFAC66","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}},{"name":"SGD","type":"bar","data":[3,3,3,3,3,3,3,3,3,3,3,3],"emphasis":{"disabled":true,"focus":"none"},"itemStyle":{"color":"#FFE3CC","borderRadius":6},"label":{"show":false,"color":"#646A73","position":"top","fontFamily":"Lato-Light","hideWhenMouseLeave":false}}],"Max":5,"interval":1,"download_name":"Rvenue","isShowTooltips":true}';
  1422. //return json_decode($data,true);
  1423. $date_from = null;
  1424. $date_to = null;
  1425. if (isset($_REQUEST['date_start']) && !empty($_REQUEST['date_start'])){
  1426. $date_start = common::dateFormatToYM($_REQUEST['date_start']);
  1427. $date_from = $date_start."-01";
  1428. }
  1429. if (isset($_REQUEST['date_end']) && !empty($_REQUEST['date_end'])){
  1430. $date_end = common::dateFormatToYM($_REQUEST['date_end']);
  1431. $date_to = date('Y-m-t', strtotime($date_end."-01"));
  1432. }
  1433. $param = '{"user_login":"'._getLoginName().'","report_type":"ALL","date_from":"'.$date_from.'","date_to":"'.$date_to.'"}';
  1434. $sql = "SELECT * FROM get_customer_revenue_report('$param');FETCH ALL FROM r2;";
  1435. error_log("Revenue_sql:".$sql);
  1436. $r2_data = common::excuteListSql($sql);
  1437. //$r2_data = common::excuteListSql("select * from _test_data_table");
  1438. $barList = array();
  1439. $groupedItems = array();
  1440. foreach ($r2_data as $item) {
  1441. if(!in_array($item['month'],$barList)){
  1442. $barList[] = $item['month'];
  1443. }
  1444. $groupedItems[$item['currency']][] = $item;
  1445. }
  1446. //补齐所有货币的月份
  1447. foreach($groupedItems as $ckey =>$cvalueArr){
  1448. $currency = array();
  1449. foreach($barList as $month){
  1450. $currency[] = common::findCurrencyByMonth($month,$ckey,$cvalueArr);
  1451. }
  1452. $groupedItems[$ckey] = $currency;
  1453. }
  1454. //处理barSeries
  1455. $barSeries = array();
  1456. //先准备4种颜色
  1457. $color = array("#FF7500","#FFAC66","#FFE3CC");
  1458. $index = 0;
  1459. $max = 0;
  1460. foreach($groupedItems as $currency => $series){
  1461. $series_max = 0;
  1462. $num = $index % 3;
  1463. $index = $index +1;
  1464. $tem_series = array();
  1465. $tem_series["name"] = $currency;
  1466. $tem_series["type"] = "bar";
  1467. $tem_series["emphasis"] = array("disabled"=>true,"focus"=>"none");
  1468. $tem_series["itemStyle"] = array("color"=>$color[$num],"borderRadius"=>6);
  1469. $tem_series["label"] = array("show"=>false,"color"=>"#646A73","position"=>"top","fontFamily"=>"Lato-Light","hideWhenMouseLeave"=>false);
  1470. //准备series data
  1471. $data = array();
  1472. $total = 0;
  1473. foreach($series as $_series){
  1474. $invoice_amount = empty($_series['invoice_amount'])? 0 : round($_series['invoice_amount'], 4);
  1475. $data[]=$invoice_amount;
  1476. $total = $total + $invoice_amount;
  1477. $max = $max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $max;
  1478. $series_max = $series_max<$_series['invoice_amount'] ? $_series['invoice_amount'] : $series_max;
  1479. }
  1480. //计算Y坐标的间隔 每种货币的
  1481. $interval = utils::calculateTicks(0,$series_max,5);
  1482. if($interval == 0){
  1483. //处理返回默认值
  1484. $interval = 2;
  1485. }
  1486. $tem_series["Max"] = $interval*5;
  1487. $tem_series["interval"] = $interval;
  1488. $tem_series["data"] = $data;
  1489. $tem_series["total"] = floatval(number_format($total, 4, '.', ''));
  1490. $barSeries[] = $tem_series;
  1491. }
  1492. //计算Y坐标的间隔
  1493. $interval = utils::calculateTicks(0,$max,5);
  1494. if($interval == 0){
  1495. //处理返回默认值
  1496. $interval = 2;
  1497. }
  1498. $revenueBarData = array("bar_title" =>"Total:","barList" => $barList,
  1499. "barSeries" =>$barSeries,"download_name"=>"Rvenue","isShowTooltips"=>true,"Max" =>$interval*5,"interval" =>$interval);
  1500. return $revenueBarData;
  1501. }
  1502. public static function findCurrencyByMonth($month,$ckey,$cvalueArr){
  1503. $data = array("month" =>$month,"currency"=>$ckey,"invoice_amount"=>0,"sort_month"=>"");
  1504. foreach($cvalueArr as $realmonth){
  1505. if($realmonth['month'] == $month){
  1506. $data = $realmonth;
  1507. }
  1508. }
  1509. return $data;
  1510. }
  1511. public static function getdefaultManagement(){
  1512. $Management = array();
  1513. $Management[] = array("id"=>1 ,
  1514. "title"=>"KPI",
  1515. "switchValue"=>true,
  1516. "text"=>"Pie chart showing figures of shipments KPI of Departure and Arrival.");
  1517. $Management[] = array("id"=>2 ,
  1518. "title"=>"Pending",
  1519. "switchValue"=>true,
  1520. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1521. $Management[] = array("id"=>3 ,
  1522. "title"=>"ETD to ETA (Days)",
  1523. "switchValue"=>true,
  1524. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1525. $Management[] = array("id"=>4 ,
  1526. "title"=>"Container Count",
  1527. "switchValue"=>true,
  1528. "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
  1529. // if(_isRevenueDisplay()){
  1530. // $Management[] = array("id"=>5 ,
  1531. // "title"=>"Revenue Spent",
  1532. // "switchValue"=>true,
  1533. // "text"=>"Revenue data for the past 12 months.");
  1534. // }
  1535. $Management[] = array("id"=>6 ,
  1536. "title"=>"Top 10 Origin/Destination",
  1537. "switchValue"=>true,
  1538. "text"=>"Figure of the top 10 origin/destination.",
  1539. "title1"=>"Top 10 Origin",
  1540. "title2"=>"Top 10 Destination");
  1541. $Management[] = array("id"=>7 ,
  1542. "title"=>"CO2e Emission by Origin (Top 10)",
  1543. "switchValue"=>true,
  1544. "text"=>"Figure of the CO2e Emission by origin.");
  1545. $Management[] = array("id"=>8 ,
  1546. "title"=>"CO2e Emission by Destination (Top 10)",
  1547. "switchValue"=>true,
  1548. "text"=>"Figure of the CO2e Emission by destination.");
  1549. $Management[] = array("id"=>9 ,
  1550. "title"=>"Recent Status",
  1551. "switchValue"=>true,
  1552. "text"=>"A shipment list with latest status update on top.");
  1553. return $Management;
  1554. }
  1555. /**
  1556. * Destroy Session
  1557. */
  1558. public static function sessionDestroy() {
  1559. session_destroy();
  1560. setcookie(session_name(), '', time() - 3600);
  1561. $_SESSION = array();
  1562. }
  1563. public static function dateFormatToYM($dateString){
  1564. $date = DateTime::createFromFormat('m/Y', $dateString);
  1565. $formattedDate = $date->format('Y-m'); // YYYY-MM
  1566. return $formattedDate;
  1567. }
  1568. public static function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
  1569. $stationInfo = "";
  1570. if(!empty($address_1)){
  1571. $stationInfo .= $address_1;
  1572. }
  1573. if(!empty($address_2)){
  1574. $stationInfo .= " ".$address_2;
  1575. }
  1576. if(!empty($address_3)){
  1577. $stationInfo .= " ".$address_3;
  1578. }
  1579. if(!empty($address_4)){
  1580. $stationInfo .= " ".$address_4;
  1581. }
  1582. $temp_str = "";
  1583. if(!empty($city)){
  1584. $temp_str .= $city." ";
  1585. }
  1586. if(!empty($state)){
  1587. $temp_str .= $state." ";
  1588. }
  1589. if(!empty($zipcode)){
  1590. $temp_str .= $zipcode." ";
  1591. }
  1592. if(!empty($country)){
  1593. $temp_str .= $country." ";
  1594. }
  1595. if(!empty($temp_str)){
  1596. return $stationInfo." ".trim($temp_str);
  1597. }
  1598. return $stationInfo;
  1599. }
  1600. public static function getInsertSqlNull($table_name, $values) {
  1601. $field = "";
  1602. $value = "";
  1603. foreach ($values as $k => $v) {
  1604. if ($k == 'tmp' || $k == 'action' || $k == 'operate' || $k == 'x' || $k == 'y') {
  1605. continue;
  1606. }
  1607. if (is_array($v)) {
  1608. $v = utils::implode(",", $v);
  1609. }
  1610. if (empty($field)) {
  1611. $field = $k;
  1612. if (utils::checkExist($v, 'now()')) {
  1613. $value = $v;
  1614. } elseif ($v == null) {
  1615. $value .= 'null';
  1616. } elseif ($v == 'TRUE' || $v == 'FALSE') {
  1617. $value .= $v;
  1618. } else {
  1619. $value = '\'' . common::check_input($v) . '\'';
  1620. }
  1621. } else {
  1622. $field .= ',' . $k;
  1623. if (utils::checkExist($v, 'now()'))
  1624. $value .= ', now()';
  1625. elseif ($v == null) {
  1626. $value .= ',null';
  1627. } else if ($v == 'TRUE' || $v == 'FALSE') {
  1628. $value .= ',' . $v;
  1629. } else {
  1630. $value .= ', \'' . common::check_input($v) . '\'';
  1631. }
  1632. }
  1633. }
  1634. return 'insert into ' . $table_name . '(' . $field . ') values (' . $value . ')';
  1635. }
  1636. //密码规则验证
  1637. public static function checkPasswordRule($login, $new_password){
  1638. $sql="select item_value from config where item='passwordCheckRules'";
  1639. $rs = common::excuteObjectSql($sql);
  1640. $str = "";
  1641. if (!empty($rs)) {
  1642. $passwordCheckRules = json_decode($rs["item_value"],true);
  1643. //校验使用次数
  1644. if (!empty($passwordCheckRules["pastPasswordCheckNum"])) {
  1645. $sql = "select password from public.ra_online_user_password_history where lower(user_login)='".common::check_input(strtolower($login))."' order by id desc limit ".$passwordCheckRules["pastPasswordCheckNum"];
  1646. $passwords = common::excuteListSql($sql);
  1647. foreach ($passwords as $pwd) {
  1648. if ($pwd['password'] == $new_password) {
  1649. $str = "This password has been recently used";
  1650. }
  1651. }
  1652. }
  1653. if(empty($str)){
  1654. $str = utils::checkPassword($new_password,$passwordCheckRules,$login);
  1655. }
  1656. }else{
  1657. $str = utils::checkPassword($new_password);
  1658. }
  1659. return $str;
  1660. }
  1661. public static function getMilestonesInfo($ocean,$EDI315TimeAndLocation){
  1662. //Milestones info列名固定
  1663. $Milestones_column = array();
  1664. $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
  1665. $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
  1666. $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
  1667. $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
  1668. //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
  1669. $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($ocean);
  1670. //Milestones 数据信息待定
  1671. $Milestones_data = array();
  1672. $Milestones_data_arr = common::excuteListSql("select sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
  1673. remark,timezone,a.code
  1674. from public.ocean_milestone a
  1675. inner join public.customer_service_milestone_sno sn on sn.code=a.code
  1676. where a.serial_no='".$ocean["serial_no"]."' and act_date is not null order by sn.sno asc");
  1677. foreach($Milestones_data_arr as $mda){
  1678. $timezone = "";
  1679. if(!empty($EDI315TimeAndLocation[$mda['code']])){
  1680. $edi315Info = $EDI315TimeAndLocation[$mda['code']];
  1681. if(!empty($edi315Info)){
  1682. $timezone = $edi315Info['timezone'];
  1683. }
  1684. //IFFICC 比较特殊用EDI的locations
  1685. if($mda['code'] == "IFFICC"){
  1686. $IFFICC_locations = $edi315Info['location'];
  1687. }
  1688. }else{
  1689. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1690. if(!empty($edi315Info)){
  1691. $timezone = $edi315Info['timezone'];
  1692. }
  1693. }
  1694. //locations 以配置的信息为准
  1695. $locations = "";
  1696. $edi315Info = $Milestones_NO_Mapping[$mda['code']];
  1697. if(!empty($edi315Info)){
  1698. $locations = $edi315Info['location'];
  1699. if($mda['code'] == "IFFICC" && !empty($IFFICC_locations)){
  1700. $locations = $IFFICC_locations;
  1701. }
  1702. }
  1703. $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
  1704. "locations" => $locations, "remarks" =>$mda['remark']);
  1705. }
  1706. $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
  1707. return $Milestones;
  1708. }
  1709. /**
  1710. * 查询uncode 对应的时区
  1711. */
  1712. public static function getCityPortsInfo($uncodes){
  1713. $data =array();
  1714. $sql = "select time_zone as timezonecode,uncode as ctrycitycode from public.city_timezone where lower(uncode) ". common::getInNotInSql($uncodes);
  1715. $uncode_rs = common::excuteListSql($sql);
  1716. foreach($uncode_rs as $value){
  1717. $data[$value['ctrycitycode']] = $value['timezonecode'];
  1718. }
  1719. return $data;
  1720. }
  1721. /**
  1722. * EDI315 有关联查询,以那个为准。但是如果是手工录入或者没有对应的情况,这以这个为准
  1723. */
  1724. public static function getMilestones_NO_Mapping_Data($ocean){
  1725. $Milestones_NO_Mapping = array();
  1726. //取origin $ocean['aa_city'] 不是必需,对应文件里未提location来源
  1727. $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1728. $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1729. $Milestones_NO_Mapping['IFFCPU'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1730. $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1731. $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1732. $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
  1733. //Place of Receipt
  1734. $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1735. $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
  1736. //Port of loading
  1737. $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1738. $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
  1739. //取destination $ocean['dd_city']不是必需
  1740. $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1741. $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
  1742. //取Port of discharge
  1743. $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1744. $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1745. $Milestones_NO_Mapping['IFFICC'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
  1746. //Place of Delivery
  1747. $Milestones_NO_Mapping['IFFAFD'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1748. $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1749. $Milestones_NO_Mapping['IFFADW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1750. $Milestones_NO_Mapping['IFFDDW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1751. $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1752. $Milestones_NO_Mapping['IFFECR'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
  1753. //final_destination $ocean['fd_city']不是必需
  1754. $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1755. $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['_fd_timezone'],"location"=>"");
  1756. return $Milestones_NO_Mapping;
  1757. }
  1758. /**
  1759. * 这个详细查询已经带模式了
  1760. */
  1761. public static function getEDI315StatusForDetail($serial_no){
  1762. $data = array();
  1763. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no
  1764. WHERE o.serial_no='$serial_no'";
  1765. $ctnr_data = common::excuteListSql($ctnr_sql);
  1766. $containerStatusData = array();
  1767. $VD = "";
  1768. $VA = "";
  1769. foreach ($ctnr_data as $cd){
  1770. //存在柜号为空的数据情况
  1771. if(empty($cd['ctnr'])){
  1772. continue;
  1773. }
  1774. //(select uncity from public.ports where uncode = s.event_code) as uncity, 按新版的逻辑这个先取消掉
  1775. $ctnr_status_sql = "select s.source_id, s.event_base as event,
  1776. to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
  1777. to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
  1778. e.description,s.event_type as eventtype,
  1779. s.event_code as eventcode, s.event_city as eventcity,
  1780. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1781. '' as uncity,
  1782. case when event ='I' or event ='TR' then 'IFFREC'::text
  1783. when event ='AE' then 'IFFONB'::text
  1784. when event ='VD' then 'IFFDEP'::text
  1785. when event ='EB' or event ='VA' then 'IFFARR'::text
  1786. when event ='UV' then 'IFFUND'::text
  1787. when event ='VA' then 'IFFAFD'::text
  1788. when event ='AV' then 'IFFCTA'::text
  1789. when event ='CT' then 'IFFICC'::text
  1790. when event ='OA' or event ='D' then 'IFFPPD'::text
  1791. when event ='RD' then 'IFFECR'::text
  1792. when event ='EE' then 'IFFECP'::text
  1793. else '' ::text
  1794. end as milestone_code
  1795. from public.ra_online_container_status_v s
  1796. left join public.ra_online_edi_event e on s.event_base = e.ra_name
  1797. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1798. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1799. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  1800. to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
  1801. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1802. //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
  1803. $container_status_column = array("EE","I","AE","VD","VA");
  1804. $containerStatusDataTemp = array();
  1805. $content = array();
  1806. //按顺序处理 新版只显示几个状态
  1807. //foreach($container_status_column as $status){
  1808. foreach($ctnr_status as $event){
  1809. //if(strtolower($event['event']) == strtolower($status)){
  1810. $eventdate = $event["eventdate"];
  1811. if (empty($event["source_id"]) || $event["source_id"]==0) {
  1812. $eventdate.= " " . $event["eventtime"];
  1813. }
  1814. $location_code = $event["eventcode"];
  1815. $content[] = array("code" =>$event['event'],"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone']);
  1816. if(strtolower($event['event']) == "vd" && !empty($eventdate)){
  1817. $VD = $eventdate;
  1818. }
  1819. if(strtolower($event['event']) == "va" && !empty($eventdate)){
  1820. $VA = $eventdate;
  1821. }
  1822. //}
  1823. }
  1824. //}
  1825. //记录所有的信息
  1826. $EDI315TimeAndLocation = array();
  1827. foreach($ctnr_status as $event){
  1828. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1829. //如果存在EB 的EB 的优先级最高
  1830. continue;
  1831. }
  1832. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1833. //如果存在OA 的OA 的优先级最高
  1834. continue;
  1835. }
  1836. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
  1837. }
  1838. $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
  1839. $containerStatusDataTemp['content'] = $content;
  1840. $containerStatusData[] = $containerStatusDataTemp;
  1841. }
  1842. $data['containerStatusData'] = $containerStatusData;
  1843. $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
  1844. $data['VD'] = $VD;
  1845. $data['VA'] = $VA;
  1846. return $data;
  1847. }
  1848. public static function getEDI315Time($serial_no,$_schemas){
  1849. //Timezone From 来自于EDI315
  1850. $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM $_schemas.oc_container oc LEFT JOIN $_schemas.ocean o ON oc.serial_no = o.serial_no
  1851. WHERE o.serial_no='$serial_no'";
  1852. $ctnr_data = common::excuteListSql($ctnr_sql);
  1853. $EDI315TimeAndLocation = array();
  1854. foreach ($ctnr_data as $cd){
  1855. //存在柜号为空的数据情况
  1856. if(empty($cd['ctnr'])){
  1857. continue;
  1858. }
  1859. $ctnr_status_sql = "select
  1860. (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
  1861. case when event ='I' or event ='TR' then 'IFFREC'::text
  1862. when event ='AE' then 'IFFONB'::text
  1863. when event ='VD' then 'IFFDEP'::text
  1864. when event ='EB' or event ='VA' then 'IFFARR'::text
  1865. when event ='UV' then 'IFFUND'::text
  1866. when event ='VA' then 'IFFAFD'::text
  1867. when event ='AV' then 'IFFCTA'::text
  1868. when event ='CT' then 'IFFICC'::text
  1869. when event ='OA' or event ='D' then 'IFFPPD'::text
  1870. when event ='RD' then 'IFFECR'::text
  1871. when event ='EE' then 'IFFECP'::text
  1872. else '' ::text
  1873. end as milestone_code
  1874. from public.ra_online_container_status_v s
  1875. left join public.ra_online_edi_event e on s.event_base = e.ra_name
  1876. where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "'
  1877. and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true
  1878. order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
  1879. to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
  1880. $ctnr_status = common::excuteListSql($ctnr_status_sql);
  1881. //记录所有的信息、替换最后一个柜子
  1882. $EDI315TimeAndLocation = array();
  1883. foreach($ctnr_status as $event){
  1884. if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
  1885. //如果存在EB 的EB 的优先级最高
  1886. continue;
  1887. }
  1888. if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
  1889. //如果存在OA 的OA 的优先级最高
  1890. continue;
  1891. }
  1892. $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone']);
  1893. }
  1894. }
  1895. return $EDI315TimeAndLocation;
  1896. }
  1897. // public static function getAirSql($air_view,$type,$sql_where){
  1898. // $r3_r4_sql = "";
  1899. // if($type == 'ata_r3'){
  1900. // $r3_r4_sql = "select count(1) as count, '0 Day' as distext
  1901. // from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1
  1902. // union all
  1903. // select count(1) as count, '1-2 Days' as distext
  1904. // from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2
  1905. // union all
  1906. // select count(1) as count, '3-6 Days' as distext
  1907. // from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6
  1908. // union all
  1909. // select count(1) as count, '7 Days' as distext
  1910. // from ($air_view) aa where 1=1 $sql_where and ata >= etd and (ata-etd) >= 6";
  1911. // }
  1912. // if($type == 'atd_r4'){
  1913. // $r3_r4_sql ="select count(1) as count, ''0 Day'' as distext
  1914. // from ($air_view) aa where 1=1 $sql_where and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1
  1915. // union all
  1916. // select count(1) as count, ''1-2 Days'' as distext
  1917. // from ($air_view) aa where 1=1 $sql_where and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2
  1918. // union all
  1919. // select count(1) as count, ''3-6 Days'' as distext
  1920. // from ($air_view) aa where 1=1 $sql_where and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6
  1921. // union all
  1922. // select count(1) as count, ''7 Days'' as distext
  1923. // from ($air_view) aa where 1=1 $sql_where and and atd >= etd and (atd-etd) >= 6";
  1924. // }
  1925. // return $r3_r4_sql;
  1926. // }
  1927. // public static function getTopBarSQL($toporiginType,$transportation,$sqlWhere,$air_v){
  1928. // if(!is_array($transportation)){
  1929. // $transportation = array($transportation);
  1930. // }
  1931. // if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
  1932. // $transportation = array("Ocean","Air","Road");
  1933. // }
  1934. // //处理生成TopBarSQL
  1935. // $_tmp_table = "";
  1936. // foreach($transportation as $mode){
  1937. // if($mode == "Ocean"){
  1938. // if(empty($_tmp_table))
  1939. // $_tmp_table .= "select shippr_uncode,shipper_city from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
  1940. // else
  1941. // $_tmp_table .= "union all select shippr_uncode,shipper_city from online_ocean where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
  1942. // }
  1943. // if($mode == "Air"){
  1944. // if(empty($_tmp_table))
  1945. // $_tmp_table .= "select shippr_uncode,shipper_city from $air_v where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
  1946. // else
  1947. // $_tmp_table .= "union all select shippr_uncode,shipper_city from $air_v where 1=1 and COALESCE(shippr_uncode,'')<>'' $sqlWhere";
  1948. // }
  1949. // if($mode == "Road"){
  1950. // }
  1951. // }
  1952. // //虽然air 没有地图信息,但是坐标查询为空的过滤掉
  1953. // $TopBarSQL = "with aa as (select count(shippr_uncode) as num,shippr_uncode,
  1954. // (array_agg(shipper_city))[1] AS shipper_city from ($_tmp_table) as _tmp group by shippr_uncode order by num desc limit 10)
  1955. // select aa.*,dd.* from aa
  1956. // left join LATERAL ( select lon as lng, lat as lat,
  1957. // '' as label, '' as infor, 3 as sort,
  1958. // null::timestamp without time zone as stime,''::text as ptype
  1959. // from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=aa.shippr_uncode ) dd on true";
  1960. // return $TopBarSQL;
  1961. // }
  1962. }
  1963. ?>