tools.class.php 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of operation_log
  7. *
  8. * @author Administrator
  9. */
  10. class tools {
  11. private static $_tools;
  12. public static function getInstance() {
  13. if (!self::$_tools) {
  14. $c = __CLASS__;
  15. self::$_tools = new $c;
  16. }
  17. return self::$_tools;
  18. }
  19. /*
  20. * update password when login success
  21. */
  22. public function updatePassword() {
  23. if ($_SESSION['ONLINE_USER']['is_demo'] == "t") {
  24. $str = "DEMO cannot update password.";
  25. } else {
  26. $opsw = common::check_input($_POST ['opsw']);
  27. $npsw = common::check_input($_POST ['npsw']);
  28. $username = _getLoginName();
  29. $msg = common::checkPasswordRule($username, $npsw);
  30. //为空代表验证通过
  31. if (empty($msg)) {
  32. $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($username) . "'";
  33. $rs = common::excuteObjectSql($sql);
  34. $str = '';
  35. if (!empty($rs)) {
  36. if ($rs['password'] == $opsw) {
  37. $sql = "UPDATE ra_online_user SET ra_password = '" . $npsw . "', last_pwd_change = now() WHERE lower(user_login) = '" . strtolower($username) . "'";
  38. $rls = common::excuteUpdateSql($sql);
  39. if (!$rls) {
  40. $str = "Password modification failed!";
  41. } else {
  42. $str = " Your password has been modified!";
  43. //发送更新成功的邮件
  44. $user_type = $_SESSION['ONLINE_USER']['user_type'];
  45. $user_login = _getLoginName();
  46. utils::sendEmailWithPasswordUpdate($user_login,$user_type);
  47. }
  48. } else {
  49. $str = "Old password is incorrect!";
  50. }
  51. } else {
  52. $str = "Old password is incorrect!";
  53. }
  54. } else {
  55. $str = $msg;
  56. }
  57. }
  58. $returnData = array("msg" => $str);
  59. common::echo_json_encode(200, $returnData);
  60. exit();
  61. }
  62. public function markSystem(){
  63. $operate = utils::_get('operate');
  64. $operate = strtolower($operate);
  65. if ($operate == "mark_save") {
  66. $suggestion = utils::implode(",",$_POST['suggestion']);
  67. $proposal = common::check_input($_POST['proposal']);
  68. $expression = common::check_input($_POST['expression']);
  69. $complete_funtionality = common::check_input($_POST['Complete_funtionality']);
  70. $accurate_data = common::check_input($_POST['Accurate_data']);
  71. $clear_information = common::check_input($_POST['Clear_information']);
  72. $easy_to_use = common::check_input($_POST['Easy_to_use']);
  73. $system_Performance = common::check_input($_POST['System_Performance']);
  74. $username = common::check_input($_POST['username']);
  75. $user_type = _isApexLogin() ? "employee" : "customer";
  76. if(!isset($_SESSION['ONLINE_USER'])){
  77. $user_type = "other";
  78. }
  79. $loginName = _getLoginName();
  80. $loginEamil = _getLoginEamil();
  81. //如果在没有登录前,没有登录信息,指定用户-- 这里逻辑取消,没有登录相当于匿名用户的评价,无法获取用户名
  82. // if(!isset($_SESSION['ONLINE_USER'])){
  83. // $user_type = "Customer";
  84. // if(!empty($username)){
  85. // $loginName = $username;
  86. // $loginEamil = common::excuteOneSql("select email from public.ra_online_user u where lower(user_login) = '" . strtolower($username) . "'");
  87. // }
  88. // }
  89. $sql = "INSERT INTO public.customer_service_user_mark(user_type, user_name, suggestion, proposal, expression, complete_funtionality,
  90. accurate_data, clear_information, easy_to_use, system_performance,
  91. created_time,email)
  92. VALUES ('$user_type', '$loginName', '$suggestion', '$proposal', '$expression', '$complete_funtionality',
  93. '$accurate_data', '$clear_information', '$easy_to_use', '$system_Performance', now(),'$loginEamil')";
  94. common::excuteUpdateSql($sql);
  95. $data = array("msg" =>"success");
  96. common::echo_json_encode(200,$data);
  97. exit();
  98. }
  99. }
  100. public function user_system_setting(){
  101. $operate = utils::_get('operate');
  102. $operate = strtolower($operate);
  103. if ($operate == "personal_profile_init") {
  104. // get system config
  105. $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')";
  106. $rs1s = common::excuteListSql($sql);
  107. foreach ($rs1s as $rs1) {
  108. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  109. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  110. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  111. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  112. }
  113. $sql="select item_value from config where item='passwordChangePeriod'";
  114. $pcp = common::excuteObjectSql($sql);
  115. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  116. if (_isApexLogin()) {
  117. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  118. //如果有新配置,则采用新配置
  119. if (!empty($pcp)) {
  120. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  121. }
  122. } else {
  123. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  124. //如果有新配置,则采用新配置
  125. if (!empty($pcp)) {
  126. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  127. }
  128. }
  129. $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,
  130. ue.date_format,ue.numbers_format
  131. from public.ra_online_user u
  132. left join public.kln_user_extend ue on u.user_login = ue.user_login
  133. where lower(u.user_login) = '".strtolower(_getLoginName())."' ";
  134. $data = common::excuteObjectSql($sql);
  135. $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
  136. common::echo_json_encode(200,$data);
  137. exit();
  138. }
  139. if ($operate == "personal_profile_save") {
  140. $save_model = common::check_input($_POST['save_model']);
  141. if ($save_model == "profile"){
  142. $first_name = common::check_input($_POST['first_name']);
  143. $last_name = common::check_input($_POST['last_name']);
  144. $is_desensitization_kln = common::check_input($_POST['is_desensitization_kln']);
  145. $sql = "update public.ra_online_user set first_name = '$first_name',last_name = '$last_name' ,is_desensitization_kln = '$is_desensitization_kln' where lower(user_login) = '".strtolower(_getLoginName())."'";
  146. session_start();
  147. $_SESSION['ONLINE_USER']['is_desensitization_kln'] = $is_desensitization_kln;
  148. }else{
  149. $date_format = common::check_input($_REQUEST['date_format']);
  150. $numbers_format = common::check_input($_REQUEST['numbers_format']);
  151. $exist_kln_user = common::excuteObjectSql("select user_login from public.kln_user_extend where lower(user_login) = '".strtolower(_getLoginName())."'");
  152. if (!empty($exist_kln_user['user_login'])){
  153. $sql = "update public.kln_user_extend set date_format = '$date_format',numbers_format = '$numbers_format' where lower(user_login) = '".strtolower(_getLoginName())."'";
  154. } else {
  155. $sql = "INSERT INTO public.kln_user_extend(user_login, date_format, numbers_format, subscribe_hbol)
  156. VALUES ('"._getLoginName()."', '$date_format', '$numbers_format', null);";
  157. }
  158. }
  159. common::excuteUpdateSql($sql);
  160. $data = array("msg" => "save Successful");
  161. common::echo_json_encode(200,$data);
  162. exit();
  163. }
  164. if ($operate == "subscribe_notification_default_init"){
  165. $default_time_zone = common::check_input($_POST['default_time_zone']);
  166. $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
  167. //检查用户是否是设置过subscribe_notification
  168. $count = common::excuteOneSql("select count(*) from public.notifications_rules where
  169. notifications_type = 'Subscribe'
  170. and lower(user_login) = '".strtolower(_getLoginName())."'");
  171. if( $count > 0){
  172. } else {
  173. //手动的保存两条,通用默认规则
  174. $sql="INSERT INTO public.notifications_rules(
  175. user_login, notifications_type, rules_type, ocean_milestone,
  176. air_milestone, frequency_type, daily_time, daily_time_zone,
  177. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  178. event_details, frequency_display, method_display,shipment_details,
  179. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  180. VALUES ('"._getLoginName()."', 'Subscribe', 'Milestone_Update', 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFDEP;IFFCSN;IFFARR;IFFAFD;IFFECR;IFFDEL',
  181. 'IFFBCF;IFFCPU;IFFREC;IFFONB;IFFARR;IFFADW;IFFDDW;IFFDEL', 'Daily', '09:00', '$default_time_zone_db',
  182. '', null, '', 'false', 'true',
  183. '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;
  184. 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','',
  185. '','','','','');";
  186. $sql.="INSERT INTO public.notifications_rules(
  187. user_login, notifications_type, rules_type,
  188. 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,
  189. 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,
  190. frequency_type, daily_time, daily_time_zone,
  191. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  192. event_details, frequency_display, method_display,shipment_details,
  193. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  194. VALUES ('"._getLoginName()."', 'Subscribe', 'ETD/ETA_Change',
  195. 'false','','','false','1','days',
  196. 'false','','','false','1','days',
  197. 'Daily', '09:00', '$default_time_zone_db',
  198. '', null, '', 'false', 'true',
  199. '[Ocean]ETA: Notify only when time difference ≥ 1 Day(s);
  200. [Air]ETA: Notify only when time difference ≥ 1 Day(s);', 'Daily, 09:00, ".$default_time_zone."', 'System Message','',
  201. '','','','','');";
  202. $rs = common::excuteUpdateSql($sql);
  203. if (!$rs) {
  204. $data = array("msg" => "Subscribe Notification Initialized Error");
  205. common::echo_json_encode(500,$data);
  206. exit();
  207. }
  208. }
  209. $data = array("msg"=>"Has been initialized");
  210. common::echo_json_encode(200,$data);
  211. exit();
  212. }
  213. if ($operate == "subscribe_notification_init") {
  214. $subscribur_data =array();
  215. //查询用户对应的Rule
  216. $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  217. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  218. from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
  219. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  220. $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
  221. foreach($all_rules as $rule_name){
  222. $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
  223. $subscribur_data[$rule_name] = $rules;
  224. }
  225. //整合拼接addedRules
  226. $addedRules = array();
  227. foreach($subscribe_rules as $addedRule){
  228. $addedRules[] = array(
  229. "visible" => false,
  230. "id" =>$addedRule['id'],
  231. "Event" =>$addedRule['rules_type'],
  232. "Event Details" =>$addedRule['event_details'],
  233. "Frequency" =>$addedRule['frequency_display'],
  234. "Methods" =>$addedRule['method_display']);
  235. }
  236. $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
  237. //获取subscribe shipment 当前页数cp,每页ps
  238. $subscribeShipmentWithPage = $this->getSubscribeShipment(1,15);
  239. $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
  240. common::echo_json_encode(200,$subscribur_data);
  241. exit();
  242. }
  243. if ($operate == "subscribe_notification_event_update"){
  244. $rules_type = common::check_input($_POST["rules_type"]);
  245. //判断该规则是否存在
  246. $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
  247. and lower(user_login) = '".strtolower(_getLoginName())."'");
  248. //检查参数是否正常
  249. $err = $this->checkedNotificationParam();
  250. if(!empty($err)){
  251. $data = array("msg" =>"Parameter error: ".$err);
  252. common::echo_json_encode(500,$data);
  253. exit();
  254. }
  255. $updateOrInsert = empty($exist) ? "insert" : "update";
  256. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
  257. $rs = common::excuteUpdateSql($sql);
  258. if ($rs === FALSE){
  259. $data = array("msg" => "Update Error");
  260. } else{
  261. $data = array("msg" => "Update Successful");
  262. //返回addedRules 全部列表
  263. $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id desc";
  264. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  265. //整合拼接addedRules
  266. $addedRules = array();
  267. foreach($subscribe_rules as $addedRule){
  268. $addedRules[] = array(
  269. "id" =>$addedRule['id'],
  270. "Event" =>$addedRule['rules_type'],
  271. "Event Details" =>$addedRule['event_details'],
  272. "Frequency" =>$addedRule['frequency_display'],
  273. "Methods" =>$addedRule['method_display']);
  274. }
  275. $data['addedRules'] = array("tableData"=>$addedRules);
  276. }
  277. common::echo_json_encode(200,$data);
  278. exit();
  279. }
  280. if ($operate == "subscribe_notification_rules_delete"){
  281. $rules_type = common::check_input($_POST['rules_type']);
  282. $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
  283. and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
  284. common::excuteUpdateSql($sql);
  285. $data = array("msg" => "Delete Successful");
  286. common::echo_json_encode(200,$data);
  287. exit();
  288. }
  289. if ($operate == "subscribe_shipment"){
  290. $serial_no = common::deCode($_POST['serial_no'], 'D');
  291. $is_subscribe = common::check_input($_POST['is_subscribe']);
  292. if($is_subscribe == "true"){
  293. $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
  294. if(!empty($exist)){
  295. $data = array("msg" => "Subscribe exist,Please check");
  296. common::echo_json_encode(200,$data);
  297. exit();
  298. }
  299. $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
  300. VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
  301. common::excuteUpdateSql($sql);
  302. $data = array("msg" => "Subscribe Successful");
  303. common::echo_json_encode(200,$data);
  304. exit();
  305. }else{
  306. //取消订阅
  307. $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
  308. common::excuteUpdateSql($sql);
  309. $data = array("msg" => "Cancel Subscribe successfully");
  310. common::echo_json_encode(200,$data);
  311. exit();
  312. }
  313. }
  314. if ($operate == "subscribe_shipment_search"){
  315. $cp = common::check_input($_POST ['cp']); //current_page
  316. $ps = common::check_input($_POST ['ps']); //ps
  317. $arrTmp = $this->getSubscribeShipment($cp,$ps);
  318. common::echo_json_encode(200,$arrTmp);
  319. exit();
  320. }
  321. }
  322. public function user_monitoring_setting(){
  323. $operate = utils::_get('operate');
  324. $operate = strtolower($operate);
  325. if ($operate == "monitoring_rules_init"){
  326. $ret = array();
  327. //Milestone Update的页面配置数据
  328. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  329. $oceanMilestone = array();
  330. $airMilestone = array();
  331. foreach($milestones as $milestone){
  332. if($milestone['type'] == "air"){
  333. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  334. }
  335. if($milestone['type'] == "sea"){
  336. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  337. }
  338. }
  339. $ret["OceanCheckBoxList"] = $oceanMilestone;
  340. $ret["AirCheckBoxList"] = $airMilestone;
  341. //Milestone Update的结构处理
  342. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  343. //$event =common::getEDICtnrEvent();
  344. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  345. from public.ra_online_edi_event e
  346. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  347. $ctnrStatus = array();
  348. foreach($event as $e){
  349. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  350. }
  351. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  352. common::echo_json_encode(200,$ret);
  353. exit();
  354. }
  355. if ($operate == "monitoring_rules_search") {
  356. $cp = common::check_input($_POST ['cp']); //current_page
  357. $ps = common::check_input($_POST ['ps']); //ps
  358. if (empty($ps))
  359. $ps = 15;
  360. $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
  361. $rc = common::excuteOneSql($sql);
  362. $tp = ceil($rc / $ps);
  363. if ($rc > 0) {
  364. $sql = "select *,replace(rules_type, '_', ' ') AS _rules_type_display,
  365. case when rules_type = 'Milestone_Update' then 'Milestone'
  366. when rules_type = 'Container_Status_Update' then 'Container'
  367. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  368. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  369. else '' end as notifications_option
  370. from public.notifications_rules
  371. where lower(user_login) = '".strtolower(_getLoginName())."'
  372. and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  373. $monitoringRules = common::excuteListSql($sql);
  374. $arrTmp = array('monitoringRules' => $monitoringRules,
  375. 'rc' => intval($rc),
  376. 'ps' => intval($ps),
  377. 'cp' => intval($cp),
  378. 'tp' => intval($tp)
  379. );
  380. } else {
  381. $arrTmp = array('monitoringRules' => array(),
  382. 'rc' => intval($rc),
  383. 'ps' => intval($ps),
  384. 'cp' => intval($cp),
  385. 'tp' => intval($tp)
  386. );
  387. }
  388. common::echo_json_encode(200,$arrTmp);
  389. exit();
  390. }
  391. if ($operate == "monitoring_rules_edit"){
  392. $id = $_POST['id'];
  393. $rules_type = common::check_input($_POST['rules_type']);
  394. $subscribe_rule_sql = "select *,
  395. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  396. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time,
  397. case when rules_type = 'Milestone_Update' then 'Milestone'
  398. when rules_type = 'Container_Status_Update' then 'Container'
  399. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  400. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  401. else '' end as notifications_option
  402. from public.notifications_rules where notifications_type = 'Monitoring' and lower(user_login) = '".strtolower(_getLoginName())."'
  403. and id = '$id' order by id";
  404. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  405. $rules = $this->getSubscribeRules($rules_type,$subscribe_rules);
  406. //数据转换前端需要的显示的格式
  407. $rules["shipment_transport_mode"] = utils::converModeToDisplay($rules["shipment_transport_mode"]);
  408. $monitoring_data[$rules_type] = $rules;
  409. common::echo_json_encode(200,$monitoring_data);
  410. exit();
  411. }
  412. if ($operate == "monitoring_rules_do") {
  413. $rules_type = common::check_input($_POST["rules_type"]);
  414. //检查参数是否正常
  415. $err = $this->checkedNotificationParam();
  416. if(!empty($err)){
  417. $data = array("msg" =>"Parameter error: ".$err);
  418. common::echo_json_encode(500,$data);
  419. exit();
  420. }
  421. //检查编辑提交的Monitoring规则,是否允许保存
  422. $msg = $this->checkedMonitoringRulesSave($rules_type);
  423. if(!empty($msg)){
  424. $data = array("msg" =>$msg);
  425. common::echo_json_encode(200,$data);
  426. exit();
  427. }
  428. $updateOrInsert = "insert";
  429. if(isset($_POST['id']) && !empty($_POST['id'])){
  430. $updateOrInsert = "update";
  431. }
  432. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
  433. $rs = common::excuteUpdateSql($sql);
  434. if ($rs === FALSE){
  435. $data = array("msg" => "Update Error");
  436. } else{
  437. $data = array("msg" => "Update Successful");
  438. }
  439. common::echo_json_encode(200,$data);
  440. exit();
  441. }
  442. if ($operate == "monitoring_rules_delete"){
  443. $id = common::check_input($_POST['id']);
  444. $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
  445. and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id'";
  446. common::excuteUpdateSql($sql);
  447. $data = array("msg" => "Delete Successful");
  448. common::echo_json_encode(200,$data);
  449. exit();
  450. }
  451. }
  452. public function notifications_rules(){
  453. $operate = utils::_get('operate');
  454. $operate = strtolower($operate);
  455. if ($operate == "notifications_init_old"){
  456. $rules_type = common::check_input($_REQUEST['rules_type']);
  457. $milestoneData = array();
  458. $containerData = array();
  459. $delayData = array();
  460. $changeData = array();
  461. if ($rules_type == "all"){
  462. $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change;Feature_Update;Passwond_Notifcations";
  463. $allData = $this->getNotifications($rules_type,"all");
  464. $milestoneData = $allData['Milestone_Update'];
  465. $containerData = $allData['Container_Status_Update'];
  466. $delayData = $allData['Departure/Arrival_Delay'];
  467. $changeData = $allData['ETD/ETA_Change'];
  468. $featureUpdate = $allData['Feature_Update'];
  469. $passwond_Notifcations = $allData['Passwond_Notifcations'];
  470. } else {
  471. $data = $this->getNotifications($rules_type,"all");
  472. if($rules_type == "Milestone_Update"){
  473. $milestoneData = $data['Milestone_Update'];
  474. }elseif($rules_type == "Container_Status_Update"){
  475. $containerData = $data['Container_Status_Update'];
  476. }elseif($rules_type == "Departure/Arrival_Delay"){
  477. $delayData = $data['Departure/Arrival_Delay'];
  478. }elseif($rules_type == "ETD/ETA_Change"){
  479. $changeData = $data['ETD/ETA_Change'];
  480. }elseif($rules_type == "Feature_Update"){
  481. $featureUpdate = $data['Feature_Update'];
  482. }elseif($rules_type == "Passwond_Notifcations"){
  483. $passwond_Notifcations = $data['Passwond_Notifcations'];
  484. }
  485. }
  486. $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,
  487. "changeData"=>$changeData,"featureUpdate"=>$featureUpdate,"passwond_Notifcations"=>$passwond_Notifcations);
  488. $instant_sum = array();
  489. foreach($data as $v){
  490. if(!empty($v['instant'])){
  491. foreach($v['instant'] as $instant){
  492. $instant_sum[] = $instant;
  493. }
  494. }
  495. if(!empty($v['daily'])){
  496. $dailys = common::handleDailyWeekedData($v['daily']);
  497. foreach($dailys as $dailyArr){
  498. //取第一组的第一个显示
  499. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
  500. $instant_sum[]= $dailyFristAndFrist;
  501. }
  502. }
  503. if(!empty($v['weekly'])){
  504. $weeklys = common::handleDailyWeekedData($v['weekly']);
  505. foreach($weeklys as $weeklyArr){
  506. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
  507. $instant_sum[]= $weeklyFristAndFrist;
  508. }
  509. }
  510. }
  511. //根据时间顺序排序
  512. $insert_dates = array_column($instant_sum, 'insert_date');
  513. array_multisort($insert_dates, SORT_DESC, $instant_sum);
  514. $info = array();
  515. foreach($instant_sum as $mInfo){
  516. $eventCard = $this->getEventCard($mInfo);
  517. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  518. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  519. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  520. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  521. }else{
  522. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  523. }
  524. }
  525. $returnData = $info;
  526. common::echo_json_encode(200,$returnData);
  527. exit();
  528. }
  529. if ($operate == "notifications_init"){
  530. $rules_type = common::check_input($_REQUEST['rules_type']);
  531. if ($rules_type == "all"){
  532. $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change;Feature_Update;Passwond_Notifcations";
  533. $data = $this->getNotificationsNew($rules_type,"all");
  534. } else {
  535. $data = $this->getNotificationsNew($rules_type,"all");
  536. }
  537. foreach($data as $k => $v){
  538. if($v['frequency_type'] == 'Daily' || $v['frequency_type'] == 'Weekly'){
  539. $numericRecords = $v['total_count'];
  540. $numericRecords_one = 0;
  541. $numericRecords_two = 0;
  542. if($v['notifiation_type'] == 'Departure/Arrival_Delay'){
  543. $numericRecords_one = $v['departure_count'];
  544. $numericRecords_two = $v['arrival_count'];
  545. }
  546. if ($v['notifiation_type'] == 'ETD/ETA_Change'){
  547. $numericRecords_one = $v['etd_count'];
  548. $numericRecords_two = $v['eta_count'];
  549. }
  550. $data[$k]["numericRecords"]= intval($numericRecords);
  551. //对Delay and change 特殊处理
  552. $data[$k]["numericRecords_one"]= intval($numericRecords_one);
  553. $data[$k]["numericRecords_two"]= intval($numericRecords_two);
  554. }
  555. }
  556. $info = array();
  557. foreach($data as $mInfo){
  558. $eventCard = $this->getEventCard($mInfo);
  559. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  560. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  561. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  562. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  563. }else{
  564. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  565. }
  566. }
  567. $returnData = $info;
  568. common::echo_json_encode(200,$returnData);
  569. exit();
  570. }
  571. if($operate == "notifications_see_all_old"){
  572. $rules_type = common::check_input($_REQUEST['rules_type']);
  573. $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
  574. $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
  575. $notificationsData = $this->getNotifications($rules_type,$frequency_type,$insert_date_format);
  576. $moreData = $notificationsData[$rules_type][strtolower($frequency_type)];
  577. //这个函数里面带有分开计数的信息
  578. $dataInfo =utils::getDailyAndweeklyFrist($moreData);
  579. $returnData = array();
  580. $notificationList = array();
  581. $ids = array();
  582. foreach($moreData as $key => $data){
  583. $eventCard = $this->getEventCard($data);
  584. //sea all的数据格式和查询全部的格式有区别
  585. if($key == 0){
  586. $returnData["title"] = $eventCard["title"];
  587. if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
  588. $returnData["etdOrdeparturNum"] = $dataInfo["numericRecords_one"];
  589. $returnData["etaOrarrivalNum"] =$dataInfo["numericRecords_two"];
  590. $returnData["type"] =$eventCard["type"];
  591. }else{
  592. $returnData["numericRecords"] = $dataInfo["numericRecords"];
  593. }
  594. }
  595. //移除不需要的字段
  596. unset($eventCard["title"]);
  597. $notificationList[] = $eventCard;
  598. $ids[] = $data['id'];
  599. }
  600. if(!empty($notificationList)){
  601. $returnData["notificationList"] = $notificationList;
  602. }
  603. //点击seall会默认全部标记为已读
  604. if(!empty($ids)){
  605. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
  606. $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
  607. common::excuteUpdateSql($markReadSql);
  608. }
  609. common::echo_json_encode(200,$returnData);
  610. exit();
  611. }
  612. if($operate == "notifications_see_all"){
  613. $rules_type = common::check_input($_REQUEST['rules_type']);
  614. $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
  615. $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
  616. $moreData = $this->getNotificationsSeeAll($rules_type,$frequency_type,$insert_date_format);
  617. //这个函数里面带有分开计数的信息
  618. $dataInfo =utils::getDailyAndweeklyFrist($moreData);
  619. $returnData = array();
  620. $notificationList = array();
  621. $ids = array();
  622. foreach($moreData as $key => $data){
  623. $eventCard = $this->getEventCard($data);
  624. //sea all的数据格式和查询全部的格式有区别
  625. if($key == 0){
  626. $returnData["title"] = $eventCard["title"];
  627. if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
  628. $returnData["etdOrdeparturNum"] = $dataInfo["numericRecords_one"];
  629. $returnData["etaOrarrivalNum"] =$dataInfo["numericRecords_two"];
  630. $returnData["type"] =$eventCard["type"];
  631. }else{
  632. $returnData["numericRecords"] = $dataInfo["numericRecords"];
  633. }
  634. }
  635. //移除不需要的字段
  636. unset($eventCard["title"]);
  637. $notificationList[] = $eventCard;
  638. $ids[] = $data['id'];
  639. }
  640. if(!empty($notificationList)){
  641. $returnData["notificationList"] = $notificationList;
  642. }
  643. //点击seall会默认全部标记为已读
  644. if(!empty($ids)){
  645. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
  646. $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
  647. common::excuteUpdateSql($markReadSql);
  648. }
  649. common::echo_json_encode(200,$returnData);
  650. exit();
  651. }
  652. if($operate == "notifications_read"){
  653. $read_type = common::check_input($_POST["read_type"]);
  654. $id = $_POST["id"];
  655. //代表改用户下的所有信息全部标记为已读
  656. if ($read_type == "true"){
  657. $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where lower(user_login) in ('".strtolower(_getLoginName())."','all_user')");
  658. }else{
  659. //处理一下前端提交的不正确参数
  660. $param_id = array();
  661. foreach($id as $_ids){
  662. if(!empty($_ids)){
  663. $param_id[] = $_ids;
  664. }
  665. }
  666. if(empty($param_id)){
  667. //为空直接返回成功
  668. $returnData = array("msg" =>"Success");
  669. common::echo_json_encode(200,$returnData);
  670. }
  671. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$param_id)));
  672. $markReadSql = "update public.kln_notifiation_info set is_send_message = now(),readed_date = now() where id in ($more_param)";
  673. $rs = common::excuteUpdateSql($markReadSql);
  674. }
  675. if ($rs === FALSE){
  676. $returnData = array("msg" =>"Error");
  677. common::echo_json_encode(500,$returnData);
  678. }else{
  679. $returnData = array("msg" =>"Success");
  680. common::echo_json_encode(200,$returnData);
  681. }
  682. exit();
  683. }
  684. if ($operate == "notifications_message_init_old"){
  685. //查询所有情况得未读情况 查询最近一年的情况
  686. $unreadSql = "with countTbale as (
  687. select ni.notifiation_type,
  688. case when COALESCE(ni.frequency_type,'') = 'Daily'
  689. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  690. when COALESCE(ni.frequency_type,'') = 'Weekly'
  691. 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')
  692. || ' - ' ||
  693. 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')
  694. else ''
  695. end as insert_date_format
  696. from public.kln_notifiation_info ni
  697. where ni.insert_date > NOW() - INTERVAL '3 months'
  698. and ni.notifications_method = 'true' and ni.is_send_message is null
  699. and lower(ni.user_login) = '".strtolower(_getLoginName())."'
  700. and ((ni.frequency_type = 'Daily'
  701. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  702. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  703. else
  704. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  705. end))
  706. or (ni.frequency_type = 'Weekly'
  707. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  708. 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)
  709. 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
  710. else
  711. 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
  712. end)))
  713. group by ni.notifiation_type,insert_date_format
  714. union all
  715. select ni.notifiation_type, '' as insert_date_format
  716. from public.kln_notifiation_info ni
  717. where ni.insert_date > NOW() - INTERVAL '3 months'
  718. and lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  719. and ni.notifications_method = 'true' and ni.is_send_message is null
  720. and frequency_type = 'Instant'
  721. )
  722. select
  723. sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as m_rc,
  724. sum(case when (1<>1 or (notifiation_type='Container_Status_Update')) then 1 else 0 end) as cs_rc,
  725. sum(case when (1<>1 or (notifiation_type='Departure/Arrival_Delay')) then 1 else 0 end) as da_rc,
  726. sum(case when (1<>1 or (notifiation_type='ETD/ETA_Change')) then 1 else 0 end) as ec_rc,
  727. sum(case when (1<>1 or (notifiation_type='Feature_Update')) then 1 else 0 end) as f_rc
  728. from countTbale ";
  729. $count = common::excuteObjectSql($unreadSql);
  730. //单独的选中的数据
  731. $rules_type = common::check_input($_REQUEST['rules_type']);
  732. $data = $this->getNotifications($rules_type,"all");
  733. $unreadCount = 0;
  734. $readCount = 0;
  735. $instant_sum = array();
  736. if(!empty($data[$rules_type]['instant'])){
  737. foreach($data[$rules_type]['instant'] as $instant){
  738. $instant_sum[] = $instant;
  739. if(!empty($instant["is_send_message"])){
  740. $readCount +=1;
  741. }else{
  742. $unreadCount +=1;
  743. }
  744. }
  745. }
  746. if(!empty($data[$rules_type]['daily'])){
  747. $dailys = common::handleDailyWeekedData($data[$rules_type]['daily']);
  748. foreach($dailys as $dailyArr){
  749. //取第一组的第一个显示
  750. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
  751. $instant_sum[]= $dailyFristAndFrist;
  752. if(!empty($dailyFristAndFrist["is_send_message"])){
  753. $readCount +=1;
  754. }else{
  755. $unreadCount +=1;
  756. }
  757. }
  758. }
  759. if(!empty($data[$rules_type]['weekly'])){
  760. $weeklys = common::handleDailyWeekedData($data[$rules_type]['weekly']);
  761. foreach($weeklys as $weeklyArr){
  762. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
  763. $instant_sum[]= $weeklyFristAndFrist;
  764. if(!empty($weeklyFristAndFrist["is_send_message"])){
  765. $readCount +=1;
  766. }else{
  767. $unreadCount +=1;
  768. }
  769. }
  770. }
  771. //根据时间顺序排序
  772. $insert_dates = array_column($instant_sum, 'insert_date');
  773. array_multisort($insert_dates, SORT_DESC, $instant_sum);
  774. $info = array();
  775. foreach($instant_sum as $mInfo){
  776. $eventCard = $this->getEventCard($mInfo);
  777. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  778. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  779. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  780. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  781. }else{
  782. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  783. }
  784. }
  785. //返回数据结构
  786. $returnData = array();
  787. $m_rc = empty($count['m_rc']) ? 0 : intval($count['m_rc']);
  788. $cs_rc = empty($count['cs_rc']) ? 0 : intval($count['cs_rc']);
  789. $da_rc = empty($count['da_rc']) ? 0 : intval($count['da_rc']);
  790. $ec_rc = empty($count['ec_rc']) ? 0 : intval($count['ec_rc']);
  791. $f_rc = empty($count['f_rc']) ? 0 : intval($count['f_rc']);
  792. $returnData['countList'] = array($m_rc,$cs_rc,$da_rc,$ec_rc,$f_rc);
  793. $returnData['allCount'] =count($instant_sum);
  794. $returnData['unreadCount'] =$unreadCount;
  795. $returnData['readCount'] =$readCount;
  796. $returnData['cardList'] =$info;
  797. common::echo_json_encode(200,$returnData);
  798. exit();
  799. }
  800. if ($operate == "notifications_message_init"){
  801. //查询所有情况得未读情况 查询最近一年的情况
  802. $unreadSql = "with countTbale as (
  803. select ni.notifiation_type,
  804. case when COALESCE(ni.frequency_type,'') = 'Daily'
  805. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  806. when COALESCE(ni.frequency_type,'') = 'Weekly'
  807. 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')
  808. || ' - ' ||
  809. 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')
  810. else ''
  811. end as insert_date_format
  812. from public.kln_notifiation_info ni
  813. where ni.insert_date > NOW() - INTERVAL '3 months'
  814. and ni.notifications_method = 'true' and ni.is_send_message is null
  815. and lower(ni.user_login) = '".strtolower(_getLoginName())."'
  816. and ((ni.frequency_type = 'Daily'
  817. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  818. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  819. else
  820. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  821. end))
  822. or (ni.frequency_type = 'Weekly'
  823. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  824. 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)
  825. 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
  826. else
  827. 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
  828. end)))
  829. group by ni.notifiation_type,insert_date_format
  830. union all
  831. select ni.notifiation_type, '' as insert_date_format
  832. from public.kln_notifiation_info ni
  833. where ni.insert_date > NOW() - INTERVAL '3 months'
  834. and lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  835. and ni.notifications_method = 'true' and ni.is_send_message is null
  836. and frequency_type = 'Instant'
  837. )
  838. select
  839. sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as m_rc,
  840. sum(case when (1<>1 or (notifiation_type='Container_Status_Update')) then 1 else 0 end) as cs_rc,
  841. sum(case when (1<>1 or (notifiation_type='Departure/Arrival_Delay')) then 1 else 0 end) as da_rc,
  842. sum(case when (1<>1 or (notifiation_type='ETD/ETA_Change')) then 1 else 0 end) as ec_rc,
  843. sum(case when (1<>1 or (notifiation_type='Feature_Update')) then 1 else 0 end) as f_rc
  844. from countTbale ";
  845. $count = common::excuteObjectSql($unreadSql);
  846. //单独的选中的数据
  847. $rules_type = common::check_input($_REQUEST['rules_type']);
  848. $data = $this->getNotificationsNew($rules_type,"all");
  849. $unreadCount = 0;
  850. $readCount = 0;
  851. foreach($data as $k => $v){
  852. if(!empty($v["is_send_message"])){
  853. $readCount +=1;
  854. }else{
  855. $unreadCount +=1;
  856. }
  857. if($v['frequency_type'] == 'Daily' || $v['frequency_type'] == 'Weekly'){
  858. $numericRecords = $v['total_count'];
  859. $numericRecords_one = 0;
  860. $numericRecords_two = 0;
  861. if($v['notifiation_type'] == 'Departure/Arrival_Delay'){
  862. $numericRecords_one = $v['departure_count'];
  863. $numericRecords_two = $v['arrival_count'];
  864. }
  865. if ($v['notifiation_type'] == 'ETD/ETA_Change'){
  866. $numericRecords_one = $v['etd_count'];
  867. $numericRecords_two = $v['eta_count'];
  868. }
  869. $data[$k]["numericRecords"]= intval($numericRecords);
  870. //对Delay and change 特殊处理
  871. $data[$k]["numericRecords_one"]= intval($numericRecords_one);
  872. $data[$k]["numericRecords_two"]= intval($numericRecords_two);
  873. }
  874. }
  875. $info = array();
  876. foreach($data as $mInfo){
  877. $eventCard = $this->getEventCard($mInfo);
  878. if(!empty($mInfo['other_type']) && $mInfo['other_type'] == "password"){
  879. $info[] = array("notificationType"=>"password","info" =>$eventCard);
  880. }elseif(!empty($mInfo['other_type']) && $mInfo['other_type'] == "feature"){
  881. $info[] = array("notificationType"=>"feature","info" =>$eventCard);
  882. }else{
  883. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  884. }
  885. }
  886. //返回数据结构
  887. $returnData = array();
  888. $m_rc = empty($count['m_rc']) ? 0 : intval($count['m_rc']);
  889. $cs_rc = empty($count['cs_rc']) ? 0 : intval($count['cs_rc']);
  890. $da_rc = empty($count['da_rc']) ? 0 : intval($count['da_rc']);
  891. $ec_rc = empty($count['ec_rc']) ? 0 : intval($count['ec_rc']);
  892. $f_rc = empty($count['f_rc']) ? 0 : intval($count['f_rc']);
  893. $returnData['countList'] = array($m_rc,$cs_rc,$da_rc,$ec_rc,$f_rc);
  894. $returnData['allCount'] =count($data);
  895. $returnData['unreadCount'] =$unreadCount;
  896. $returnData['readCount'] =$readCount;
  897. $returnData['cardList'] =$info;
  898. common::echo_json_encode(200,$returnData);
  899. exit();
  900. }
  901. if ($operate == "check_notifications_message"){
  902. $checkUnread = "select id
  903. from public.kln_notifiation_info ni
  904. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  905. from public.kln_ocean oo
  906. where oo.serial_no = ni.serial_no limit 1) ccc on true
  907. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  908. AND ni.insert_date > NOW() - INTERVAL '3 months'
  909. and (ni.frequency_type = 'Instant'
  910. or (ni.frequency_type = 'Daily'
  911. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  912. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  913. else
  914. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  915. end))
  916. or (ni.frequency_type = 'Weekly'
  917. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  918. 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)
  919. 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
  920. else
  921. 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
  922. end)))
  923. and ni.notifications_method = true and is_send_message is null limit 1";
  924. $unread = common::excuteObjectSql($checkUnread);
  925. $returnData = array("has_message" =>!empty($unread));
  926. common::echo_json_encode(200,$returnData);
  927. }
  928. }
  929. /**
  930. * 遍历查找对应的rule。
  931. */
  932. public function getSubscribeRules($rule_name,$subscribe_rules){
  933. //初始是不显示,没有值的情况
  934. $ret = array("is_display" => false);
  935. foreach($subscribe_rules as $rules){
  936. if($rules['rules_type'] == $rule_name){
  937. $rules["is_display"] = true;
  938. $rules["daily_time"] = $rules["_daily_time"];
  939. $rules["weekly_time"] = $rules["_weekly_time"];
  940. $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
  941. $rules["daily_time_zone"] = utils::comvertutcinfo($rules["daily_time_zone"]);
  942. $rules["weekly_time_zone"] = utils::comvertutcinfo($rules["weekly_time_zone"]);
  943. //字符串转数字
  944. $rules["ocean_atd_sub_etd"] = common::convertoint($rules["ocean_atd_sub_etd"]);
  945. $rules["ocean_ata_sub_eta"] = common::convertoint($rules["ocean_ata_sub_eta"]);
  946. $rules["air_atd_sub_etd"] = common::convertoint($rules["air_atd_sub_etd"]);
  947. $rules["air_ata_sub_eta"] = common::convertoint($rules["air_ata_sub_eta"]);
  948. $rules["ocean_etd_old_sub_new"] = common::convertoint($rules["ocean_etd_old_sub_new"]);
  949. $rules["ocean_eta_old_sub_new"] = common::convertoint($rules["ocean_eta_old_sub_new"]);
  950. $rules["air_etd_old_sub_new"] = common::convertoint($rules["air_etd_old_sub_new"]);
  951. $rules["air_eta_old_sub_new"] = common::convertoint($rules["air_eta_old_sub_new"]);
  952. $rules["shipment_etd_limit"] = common::convertoint($rules["shipment_etd_limit"]);
  953. $rules["shipment_eta_limit"] = common::convertoint($rules["shipment_eta_limit"]);
  954. $rules["shipment_etd_limit_from"] = common::convertoint($rules["shipment_etd_limit_from"]);
  955. $rules["shipment_eta_limit_from"] = common::convertoint($rules["shipment_eta_limit_from"]);
  956. // $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  957. $rules["ocean_atd_sub_etd_unit"] = common::convertoVue($rules["ocean_atd_sub_etd_unit"]);
  958. $rules["ocean_ata_sub_eta_unit"] = common::convertoVue($rules["ocean_ata_sub_eta_unit"]);
  959. $rules["air_atd_sub_etd_unit"] = common::convertoVue($rules["air_atd_sub_etd_unit"]);
  960. $rules["air_ata_sub_eta_unit"] = common::convertoVue($rules["air_ata_sub_eta_unit"]);
  961. $rules["ocean_etd_old_sub_new_unit"] = common::convertoVue($rules["ocean_etd_old_sub_new_unit"]);
  962. $rules["ocean_eta_old_sub_new_unit"] = common::convertoVue($rules["ocean_eta_old_sub_new_unit"]);
  963. $rules["air_etd_old_sub_new_unit"] = common::convertoVue($rules["air_etd_old_sub_new_unit"]);
  964. $rules["air_eta_old_sub_new_unit"] = common::convertoVue($rules["air_eta_old_sub_new_unit"]);
  965. $ret = $rules;
  966. }
  967. }
  968. //Milestone Update的结构处理,处理init page load
  969. if($rule_name == "Milestone_Update"){
  970. //Milestone Update的页面配置数据
  971. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  972. $oceanMilestone = array();
  973. $airMilestone = array();
  974. foreach($milestones as $milestone){
  975. if($milestone['type'] == "air"){
  976. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  977. }
  978. if($milestone['type'] == "sea"){
  979. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  980. }
  981. }
  982. $ret["OceanCheckBoxList"] = $oceanMilestone;
  983. $ret["AirCheckBoxList"] = $airMilestone;
  984. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  985. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  986. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  987. $ret["AirCheckedList"] = $airMilestoneSetting;
  988. }
  989. //Milestone Update的结构处理
  990. if($rule_name == "Container_Status_Update"){
  991. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  992. //$event =common::getEDICtnrEvent();
  993. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  994. from public.ra_online_edi_event e
  995. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  996. $ctnrStatus = array();
  997. foreach($event as $e){
  998. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  999. }
  1000. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  1001. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  1002. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  1003. }
  1004. return $ret;
  1005. }
  1006. /**
  1007. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  1008. * cp current_page
  1009. */
  1010. public function getSubscribeShipment($cp,$ps){
  1011. if (empty($cp)){
  1012. $cp = 1;
  1013. }
  1014. if (empty($ps)){
  1015. $ps = 15;
  1016. }
  1017. $sql = "select count(1) from public.kln_user_subscribed u
  1018. inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  1019. where lower(user_login) = '".strtolower(_getLoginName())."'";
  1020. $rc = common::excuteOneSql($sql);
  1021. $tp = ceil($rc / $ps);
  1022. if ($rc > 0) {
  1023. $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
  1024. o.shipper,o.consignee,o.etd,o.eta,
  1025. case when transport_mode = 'sea'
  1026. then (select sn.description
  1027. from public.ocean_milestone a
  1028. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  1029. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1030. when transport_mode = 'air' and order_from = 'public'
  1031. then (select sn.description
  1032. from public.air_milestone a
  1033. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  1034. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1035. when transport_mode = 'air' and order_from = 'sfs'
  1036. then (select sn.description
  1037. from sfs.air_milestone a
  1038. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  1039. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1040. else '' end as recent_milestone
  1041. from public.kln_user_subscribed u
  1042. inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  1043. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  1044. $subscribeShipment = common::excuteListSql($sql);
  1045. foreach($subscribeShipment as $key => $val){
  1046. $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
  1047. }
  1048. $arrTmp = array('tableData' => $subscribeShipment,
  1049. 'rc' => intval($rc),
  1050. 'ps' => intval($ps),
  1051. 'cp' => intval($cp),
  1052. 'tp' => intval($tp)
  1053. );
  1054. } else {
  1055. $arrTmp = array('tableData' => array(),
  1056. 'rc' => intval($rc),
  1057. 'ps' => intval($ps),
  1058. 'cp' => intval($cp),
  1059. 'tp' => intval($tp),
  1060. );
  1061. }
  1062. return $arrTmp;
  1063. }
  1064. public function checkedNotificationParam(){
  1065. $rules_type = common::check_input($_POST["rules_type"]);
  1066. //先判断异常数据
  1067. $msg = "";
  1068. if ($rules_type == "Departure/Arrival_Delay"){
  1069. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  1070. if (!empty($ocean_atd_sub_etd) && !ctype_digit($ocean_atd_sub_etd)) {
  1071. $msg = "Ocean Delayed(ATD-ETD) is not Number";
  1072. }
  1073. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  1074. if (!empty($ocean_ata_sub_eta) && !ctype_digit($ocean_ata_sub_eta)) {
  1075. $msg = "Ocean Delayed(ATA-ETA) is not Number";
  1076. }
  1077. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  1078. if (!empty($air_atd_sub_etd) && !ctype_digit($air_atd_sub_etd)) {
  1079. $msg = "Air Delayed(ATD-ETD) is not Number";
  1080. }
  1081. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  1082. if (!empty($air_ata_sub_eta) && !ctype_digit($air_ata_sub_eta)) {
  1083. $msg = "Air Delayed(ATA-ETA) is not Number";
  1084. }
  1085. }
  1086. if ($rules_type == "ETD/ETA_Change"){
  1087. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  1088. if (!empty($ocean_etd_old_sub_new) && !ctype_digit($ocean_etd_old_sub_new)) {
  1089. $msg = "Ocean Notify(ETD) is not Number";
  1090. }
  1091. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  1092. if (!empty($ocean_eta_old_sub_new) && !ctype_digit($ocean_eta_old_sub_new)) {
  1093. $msg = "Ocean Notify(ETA) is not Number";
  1094. }
  1095. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  1096. if (!empty($air_etd_old_sub_new) && !ctype_digit($air_etd_old_sub_new)) {
  1097. $msg = "Air Notify(ETD) is not Number";
  1098. }
  1099. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  1100. if (!empty($air_eta_old_sub_new) && !ctype_digit($air_eta_old_sub_new)) {
  1101. $msg = "Air Notify(ETA) is not Number";
  1102. }
  1103. }
  1104. return $msg;
  1105. }
  1106. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  1107. $sql = "";
  1108. //先删后加 这个逻辑有移除
  1109. // if($updateOrInsert == "update"){
  1110. // $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  1111. // and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1112. // and id = '$id';";
  1113. // }
  1114. //这个几个参数是所有规则都有的参数
  1115. $frequency_type = common::check_input($_POST['frequency_type']);
  1116. $daily_time = "null";
  1117. $daily_time_zone = "";
  1118. $weekly_week = "";
  1119. $weekly_time = "null";
  1120. $weekly_time_zone = "";
  1121. if(strtolower($frequency_type) == "daily"){
  1122. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  1123. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  1124. $daily_time_zone = utils::comvertutcinfo($daily_time_zone);
  1125. } elseif (strtolower($frequency_type) == "weekly"){
  1126. $weekly_week = common::check_input($_POST['weekly_week']);
  1127. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  1128. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  1129. $weekly_time_zone = utils::comvertutcinfo($weekly_time_zone);
  1130. }
  1131. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  1132. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  1133. $event_details = common::check_input($_POST['event_details']);
  1134. $frequency_display = common::check_input($_POST['frequency_display']);
  1135. $method_display = common::check_input($_POST['method_display']);
  1136. $shipment_detail = common::check_input($_POST['shipment_details']);
  1137. //当规则是 Monitoring类型是,需要配置的range
  1138. $shipment_transport_mode = "";
  1139. $shipment_etd_limit = "";
  1140. $shipment_eta_limit = "";
  1141. $shipment_etd_limit_from = "";
  1142. $shipment_eta_limit_from = "";
  1143. if($notifications_type == "Monitoring"){
  1144. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  1145. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  1146. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  1147. $shipment_etd_limit_from = common::check_input($_POST['shipment_etd_limit_from']);
  1148. $shipment_eta_limit_from = common::check_input($_POST['shipment_eta_limit_from']);
  1149. }
  1150. if ($rules_type == "Milestone_Update"){
  1151. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  1152. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  1153. //改为update 不在是删除后添加,为了保留原始顺序
  1154. if ($updateOrInsert == "update"){
  1155. $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
  1156. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1157. 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',
  1158. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1159. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1160. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1161. where rules_type = '$rules_type'
  1162. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1163. and id = '$id';";
  1164. } else {
  1165. $sql.="INSERT INTO public.notifications_rules(
  1166. user_login, notifications_type, rules_type, ocean_milestone,
  1167. air_milestone, frequency_type, daily_time, daily_time_zone,
  1168. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1169. event_details, frequency_display, method_display,shipment_details,
  1170. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1171. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  1172. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  1173. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1174. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1175. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1176. }
  1177. }
  1178. if ($rules_type == "Container_Status_Update"){
  1179. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  1180. //改为update 不在是删除后添加,为了保留原始顺序
  1181. if ($updateOrInsert == "update"){
  1182. $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
  1183. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1184. 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',
  1185. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1186. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1187. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1188. where rules_type = '$rules_type'
  1189. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1190. and id = '$id';";
  1191. }else{
  1192. $sql.="INSERT INTO public.notifications_rules(
  1193. user_login, notifications_type, rules_type, ocean_ctnr_status,
  1194. frequency_type, daily_time, daily_time_zone,
  1195. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1196. event_details, frequency_display, method_display,shipment_details,
  1197. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1198. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  1199. '$frequency_type', $daily_time, '$daily_time_zone',
  1200. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1201. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1202. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1203. }
  1204. }
  1205. if ($rules_type == "Departure/Arrival_Delay"){
  1206. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  1207. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  1208. if(!empty($ocean_atd_sub_etd_unit)){
  1209. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1210. }
  1211. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  1212. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  1213. if(!empty($ocean_ata_sub_eta_unit)){
  1214. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1215. }
  1216. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  1217. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  1218. if(!empty($air_atd_sub_etd_unit)){
  1219. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1220. }
  1221. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  1222. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  1223. if(!empty($air_ata_sub_eta_unit)){
  1224. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1225. }
  1226. //改为update 不在是删除后添加,为了保留原始顺序
  1227. if ($updateOrInsert == "update"){
  1228. $sql.="update public.notifications_rules set
  1229. ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
  1230. ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
  1231. air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
  1232. air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
  1233. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1234. 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',
  1235. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1236. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1237. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1238. where rules_type = '$rules_type'
  1239. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1240. and id = '$id';";
  1241. }else{
  1242. $sql.="INSERT INTO public.notifications_rules(
  1243. user_login, notifications_type, rules_type,
  1244. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  1245. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  1246. frequency_type, daily_time, daily_time_zone,
  1247. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1248. event_details, frequency_display, method_display,shipment_details,
  1249. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1250. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1251. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  1252. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  1253. '$frequency_type', $daily_time, '$daily_time_zone',
  1254. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1255. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1256. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1257. }
  1258. }
  1259. if ($rules_type == "ETD/ETA_Change"){
  1260. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  1261. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  1262. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  1263. if(!empty($ocean_etd_old_sub_new_unit)){
  1264. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1265. }
  1266. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  1267. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  1268. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  1269. if(!empty($ocean_eta_old_sub_new_unit)){
  1270. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1271. }
  1272. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  1273. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  1274. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  1275. if(!empty($air_etd_old_sub_new_unit)){
  1276. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1277. }
  1278. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  1279. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  1280. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  1281. if(!empty($air_eta_old_sub_new_unit)){
  1282. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1283. }
  1284. //改为update 不在是删除后添加,为了保留原始顺序
  1285. if ($updateOrInsert == "update"){
  1286. $sql.="update public.notifications_rules set
  1287. 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',
  1288. 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',
  1289. 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',
  1290. 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',
  1291. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1292. 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',
  1293. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1294. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1295. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1296. where rules_type = '$rules_type'
  1297. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1298. and id = '$id';";
  1299. }else{
  1300. $sql.="INSERT INTO public.notifications_rules(
  1301. user_login, notifications_type, rules_type,
  1302. 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,
  1303. 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,
  1304. frequency_type, daily_time, daily_time_zone,
  1305. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1306. event_details, frequency_display, method_display,shipment_details,
  1307. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1308. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1309. '$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',
  1310. '$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',
  1311. '$frequency_type', $daily_time, '$daily_time_zone',
  1312. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1313. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1314. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1315. }
  1316. }
  1317. //保存用户默认的时区
  1318. $default_time_zone = common::check_input($_POST['default_time_zone']);
  1319. $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
  1320. $sql .= "update public.kln_user_extend set default_time_zone = '$default_time_zone_db' where lower(user_login) = '".strtolower(_getLoginName())."';";
  1321. return $sql;
  1322. }
  1323. /**
  1324. * 检查编辑提交的Monitoring规则,是否允许保存
  1325. */
  1326. public function checkedMonitoringRulesSave($rules_type){
  1327. $sql_where = "";
  1328. if(isset($_POST['id']) && !empty($_POST['id'])){
  1329. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  1330. }
  1331. $rules = common::excuteListSql("select *,
  1332. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  1333. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  1334. from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  1335. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  1336. foreach($rules as $rule){
  1337. //判断range 是否一样
  1338. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit","shipment_etd_limit_from","shipment_eta_limit_from");
  1339. $range_flag = true;
  1340. foreach($checkRangeFiled as $filed){
  1341. if($filed == "shipment_transport_mode"){
  1342. $postValue = utils::converModeToDB($_POST[$filed]);
  1343. $rule_mode_arr = explode(";", $rule[$filed]);
  1344. $post_mode_arr = explode(";", $postValue);
  1345. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1346. $range_flag = false;
  1347. }
  1348. }else{
  1349. //正常字段直接比较就行
  1350. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1351. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1352. if($postValue != $dbValue){
  1353. $range_flag = false;
  1354. }
  1355. }
  1356. }
  1357. //判断details 是否一样
  1358. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  1359. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  1360. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  1361. "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",
  1362. "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");
  1363. $details_flag = true;
  1364. foreach($checkDetailsFiled as $filed){
  1365. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  1366. $rule_mode_arr = empty($rule[$filed])? array() :explode(";", $rule[$filed]);
  1367. $post_mode_arr = $_POST[$filed];
  1368. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1369. $details_flag = false;
  1370. }
  1371. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  1372. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  1373. if($post_boolean != $rule[$filed]){
  1374. $details_flag = false;
  1375. }
  1376. } elseif ($filed == "ocean_atd_sub_etd_unit" || $filed == "ocean_ata_sub_eta_unit"
  1377. || $filed == "air_atd_sub_etd_unit" || $filed == "air_ata_sub_eta_unit"
  1378. || $filed == "ocean_etd_old_sub_new_unit" || $filed == "ocean_eta_old_sub_new_unit"
  1379. || $filed == "air_etd_old_sub_new_unit" || $filed == "air_eta_old_sub_new_unit"){
  1380. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1381. if(!empty($postValue)){
  1382. $postValue = $postValue=="Day(s)" ? "days":"hours";
  1383. }
  1384. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1385. if($postValue != $dbValue){
  1386. $details_flag = false;
  1387. }
  1388. } else {
  1389. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1390. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1391. if($postValue != $dbValue){
  1392. $details_flag = false;
  1393. }
  1394. }
  1395. }
  1396. //判断frequency 是否一样
  1397. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  1398. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  1399. $frequency_flag = true;
  1400. foreach($checkFrequencyFiled as $filed){
  1401. if($filed == "daily_time" || $filed == "weekly_time"){
  1402. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1403. //_daily_time _weekly_time
  1404. $dbValue = !empty($rule["_".$filed]) ? $rule["_".$filed] : "";
  1405. if($postValue != $dbValue){
  1406. $frequency_flag = false;
  1407. }
  1408. } else {
  1409. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1410. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1411. if($postValue != $dbValue){
  1412. $frequency_flag = false;
  1413. }
  1414. }
  1415. }
  1416. //判断通知方式是否一样
  1417. $checkMethodFiled = array("method_by_email","method_by_message");
  1418. $method_flag = true;
  1419. foreach($checkMethodFiled as $filed){
  1420. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  1421. if($postValue != $rule[$filed]){
  1422. $method_flag = false;
  1423. }
  1424. }
  1425. //五个条件一样,不允许保存
  1426. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  1427. $msg = "Unable to Save";
  1428. break;
  1429. }
  1430. //前三个重回,后面不重合,提示但允许保存
  1431. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  1432. $msg = "Similar Rule Detected";
  1433. break;
  1434. }
  1435. }
  1436. return $msg;
  1437. }
  1438. public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
  1439. if ($frequency_type == "all"){
  1440. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1441. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1442. $sql_where = " and (ni.frequency_type = 'Instant'
  1443. or (ni.frequency_type = 'Daily'
  1444. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1445. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1446. else
  1447. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1448. end))
  1449. or (ni.frequency_type = 'Weekly'
  1450. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1451. 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)
  1452. 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
  1453. else
  1454. 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
  1455. end)))";
  1456. } elseif($frequency_type == "Daily"){
  1457. $sql_where = " and (ni.frequency_type = 'Daily'
  1458. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1459. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1460. else
  1461. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1462. end))";
  1463. } elseif($frequency_type == "Weekly"){
  1464. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1465. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1466. // 如今天是4-14,最小边界值是4.8- 4.14
  1467. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1468. // 当 前时间是 4.15时,但到规定的time,取4.15
  1469. $sql_where = " and (ni.frequency_type = 'Weekly'
  1470. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1471. 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)
  1472. 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
  1473. else
  1474. 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
  1475. end))";
  1476. }
  1477. if (!empty($_REQUEST['current_time'])){
  1478. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1479. // and ni.is_send_message is null";
  1480. //这里都以服务器时间,检查标准
  1481. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
  1482. }
  1483. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1484. $sql_where .= " and ni.is_send_message is null";
  1485. }
  1486. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  1487. $aa_where = "";
  1488. if (!empty($insert_date_format)){
  1489. $aa_where = " where insert_date_format = '$insert_date_format'";
  1490. }
  1491. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1492. $sql = "select *
  1493. from (select ni.*,
  1494. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1495. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1496. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1497. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1498. else 0
  1499. end as _delay_diff,
  1500. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1501. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1502. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1503. 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')
  1504. || ' - ' ||
  1505. 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')
  1506. else ''
  1507. end as insert_date_format,
  1508. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1509. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1510. when COALESCE(ni.frequency_type,'') = 'Daily'
  1511. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1512. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1513. 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
  1514. else ''
  1515. end as first_notifiation_date,
  1516. case when ni.notifiation_type ='Milestone_Update'
  1517. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1518. else ''
  1519. end as milestone_previous_json,
  1520. case when ni.notifiation_type ='Container_Status_Update'
  1521. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1522. else ''
  1523. end as ctnr_previous_json,
  1524. case when ni.notifiation_type ='Container_Status_Update'
  1525. then (select description
  1526. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1527. else ''
  1528. end as ctnr_desc,
  1529. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  1530. from public.kln_notifiation_info ni
  1531. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1532. from public.kln_ocean oo
  1533. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1534. 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
  1535. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1536. and ni.insert_date > NOW() - INTERVAL '3 months'
  1537. and lower(ni.notifiation_type) in ($more_param)
  1538. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
  1539. error_log($sql);
  1540. $data_all_type = common::excuteListSql($sql);
  1541. $data_group = array();
  1542. $data_group_uniqe = array();
  1543. foreach($data_all_type as $dat){
  1544. $uniqe_group_str = $dat['notifiation_type'];
  1545. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  1546. $tempArr = $data_group[$uniqe_group_str];
  1547. $tempArr[] = $dat;
  1548. $data_group[$uniqe_group_str] = $tempArr;
  1549. } else {
  1550. $data_group[$uniqe_group_str] = array($dat);
  1551. $data_group_uniqe[] = $uniqe_group_str;
  1552. }
  1553. }
  1554. $retData = array();
  1555. foreach($data_group as $key => $data){
  1556. $notifiation_type_db = $key;
  1557. //统一处理数据Instant Daily weekly_week 先分开在处理
  1558. $instant = array();
  1559. $daily = array();
  1560. $daily_uniqe = array();
  1561. $weekly = array();
  1562. $weekly_uniqe = array();
  1563. foreach($data as $d){
  1564. if ($d['frequency_type'] == "Instant"){
  1565. $instant[] = $d;
  1566. }
  1567. //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  1568. $uniqe_str = $d['serial_no'];
  1569. if ($notifiation_type_db == "Milestone_Update"){
  1570. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
  1571. }else if ($notifiation_type_db == "Container_Status_Update"){
  1572. $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
  1573. }else if($notifiation_type_db == "Departure/Arrival_Delay"){
  1574. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
  1575. }else if($notifiation_type_db == "ETD/ETA_Change"){
  1576. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
  1577. }
  1578. if ($d['frequency_type'] == "Daily"){
  1579. if(!utils::in_array($uniqe_str,$daily_uniqe)){
  1580. $daily[$uniqe_str] = $d;
  1581. $daily_uniqe[] = $uniqe_str;
  1582. }
  1583. }
  1584. if ($d['frequency_type'] == "Weekly"){
  1585. if(!utils::in_array($uniqe_str,$weekly_uniqe)){
  1586. $weekly[$uniqe_str] = $d;
  1587. $weekly_uniqe[] = $uniqe_str;
  1588. }
  1589. }
  1590. }
  1591. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
  1592. }
  1593. return $retData;
  1594. }
  1595. public function getNotificationsNew($notifiation_type,$frequency_type,$insert_date_format = null){
  1596. if ($frequency_type == "all"){
  1597. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1598. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1599. $sql_where = " and (ni.frequency_type = 'Instant'
  1600. or (ni.frequency_type = 'Daily'
  1601. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1602. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1603. else
  1604. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1605. end))
  1606. or (ni.frequency_type = 'Weekly'
  1607. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1608. 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)
  1609. 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
  1610. else
  1611. 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
  1612. end)))";
  1613. } elseif($frequency_type == "Daily"){
  1614. $sql_where = " and (ni.frequency_type = 'Daily'
  1615. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1616. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1617. else
  1618. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1619. end))";
  1620. } elseif($frequency_type == "Weekly"){
  1621. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1622. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1623. // 如今天是4-14,最小边界值是4.8- 4.14
  1624. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1625. // 当 前时间是 4.15时,但到规定的time,取4.15
  1626. $sql_where = " and (ni.frequency_type = 'Weekly'
  1627. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1628. 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)
  1629. 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
  1630. else
  1631. 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
  1632. end))";
  1633. }
  1634. if (!empty($_REQUEST['current_time'])){
  1635. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1636. // and ni.is_send_message is null";
  1637. //这里都以服务器时间,检查标准
  1638. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
  1639. }
  1640. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1641. $sql_where .= " and ni.is_send_message is null";
  1642. }
  1643. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'false'){
  1644. $sql_where .= " and ni.is_send_message is not null";
  1645. }
  1646. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1647. $cp = common::check_input($_REQUEST['cp']); //current_page
  1648. $ps = common::check_input($_REQUEST['ps']); //ps
  1649. if (empty($ps) || empty($cp)){
  1650. $limit_param = " ";
  1651. } else {
  1652. $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
  1653. }
  1654. $sql= "WITH base_data AS (
  1655. SELECT
  1656. id,
  1657. notifiation_type,
  1658. frequency_type,
  1659. insert_date,
  1660. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1661. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1662. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1663. 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')
  1664. || ' - ' ||
  1665. 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')
  1666. else ''
  1667. end as insert_date_format,
  1668. -- 提取用于去重的字段
  1669. serial_no,
  1670. milestone_code,
  1671. ctnr,
  1672. ctnr_status_code,
  1673. delay_name,
  1674. date_change_name
  1675. FROM public.kln_notifiation_info ni
  1676. WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1677. AND ni.insert_date > NOW() - INTERVAL '3 months'
  1678. and lower(ni.notifiation_type) in ($more_param)
  1679. ".$sql_where." and ni.notifications_method = true
  1680. ),
  1681. -- Step 1: 按 insert_date_format + notifiation_type 分组,统计去重数量
  1682. grouped_stats AS (
  1683. SELECT
  1684. insert_date_format,
  1685. notifiation_type,
  1686. COUNT(DISTINCT
  1687. CASE WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  1688. WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  1689. WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  1690. WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  1691. END
  1692. ) AS total_count,
  1693. -- Departure / Arrival 单独统计
  1694. COUNT(DISTINCT
  1695. CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Departure%' THEN (serial_no || '_' || delay_name) END
  1696. ) AS departure_count,
  1697. COUNT(DISTINCT
  1698. CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Arrival%' THEN (serial_no || '_' || delay_name) END
  1699. ) AS arrival_count,
  1700. -- ETD / ETA 单独统计
  1701. COUNT(DISTINCT
  1702. CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETD%' THEN (serial_no || '_' || date_change_name) END
  1703. ) AS etd_count,
  1704. COUNT(DISTINCT
  1705. CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETA%' THEN (serial_no || '_' || date_change_name) END
  1706. ) AS eta_count
  1707. FROM base_data
  1708. where frequency_type <> 'Instant'
  1709. GROUP BY insert_date_format, notifiation_type
  1710. ),
  1711. -- Step 2: 找出每个 insert_date_format + notifiation_type 组内的最新一条记录
  1712. latest_records AS (
  1713. SELECT DISTINCT ON (insert_date_format, notifiation_type)
  1714. bd.id,
  1715. bd.notifiation_type,
  1716. bd.insert_date,
  1717. bd.insert_date_format
  1718. FROM base_data bd
  1719. where frequency_type <> 'Instant'
  1720. ORDER BY insert_date_format, notifiation_type, insert_date DESC
  1721. ),
  1722. daily_weekly_summary AS (
  1723. SELECT
  1724. lr.id,
  1725. lr.insert_date,
  1726. gs.total_count,
  1727. gs.departure_count,
  1728. gs.arrival_count,
  1729. gs.etd_count,
  1730. gs.eta_count
  1731. FROM latest_records lr
  1732. LEFT JOIN grouped_stats gs
  1733. ON lr.insert_date_format = gs.insert_date_format
  1734. AND lr.notifiation_type = gs.notifiation_type
  1735. UNION ALL
  1736. SELECT
  1737. id,
  1738. insert_date,
  1739. NULL::INT AS total_count,
  1740. NULL::INT AS departure_count,
  1741. NULL::INT AS arrival_count,
  1742. NULL::INT AS etd_count,
  1743. NULL::INT AS eta_count
  1744. FROM base_data where frequency_type = 'Instant'
  1745. ),
  1746. summary AS (
  1747. SELECT id ,
  1748. insert_date,
  1749. total_count,
  1750. departure_count,
  1751. arrival_count,
  1752. etd_count,
  1753. eta_count
  1754. FROM daily_weekly_summary order by insert_date desc ".$limit_param."
  1755. )
  1756. select *
  1757. from (select ni.*,
  1758. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1759. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1760. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1761. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1762. else 0
  1763. end as _delay_diff,
  1764. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1765. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1766. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1767. 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')
  1768. || ' - ' ||
  1769. 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')
  1770. else ''
  1771. end as insert_date_format,
  1772. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1773. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1774. when COALESCE(ni.frequency_type,'') = 'Daily'
  1775. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1776. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1777. 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
  1778. else ''
  1779. end as first_notifiation_date,
  1780. case when ni.notifiation_type ='Milestone_Update'
  1781. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1782. else ''
  1783. end as milestone_previous_json,
  1784. case when ni.notifiation_type ='Container_Status_Update'
  1785. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1786. else ''
  1787. end as ctnr_previous_json,
  1788. case when ni.notifiation_type ='Container_Status_Update'
  1789. then (select description
  1790. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1791. else ''
  1792. end as ctnr_desc,
  1793. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
  1794. from public.kln_notifiation_info ni
  1795. inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
  1796. from summary
  1797. where id = ni.id ) eee on true
  1798. left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1799. from public.kln_ocean oo
  1800. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1801. 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
  1802. order by ni.insert_date desc) aa";
  1803. // $sql = "WITH base_data AS (
  1804. // SELECT
  1805. // id,
  1806. // notifiation_type,
  1807. // frequency_type,
  1808. // insert_date,
  1809. // case when COALESCE(ni.frequency_type,'') = 'Daily'
  1810. // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1811. // when COALESCE(ni.frequency_type,'') = 'Weekly'
  1812. // 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')
  1813. // || ' - ' ||
  1814. // 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')
  1815. // else ''
  1816. // end as insert_date_format,
  1817. // -- 提取用于去重的字段
  1818. // serial_no,
  1819. // milestone_code,
  1820. // ctnr,
  1821. // ctnr_status_code,
  1822. // delay_name,
  1823. // date_change_name
  1824. // FROM public.kln_notifiation_info ni
  1825. // WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1826. // AND ni.insert_date > NOW() - INTERVAL '3 months'
  1827. // and lower(ni.notifiation_type) in ($more_param)
  1828. // AND frequency_type IN ('Daily', 'Weekly')
  1829. // ".$sql_where." and ni.notifications_method = true
  1830. // ),
  1831. // base_instant_data AS (
  1832. // SELECT id,insert_date FROM public.kln_notifiation_info ni
  1833. // WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1834. // AND ni.insert_date > NOW() - INTERVAL '3 months'
  1835. // and lower(ni.notifiation_type) in ($more_param)
  1836. // AND frequency_type = 'Instant'
  1837. // ".$sql_where." and ni.notifications_method = true
  1838. // ),
  1839. // -- Step 1: 按 insert_date_format + notifiation_type 分组,统计去重数量
  1840. // grouped_stats AS (
  1841. // SELECT
  1842. // insert_date_format,
  1843. // notifiation_type,
  1844. // COUNT(DISTINCT
  1845. // CASE WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  1846. // WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  1847. // WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  1848. // WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  1849. // END
  1850. // ) AS total_count,
  1851. // -- Departure / Arrival 单独统计
  1852. // COUNT(DISTINCT
  1853. // CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Departure%' THEN (serial_no || '_' || delay_name) END
  1854. // ) AS departure_count,
  1855. // COUNT(DISTINCT
  1856. // CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Arrival%' THEN (serial_no || '_' || delay_name) END
  1857. // ) AS arrival_count,
  1858. // -- ETD / ETA 单独统计
  1859. // COUNT(DISTINCT
  1860. // CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETD%' THEN (serial_no || '_' || date_change_name) END
  1861. // ) AS etd_count,
  1862. // COUNT(DISTINCT
  1863. // CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETA%' THEN (serial_no || '_' || date_change_name) END
  1864. // ) AS eta_count
  1865. // FROM base_data
  1866. // where notifiation_type in ('Milestone_Update','Container_Status_Update','Departure/Arrival_Delay','ETD/ETA_Change')
  1867. // GROUP BY insert_date_format, notifiation_type
  1868. // ),
  1869. // -- Step 2: 找出每个 insert_date_format + notifiation_type 组内的最新一条记录
  1870. // latest_records AS (
  1871. // SELECT DISTINCT ON (insert_date_format, notifiation_type)
  1872. // ni.id,
  1873. // ni.notifiation_type,
  1874. // ni.insert_date,
  1875. // bd.insert_date_format
  1876. // FROM public.kln_notifiation_info ni
  1877. // INNER JOIN base_data bd
  1878. // ON ni.id = bd.id
  1879. // ORDER BY insert_date_format, notifiation_type, ni.insert_date DESC
  1880. // ),
  1881. // daily_weekly_summary AS (
  1882. // SELECT
  1883. // lr.id,
  1884. // lr.insert_date,
  1885. // gs.total_count,
  1886. // gs.departure_count,
  1887. // gs.arrival_count,
  1888. // gs.etd_count,
  1889. // gs.eta_count
  1890. // FROM latest_records lr
  1891. // LEFT JOIN grouped_stats gs
  1892. // ON lr.insert_date_format = gs.insert_date_format
  1893. // AND lr.notifiation_type = gs.notifiation_type
  1894. // UNION ALL
  1895. // SELECT
  1896. // id,
  1897. // insert_date,
  1898. // NULL::INT AS total_count,
  1899. // NULL::INT AS departure_count,
  1900. // NULL::INT AS arrival_count,
  1901. // NULL::INT AS etd_count,
  1902. // NULL::INT AS eta_count
  1903. // FROM base_instant_data
  1904. // ),
  1905. // summary AS (
  1906. // SELECT id ,
  1907. // insert_date,
  1908. // total_count,
  1909. // departure_count,
  1910. // arrival_count,
  1911. // etd_count,
  1912. // eta_count
  1913. // FROM daily_weekly_summary order by insert_date desc ".$limit_param."
  1914. // )
  1915. // select *
  1916. // from (select ni.*,
  1917. // case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1918. // then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1919. // when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1920. // then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1921. // else 0
  1922. // end as _delay_diff,
  1923. // case when COALESCE(ni.frequency_type,'') = 'Daily'
  1924. // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1925. // when COALESCE(ni.frequency_type,'') = 'Weekly'
  1926. // 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')
  1927. // || ' - ' ||
  1928. // 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')
  1929. // else ''
  1930. // end as insert_date_format,
  1931. // case when COALESCE(ni.frequency_type,'') = 'Instant'
  1932. // then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1933. // when COALESCE(ni.frequency_type,'') = 'Daily'
  1934. // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1935. // when COALESCE(ni.frequency_type,'') = 'Weekly'
  1936. // 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
  1937. // else ''
  1938. // end as first_notifiation_date,
  1939. // case when ni.notifiation_type ='Milestone_Update'
  1940. // then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1941. // else ''
  1942. // end as milestone_previous_json,
  1943. // case when ni.notifiation_type ='Container_Status_Update'
  1944. // then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1945. // else ''
  1946. // end as ctnr_previous_json,
  1947. // case when ni.notifiation_type ='Container_Status_Update'
  1948. // then (select description
  1949. // from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1950. // else ''
  1951. // end as ctnr_desc,
  1952. // ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
  1953. // from public.kln_notifiation_info ni
  1954. // left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1955. // from public.kln_ocean oo
  1956. // where oo.serial_no = ni.serial_no limit 1) ccc on true
  1957. // inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
  1958. // from summary
  1959. // where id = ni.id ) eee on true
  1960. // 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
  1961. // order by ni.insert_date desc) aa";
  1962. error_log($sql);
  1963. $retData = common::excuteListSql($sql);
  1964. return $retData;
  1965. }
  1966. public function getNotificationsSeeAll($notifiation_type,$frequency_type,$insert_date_format = null){
  1967. if ($frequency_type == "all"){
  1968. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1969. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1970. $sql_where = " and (ni.frequency_type = 'Instant'
  1971. or (ni.frequency_type = 'Daily'
  1972. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1973. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1974. else
  1975. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1976. end))
  1977. or (ni.frequency_type = 'Weekly'
  1978. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1979. 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)
  1980. 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
  1981. else
  1982. 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
  1983. end)))";
  1984. } elseif($frequency_type == "Daily"){
  1985. $sql_where = " and (ni.frequency_type = 'Daily'
  1986. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1987. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1988. else
  1989. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1990. end))";
  1991. } elseif($frequency_type == "Weekly"){
  1992. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1993. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1994. // 如今天是4-14,最小边界值是4.8- 4.14
  1995. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1996. // 当 前时间是 4.15时,但到规定的time,取4.15
  1997. $sql_where = " and (ni.frequency_type = 'Weekly'
  1998. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1999. 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)
  2000. 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
  2001. else
  2002. 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
  2003. end))";
  2004. }
  2005. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  2006. if (!empty($insert_date_format)){
  2007. $sql_where = " and eee.insert_date_format = '$insert_date_format'";
  2008. }
  2009. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  2010. $cp = common::check_input($_REQUEST['cp']); //current_page
  2011. $ps = common::check_input($_REQUEST['ps']); //ps
  2012. if (empty($ps) || empty($cp)){
  2013. $limit_param = " ";
  2014. } else {
  2015. $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
  2016. }
  2017. $sql = "with aa as (select ni.*,
  2018. ROW_NUMBER() OVER (
  2019. PARTITION BY
  2020. CASE
  2021. WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  2022. WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  2023. WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  2024. WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  2025. END
  2026. ORDER BY insert_date DESC
  2027. ) AS rn,
  2028. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  2029. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  2030. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  2031. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  2032. else 0
  2033. end as _delay_diff,
  2034. eee.insert_date_format,
  2035. case when COALESCE(ni.frequency_type,'') = 'Instant'
  2036. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  2037. when COALESCE(ni.frequency_type,'') = 'Daily'
  2038. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  2039. when COALESCE(ni.frequency_type,'') = 'Weekly'
  2040. 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
  2041. else ''
  2042. end as first_notifiation_date,
  2043. case when ni.notifiation_type ='Container_Status_Update'
  2044. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  2045. else ''
  2046. end as ctnr_previous_json,
  2047. case when ni.notifiation_type ='Container_Status_Update'
  2048. then (select description
  2049. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  2050. else ''
  2051. end as ctnr_desc
  2052. from public.kln_notifiation_info ni
  2053. 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
  2054. left join LATERAL (select
  2055. case when COALESCE(ni.frequency_type,'') = 'Daily'
  2056. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  2057. when COALESCE(ni.frequency_type,'') = 'Weekly'
  2058. 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')
  2059. || ' - ' ||
  2060. 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')
  2061. else ''
  2062. end as insert_date_format
  2063. ) eee on true
  2064. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  2065. and ni.insert_date > NOW() - INTERVAL '3 months'
  2066. and lower(ni.notifiation_type) in ($more_param)
  2067. ".$sql_where." and ni.notifications_method = true
  2068. order by ni.insert_date desc),
  2069. bb as (select * from aa where rn = 1)
  2070. select *,
  2071. case when bb.notifiation_type ='Milestone_Update'
  2072. then public.getPreviousMilestone(bb.serial_no,bb.milestone_code,ccc.transport_mode,ccc.order_from)
  2073. else ''
  2074. end as milestone_previous_json,
  2075. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  2076. from bb
  2077. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  2078. from public.kln_ocean oo
  2079. where oo.serial_no = bb.serial_no limit 1) ccc on true " .$limit_param;
  2080. // $sql = "select *
  2081. // from (select ni.*,
  2082. // ROW_NUMBER() OVER (
  2083. // PARTITION BY
  2084. // CASE
  2085. // WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  2086. // WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  2087. // WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  2088. // WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  2089. // END
  2090. // ORDER BY insert_date DESC
  2091. // ) AS rn,
  2092. // case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  2093. // then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  2094. // when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  2095. // then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  2096. // else 0
  2097. // end as _delay_diff,
  2098. // eee.insert_date_format,
  2099. // case when COALESCE(ni.frequency_type,'') = 'Instant'
  2100. // then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  2101. // when COALESCE(ni.frequency_type,'') = 'Daily'
  2102. // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  2103. // when COALESCE(ni.frequency_type,'') = 'Weekly'
  2104. // 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
  2105. // else ''
  2106. // end as first_notifiation_date,
  2107. // case when ni.notifiation_type ='Milestone_Update'
  2108. // then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  2109. // else ''
  2110. // end as milestone_previous_json,
  2111. // case when ni.notifiation_type ='Container_Status_Update'
  2112. // then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  2113. // else ''
  2114. // end as ctnr_previous_json,
  2115. // case when ni.notifiation_type ='Container_Status_Update'
  2116. // then (select description
  2117. // from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  2118. // else ''
  2119. // end as ctnr_desc,
  2120. // ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  2121. // from public.kln_notifiation_info ni
  2122. // inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  2123. // from public.kln_ocean oo
  2124. // where oo.serial_no = ni.serial_no limit 1) ccc on true
  2125. // 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
  2126. // left join LATERAL (select case when COALESCE(ni.frequency_type,'') = 'Daily'
  2127. // then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  2128. // when COALESCE(ni.frequency_type,'') = 'Weekly'
  2129. // 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')
  2130. // || ' - ' ||
  2131. // 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')
  2132. // else ''
  2133. // end as insert_date_format) eee on true
  2134. // where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  2135. // and ni.insert_date > NOW() - INTERVAL '3 months'
  2136. // and lower(ni.notifiation_type) in ($more_param)
  2137. // ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa
  2138. // WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
  2139. error_log($sql);
  2140. $retData = common::excuteListSql($sql);
  2141. return $retData;
  2142. }
  2143. public function getEventCard($mInfo){
  2144. $eventCard = array();
  2145. $notifiation_type = $mInfo['notifiation_type'];
  2146. if($notifiation_type == "Milestone_Update"){
  2147. $eventCard = array("type" =>'milestone',
  2148. "numericRecords"=>0,
  2149. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2150. "title"=>"Milestone Update",
  2151. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  2152. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  2153. "tag"=>$mInfo["milestone_description"],
  2154. "location"=>$mInfo["milestone_locations"],
  2155. "timezone"=>$mInfo["milestone_timezone"],
  2156. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  2157. "timeLabel"=>"",
  2158. "previous"=>"",
  2159. "frequency_type"=>$mInfo["frequency_type"],
  2160. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2161. "order_from"=>$mInfo["order_from"],
  2162. "id"=>$mInfo["id"],
  2163. "insert_date_format"=>'',
  2164. "rules_type"=>$mInfo["notifiation_type"],
  2165. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  2166. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2167. "info"=>new stdClass());
  2168. if ($mInfo["frequency_type"] == "Daily"){
  2169. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2170. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  2171. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2172. //seeall 的时候,前端不需要id
  2173. $eventCard["id"] = '';
  2174. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  2175. if(!empty($milestone_previous['milestone']['milestone_date'])){
  2176. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  2177. "date" => $milestone_previous['milestone']['milestone_date'],
  2178. "time" => $milestone_previous['milestone']['milestone_time'],
  2179. "timezone" =>$milestone_previous['milestone']['timezone']);
  2180. }
  2181. } else if($mInfo["frequency_type"] == "Weekly"){
  2182. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2183. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  2184. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2185. //seeall 的时候,前端不需要id
  2186. $eventCard["id"] = '';
  2187. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  2188. if(!empty($milestone_previous['milestone']['milestone_date'])){
  2189. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  2190. "date" => $milestone_previous['milestone']['milestone_date'],
  2191. "time" => $milestone_previous['milestone']['milestone_time'],
  2192. "timezone" =>$milestone_previous['milestone']['timezone']);
  2193. }
  2194. }
  2195. }
  2196. if($notifiation_type == "Container_Status_Update"){
  2197. //当前状态的描述ctnr_desc
  2198. //$ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  2199. $eventCard = array("type" =>'container',
  2200. "numericRecords"=>0,
  2201. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2202. "title"=>"Container_Status_Update",
  2203. "mode"=>"Ocean Freight",
  2204. "no"=>$mInfo["ctnr"],
  2205. "tag"=>$mInfo["ctnr_desc"],
  2206. "location"=>$mInfo["ctnr_status_locations"],
  2207. "timezone"=>$mInfo["ctnr_status_timezone"],
  2208. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  2209. "timeLabel"=>"",
  2210. "previous"=>"",
  2211. "frequency_type"=>$mInfo["frequency_type"],
  2212. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2213. "order_from"=>$mInfo["order_from"],
  2214. "id"=>$mInfo["id"],
  2215. "insert_date_format"=>'',
  2216. "rules_type"=>$mInfo["notifiation_type"],
  2217. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2218. "info"=>new stdClass());
  2219. if ($mInfo["frequency_type"] == "Daily"){
  2220. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2221. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  2222. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2223. //seeall 的时候,前端不需要id
  2224. $eventCard["id"] = '';
  2225. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  2226. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  2227. //当前状态 前一个的描述
  2228. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  2229. "date" => $ctnr_previous["ctnrStatus"]["date"],
  2230. "time" => $ctnr_previous["ctnrStatus"]["time"],
  2231. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  2232. }
  2233. } else if($mInfo["frequency_type"] == "Weekly"){
  2234. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2235. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  2236. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2237. //seeall 的时候,前端不需要id
  2238. $eventCard["id"] = '';
  2239. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  2240. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  2241. //当前状态 前一个的描述
  2242. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  2243. "date" => $ctnr_previous["ctnrStatus"]["date"],
  2244. "time" => $ctnr_previous["ctnrStatus"]["time"],
  2245. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  2246. }
  2247. }
  2248. }
  2249. if($notifiation_type == "Departure/Arrival_Delay"){
  2250. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  2251. $title = $mInfo["delay_name"];
  2252. $outsideLocation = "";
  2253. $outsideTimezone = "";
  2254. $outsideTimeLabel= "";
  2255. $insideTimeLabel= "";
  2256. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  2257. $outsideTimeLabel = "ETD";
  2258. $insideTimeLabel = "ATD";
  2259. }
  2260. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  2261. $outsideTimeLabel = "ETA";
  2262. $insideTimeLabel = "ATA";
  2263. }
  2264. //直航的的
  2265. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  2266. $outsideLocation = $mInfo["delay_locations_from"];
  2267. }
  2268. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  2269. $outsideLocation = $mInfo["delay_locations_to"];
  2270. }
  2271. $route = array();
  2272. $leg = array();
  2273. if($mInfo["delay_is_direct"] <>'t'){
  2274. $title = substr($mInfo["delay_name"],8);
  2275. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  2276. //当前current Leg
  2277. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  2278. if($mInfo["delay_current"] == "2"){
  2279. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  2280. }
  2281. }
  2282. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  2283. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  2284. $delay_diff = $mInfo["_delay_diff"];
  2285. $delay_unit = $mInfo["delay_unit"];
  2286. $eventCard = array("type" =>'delay',
  2287. "numericRecords"=>0,
  2288. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2289. "title"=>$title,
  2290. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  2291. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  2292. //第一个字母大写
  2293. "tag"=>ucfirst($mInfo["delay_name"]),
  2294. "location"=>$outsideLocation,
  2295. "timezone"=>$mInfo["delay_timezone"],
  2296. "time"=>$est_date,
  2297. "timeLabel"=>$outsideTimeLabel,
  2298. "previous"=>"",
  2299. "frequency_type"=>$mInfo["frequency_type"],
  2300. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2301. "order_from"=>$mInfo["order_from"],
  2302. "id"=>$mInfo["id"],
  2303. "insert_date_format"=>'',
  2304. "rules_type"=>$mInfo["notifiation_type"],
  2305. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  2306. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2307. "info"=>array("route"=>$route,
  2308. "leg"=>$leg,
  2309. "etdOrdeparturNum"=>0,
  2310. "etaOrarrivalNum"=>0,
  2311. "time"=>$act_date,
  2312. "timeLabel"=>$insideTimeLabel,
  2313. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  2314. "timezone"=>$mInfo["delay_timezone"]
  2315. ));
  2316. if ($mInfo["frequency_type"] == "Daily"){
  2317. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2318. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2319. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2320. $eventCard["title"] = "Delay Daily Summary(".$mInfo["insert_date_format"].")";
  2321. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2322. //seeall 的时候,前端不需要id
  2323. $eventCard["id"] = '';
  2324. } else if($mInfo["frequency_type"] == "Weekly"){
  2325. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2326. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2327. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2328. $eventCard["title"] = "Delay Weekly Summary(".$mInfo["insert_date_format"].")";
  2329. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2330. //seeall 的时候,前端不需要id
  2331. $eventCard["id"] = '';
  2332. }
  2333. }
  2334. if($notifiation_type == "ETD/ETA_Change"){
  2335. $title = $mInfo["date_change_name"];
  2336. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  2337. $outsideTimeLabel = "Original ETD";
  2338. $insideTimeLabel = "Updated ETD";
  2339. }
  2340. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  2341. $outsideTimeLabel = "Original ETA";
  2342. $insideTimeLabel = "Updated ETA";
  2343. }
  2344. if($mInfo["date_change_is_direct"] <>'t'){
  2345. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  2346. $title = substr($mInfo["date_change_name"],8);
  2347. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  2348. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  2349. if($mInfo["date_change_current"] == "2"){
  2350. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  2351. }
  2352. }
  2353. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  2354. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  2355. $eventCard = array("type" =>'change',
  2356. "numericRecords"=>0,
  2357. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2358. "title"=>$title,
  2359. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  2360. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  2361. "tag"=>ucfirst($mInfo["date_change_name"]),
  2362. "location"=>"",
  2363. "timezone"=>$mInfo["date_change_timezone"],
  2364. "time"=>$original_date,
  2365. "timeLabel"=>$outsideTimeLabel,
  2366. "previous"=>"",
  2367. "frequency_type"=>$mInfo["frequency_type"],
  2368. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2369. "order_from"=>$mInfo["order_from"],
  2370. "id"=>$mInfo["id"],
  2371. "insert_date_format"=>'',
  2372. "rules_type"=>$mInfo["notifiation_type"],
  2373. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  2374. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2375. "info"=>array("route"=>$route,
  2376. "leg"=>$leg,
  2377. "etdOrdeparturNum"=>0,
  2378. "etaOrarrivalNum"=>0,
  2379. "time"=>$updated_date,
  2380. "timeLabel"=>$insideTimeLabel,
  2381. "delayTimeTip"=>"",
  2382. "timezone"=>$mInfo["date_change_timezone"]
  2383. ));
  2384. if ($mInfo["frequency_type"] == "Daily"){
  2385. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2386. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2387. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2388. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  2389. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2390. $eventCard["id"] = "";
  2391. } else if($mInfo["frequency_type"] == "Weekly"){
  2392. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2393. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2394. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2395. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  2396. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2397. $eventCard["id"] = "";
  2398. }
  2399. }
  2400. if($notifiation_type == "Feature_Update" || $notifiation_type == "Passwond_Notifcations"){
  2401. $title = $mInfo["other_type"] == "password" ? "Password Notifications" : "Feature Update";
  2402. $isExpiration = false;
  2403. if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
  2404. $isExpiration = true;
  2405. }
  2406. $path = $mInfo["id"];
  2407. if(!empty($mInfo["serial_no"])){
  2408. $path =$mInfo["serial_no"];
  2409. }
  2410. $eventCard = array(
  2411. "title" => $title,
  2412. "id"=> $mInfo["id"],
  2413. "header"=> $mInfo["other_name"],
  2414. "content"=>$mInfo["other_desc"],
  2415. "content_two"=>$mInfo["other_desc_two"],
  2416. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2417. "isExpiration"=> $isExpiration,
  2418. "rules_type"=>$mInfo["notifiation_type"],
  2419. "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$path.".png",
  2420. "view_more_link" =>"main_new_version.php?action=feature_update&id=".$path
  2421. );
  2422. }
  2423. return $eventCard;
  2424. }
  2425. /**
  2426. * 返回当前柜子的status信息描述,目前作废
  2427. */
  2428. public static function getContainerStatusDesc($ctnr_status_code){
  2429. $event =common::getEDICtnrEvent();
  2430. $ctnrStatusdesc = "";
  2431. foreach($event as $e){
  2432. if($e['event_name'] == $ctnr_status_code){
  2433. $ctnrStatusdesc = $e['description'];
  2434. }
  2435. }
  2436. return $ctnrStatusdesc;
  2437. }
  2438. }
  2439. ?>