| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of operation_log
- *
- * @author Administrator
- */
- class tools {
- private static $_tools;
- public static function getInstance() {
- if (!self::$_tools) {
- $c = __CLASS__;
- self::$_tools = new $c;
- }
- return self::$_tools;
- }
- /*
- * update password when login success
- */
- public function updatePassword() {
- if ($_SESSION['ONLINE_USER']['is_demo'] == "t") {
- $str = "DEMO cannot update password.";
- } else {
- $opsw = common::check_input($_POST ['opsw']);
- $npsw = common::check_input($_POST ['npsw']);
- $username = _getLoginName();
- $msg = common::checkPasswordRule($username, $npsw);
- //为空代表验证通过
- if (empty($msg)) {
- $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($username) . "'";
- $rs = common::excuteObjectSql($sql);
- $str = '';
- if (!empty($rs)) {
- if ($rs['password'] == $opsw) {
- $sql = "UPDATE ra_online_user SET ra_password = '" . $npsw . "', last_pwd_change = now() WHERE lower(user_login) = '" . strtolower($username) . "'";
- $rls = common::excuteUpdateSql($sql);
- if (!$rls) {
- $str = "Password modification failed!";
- } else {
- $str = " Your password has been modified!";
- }
- } else {
- $str = "Old password is incorrect!";
- }
- } else {
- $str = "Old password is incorrect!";
- }
- } else {
- $str = $msg;
- }
- }
- $returnData = array("msg" => $str);
- common::echo_json_encode(200, $returnData);
- exit();
- }
- public function markSystem(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "mark_save") {
- $suggestion = utils::implode(",",$_POST['suggestion']);
- $proposal = common::check_input($_POST['proposal']);
- $expression = common::check_input($_POST['expression']);
- $complete_funtionality = common::check_input($_POST['Complete_funtionality']);
- $accurate_data = common::check_input($_POST['Accurate_data']);
- $clear_information = common::check_input($_POST['Clear_information']);
- $easy_to_use = common::check_input($_POST['Easy_to_use']);
- $system_Performance = common::check_input($_POST['System_Performance']);
- $username = common::check_input($_POST['username']);
- $user_type = _isApexLogin() ? "employee" : "customer";
- if(!isset($_SESSION['ONLINE_USER'])){
- $user_type = "other";
- }
- $loginName = _getLoginName();
- $loginEamil = _getLoginEamil();
- //如果在没有登录前,没有登录信息,指定用户-- 这里逻辑取消,没有登录相当于匿名用户的评价,无法获取用户名
- // if(!isset($_SESSION['ONLINE_USER'])){
- // $user_type = "Customer";
- // if(!empty($username)){
- // $loginName = $username;
- // $loginEamil = common::excuteOneSql("select email from public.ra_online_user u where lower(user_login) = '" . strtolower($username) . "'");
- // }
- // }
- $sql = "INSERT INTO public.customer_service_user_mark(user_type, user_name, suggestion, proposal, expression, complete_funtionality,
- accurate_data, clear_information, easy_to_use, system_performance,
- created_time,email)
- VALUES ('$user_type', '$loginName', '$suggestion', '$proposal', '$expression', '$complete_funtionality',
- '$accurate_data', '$clear_information', '$easy_to_use', '$system_Performance', now(),'$loginEamil')";
- common::excuteUpdateSql($sql);
- $data = array("msg" =>"success");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- public function user_system_setting(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "personal_profile_init") {
- // get system config
- $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_password_change_cycle', 'customer_password_change_cycle')";
- $rs1s = common::excuteListSql($sql);
- foreach ($rs1s as $rs1) {
- if ($rs1['ra_name'] == 'employee_password_change_cycle')
- $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_password_change_cycle')
- $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- }
- $sql="select item_value from config where item='passwordChangePeriod'";
- $pcp = common::excuteObjectSql($sql);
- $passwordChangePeriod = json_decode($pcp["item_value"],true);
- if (_isApexLogin()) {
- $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
- }
- } else {
- $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
- }
- }
-
- $sql = "select u.first_name,u.last_name,u.user_login,u.email,EXTRACT(DAY from (now() - u.last_pwd_change)) as last_pwd_change_date,
- ue.date_format,ue.numbers_format
- from public.ra_online_user u
- left join public.kln_user_extend ue on u.user_login = ue.user_login
- where lower(u.user_login) = '".strtolower(_getLoginName())."' ";
- $data = common::excuteObjectSql($sql);
- $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "personal_profile_save") {
- $save_model = common::check_input($_POST['save_model']);
- if ($save_model == "profile"){
- $first_name = common::check_input($_POST['first_name']);
- $last_name = common::check_input($_POST['last_name']);
- $sql = "update public.ra_online_user set first_name = '$first_name',last_name = '$last_name' where lower(user_login) = '".strtolower(_getLoginName())."'";
- }else{
- $date_format = common::check_input($_REQUEST['date_format']);
- $numbers_format = common::check_input($_REQUEST['numbers_format']);
- $exist_kln_user = common::excuteObjectSql("select user_login from public.kln_user_extend where lower(user_login) = '".strtolower(_getLoginName())."'");
- if (!empty($exist_kln_user['user_login'])){
- $sql = "update public.kln_user_extend set date_format = '$date_format',numbers_format = '$numbers_format' where lower(user_login) = '".strtolower(_getLoginName())."'";
- } else {
- $sql = "INSERT INTO public.kln_user_extend(user_login, date_format, numbers_format, subscribe_hbol)
- VALUES ('"._getLoginName()."', '$date_format', '$numbers_format', null);";
- }
- }
- common::excuteUpdateSql($sql);
- $data = array("msg" => "save Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_notification_default_init"){
- $default_time_zone = common::check_input($_POST['default_time_zone']);
- $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
- //检查用户是否是设置过subscribe_notification
- $count = common::excuteOneSql("select count(*) from public.notifications_rules where
- notifications_type = 'Subscribe'
- and lower(user_login) = '".strtolower(_getLoginName())."'");
- if( $count > 0){
-
- } else {
- //手动的保存两条,通用默认规则
- $sql="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type, ocean_milestone,
- air_milestone, frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('"._getLoginName()."', 'Subscribe', 'Milestone_Update', 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFDEP;IFFCSN;IFFARR;IFFAFD;IFFECR;IFFDEL',
- 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFARR;IFFADW;IFFDDW;IFFDEL', 'Daily', '09:00', '$default_time_zone_db',
- '', null, '', 'false', 'true',
- 'Ocean Milestones: Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,On Board,Departure,Arrival Notification,Arrived at Final Discharge Port,Arrived at Final Destination,Empty Container Return,Document Turnover / Delivered;
- Air Milestones: Booking Confirmation,Cargo Pickup,Cargo Arrived at CFS,Departure,Landed at Destination Port,Arrived Destination Warehouse,Departed Destination Warehouse,Document Turnover / Delivered;', 'Daily, 09:00, ".$default_time_zone."', 'System Message','',
- '','','','','');";
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type,
- ocean_etd_change, ocean_etd_old_sub_new,ocean_etd_old_sub_new_unit,ocean_eta_change,ocean_eta_old_sub_new,ocean_eta_old_sub_new_unit,
- air_etd_change, air_etd_old_sub_new,air_etd_old_sub_new_unit,air_eta_change,air_eta_old_sub_new,air_eta_old_sub_new_unit,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('"._getLoginName()."', 'Subscribe', 'ETD/ETA_Change',
- 'false','','','false','1','days',
- 'false','','','false','1','days',
- 'Daily', '09:00', '$default_time_zone_db',
- '', null, '', 'false', 'true',
- '[Ocean]ETA: Notify only when time difference ≥ 1 Day(s);
- [Air]ETA: Notify only when time difference ≥ 1 Day(s);', 'Daily, 09:00, ".$default_time_zone."', 'System Message','',
- '','','','','');";
- $rs = common::excuteUpdateSql($sql);
- if (!$rs) {
- $data = array("msg" => "Subscribe Notification Initialized Error");
- common::echo_json_encode(500,$data);
- exit();
- }
- }
- $data = array("msg"=>"Has been initialized");
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_notification_init") {
- $subscribur_data =array();
- //查询用户对应的Rule
- $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
- TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
- from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
- foreach($all_rules as $rule_name){
- $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
- $subscribur_data[$rule_name] = $rules;
- }
- //整合拼接addedRules
- $addedRules = array();
- foreach($subscribe_rules as $addedRule){
- $addedRules[] = array(
- "visible" => false,
- "id" =>$addedRule['id'],
- "Event" =>$addedRule['rules_type'],
- "Event Details" =>$addedRule['event_details'],
- "Frequency" =>$addedRule['frequency_display'],
- "Methods" =>$addedRule['method_display']);
- }
- $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
- //获取subscribe shipment 当前页数cp,每页ps
- $subscribeShipmentWithPage = $this->getSubscribeShipment(1,15);
- $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
- common::echo_json_encode(200,$subscribur_data);
- exit();
- }
- if ($operate == "subscribe_notification_event_update"){
- $rules_type = common::check_input($_POST["rules_type"]);
- //判断该规则是否存在
- $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
- and lower(user_login) = '".strtolower(_getLoginName())."'");
- //检查参数是否正常
- $err = $this->checkedNotificationParam();
- if(!empty($err)){
- $data = array("msg" =>"Parameter error: ".$err);
- common::echo_json_encode(500,$data);
- exit();
- }
- $updateOrInsert = empty($exist) ? "insert" : "update";
- $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
- $rs = common::excuteUpdateSql($sql);
- if ($rs === FALSE){
- $data = array("msg" => "Update Error");
- } else{
- $data = array("msg" => "Update Successful");
- //返回addedRules 全部列表
- $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- //整合拼接addedRules
- $addedRules = array();
- foreach($subscribe_rules as $addedRule){
- $addedRules[] = array(
- "id" =>$addedRule['id'],
- "Event" =>$addedRule['rules_type'],
- "Event Details" =>$addedRule['event_details'],
- "Frequency" =>$addedRule['frequency_display'],
- "Methods" =>$addedRule['method_display']);
- }
- $data['addedRules'] = array("tableData"=>$addedRules);
- }
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_notification_rules_delete"){
- $rules_type = common::check_input($_POST['rules_type']);
- $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
- and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Delete Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_shipment"){
- $serial_no = common::deCode($_POST['serial_no'], 'D');
- $is_subscribe = common::check_input($_POST['is_subscribe']);
- if($is_subscribe == "true"){
- $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
- if(!empty($exist)){
- $data = array("msg" => "Subscribe exist,Please check");
- common::echo_json_encode(200,$data);
- exit();
- }
-
- $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
- VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Subscribe Successful");
- common::echo_json_encode(200,$data);
- exit();
- }else{
- //取消订阅
- $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Cancel Subscribe successfully");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- if ($operate == "subscribe_shipment_search"){
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- $arrTmp = $this->getSubscribeShipment($cp,$ps);
- common::echo_json_encode(200,$arrTmp);
- exit();
- }
- }
- public function user_monitoring_setting(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "monitoring_rules_init"){
- $ret = array();
- //Milestone Update的页面配置数据
- $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
- $oceanMilestone = array();
- $airMilestone = array();
- foreach($milestones as $milestone){
- if($milestone['type'] == "air"){
- $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
- }
- if($milestone['type'] == "sea"){
- $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
- }
- }
- $ret["OceanCheckBoxList"] = $oceanMilestone;
- $ret["AirCheckBoxList"] = $airMilestone;
- //Milestone Update的结构处理
- //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
- //$event =common::getEDICtnrEvent();
- $event = common::excuteListSql("select ra_name as event_name,ra_order,description
- from public.ra_online_edi_event e
- where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
- $ctnrStatus = array();
- foreach($event as $e){
- $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
- }
- $ret["CtnrCheckBoxList"] = $ctnrStatus;
- common::echo_json_encode(200,$ret);
- exit();
- }
- if ($operate == "monitoring_rules_search") {
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 15;
- $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
- $rc = common::excuteOneSql($sql);
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "select *,replace(rules_type, '_', ' ') AS _rules_type_display,
- case when rules_type = 'Milestone_Update' then 'Milestone'
- when rules_type = 'Container_Status_Update' then 'Container'
- when rules_type = 'Departure/Arrival_Delay' then 'Departure'
- when rules_type = 'ETD/ETA_Change' then 'ETDChange'
- else '' end as notifications_option
- from public.notifications_rules
- where lower(user_login) = '".strtolower(_getLoginName())."'
- and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
- $monitoringRules = common::excuteListSql($sql);
- $arrTmp = array('monitoringRules' => $monitoringRules,
- 'rc' => intval($rc),
- 'ps' => intval($ps),
- 'cp' => intval($cp),
- 'tp' => intval($tp)
- );
- } else {
- $arrTmp = array('monitoringRules' => array(),
- 'rc' => intval($rc),
- 'ps' => intval($ps),
- 'cp' => intval($cp),
- 'tp' => intval($tp)
- );
- }
- common::echo_json_encode(200,$arrTmp);
- exit();
- }
- if ($operate == "monitoring_rules_edit"){
- $id = $_POST['id'];
- $rules_type = common::check_input($_POST['rules_type']);
- $subscribe_rule_sql = "select *,
- TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
- TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time,
- case when rules_type = 'Milestone_Update' then 'Milestone'
- when rules_type = 'Container_Status_Update' then 'Container'
- when rules_type = 'Departure/Arrival_Delay' then 'Departure'
- when rules_type = 'ETD/ETA_Change' then 'ETDChange'
- else '' end as notifications_option
- from public.notifications_rules where notifications_type = 'Monitoring' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id' order by id";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- $rules = $this->getSubscribeRules($rules_type,$subscribe_rules);
-
- //数据转换前端需要的显示的格式
- $rules["shipment_transport_mode"] = utils::converModeToDisplay($rules["shipment_transport_mode"]);
- $monitoring_data[$rules_type] = $rules;
- common::echo_json_encode(200,$monitoring_data);
- exit();
- }
- if ($operate == "monitoring_rules_do") {
- $rules_type = common::check_input($_POST["rules_type"]);
- //检查参数是否正常
- $err = $this->checkedNotificationParam();
- if(!empty($err)){
- $data = array("msg" =>"Parameter error: ".$err);
- common::echo_json_encode(500,$data);
- exit();
- }
- //检查编辑提交的Monitoring规则,是否允许保存
- $msg = $this->checkedMonitoringRulesSave($rules_type);
- if(!empty($msg)){
- $data = array("msg" =>$msg);
- common::echo_json_encode(200,$data);
- exit();
- }
- $updateOrInsert = "insert";
- if(isset($_POST['id']) && !empty($_POST['id'])){
- $updateOrInsert = "update";
- }
- $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
- $rs = common::excuteUpdateSql($sql);
- if ($rs === FALSE){
- $data = array("msg" => "Update Error");
- } else{
- $data = array("msg" => "Update Successful");
- }
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "monitoring_rules_delete"){
- $id = common::check_input($_POST['id']);
- $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
- and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id'";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Delete Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- public function notifications_rules(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "notifications_init_old"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $milestoneData = array();
- $containerData = array();
- $delayData = array();
- $changeData = array();
- if ($rules_type == "all"){
- $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change;Feature_Update;Passwond_Notifcations";
- $allData = $this->getNotifications($rules_type,"all");
- $milestoneData = $allData['Milestone_Update'];
- $containerData = $allData['Container_Status_Update'];
- $delayData = $allData['Departure/Arrival_Delay'];
- $changeData = $allData['ETD/ETA_Change'];
- $featureUpdate = $allData['Feature_Update'];
- $passwond_Notifcations = $allData['Passwond_Notifcations'];
- } else {
- $data = $this->getNotifications($rules_type,"all");
- if($rules_type == "Milestone_Update"){
- $milestoneData = $data['Milestone_Update'];
- }elseif($rules_type == "Container_Status_Update"){
- $containerData = $data['Container_Status_Update'];
- }elseif($rules_type == "Departure/Arrival_Delay"){
- $delayData = $data['Departure/Arrival_Delay'];
- }elseif($rules_type == "ETD/ETA_Change"){
- $changeData = $data['ETD/ETA_Change'];
- }elseif($rules_type == "Feature_Update"){
- $featureUpdate = $data['Feature_Update'];
- }elseif($rules_type == "Passwond_Notifcations"){
- $passwond_Notifcations = $data['Passwond_Notifcations'];
- }
- }
- $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,
- "changeData"=>$changeData,"featureUpdate"=>$featureUpdate,"passwond_Notifcations"=>$passwond_Notifcations);
- $instant_sum = array();
- foreach($data as $v){
- if(!empty($v['instant'])){
- foreach($v['instant'] as $instant){
- $instant_sum[] = $instant;
- }
- }
- if(!empty($v['daily'])){
- $dailys = common::handleDailyWeekedData($v['daily']);
- foreach($dailys as $dailyArr){
- //取第一组的第一个显示
- $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
- $instant_sum[]= $dailyFristAndFrist;
- }
- }
- if(!empty($v['weekly'])){
- $weeklys = common::handleDailyWeekedData($v['weekly']);
- foreach($weeklys as $weeklyArr){
- $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
- $instant_sum[]= $weeklyFristAndFrist;
- }
- }
- }
- //根据时间顺序排序
- $insert_dates = array_column($instant_sum, 'insert_date');
- array_multisort($insert_dates, SORT_DESC, $instant_sum);
- $info = array();
- foreach($instant_sum as $mInfo){
- $eventCard = $this->getEventCard($mInfo);
- if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
- $info[] = array("notificationType"=>"password","info" =>$eventCard);
- }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
- $info[] = array("notificationType"=>"feature","info" =>$eventCard);
- }else{
- $info[] = array("notificationType"=>"event","info" =>$eventCard);
- }
- }
- $returnData = $info;
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if ($operate == "notifications_init"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- if ($rules_type == "all"){
- $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change;Feature_Update;Passwond_Notifcations";
- $data = $this->getNotificationsNew($rules_type,"all");
- } else {
- $data = $this->getNotificationsNew($rules_type,"all");
-
- }
- foreach($data as $k => $v){
- if($v['frequency_type'] == 'Daily' || $v['frequency_type'] == 'Weekly'){
- $numericRecords = $v['total_count'];
- $numericRecords_one = 0;
- $numericRecords_two = 0;
- if($v['notifiation_type'] == 'Departure/Arrival_Delay'){
- $numericRecords_one = $v['departure_count'];
- $numericRecords_two = $v['arrival_count'];
- }
- if ($v['notifiation_type'] == 'ETD/ETA_Change'){
- $numericRecords_one = $v['etd_count'];
- $numericRecords_two = $v['eta_count'];
- }
-
- $data[$k]["numericRecords"]= intval($numericRecords);
- //对Delay and change 特殊处理
- $data[$k]["numericRecords_one"]= intval($numericRecords_one);
- $data[$k]["numericRecords_two"]= intval($numericRecords_two);
- }
- }
- $info = array();
- foreach($data as $mInfo){
- $eventCard = $this->getEventCard($mInfo);
- if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
- $info[] = array("notificationType"=>"password","info" =>$eventCard);
- }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
- $info[] = array("notificationType"=>"feature","info" =>$eventCard);
- }else{
- $info[] = array("notificationType"=>"event","info" =>$eventCard);
- }
- }
- $returnData = $info;
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if($operate == "notifications_see_all_old"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
- $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
- $notificationsData = $this->getNotifications($rules_type,$frequency_type,$insert_date_format);
- $moreData = $notificationsData[$rules_type][strtolower($frequency_type)];
- //这个函数里面带有分开计数的信息
- $dataInfo =utils::getDailyAndweeklyFrist($moreData);
- $returnData = array();
- $notificationList = array();
- $ids = array();
- foreach($moreData as $key => $data){
- $eventCard = $this->getEventCard($data);
- //sea all的数据格式和查询全部的格式有区别
- if($key == 0){
- $returnData["title"] = $eventCard["title"];
- if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
- $returnData["etdOrdeparturNum"] = $dataInfo["numericRecords_one"];
- $returnData["etaOrarrivalNum"] =$dataInfo["numericRecords_two"];
- $returnData["type"] =$eventCard["type"];
- }else{
- $returnData["numericRecords"] = $dataInfo["numericRecords"];
- }
- }
- //移除不需要的字段
- unset($eventCard["title"]);
- $notificationList[] = $eventCard;
- $ids[] = $data['id'];
- }
- if(!empty($notificationList)){
- $returnData["notificationList"] = $notificationList;
- }
- //点击seall会默认全部标记为已读
- if(!empty($ids)){
- $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
- $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
- common::excuteUpdateSql($markReadSql);
- }
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if($operate == "notifications_see_all"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
- $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
- $moreData = $this->getNotificationsSeeAll($rules_type,$frequency_type,$insert_date_format);
- //这个函数里面带有分开计数的信息
- $dataInfo =utils::getDailyAndweeklyFrist($moreData);
- $returnData = array();
- $notificationList = array();
- $ids = array();
- foreach($moreData as $key => $data){
- $eventCard = $this->getEventCard($data);
- //sea all的数据格式和查询全部的格式有区别
- if($key == 0){
- $returnData["title"] = $eventCard["title"];
- if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
- $returnData["etdOrdeparturNum"] = $dataInfo["numericRecords_one"];
- $returnData["etaOrarrivalNum"] =$dataInfo["numericRecords_two"];
- $returnData["type"] =$eventCard["type"];
- }else{
- $returnData["numericRecords"] = $dataInfo["numericRecords"];
- }
- }
- //移除不需要的字段
- unset($eventCard["title"]);
- $notificationList[] = $eventCard;
- $ids[] = $data['id'];
- }
- if(!empty($notificationList)){
- $returnData["notificationList"] = $notificationList;
- }
- //点击seall会默认全部标记为已读
- if(!empty($ids)){
- $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
- $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
- common::excuteUpdateSql($markReadSql);
- }
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if($operate == "notifications_read"){
- $read_type = common::check_input($_POST["read_type"]);
- $id = $_POST["id"];
- //代表改用户下的所有信息全部标记为已读
- if ($read_type == "true"){
- $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where lower(user_login) in ('".strtolower(_getLoginName())."','all_user')");
- }else{
- //处理一下前端提交的不正确参数
- $param_id = array();
- foreach($id as $_ids){
- if(!empty($_ids)){
- $param_id[] = $_ids;
- }
- }
- if(empty($param_id)){
- //为空直接返回成功
- $returnData = array("msg" =>"Success");
- common::echo_json_encode(200,$returnData);
- }
- $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$param_id)));
- $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
- $rs = common::excuteUpdateSql($markReadSql);
- }
- if ($rs === FALSE){
- $returnData = array("msg" =>"Error");
- common::echo_json_encode(500,$returnData);
- }else{
- $returnData = array("msg" =>"Success");
- common::echo_json_encode(200,$returnData);
- }
- exit();
- }
- if ($operate == "notifications_message_init_old"){
- //查询所有情况得未读情况 查询最近一年的情况
- $unreadSql = "with countTbale as (
- select ni.notifiation_type,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format
- from public.kln_notifiation_info ni
- where ni.insert_date > NOW() - INTERVAL '3 months'
- and ni.notifications_method = 'true' and ni.is_send_message is null
- and lower(ni.user_login) = '".strtolower(_getLoginName())."'
- and ((ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))
- group by ni.notifiation_type,insert_date_format
- union all
- select ni.notifiation_type, '' as insert_date_format
- from public.kln_notifiation_info ni
- where ni.insert_date > NOW() - INTERVAL '3 months'
- and lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- and ni.notifications_method = 'true' and ni.is_send_message is null
- and frequency_type = 'Instant'
- )
- select
- sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as m_rc,
- sum(case when (1<>1 or (notifiation_type='Container_Status_Update')) then 1 else 0 end) as cs_rc,
- sum(case when (1<>1 or (notifiation_type='Departure/Arrival_Delay')) then 1 else 0 end) as da_rc,
- sum(case when (1<>1 or (notifiation_type='ETD/ETA_Change')) then 1 else 0 end) as ec_rc,
- sum(case when (1<>1 or (notifiation_type='Feature_Update')) then 1 else 0 end) as f_rc
- from countTbale ";
- $count = common::excuteObjectSql($unreadSql);
- //单独的选中的数据
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $data = $this->getNotifications($rules_type,"all");
- $unreadCount = 0;
- $readCount = 0;
- $instant_sum = array();
- if(!empty($data[$rules_type]['instant'])){
- foreach($data[$rules_type]['instant'] as $instant){
- $instant_sum[] = $instant;
- if(!empty($instant["is_send_message"])){
- $readCount +=1;
- }else{
- $unreadCount +=1;
- }
- }
- }
- if(!empty($data[$rules_type]['daily'])){
- $dailys = common::handleDailyWeekedData($data[$rules_type]['daily']);
- foreach($dailys as $dailyArr){
- //取第一组的第一个显示
- $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
- $instant_sum[]= $dailyFristAndFrist;
- if(!empty($dailyFristAndFrist["is_send_message"])){
- $readCount +=1;
- }else{
- $unreadCount +=1;
- }
- }
- }
- if(!empty($data[$rules_type]['weekly'])){
- $weeklys = common::handleDailyWeekedData($data[$rules_type]['weekly']);
- foreach($weeklys as $weeklyArr){
- $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
- $instant_sum[]= $weeklyFristAndFrist;
- if(!empty($weeklyFristAndFrist["is_send_message"])){
- $readCount +=1;
- }else{
- $unreadCount +=1;
- }
- }
- }
- //根据时间顺序排序
- $insert_dates = array_column($instant_sum, 'insert_date');
- array_multisort($insert_dates, SORT_DESC, $instant_sum);
- $info = array();
- foreach($instant_sum as $mInfo){
- $eventCard = $this->getEventCard($mInfo);
- if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
- $info[] = array("notificationType"=>"password","info" =>$eventCard);
- }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
- $info[] = array("notificationType"=>"feature","info" =>$eventCard);
- }else{
- $info[] = array("notificationType"=>"event","info" =>$eventCard);
- }
- }
- //返回数据结构
- $returnData = array();
- $m_rc = empty($count['m_rc']) ? 0 : intval($count['m_rc']);
- $cs_rc = empty($count['cs_rc']) ? 0 : intval($count['cs_rc']);
- $da_rc = empty($count['da_rc']) ? 0 : intval($count['da_rc']);
- $ec_rc = empty($count['ec_rc']) ? 0 : intval($count['ec_rc']);
- $f_rc = empty($count['f_rc']) ? 0 : intval($count['f_rc']);
- $returnData['countList'] = array($m_rc,$cs_rc,$da_rc,$ec_rc,$f_rc);
- $returnData['allCount'] =count($instant_sum);
- $returnData['unreadCount'] =$unreadCount;
- $returnData['readCount'] =$readCount;
- $returnData['cardList'] =$info;
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if ($operate == "notifications_message_init"){
- //查询所有情况得未读情况 查询最近一年的情况
- $unreadSql = "with countTbale as (
- select ni.notifiation_type,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format
- from public.kln_notifiation_info ni
- where ni.insert_date > NOW() - INTERVAL '3 months'
- and ni.notifications_method = 'true' and ni.is_send_message is null
- and lower(ni.user_login) = '".strtolower(_getLoginName())."'
- and ((ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))
- group by ni.notifiation_type,insert_date_format
- union all
- select ni.notifiation_type, '' as insert_date_format
- from public.kln_notifiation_info ni
- where ni.insert_date > NOW() - INTERVAL '3 months'
- and lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- and ni.notifications_method = 'true' and ni.is_send_message is null
- and frequency_type = 'Instant'
- )
- select
- sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as m_rc,
- sum(case when (1<>1 or (notifiation_type='Container_Status_Update')) then 1 else 0 end) as cs_rc,
- sum(case when (1<>1 or (notifiation_type='Departure/Arrival_Delay')) then 1 else 0 end) as da_rc,
- sum(case when (1<>1 or (notifiation_type='ETD/ETA_Change')) then 1 else 0 end) as ec_rc,
- sum(case when (1<>1 or (notifiation_type='Feature_Update')) then 1 else 0 end) as f_rc
- from countTbale ";
-
- $count = common::excuteObjectSql($unreadSql);
- //单独的选中的数据
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $data = $this->getNotificationsNew($rules_type,"all");
- $unreadCount = 0;
- $readCount = 0;
- foreach($data as $k => $v){
- if(!empty($v["is_send_message"])){
- $readCount +=1;
- }else{
- $unreadCount +=1;
- }
- if($v['frequency_type'] == 'Daily' || $v['frequency_type'] == 'Weekly'){
- $numericRecords = $v['total_count'];
- $numericRecords_one = 0;
- $numericRecords_two = 0;
- if($v['notifiation_type'] == 'Departure/Arrival_Delay'){
- $numericRecords_one = $v['departure_count'];
- $numericRecords_two = $v['arrival_count'];
- }
- if ($v['notifiation_type'] == 'ETD/ETA_Change'){
- $numericRecords_one = $v['etd_count'];
- $numericRecords_two = $v['eta_count'];
- }
-
- $data[$k]["numericRecords"]= intval($numericRecords);
- //对Delay and change 特殊处理
- $data[$k]["numericRecords_one"]= intval($numericRecords_one);
- $data[$k]["numericRecords_two"]= intval($numericRecords_two);
- }
- }
- $info = array();
- foreach($data as $mInfo){
- $eventCard = $this->getEventCard($mInfo);
- if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
- $info[] = array("notificationType"=>"password","info" =>$eventCard);
- }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
- $info[] = array("notificationType"=>"feature","info" =>$eventCard);
- }else{
- $info[] = array("notificationType"=>"event","info" =>$eventCard);
- }
- }
- //返回数据结构
- $returnData = array();
- $m_rc = empty($count['m_rc']) ? 0 : intval($count['m_rc']);
- $cs_rc = empty($count['cs_rc']) ? 0 : intval($count['cs_rc']);
- $da_rc = empty($count['da_rc']) ? 0 : intval($count['da_rc']);
- $ec_rc = empty($count['ec_rc']) ? 0 : intval($count['ec_rc']);
- $f_rc = empty($count['f_rc']) ? 0 : intval($count['f_rc']);
- $returnData['countList'] = array($m_rc,$cs_rc,$da_rc,$ec_rc,$f_rc);
- $returnData['allCount'] =count($data);
- $returnData['unreadCount'] =$unreadCount;
- $returnData['readCount'] =$readCount;
- $returnData['cardList'] =$info;
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if ($operate == "check_notifications_message"){
- $checkUnread = "select id
- from public.kln_notifiation_info ni
- inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- from public.kln_ocean oo
- where oo.serial_no = ni.serial_no limit 1) ccc on true
- where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- AND ni.insert_date > NOW() - INTERVAL '3 months'
- and (ni.frequency_type = 'Instant'
- or (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))
- and ni.notifications_method = true and is_send_message is null limit 1";
- $unread = common::excuteObjectSql($checkUnread);
- $returnData = array("has_message" =>!empty($unread));
- common::echo_json_encode(200,$returnData);
- }
- }
- /**
- * 遍历查找对应的rule。
- */
- public function getSubscribeRules($rule_name,$subscribe_rules){
- //初始是不显示,没有值的情况
- $ret = array("is_display" => false);
- foreach($subscribe_rules as $rules){
- if($rules['rules_type'] == $rule_name){
- $rules["is_display"] = true;
- $rules["daily_time"] = $rules["_daily_time"];
- $rules["weekly_time"] = $rules["_weekly_time"];
- $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
- $rules["daily_time_zone"] = utils::comvertutcinfo($rules["daily_time_zone"]);
- $rules["weekly_time_zone"] = utils::comvertutcinfo($rules["weekly_time_zone"]);
- //字符串转数字
- $rules["ocean_atd_sub_etd"] = common::convertoint($rules["ocean_atd_sub_etd"]);
- $rules["ocean_ata_sub_eta"] = common::convertoint($rules["ocean_ata_sub_eta"]);
- $rules["air_atd_sub_etd"] = common::convertoint($rules["air_atd_sub_etd"]);
- $rules["air_ata_sub_eta"] = common::convertoint($rules["air_ata_sub_eta"]);
- $rules["ocean_etd_old_sub_new"] = common::convertoint($rules["ocean_etd_old_sub_new"]);
- $rules["ocean_eta_old_sub_new"] = common::convertoint($rules["ocean_eta_old_sub_new"]);
- $rules["air_etd_old_sub_new"] = common::convertoint($rules["air_etd_old_sub_new"]);
- $rules["air_eta_old_sub_new"] = common::convertoint($rules["air_eta_old_sub_new"]);
- $rules["shipment_etd_limit"] = common::convertoint($rules["shipment_etd_limit"]);
- $rules["shipment_eta_limit"] = common::convertoint($rules["shipment_eta_limit"]);
- $rules["shipment_etd_limit_from"] = common::convertoint($rules["shipment_etd_limit_from"]);
- $rules["shipment_eta_limit_from"] = common::convertoint($rules["shipment_eta_limit_from"]);
- // $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
- $rules["ocean_atd_sub_etd_unit"] = common::convertoVue($rules["ocean_atd_sub_etd_unit"]);
- $rules["ocean_ata_sub_eta_unit"] = common::convertoVue($rules["ocean_ata_sub_eta_unit"]);
- $rules["air_atd_sub_etd_unit"] = common::convertoVue($rules["air_atd_sub_etd_unit"]);
- $rules["air_ata_sub_eta_unit"] = common::convertoVue($rules["air_ata_sub_eta_unit"]);
- $rules["ocean_etd_old_sub_new_unit"] = common::convertoVue($rules["ocean_etd_old_sub_new_unit"]);
- $rules["ocean_eta_old_sub_new_unit"] = common::convertoVue($rules["ocean_eta_old_sub_new_unit"]);
- $rules["air_etd_old_sub_new_unit"] = common::convertoVue($rules["air_etd_old_sub_new_unit"]);
- $rules["air_eta_old_sub_new_unit"] = common::convertoVue($rules["air_eta_old_sub_new_unit"]);
-
- $ret = $rules;
- }
- }
- //Milestone Update的结构处理,处理init page load
- if($rule_name == "Milestone_Update"){
- //Milestone Update的页面配置数据
- $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
- $oceanMilestone = array();
- $airMilestone = array();
- foreach($milestones as $milestone){
- if($milestone['type'] == "air"){
- $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
- }
- if($milestone['type'] == "sea"){
- $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
- }
- }
- $ret["OceanCheckBoxList"] = $oceanMilestone;
- $ret["AirCheckBoxList"] = $airMilestone;
- $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
- $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
- $ret["OceanCheckedList"] = $oceanMilestoneSetting;
- $ret["AirCheckedList"] = $airMilestoneSetting;
- }
- //Milestone Update的结构处理
- if($rule_name == "Container_Status_Update"){
- //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
- //$event =common::getEDICtnrEvent();
- $event = common::excuteListSql("select ra_name as event_name,ra_order,description
- from public.ra_online_edi_event e
- where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
- $ctnrStatus = array();
- foreach($event as $e){
- $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
- }
- $ret["CtnrCheckBoxList"] = $ctnrStatus;
-
- $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
- $ret["CtnrCheckedList"] = $ctnrStatusSetting;
-
- }
- return $ret;
- }
- /**
- * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
- * cp current_page
- */
- public function getSubscribeShipment($cp,$ps){
- if (empty($cp)){
- $cp = 1;
- }
- if (empty($ps)){
- $ps = 15;
- }
- $sql = "select count(1) from public.kln_user_subscribed u
- inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
- where lower(user_login) = '".strtolower(_getLoginName())."'";
- $rc = common::excuteOneSql($sql);
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
- o.shipper,o.consignee,o.etd,o.eta,
- case when transport_mode = 'sea'
- then (select sn.description
- from public.ocean_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- when transport_mode = 'air' and order_from = 'public'
- then (select sn.description
- from public.air_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- when transport_mode = 'air' and order_from = 'sfs'
- then (select sn.description
- from sfs.air_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- else '' end as recent_milestone
- from public.kln_user_subscribed u
- inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
- where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
- $subscribeShipment = common::excuteListSql($sql);
- foreach($subscribeShipment as $key => $val){
- $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
- }
- $arrTmp = array('tableData' => $subscribeShipment,
- 'rc' => intval($rc),
- 'ps' => intval($ps),
- 'cp' => intval($cp),
- 'tp' => intval($tp)
- );
- } else {
- $arrTmp = array('tableData' => array(),
- 'rc' => intval($rc),
- 'ps' => intval($ps),
- 'cp' => intval($cp),
- 'tp' => intval($tp),
- );
- }
- return $arrTmp;
- }
- public function checkedNotificationParam(){
- $rules_type = common::check_input($_POST["rules_type"]);
- //先判断异常数据
- $msg = "";
- if ($rules_type == "Departure/Arrival_Delay"){
- $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
- if (!empty($ocean_atd_sub_etd) && !ctype_digit($ocean_atd_sub_etd)) {
- $msg = "Ocean Delayed(ATD-ETD) is not Number";
- }
-
- $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
- if (!empty($ocean_ata_sub_eta) && !ctype_digit($ocean_ata_sub_eta)) {
- $msg = "Ocean Delayed(ATA-ETA) is not Number";
- }
- $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
- if (!empty($air_atd_sub_etd) && !ctype_digit($air_atd_sub_etd)) {
- $msg = "Air Delayed(ATD-ETD) is not Number";
- }
- $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
- if (!empty($air_ata_sub_eta) && !ctype_digit($air_ata_sub_eta)) {
- $msg = "Air Delayed(ATA-ETA) is not Number";
- }
- }
- if ($rules_type == "ETD/ETA_Change"){
- $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
- if (!empty($ocean_etd_old_sub_new) && !ctype_digit($ocean_etd_old_sub_new)) {
- $msg = "Ocean Notify(ETD) is not Number";
- }
-
- $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
- if (!empty($ocean_eta_old_sub_new) && !ctype_digit($ocean_eta_old_sub_new)) {
- $msg = "Ocean Notify(ETA) is not Number";
- }
-
- $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
- if (!empty($air_etd_old_sub_new) && !ctype_digit($air_etd_old_sub_new)) {
- $msg = "Air Notify(ETD) is not Number";
- }
-
- $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
- if (!empty($air_eta_old_sub_new) && !ctype_digit($air_eta_old_sub_new)) {
- $msg = "Air Notify(ETA) is not Number";
- }
-
- }
- return $msg;
- }
- public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
- $sql = "";
- //先删后加 这个逻辑有移除
- // if($updateOrInsert == "update"){
- // $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
- // and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- // and id = '$id';";
- // }
- //这个几个参数是所有规则都有的参数
- $frequency_type = common::check_input($_POST['frequency_type']);
- $daily_time = "null";
- $daily_time_zone = "";
- $weekly_week = "";
- $weekly_time = "null";
- $weekly_time_zone = "";
- if(strtolower($frequency_type) == "daily"){
- $daily_time = "'".common::check_input($_POST['daily_time'])."'";
- $daily_time_zone = common::check_input($_POST['daily_time_zone']);
- $daily_time_zone = utils::comvertutcinfo($daily_time_zone);
- } elseif (strtolower($frequency_type) == "weekly"){
- $weekly_week = common::check_input($_POST['weekly_week']);
- $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
- $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
- $weekly_time_zone = utils::comvertutcinfo($weekly_time_zone);
- }
-
- $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
- $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
- $event_details = common::check_input($_POST['event_details']);
- $frequency_display = common::check_input($_POST['frequency_display']);
- $method_display = common::check_input($_POST['method_display']);
- $shipment_detail = common::check_input($_POST['shipment_details']);
- //当规则是 Monitoring类型是,需要配置的range
- $shipment_transport_mode = "";
- $shipment_etd_limit = "";
- $shipment_eta_limit = "";
- $shipment_etd_limit_from = "";
- $shipment_eta_limit_from = "";
- if($notifications_type == "Monitoring"){
- $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
- $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
- $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
- $shipment_etd_limit_from = common::check_input($_POST['shipment_etd_limit_from']);
- $shipment_eta_limit_from = common::check_input($_POST['shipment_eta_limit_from']);
- }
- if ($rules_type == "Milestone_Update"){
- $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
- $air_milestone = utils::implode(";",$_POST['air_milestone']);
- //改为update 不在是删除后添加,为了保留原始顺序
- if ($updateOrInsert == "update"){
- $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
- frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
- weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
- event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
- shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
- shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
- where rules_type = '$rules_type'
- and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id';";
- } else {
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type, ocean_milestone,
- air_milestone, frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
- '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
- }
- }
- if ($rules_type == "Container_Status_Update"){
- $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
- //改为update 不在是删除后添加,为了保留原始顺序
- if ($updateOrInsert == "update"){
- $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
- frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
- weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
- event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
- shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
- shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
- where rules_type = '$rules_type'
- and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id';";
- }else{
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type, ocean_ctnr_status,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
- }
- }
- if ($rules_type == "Departure/Arrival_Delay"){
- $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
- $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
- if(!empty($ocean_atd_sub_etd_unit)){
- $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
- }
- $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
- $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
- if(!empty($ocean_ata_sub_eta_unit)){
- $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
- }
- $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
- $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
- if(!empty($air_atd_sub_etd_unit)){
- $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
- }
- $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
- $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
- if(!empty($air_ata_sub_eta_unit)){
- $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
- }
- //改为update 不在是删除后添加,为了保留原始顺序
- if ($updateOrInsert == "update"){
- $sql.="update public.notifications_rules set
- ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
- ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
- air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
- air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
- frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
- weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
- event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
- shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
- shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
- where rules_type = '$rules_type'
- and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id';";
- }else{
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type,
- ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
- air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
- '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
- '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
- }
- }
- if ($rules_type == "ETD/ETA_Change"){
- $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
- $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
- $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
- if(!empty($ocean_etd_old_sub_new_unit)){
- $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
- $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
- $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
- if(!empty($ocean_eta_old_sub_new_unit)){
- $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
- $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
- $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
- if(!empty($air_etd_old_sub_new_unit)){
- $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
- $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
- $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
- if(!empty($air_eta_old_sub_new_unit)){
- $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- //改为update 不在是删除后添加,为了保留原始顺序
- if ($updateOrInsert == "update"){
- $sql.="update public.notifications_rules set
- ocean_etd_change = '$ocean_etd_change',ocean_etd_old_sub_new = '$ocean_etd_old_sub_new',ocean_etd_old_sub_new_unit = '$ocean_etd_old_sub_new_unit',
- ocean_eta_change = '$ocean_eta_change',ocean_eta_old_sub_new = '$ocean_eta_old_sub_new',ocean_eta_old_sub_new_unit = '$ocean_eta_old_sub_new_unit',
- air_etd_change = '$air_etd_change',air_etd_old_sub_new = '$air_etd_old_sub_new',air_etd_old_sub_new_unit = '$air_etd_old_sub_new_unit',
- air_eta_change = '$air_eta_change',air_eta_old_sub_new = '$air_eta_old_sub_new',air_eta_old_sub_new_unit = '$air_eta_old_sub_new_unit',
- frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
- weekly_week = '$weekly_week', weekly_time = $weekly_time, weekly_time_zone = '$weekly_time_zone', method_by_email = '$method_by_email',method_by_message = '$method_by_message',
- event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
- shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
- shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
- where rules_type = '$rules_type'
- and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id';";
- }else{
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type,
- ocean_etd_change, ocean_etd_old_sub_new,ocean_etd_old_sub_new_unit,ocean_eta_change,ocean_eta_old_sub_new,ocean_eta_old_sub_new_unit,
- air_etd_change, air_etd_old_sub_new,air_etd_old_sub_new_unit,air_eta_change,air_eta_old_sub_new,air_eta_old_sub_new_unit,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
- '$ocean_etd_change','$ocean_etd_old_sub_new','$ocean_etd_old_sub_new_unit','$ocean_eta_change','$ocean_eta_old_sub_new','$ocean_eta_old_sub_new_unit',
- '$air_etd_change','$air_etd_old_sub_new','$air_etd_old_sub_new_unit','$air_eta_change','$air_eta_old_sub_new','$air_eta_old_sub_new_unit',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
- }
- }
- //保存用户默认的时区
- $default_time_zone = common::check_input($_POST['default_time_zone']);
- $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
- $sql .= "update public.kln_user_extend set default_time_zone = '$default_time_zone_db' where lower(user_login) = '".strtolower(_getLoginName())."';";
- return $sql;
- }
- /**
- * 检查编辑提交的Monitoring规则,是否允许保存
- */
- public function checkedMonitoringRulesSave($rules_type){
- $sql_where = "";
- if(isset($_POST['id']) && !empty($_POST['id'])){
- $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
- }
- $rules = common::excuteListSql("select *,
- TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
- TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
- from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
- and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
- foreach($rules as $rule){
- //判断range 是否一样
- $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit","shipment_etd_limit_from","shipment_eta_limit_from");
- $range_flag = true;
- foreach($checkRangeFiled as $filed){
- if($filed == "shipment_transport_mode"){
- $postValue = utils::converModeToDB($_POST[$filed]);
- $rule_mode_arr = explode(";", $rule[$filed]);
- $post_mode_arr = explode(";", $postValue);
- if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
- $range_flag = false;
- }
- }else{
- //正常字段直接比较就行
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
- if($postValue != $dbValue){
- $range_flag = false;
- }
- }
- }
- //判断details 是否一样
- $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
- "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
- "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
- "ocean_etd_change","ocean_etd_old_sub_new","ocean_etd_old_sub_new_unit","ocean_eta_change","ocean_eta_old_sub_new","ocean_eta_old_sub_new_unit",
- "air_etd_change","air_etd_old_sub_new","air_etd_old_sub_new_unit","air_eta_change","air_eta_old_sub_new","air_eta_old_sub_new_unit");
- $details_flag = true;
- foreach($checkDetailsFiled as $filed){
- if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
- $rule_mode_arr = empty($rule[$filed])? array() :explode(";", $rule[$filed]);
- $post_mode_arr = $_POST[$filed];
- if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
- $details_flag = false;
- }
- } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
- $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
- if($post_boolean != $rule[$filed]){
- $details_flag = false;
- }
- } elseif ($filed == "ocean_atd_sub_etd_unit" || $filed == "ocean_ata_sub_eta_unit"
- || $filed == "air_atd_sub_etd_unit" || $filed == "air_ata_sub_eta_unit"
- || $filed == "ocean_etd_old_sub_new_unit" || $filed == "ocean_eta_old_sub_new_unit"
- || $filed == "air_etd_old_sub_new_unit" || $filed == "air_eta_old_sub_new_unit"){
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- if(!empty($postValue)){
- $postValue = $postValue=="Day(s)" ? "days":"hours";
- }
- $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
- if($postValue != $dbValue){
- $details_flag = false;
- }
- } else {
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
- if($postValue != $dbValue){
- $details_flag = false;
- }
- }
- }
-
- //判断frequency 是否一样
- $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
- "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
- $frequency_flag = true;
- foreach($checkFrequencyFiled as $filed){
- if($filed == "daily_time" || $filed == "weekly_time"){
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- //_daily_time _weekly_time
- $dbValue = !empty($rule["_".$filed]) ? $rule["_".$filed] : "";
- if($postValue != $dbValue){
- $frequency_flag = false;
- }
- } else {
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
- if($postValue != $dbValue){
- $frequency_flag = false;
- }
- }
- }
-
- //判断通知方式是否一样
- $checkMethodFiled = array("method_by_email","method_by_message");
- $method_flag = true;
- foreach($checkMethodFiled as $filed){
- $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
- if($postValue != $rule[$filed]){
- $method_flag = false;
- }
- }
- //五个条件一样,不允许保存
- if($range_flag && $details_flag && $frequency_flag && $method_flag){
- $msg = "Unable to Save";
- break;
- }
- //前三个重回,后面不重合,提示但允许保存
- if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
- $msg = "Similar Rule Detected";
- break;
- }
- }
- return $msg;
- }
- public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
- if ($frequency_type == "all"){
- //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
- //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
- $sql_where = " and (ni.frequency_type = 'Instant'
- or (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
-
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))";
- } elseif($frequency_type == "Daily"){
- $sql_where = " and (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))";
- } elseif($frequency_type == "Weekly"){
- //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
- // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
- // 如今天是4-14,最小边界值是4.8- 4.14
- // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
- // 当 前时间是 4.15时,但到规定的time,取4.15
- $sql_where = " and (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end))";
- }
- if (!empty($_REQUEST['current_time'])){
- // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
- // and ni.is_send_message is null";
- //这里都以服务器时间,检查标准
- $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
- }
- if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
- $sql_where .= " and ni.is_send_message is null";
- }
- //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
- $aa_where = "";
- if (!empty($insert_date_format)){
- $aa_where = " where insert_date_format = '$insert_date_format'";
- }
-
- $more_param = common::getInNotInSqlForSearch($notifiation_type);
- $sql = "select *
- from (select ni.*,
- case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
- else 0
- end as _delay_diff,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format,
- case when COALESCE(ni.frequency_type,'') = 'Instant'
- then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
- when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
- else ''
- end as first_notifiation_date,
- case when ni.notifiation_type ='Milestone_Update'
- then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
- else ''
- end as milestone_previous_json,
- case when ni.notifiation_type ='Container_Status_Update'
- then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
- else ''
- end as ctnr_previous_json,
- case when ni.notifiation_type ='Container_Status_Update'
- then (select description
- from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
- else ''
- end as ctnr_desc,
- ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
- from public.kln_notifiation_info ni
- inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- from public.kln_ocean oo
- where oo.serial_no = ni.serial_no limit 1) ccc on true
- left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
- where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- and ni.insert_date > NOW() - INTERVAL '3 months'
- and lower(ni.notifiation_type) in ($more_param)
- ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
- error_log($sql);
- $data_all_type = common::excuteListSql($sql);
- $data_group = array();
- $data_group_uniqe = array();
- foreach($data_all_type as $dat){
- $uniqe_group_str = $dat['notifiation_type'];
- if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
- $tempArr = $data_group[$uniqe_group_str];
- $tempArr[] = $dat;
- $data_group[$uniqe_group_str] = $tempArr;
- } else {
- $data_group[$uniqe_group_str] = array($dat);
- $data_group_uniqe[] = $uniqe_group_str;
- }
- }
- $retData = array();
- foreach($data_group as $key => $data){
- $notifiation_type_db = $key;
- //统一处理数据Instant Daily weekly_week 先分开在处理
- $instant = array();
- $daily = array();
- $daily_uniqe = array();
- $weekly = array();
- $weekly_uniqe = array();
- foreach($data as $d){
- if ($d['frequency_type'] == "Instant"){
- $instant[] = $d;
- }
- //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
- $uniqe_str = $d['serial_no'];
- if ($notifiation_type_db == "Milestone_Update"){
- $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
- }else if ($notifiation_type_db == "Container_Status_Update"){
- $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
- }else if($notifiation_type_db == "Departure/Arrival_Delay"){
- $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
- }else if($notifiation_type_db == "ETD/ETA_Change"){
- $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
- }
- if ($d['frequency_type'] == "Daily"){
- if(!utils::in_array($uniqe_str,$daily_uniqe)){
- $daily[$uniqe_str] = $d;
- $daily_uniqe[] = $uniqe_str;
- }
- }
- if ($d['frequency_type'] == "Weekly"){
- if(!utils::in_array($uniqe_str,$weekly_uniqe)){
- $weekly[$uniqe_str] = $d;
- $weekly_uniqe[] = $uniqe_str;
- }
- }
- }
- $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
- }
- return $retData;
- }
- public function getNotificationsNew($notifiation_type,$frequency_type,$insert_date_format = null){
- if ($frequency_type == "all"){
- //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
- //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
- $sql_where = " and (ni.frequency_type = 'Instant'
- or (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
-
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))";
- } elseif($frequency_type == "Daily"){
- $sql_where = " and (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))";
- } elseif($frequency_type == "Weekly"){
- //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
- // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
- // 如今天是4-14,最小边界值是4.8- 4.14
- // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
- // 当 前时间是 4.15时,但到规定的time,取4.15
- $sql_where = " and (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end))";
- }
- if (!empty($_REQUEST['current_time'])){
- // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
- // and ni.is_send_message is null";
- //这里都以服务器时间,检查标准
- $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
- }
- if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
- $sql_where .= " and ni.is_send_message is null";
- }
- if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'false'){
- $sql_where .= " and ni.is_send_message is not null";
- }
- $more_param = common::getInNotInSqlForSearch($notifiation_type);
- $cp = common::check_input($_REQUEST['cp']); //current_page
- $ps = common::check_input($_REQUEST['ps']); //ps
- if (empty($ps) || empty($cp)){
- $limit_param = " ";
- } else {
- $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
- }
- $sql= "WITH base_data AS (
- SELECT
- id,
- notifiation_type,
- frequency_type,
- insert_date,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format,
- -- 提取用于去重的字段
- serial_no,
- milestone_code,
- ctnr,
- ctnr_status_code,
- delay_name,
- date_change_name
- FROM public.kln_notifiation_info ni
- WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- AND ni.insert_date > NOW() - INTERVAL '3 months'
- and lower(ni.notifiation_type) in ($more_param)
- ".$sql_where." and ni.notifications_method = true
- ),
- -- Step 1: 按 insert_date_format + notifiation_type 分组,统计去重数量
- grouped_stats AS (
- SELECT
- insert_date_format,
- notifiation_type,
- COUNT(DISTINCT
- CASE WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
- WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
- WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
- WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
- END
- ) AS total_count,
- -- Departure / Arrival 单独统计
- COUNT(DISTINCT
- CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Departure%' THEN (serial_no || '_' || delay_name) END
- ) AS departure_count,
- COUNT(DISTINCT
- CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Arrival%' THEN (serial_no || '_' || delay_name) END
- ) AS arrival_count,
- -- ETD / ETA 单独统计
- COUNT(DISTINCT
- CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETD%' THEN (serial_no || '_' || date_change_name) END
- ) AS etd_count,
- COUNT(DISTINCT
- CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETA%' THEN (serial_no || '_' || date_change_name) END
- ) AS eta_count
- FROM base_data
- where frequency_type <> 'Instant'
- GROUP BY insert_date_format, notifiation_type
- ),
- -- Step 2: 找出每个 insert_date_format + notifiation_type 组内的最新一条记录
- latest_records AS (
- SELECT DISTINCT ON (insert_date_format, notifiation_type)
- bd.id,
- bd.notifiation_type,
- bd.insert_date,
- bd.insert_date_format
- FROM base_data bd
- where frequency_type <> 'Instant'
- ORDER BY insert_date_format, notifiation_type, insert_date DESC
- ),
- daily_weekly_summary AS (
- SELECT
- lr.id,
- lr.insert_date,
- gs.total_count,
- gs.departure_count,
- gs.arrival_count,
- gs.etd_count,
- gs.eta_count
- FROM latest_records lr
- LEFT JOIN grouped_stats gs
- ON lr.insert_date_format = gs.insert_date_format
- AND lr.notifiation_type = gs.notifiation_type
- UNION ALL
- SELECT
- id,
- insert_date,
- NULL::INT AS total_count,
- NULL::INT AS departure_count,
- NULL::INT AS arrival_count,
- NULL::INT AS etd_count,
- NULL::INT AS eta_count
- FROM base_data where frequency_type = 'Instant'
- ),
- summary AS (
- SELECT id ,
- insert_date,
- total_count,
- departure_count,
- arrival_count,
- etd_count,
- eta_count
- FROM daily_weekly_summary order by insert_date desc ".$limit_param."
- )
- select *
- from (select ni.*,
- case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
- else 0
- end as _delay_diff,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format,
- case when COALESCE(ni.frequency_type,'') = 'Instant'
- then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
- when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
- else ''
- end as first_notifiation_date,
- case when ni.notifiation_type ='Milestone_Update'
- then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
- else ''
- end as milestone_previous_json,
- case when ni.notifiation_type ='Container_Status_Update'
- then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
- else ''
- end as ctnr_previous_json,
- case when ni.notifiation_type ='Container_Status_Update'
- then (select description
- from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
- else ''
- end as ctnr_desc,
- ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
- from public.kln_notifiation_info ni
- inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
- from summary
- where id = ni.id ) eee on true
- left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- from public.kln_ocean oo
- where oo.serial_no = ni.serial_no limit 1) ccc on true
- left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
- order by ni.insert_date desc) aa";
-
- // $sql = "WITH base_data AS (
- // SELECT
- // id,
- // notifiation_type,
- // frequency_type,
- // insert_date,
- // case when COALESCE(ni.frequency_type,'') = 'Daily'
- // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- // when COALESCE(ni.frequency_type,'') = 'Weekly'
- // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- // || ' - ' ||
- // to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- // else ''
- // end as insert_date_format,
- // -- 提取用于去重的字段
- // serial_no,
- // milestone_code,
- // ctnr,
- // ctnr_status_code,
- // delay_name,
- // date_change_name
- // FROM public.kln_notifiation_info ni
- // WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- // AND ni.insert_date > NOW() - INTERVAL '3 months'
- // and lower(ni.notifiation_type) in ($more_param)
- // AND frequency_type IN ('Daily', 'Weekly')
- // ".$sql_where." and ni.notifications_method = true
- // ),
- // base_instant_data AS (
- // SELECT id,insert_date FROM public.kln_notifiation_info ni
- // WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- // AND ni.insert_date > NOW() - INTERVAL '3 months'
- // and lower(ni.notifiation_type) in ($more_param)
- // AND frequency_type = 'Instant'
- // ".$sql_where." and ni.notifications_method = true
- // ),
- // -- Step 1: 按 insert_date_format + notifiation_type 分组,统计去重数量
- // grouped_stats AS (
- // SELECT
- // insert_date_format,
- // notifiation_type,
- // COUNT(DISTINCT
- // CASE WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
- // WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
- // WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
- // WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
- // END
- // ) AS total_count,
- // -- Departure / Arrival 单独统计
- // COUNT(DISTINCT
- // CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Departure%' THEN (serial_no || '_' || delay_name) END
- // ) AS departure_count,
- // COUNT(DISTINCT
- // CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Arrival%' THEN (serial_no || '_' || delay_name) END
- // ) AS arrival_count,
- // -- ETD / ETA 单独统计
- // COUNT(DISTINCT
- // CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETD%' THEN (serial_no || '_' || date_change_name) END
- // ) AS etd_count,
- // COUNT(DISTINCT
- // CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETA%' THEN (serial_no || '_' || date_change_name) END
- // ) AS eta_count
- // FROM base_data
- // where notifiation_type in ('Milestone_Update','Container_Status_Update','Departure/Arrival_Delay','ETD/ETA_Change')
- // GROUP BY insert_date_format, notifiation_type
- // ),
- // -- Step 2: 找出每个 insert_date_format + notifiation_type 组内的最新一条记录
- // latest_records AS (
- // SELECT DISTINCT ON (insert_date_format, notifiation_type)
- // ni.id,
- // ni.notifiation_type,
- // ni.insert_date,
- // bd.insert_date_format
- // FROM public.kln_notifiation_info ni
- // INNER JOIN base_data bd
- // ON ni.id = bd.id
- // ORDER BY insert_date_format, notifiation_type, ni.insert_date DESC
- // ),
- // daily_weekly_summary AS (
- // SELECT
- // lr.id,
- // lr.insert_date,
- // gs.total_count,
- // gs.departure_count,
- // gs.arrival_count,
- // gs.etd_count,
- // gs.eta_count
- // FROM latest_records lr
- // LEFT JOIN grouped_stats gs
- // ON lr.insert_date_format = gs.insert_date_format
- // AND lr.notifiation_type = gs.notifiation_type
- // UNION ALL
- // SELECT
- // id,
- // insert_date,
- // NULL::INT AS total_count,
- // NULL::INT AS departure_count,
- // NULL::INT AS arrival_count,
- // NULL::INT AS etd_count,
- // NULL::INT AS eta_count
- // FROM base_instant_data
- // ),
- // summary AS (
- // SELECT id ,
- // insert_date,
- // total_count,
- // departure_count,
- // arrival_count,
- // etd_count,
- // eta_count
- // FROM daily_weekly_summary order by insert_date desc ".$limit_param."
- // )
- // select *
- // from (select ni.*,
- // case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- // then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- // when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- // then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
- // else 0
- // end as _delay_diff,
- // case when COALESCE(ni.frequency_type,'') = 'Daily'
- // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- // when COALESCE(ni.frequency_type,'') = 'Weekly'
- // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- // || ' - ' ||
- // to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- // else ''
- // end as insert_date_format,
- // case when COALESCE(ni.frequency_type,'') = 'Instant'
- // then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
- // when COALESCE(ni.frequency_type,'') = 'Daily'
- // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
- // when COALESCE(ni.frequency_type,'') = 'Weekly'
- // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
- // else ''
- // end as first_notifiation_date,
- // case when ni.notifiation_type ='Milestone_Update'
- // then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
- // else ''
- // end as milestone_previous_json,
- // case when ni.notifiation_type ='Container_Status_Update'
- // then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
- // else ''
- // end as ctnr_previous_json,
- // case when ni.notifiation_type ='Container_Status_Update'
- // then (select description
- // from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
- // else ''
- // end as ctnr_desc,
- // ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
- // from public.kln_notifiation_info ni
- // left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- // from public.kln_ocean oo
- // where oo.serial_no = ni.serial_no limit 1) ccc on true
- // inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
- // from summary
- // where id = ni.id ) eee on true
- // left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
- // order by ni.insert_date desc) aa";
- error_log($sql);
- $retData = common::excuteListSql($sql);
- return $retData;
- }
- public function getNotificationsSeeAll($notifiation_type,$frequency_type,$insert_date_format = null){
- if ($frequency_type == "all"){
- //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
- //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
- $sql_where = " and (ni.frequency_type = 'Instant'
- or (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))
-
- or (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end)))";
- } elseif($frequency_type == "Daily"){
- $sql_where = " and (ni.frequency_type = 'Daily'
- and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
- then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
- else
- timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
- end))";
- } elseif($frequency_type == "Weekly"){
- //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
- // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
- // 如今天是4-14,最小边界值是4.8- 4.14
- // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
- // 当 前时间是 4.15时,但到规定的time,取4.15
- $sql_where = " and (ni.frequency_type = 'Weekly'
- and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
- and timezone(ni.weekly_time_zone,NOW())::date = (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date)
- then timezone(ni.weekly_time_zone,ni.insert_date)::date < ((timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date - '7 days'::INTERVAL)::date
- else
- timezone(ni.weekly_time_zone,ni.insert_date)::date < (timezone(ni.weekly_time_zone,NOW())::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,NOW())::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL)::date
- end))";
- }
- //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
- if (!empty($insert_date_format)){
- $sql_where = " and eee.insert_date_format = '$insert_date_format'";
- }
-
- $more_param = common::getInNotInSqlForSearch($notifiation_type);
- $cp = common::check_input($_REQUEST['cp']); //current_page
- $ps = common::check_input($_REQUEST['ps']); //ps
- if (empty($ps) || empty($cp)){
- $limit_param = " ";
- } else {
- $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
- }
- $sql = "with aa as (select ni.*,
- ROW_NUMBER() OVER (
- PARTITION BY
- CASE
- WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
- WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
- WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
- WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
- END
- ORDER BY insert_date DESC
- ) AS rn,
- case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
- else 0
- end as _delay_diff,
- eee.insert_date_format,
- case when COALESCE(ni.frequency_type,'') = 'Instant'
- then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
- when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
- else ''
- end as first_notifiation_date,
- case when ni.notifiation_type ='Container_Status_Update'
- then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
- else ''
- end as ctnr_previous_json,
- case when ni.notifiation_type ='Container_Status_Update'
- then (select description
- from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
- else ''
- end as ctnr_desc
- from public.kln_notifiation_info ni
- left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
- left join LATERAL (select
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- || ' - ' ||
- to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- else ''
- end as insert_date_format
- ) eee on true
- where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- and ni.insert_date > NOW() - INTERVAL '3 months'
- and lower(ni.notifiation_type) in ($more_param)
- ".$sql_where." and ni.notifications_method = true
- order by ni.insert_date desc),
- bb as (select * from aa where rn = 1)
- select *,
- case when bb.notifiation_type ='Milestone_Update'
- then public.getPreviousMilestone(bb.serial_no,bb.milestone_code,ccc.transport_mode,ccc.order_from)
- else ''
- end as milestone_previous_json,
- ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
- from bb
- inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- from public.kln_ocean oo
- where oo.serial_no = bb.serial_no limit 1) ccc on true " .$limit_param;
- // $sql = "select *
- // from (select ni.*,
- // ROW_NUMBER() OVER (
- // PARTITION BY
- // CASE
- // WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
- // WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
- // WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
- // WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
- // END
- // ORDER BY insert_date DESC
- // ) AS rn,
- // case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- // then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- // when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- // then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
- // else 0
- // end as _delay_diff,
- // eee.insert_date_format,
- // case when COALESCE(ni.frequency_type,'') = 'Instant'
- // then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
- // when COALESCE(ni.frequency_type,'') = 'Daily'
- // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
- // when COALESCE(ni.frequency_type,'') = 'Weekly'
- // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7) + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'YYYY-mm-dd')||' '||ni.weekly_time
- // else ''
- // end as first_notifiation_date,
- // case when ni.notifiation_type ='Milestone_Update'
- // then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
- // else ''
- // end as milestone_previous_json,
- // case when ni.notifiation_type ='Container_Status_Update'
- // then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
- // else ''
- // end as ctnr_previous_json,
- // case when ni.notifiation_type ='Container_Status_Update'
- // then (select description
- // from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
- // else ''
- // end as ctnr_desc,
- // ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
- // from public.kln_notifiation_info ni
- // inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
- // from public.kln_ocean oo
- // where oo.serial_no = ni.serial_no limit 1) ccc on true
- // left join LATERAL (select COALESCE(ke.default_time_zone,'UTC-08') as default_time_zone from public.kln_user_extend ke where lower(ke.user_login) = lower(ni.user_login) limit 1) ddd on true
- // left join LATERAL (select case when COALESCE(ni.frequency_type,'') = 'Daily'
- // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
- // when COALESCE(ni.frequency_type,'') = 'Weekly'
- // then to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date - (((EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer - ni.weekly_week::integer + 7) % 7) ||' days')::INTERVAL,'Mon DD, YYYY')
- // || ' - ' ||
- // to_char(timezone(ni.weekly_time_zone,ni.insert_date)::date + (((ni.weekly_week::integer - EXTRACT(dow FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer + 7) % 7)-1 + CASE WHEN EXTRACT(DOW FROM timezone(ni.weekly_time_zone,ni.insert_date)::date)::integer=ni.weekly_week::integer THEN 7 ELSE 0 END ||' days')::INTERVAL,'Mon DD, YYYY')
- // else ''
- // end as insert_date_format) eee on true
- // where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
- // and ni.insert_date > NOW() - INTERVAL '3 months'
- // and lower(ni.notifiation_type) in ($more_param)
- // ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa
- // WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
- error_log($sql);
- $retData = common::excuteListSql($sql);
- return $retData;
- }
- public function getEventCard($mInfo){
- $eventCard = array();
- $notifiation_type = $mInfo['notifiation_type'];
- if($notifiation_type == "Milestone_Update"){
- $eventCard = array("type" =>'milestone',
- "numericRecords"=>0,
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "title"=>"Milestone Update",
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
- "tag"=>$mInfo["milestone_description"],
- "location"=>$mInfo["milestone_locations"],
- "timezone"=>$mInfo["milestone_timezone"],
- "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
- "timeLabel"=>"",
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "insert_date_format"=>'',
- "rules_type"=>$mInfo["notifiation_type"],
- "is_display_hbol"=>!empty($mInfo["h_bol"]),
- "first_notifiation_date"=>$mInfo["first_notifiation_date"],
- "info"=>new stdClass());
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
- if(!empty($milestone_previous['milestone']['milestone_date'])){
- $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
- "date" => $milestone_previous['milestone']['milestone_date'],
- "time" => $milestone_previous['milestone']['milestone_time'],
- "timezone" =>$milestone_previous['milestone']['timezone']);
- }
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
- if(!empty($milestone_previous['milestone']['milestone_date'])){
- $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
- "date" => $milestone_previous['milestone']['milestone_date'],
- "time" => $milestone_previous['milestone']['milestone_time'],
- "timezone" =>$milestone_previous['milestone']['timezone']);
- }
-
- }
- }
- if($notifiation_type == "Container_Status_Update"){
- //当前状态的描述ctnr_desc
- //$ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
- $eventCard = array("type" =>'container',
- "numericRecords"=>0,
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "title"=>"Container_Status_Update",
- "mode"=>"Ocean Freight",
- "no"=>$mInfo["ctnr"],
- "tag"=>$mInfo["ctnr_desc"],
- "location"=>$mInfo["ctnr_status_locations"],
- "timezone"=>$mInfo["ctnr_status_timezone"],
- "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
- "timeLabel"=>"",
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "insert_date_format"=>'',
- "rules_type"=>$mInfo["notifiation_type"],
- "first_notifiation_date"=>$mInfo["first_notifiation_date"],
- "info"=>new stdClass());
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
- if(!empty($ctnr_previous["ctnrStatus"]["date"])){
- //当前状态 前一个的描述
- $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
- "date" => $ctnr_previous["ctnrStatus"]["date"],
- "time" => $ctnr_previous["ctnrStatus"]["time"],
- "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
- }
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
- if(!empty($ctnr_previous["ctnrStatus"]["date"])){
- //当前状态 前一个的描述
- $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
- "date" => $ctnr_previous["ctnrStatus"]["date"],
- "time" => $ctnr_previous["ctnrStatus"]["time"],
- "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
- }
- }
- }
- if($notifiation_type == "Departure/Arrival_Delay"){
- //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
- $title = $mInfo["delay_name"];
- $outsideLocation = "";
- $outsideTimezone = "";
- $outsideTimeLabel= "";
- $insideTimeLabel= "";
- if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
- $outsideTimeLabel = "ETD";
- $insideTimeLabel = "ATD";
- }
- if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
- $outsideTimeLabel = "ETA";
- $insideTimeLabel = "ATA";
- }
- //直航的的
- if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
- $outsideLocation = $mInfo["delay_locations_from"];
- }
- if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
- $outsideLocation = $mInfo["delay_locations_to"];
- }
- $route = array();
- $leg = array();
- if($mInfo["delay_is_direct"] <>'t'){
- $title = substr($mInfo["delay_name"],8);
- $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
- //当前current Leg
- $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
- if($mInfo["delay_current"] == "2"){
- $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
- }
- }
- $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
- $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
- $delay_diff = $mInfo["_delay_diff"];
- $delay_unit = $mInfo["delay_unit"];
- $eventCard = array("type" =>'delay',
- "numericRecords"=>0,
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "title"=>$title,
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
- //第一个字母大写
- "tag"=>ucfirst($mInfo["delay_name"]),
- "location"=>$outsideLocation,
- "timezone"=>$mInfo["delay_timezone"],
- "time"=>$est_date,
- "timeLabel"=>$outsideTimeLabel,
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "insert_date_format"=>'',
- "rules_type"=>$mInfo["notifiation_type"],
- "is_display_hbol"=>!empty($mInfo["h_bol"]),
- "first_notifiation_date"=>$mInfo["first_notifiation_date"],
- "info"=>array("route"=>$route,
- "leg"=>$leg,
- "etdOrdeparturNum"=>0,
- "etaOrarrivalNum"=>0,
- "time"=>$act_date,
- "timeLabel"=>$insideTimeLabel,
- "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
- "timezone"=>$mInfo["delay_timezone"]
- ));
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "Delay Daily Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "Delay Weekly Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- //seeall 的时候,前端不需要id
- $eventCard["id"] = '';
- }
- }
- if($notifiation_type == "ETD/ETA_Change"){
- $title = $mInfo["date_change_name"];
- if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
- $outsideTimeLabel = "Original ETD";
- $insideTimeLabel = "Updated ETD";
- }
- if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
- $outsideTimeLabel = "Original ETA";
- $insideTimeLabel = "Updated ETA";
- }
-
- if($mInfo["date_change_is_direct"] <>'t'){
- //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
- $title = substr($mInfo["date_change_name"],8);
- $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
- $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
- if($mInfo["date_change_current"] == "2"){
- $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
- }
- }
- $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
- $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
- $eventCard = array("type" =>'change',
- "numericRecords"=>0,
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "title"=>$title,
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
- "tag"=>ucfirst($mInfo["date_change_name"]),
- "location"=>"",
- "timezone"=>$mInfo["date_change_timezone"],
- "time"=>$original_date,
- "timeLabel"=>$outsideTimeLabel,
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "insert_date_format"=>'',
- "rules_type"=>$mInfo["notifiation_type"],
- "is_display_hbol"=>!empty($mInfo["h_bol"]),
- "first_notifiation_date"=>$mInfo["first_notifiation_date"],
- "info"=>array("route"=>$route,
- "leg"=>$leg,
- "etdOrdeparturNum"=>0,
- "etaOrarrivalNum"=>0,
- "time"=>$updated_date,
- "timeLabel"=>$insideTimeLabel,
- "delayTimeTip"=>"",
- "timezone"=>$mInfo["date_change_timezone"]
- ));
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- $eventCard["id"] = "";
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
- $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
- $eventCard["id"] = "";
- }
- }
- if($notifiation_type == "Feature_Update" || $notifiation_type == "Passwond_Notifcations"){
- $title = $mInfo["other_type"] == "password" ? "Password Notifications" : "Feature Update";
- $isExpiration = false;
- if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
- $isExpiration = true;
- }
- $path = $mInfo["id"];
- if(!empty($mInfo["serial_no"])){
- $path =$mInfo["serial_no"];
- }
- $eventCard = array(
- "title" => $title,
- "id"=> $mInfo["id"],
- "header"=> $mInfo["other_name"],
- "content"=>$mInfo["other_desc"],
- "content_two"=>$mInfo["other_desc_two"],
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "isExpiration"=> $isExpiration,
- "rules_type"=>$mInfo["notifiation_type"],
- "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$path.".png",
- "view_more_link" =>"main_new_version.php?action=feature_update&id=".$path
- );
- }
- return $eventCard;
- }
- /**
- * 返回当前柜子的status信息描述,目前作废
- */
- public static function getContainerStatusDesc($ctnr_status_code){
- $event =common::getEDICtnrEvent();
- $ctnrStatusdesc = "";
- foreach($event as $e){
- if($e['event_name'] == $ctnr_status_code){
- $ctnrStatusdesc = $e['description'];
- }
- }
- return $ctnrStatusdesc;
- }
- }
- ?>
|