tools.class.php 163 KB

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