tools.class.php 145 KB

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