| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409 |
- <?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) = '".strtolower(_getLoginName())."'");
- }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 '1 year'
- 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 '1 year'
- 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 '1 year'
- 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 '1 year'
- 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.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
- left 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
- left 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 '1 year'
- 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)){
- $ps = 20;
- }
- if (empty($cp)){
- $cp = 1;
- }
- //$limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
- $limit_param = " ";
- $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 '1 year'
- 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 '1 year'
- 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)){
- $ps = 20;
- }
- if (empty($cp)){
- $cp = 1;
- }
- //$limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
- $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 '1 year'
- 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;
- }
- $eventCard = array(
- "title" => $title,
- "id"=> $mInfo["id"],
- "header"=> $mInfo["other_name"],
- "content"=>$mInfo["other_desc"],
- "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
- "isExpiration"=> $isExpiration,
- "rules_type"=>$mInfo["notifiation_type"],
- "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$mInfo["id"].".jpg",
- "view_more_link" =>"main_new_version.php?action=feature_update&id=".$mInfo["id"]
- );
- }
- 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;
- }
- }
- ?>
|