tools.class.php 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410
  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) in ('".strtolower(_getLoginName())."','all_user')");
  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.insert_date > NOW() - INTERVAL '3 months'
  902. and (ni.frequency_type = 'Instant'
  903. or (ni.frequency_type = 'Daily'
  904. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  905. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  906. else
  907. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  908. end))
  909. or (ni.frequency_type = 'Weekly'
  910. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  911. 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)
  912. 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
  913. else
  914. 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
  915. end)))
  916. and ni.notifications_method = true and is_send_message is null limit 1";
  917. $unread = common::excuteObjectSql($checkUnread);
  918. $returnData = array("has_message" =>!empty($unread));
  919. common::echo_json_encode(200,$returnData);
  920. }
  921. }
  922. /**
  923. * 遍历查找对应的rule。
  924. */
  925. public function getSubscribeRules($rule_name,$subscribe_rules){
  926. //初始是不显示,没有值的情况
  927. $ret = array("is_display" => false);
  928. foreach($subscribe_rules as $rules){
  929. if($rules['rules_type'] == $rule_name){
  930. $rules["is_display"] = true;
  931. $rules["daily_time"] = $rules["_daily_time"];
  932. $rules["weekly_time"] = $rules["_weekly_time"];
  933. $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
  934. $rules["daily_time_zone"] = utils::comvertutcinfo($rules["daily_time_zone"]);
  935. $rules["weekly_time_zone"] = utils::comvertutcinfo($rules["weekly_time_zone"]);
  936. //字符串转数字
  937. $rules["ocean_atd_sub_etd"] = common::convertoint($rules["ocean_atd_sub_etd"]);
  938. $rules["ocean_ata_sub_eta"] = common::convertoint($rules["ocean_ata_sub_eta"]);
  939. $rules["air_atd_sub_etd"] = common::convertoint($rules["air_atd_sub_etd"]);
  940. $rules["air_ata_sub_eta"] = common::convertoint($rules["air_ata_sub_eta"]);
  941. $rules["ocean_etd_old_sub_new"] = common::convertoint($rules["ocean_etd_old_sub_new"]);
  942. $rules["ocean_eta_old_sub_new"] = common::convertoint($rules["ocean_eta_old_sub_new"]);
  943. $rules["air_etd_old_sub_new"] = common::convertoint($rules["air_etd_old_sub_new"]);
  944. $rules["air_eta_old_sub_new"] = common::convertoint($rules["air_eta_old_sub_new"]);
  945. $rules["shipment_etd_limit"] = common::convertoint($rules["shipment_etd_limit"]);
  946. $rules["shipment_eta_limit"] = common::convertoint($rules["shipment_eta_limit"]);
  947. $rules["shipment_etd_limit_from"] = common::convertoint($rules["shipment_etd_limit_from"]);
  948. $rules["shipment_eta_limit_from"] = common::convertoint($rules["shipment_eta_limit_from"]);
  949. // $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  950. $rules["ocean_atd_sub_etd_unit"] = common::convertoVue($rules["ocean_atd_sub_etd_unit"]);
  951. $rules["ocean_ata_sub_eta_unit"] = common::convertoVue($rules["ocean_ata_sub_eta_unit"]);
  952. $rules["air_atd_sub_etd_unit"] = common::convertoVue($rules["air_atd_sub_etd_unit"]);
  953. $rules["air_ata_sub_eta_unit"] = common::convertoVue($rules["air_ata_sub_eta_unit"]);
  954. $rules["ocean_etd_old_sub_new_unit"] = common::convertoVue($rules["ocean_etd_old_sub_new_unit"]);
  955. $rules["ocean_eta_old_sub_new_unit"] = common::convertoVue($rules["ocean_eta_old_sub_new_unit"]);
  956. $rules["air_etd_old_sub_new_unit"] = common::convertoVue($rules["air_etd_old_sub_new_unit"]);
  957. $rules["air_eta_old_sub_new_unit"] = common::convertoVue($rules["air_eta_old_sub_new_unit"]);
  958. $ret = $rules;
  959. }
  960. }
  961. //Milestone Update的结构处理,处理init page load
  962. if($rule_name == "Milestone_Update"){
  963. //Milestone Update的页面配置数据
  964. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  965. $oceanMilestone = array();
  966. $airMilestone = array();
  967. foreach($milestones as $milestone){
  968. if($milestone['type'] == "air"){
  969. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  970. }
  971. if($milestone['type'] == "sea"){
  972. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  973. }
  974. }
  975. $ret["OceanCheckBoxList"] = $oceanMilestone;
  976. $ret["AirCheckBoxList"] = $airMilestone;
  977. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  978. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  979. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  980. $ret["AirCheckedList"] = $airMilestoneSetting;
  981. }
  982. //Milestone Update的结构处理
  983. if($rule_name == "Container_Status_Update"){
  984. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  985. //$event =common::getEDICtnrEvent();
  986. $event = common::excuteListSql("select ra_name as event_name,ra_order,description
  987. from public.ra_online_edi_event e
  988. where e.ra_name in('I','VD','VA','UV','AL','AR','OA','RD') order by e.ra_order desc");
  989. $ctnrStatus = array();
  990. foreach($event as $e){
  991. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  992. }
  993. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  994. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  995. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  996. }
  997. return $ret;
  998. }
  999. /**
  1000. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  1001. * cp current_page
  1002. */
  1003. public function getSubscribeShipment($cp,$ps){
  1004. if (empty($cp)){
  1005. $cp = 1;
  1006. }
  1007. if (empty($ps)){
  1008. $ps = 15;
  1009. }
  1010. $sql = "select count(1) from public.kln_user_subscribed u
  1011. inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  1012. where lower(user_login) = '".strtolower(_getLoginName())."'";
  1013. $rc = common::excuteOneSql($sql);
  1014. $tp = ceil($rc / $ps);
  1015. if ($rc > 0) {
  1016. $sql = "select o.serial_no,order_from as _schemas,o.h_bol,
  1017. o.shipper,o.consignee,o.etd,o.eta,
  1018. case when transport_mode = 'sea'
  1019. then (select sn.description
  1020. from public.ocean_milestone a
  1021. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  1022. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1023. when transport_mode = 'air' and order_from = 'public'
  1024. then (select sn.description
  1025. from public.air_milestone a
  1026. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  1027. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1028. when transport_mode = 'air' and order_from = 'sfs'
  1029. then (select sn.description
  1030. from sfs.air_milestone a
  1031. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  1032. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  1033. else '' end as recent_milestone
  1034. from public.kln_user_subscribed u
  1035. inner join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  1036. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  1037. $subscribeShipment = common::excuteListSql($sql);
  1038. foreach($subscribeShipment as $key => $val){
  1039. $subscribeShipment[$key]["__serial_no"] = common::deCode($val['serial_no'], 'E');
  1040. }
  1041. $arrTmp = array('tableData' => $subscribeShipment,
  1042. 'rc' => intval($rc),
  1043. 'ps' => intval($ps),
  1044. 'cp' => intval($cp),
  1045. 'tp' => intval($tp)
  1046. );
  1047. } else {
  1048. $arrTmp = array('tableData' => array(),
  1049. 'rc' => intval($rc),
  1050. 'ps' => intval($ps),
  1051. 'cp' => intval($cp),
  1052. 'tp' => intval($tp),
  1053. );
  1054. }
  1055. return $arrTmp;
  1056. }
  1057. public function checkedNotificationParam(){
  1058. $rules_type = common::check_input($_POST["rules_type"]);
  1059. //先判断异常数据
  1060. $msg = "";
  1061. if ($rules_type == "Departure/Arrival_Delay"){
  1062. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  1063. if (!empty($ocean_atd_sub_etd) && !ctype_digit($ocean_atd_sub_etd)) {
  1064. $msg = "Ocean Delayed(ATD-ETD) is not Number";
  1065. }
  1066. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  1067. if (!empty($ocean_ata_sub_eta) && !ctype_digit($ocean_ata_sub_eta)) {
  1068. $msg = "Ocean Delayed(ATA-ETA) is not Number";
  1069. }
  1070. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  1071. if (!empty($air_atd_sub_etd) && !ctype_digit($air_atd_sub_etd)) {
  1072. $msg = "Air Delayed(ATD-ETD) is not Number";
  1073. }
  1074. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  1075. if (!empty($air_ata_sub_eta) && !ctype_digit($air_ata_sub_eta)) {
  1076. $msg = "Air Delayed(ATA-ETA) is not Number";
  1077. }
  1078. }
  1079. if ($rules_type == "ETD/ETA_Change"){
  1080. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  1081. if (!empty($ocean_etd_old_sub_new) && !ctype_digit($ocean_etd_old_sub_new)) {
  1082. $msg = "Ocean Notify(ETD) is not Number";
  1083. }
  1084. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  1085. if (!empty($ocean_eta_old_sub_new) && !ctype_digit($ocean_eta_old_sub_new)) {
  1086. $msg = "Ocean Notify(ETA) is not Number";
  1087. }
  1088. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  1089. if (!empty($air_etd_old_sub_new) && !ctype_digit($air_etd_old_sub_new)) {
  1090. $msg = "Air Notify(ETD) is not Number";
  1091. }
  1092. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  1093. if (!empty($air_eta_old_sub_new) && !ctype_digit($air_eta_old_sub_new)) {
  1094. $msg = "Air Notify(ETA) is not Number";
  1095. }
  1096. }
  1097. return $msg;
  1098. }
  1099. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  1100. $sql = "";
  1101. //先删后加 这个逻辑有移除
  1102. // if($updateOrInsert == "update"){
  1103. // $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  1104. // and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1105. // and id = '$id';";
  1106. // }
  1107. //这个几个参数是所有规则都有的参数
  1108. $frequency_type = common::check_input($_POST['frequency_type']);
  1109. $daily_time = "null";
  1110. $daily_time_zone = "";
  1111. $weekly_week = "";
  1112. $weekly_time = "null";
  1113. $weekly_time_zone = "";
  1114. if(strtolower($frequency_type) == "daily"){
  1115. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  1116. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  1117. $daily_time_zone = utils::comvertutcinfo($daily_time_zone);
  1118. } elseif (strtolower($frequency_type) == "weekly"){
  1119. $weekly_week = common::check_input($_POST['weekly_week']);
  1120. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  1121. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  1122. $weekly_time_zone = utils::comvertutcinfo($weekly_time_zone);
  1123. }
  1124. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  1125. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  1126. $event_details = common::check_input($_POST['event_details']);
  1127. $frequency_display = common::check_input($_POST['frequency_display']);
  1128. $method_display = common::check_input($_POST['method_display']);
  1129. $shipment_detail = common::check_input($_POST['shipment_details']);
  1130. //当规则是 Monitoring类型是,需要配置的range
  1131. $shipment_transport_mode = "";
  1132. $shipment_etd_limit = "";
  1133. $shipment_eta_limit = "";
  1134. $shipment_etd_limit_from = "";
  1135. $shipment_eta_limit_from = "";
  1136. if($notifications_type == "Monitoring"){
  1137. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  1138. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  1139. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  1140. $shipment_etd_limit_from = common::check_input($_POST['shipment_etd_limit_from']);
  1141. $shipment_eta_limit_from = common::check_input($_POST['shipment_eta_limit_from']);
  1142. }
  1143. if ($rules_type == "Milestone_Update"){
  1144. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  1145. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  1146. //改为update 不在是删除后添加,为了保留原始顺序
  1147. if ($updateOrInsert == "update"){
  1148. $sql.="update public.notifications_rules set ocean_milestone = '$ocean_milestone',air_milestone = '$air_milestone',
  1149. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1150. 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',
  1151. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1152. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1153. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1154. where rules_type = '$rules_type'
  1155. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1156. and id = '$id';";
  1157. } else {
  1158. $sql.="INSERT INTO public.notifications_rules(
  1159. user_login, notifications_type, rules_type, ocean_milestone,
  1160. air_milestone, frequency_type, daily_time, daily_time_zone,
  1161. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1162. event_details, frequency_display, method_display,shipment_details,
  1163. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1164. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  1165. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  1166. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1167. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1168. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1169. }
  1170. }
  1171. if ($rules_type == "Container_Status_Update"){
  1172. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  1173. //改为update 不在是删除后添加,为了保留原始顺序
  1174. if ($updateOrInsert == "update"){
  1175. $sql.="update public.notifications_rules set ocean_ctnr_status = '$ocean_ctnr_status',
  1176. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1177. 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',
  1178. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1179. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1180. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1181. where rules_type = '$rules_type'
  1182. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1183. and id = '$id';";
  1184. }else{
  1185. $sql.="INSERT INTO public.notifications_rules(
  1186. user_login, notifications_type, rules_type, ocean_ctnr_status,
  1187. frequency_type, daily_time, daily_time_zone,
  1188. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1189. event_details, frequency_display, method_display,shipment_details,
  1190. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1191. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  1192. '$frequency_type', $daily_time, '$daily_time_zone',
  1193. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1194. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1195. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1196. }
  1197. }
  1198. if ($rules_type == "Departure/Arrival_Delay"){
  1199. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  1200. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  1201. if(!empty($ocean_atd_sub_etd_unit)){
  1202. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1203. }
  1204. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  1205. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  1206. if(!empty($ocean_ata_sub_eta_unit)){
  1207. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1208. }
  1209. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  1210. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  1211. if(!empty($air_atd_sub_etd_unit)){
  1212. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  1213. }
  1214. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  1215. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  1216. if(!empty($air_ata_sub_eta_unit)){
  1217. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  1218. }
  1219. //改为update 不在是删除后添加,为了保留原始顺序
  1220. if ($updateOrInsert == "update"){
  1221. $sql.="update public.notifications_rules set
  1222. ocean_atd_sub_etd = '$ocean_atd_sub_etd',ocean_atd_sub_etd_unit = '$ocean_atd_sub_etd_unit',
  1223. ocean_ata_sub_eta = '$ocean_ata_sub_eta',ocean_ata_sub_eta_unit = '$ocean_ata_sub_eta_unit',
  1224. air_atd_sub_etd = '$air_atd_sub_etd',air_atd_sub_etd_unit = '$air_atd_sub_etd_unit',
  1225. air_ata_sub_eta = '$air_ata_sub_eta',air_ata_sub_eta_unit = '$air_ata_sub_eta_unit',
  1226. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1227. 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',
  1228. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1229. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1230. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1231. where rules_type = '$rules_type'
  1232. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1233. and id = '$id';";
  1234. }else{
  1235. $sql.="INSERT INTO public.notifications_rules(
  1236. user_login, notifications_type, rules_type,
  1237. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  1238. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  1239. frequency_type, daily_time, daily_time_zone,
  1240. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1241. event_details, frequency_display, method_display,shipment_details,
  1242. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1243. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1244. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  1245. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  1246. '$frequency_type', $daily_time, '$daily_time_zone',
  1247. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1248. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1249. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1250. }
  1251. }
  1252. if ($rules_type == "ETD/ETA_Change"){
  1253. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  1254. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  1255. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  1256. if(!empty($ocean_etd_old_sub_new_unit)){
  1257. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1258. }
  1259. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  1260. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  1261. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  1262. if(!empty($ocean_eta_old_sub_new_unit)){
  1263. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1264. }
  1265. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  1266. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  1267. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  1268. if(!empty($air_etd_old_sub_new_unit)){
  1269. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1270. }
  1271. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  1272. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  1273. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  1274. if(!empty($air_eta_old_sub_new_unit)){
  1275. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  1276. }
  1277. //改为update 不在是删除后添加,为了保留原始顺序
  1278. if ($updateOrInsert == "update"){
  1279. $sql.="update public.notifications_rules set
  1280. 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',
  1281. 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',
  1282. 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',
  1283. 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',
  1284. frequency_type = '$frequency_type',daily_time = $daily_time, daily_time_zone = '$daily_time_zone',
  1285. 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',
  1286. event_details = '$event_details', frequency_display = '$frequency_display', method_display = '$method_display', shipment_details = '$shipment_detail',
  1287. shipment_transport_mode = '$shipment_transport_mode', shipment_etd_limit = '$shipment_etd_limit', shipment_eta_limit = '$shipment_eta_limit',
  1288. shipment_etd_limit_from = '$shipment_etd_limit_from', shipment_eta_limit_from = '$shipment_eta_limit_from'
  1289. where rules_type = '$rules_type'
  1290. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  1291. and id = '$id';";
  1292. }else{
  1293. $sql.="INSERT INTO public.notifications_rules(
  1294. user_login, notifications_type, rules_type,
  1295. 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,
  1296. 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,
  1297. frequency_type, daily_time, daily_time_zone,
  1298. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  1299. event_details, frequency_display, method_display,shipment_details,
  1300. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit,shipment_etd_limit_from,shipment_eta_limit_from)
  1301. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  1302. '$ocean_etd_change','$ocean_etd_old_sub_new','$ocean_etd_old_sub_new_unit','$ocean_eta_change','$ocean_eta_old_sub_new','$ocean_eta_old_sub_new_unit',
  1303. '$air_etd_change','$air_etd_old_sub_new','$air_etd_old_sub_new_unit','$air_eta_change','$air_eta_old_sub_new','$air_eta_old_sub_new_unit',
  1304. '$frequency_type', $daily_time, '$daily_time_zone',
  1305. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  1306. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  1307. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit','$shipment_etd_limit_from','$shipment_eta_limit_from');";
  1308. }
  1309. }
  1310. //保存用户默认的时区
  1311. $default_time_zone = common::check_input($_POST['default_time_zone']);
  1312. $default_time_zone_db = utils::comvertutcinfo($default_time_zone);
  1313. $sql .= "update public.kln_user_extend set default_time_zone = '$default_time_zone_db' where lower(user_login) = '".strtolower(_getLoginName())."';";
  1314. return $sql;
  1315. }
  1316. /**
  1317. * 检查编辑提交的Monitoring规则,是否允许保存
  1318. */
  1319. public function checkedMonitoringRulesSave($rules_type){
  1320. $sql_where = "";
  1321. if(isset($_POST['id']) && !empty($_POST['id'])){
  1322. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  1323. }
  1324. $rules = common::excuteListSql("select *,
  1325. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  1326. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  1327. from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  1328. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  1329. foreach($rules as $rule){
  1330. //判断range 是否一样
  1331. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit","shipment_etd_limit_from","shipment_eta_limit_from");
  1332. $range_flag = true;
  1333. foreach($checkRangeFiled as $filed){
  1334. if($filed == "shipment_transport_mode"){
  1335. $postValue = utils::converModeToDB($_POST[$filed]);
  1336. $rule_mode_arr = explode(";", $rule[$filed]);
  1337. $post_mode_arr = explode(";", $postValue);
  1338. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1339. $range_flag = false;
  1340. }
  1341. }else{
  1342. //正常字段直接比较就行
  1343. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1344. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1345. if($postValue != $dbValue){
  1346. $range_flag = false;
  1347. }
  1348. }
  1349. }
  1350. //判断details 是否一样
  1351. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  1352. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  1353. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  1354. "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",
  1355. "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");
  1356. $details_flag = true;
  1357. foreach($checkDetailsFiled as $filed){
  1358. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  1359. $rule_mode_arr = empty($rule[$filed])? array() :explode(";", $rule[$filed]);
  1360. $post_mode_arr = $_POST[$filed];
  1361. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  1362. $details_flag = false;
  1363. }
  1364. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  1365. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  1366. if($post_boolean != $rule[$filed]){
  1367. $details_flag = false;
  1368. }
  1369. } elseif ($filed == "ocean_atd_sub_etd_unit" || $filed == "ocean_ata_sub_eta_unit"
  1370. || $filed == "air_atd_sub_etd_unit" || $filed == "air_ata_sub_eta_unit"
  1371. || $filed == "ocean_etd_old_sub_new_unit" || $filed == "ocean_eta_old_sub_new_unit"
  1372. || $filed == "air_etd_old_sub_new_unit" || $filed == "air_eta_old_sub_new_unit"){
  1373. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1374. if(!empty($postValue)){
  1375. $postValue = $postValue=="Day(s)" ? "days":"hours";
  1376. }
  1377. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1378. if($postValue != $dbValue){
  1379. $details_flag = false;
  1380. }
  1381. } else {
  1382. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1383. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1384. if($postValue != $dbValue){
  1385. $details_flag = false;
  1386. }
  1387. }
  1388. }
  1389. //判断frequency 是否一样
  1390. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  1391. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  1392. $frequency_flag = true;
  1393. foreach($checkFrequencyFiled as $filed){
  1394. if($filed == "daily_time" || $filed == "weekly_time"){
  1395. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1396. //_daily_time _weekly_time
  1397. $dbValue = !empty($rule["_".$filed]) ? $rule["_".$filed] : "";
  1398. if($postValue != $dbValue){
  1399. $frequency_flag = false;
  1400. }
  1401. } else {
  1402. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  1403. $dbValue = !empty($rule[$filed]) ? $rule[$filed] : "";
  1404. if($postValue != $dbValue){
  1405. $frequency_flag = false;
  1406. }
  1407. }
  1408. }
  1409. //判断通知方式是否一样
  1410. $checkMethodFiled = array("method_by_email","method_by_message");
  1411. $method_flag = true;
  1412. foreach($checkMethodFiled as $filed){
  1413. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  1414. if($postValue != $rule[$filed]){
  1415. $method_flag = false;
  1416. }
  1417. }
  1418. //五个条件一样,不允许保存
  1419. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  1420. $msg = "Unable to Save";
  1421. break;
  1422. }
  1423. //前三个重回,后面不重合,提示但允许保存
  1424. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  1425. $msg = "Similar Rule Detected";
  1426. break;
  1427. }
  1428. }
  1429. return $msg;
  1430. }
  1431. public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
  1432. if ($frequency_type == "all"){
  1433. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1434. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1435. $sql_where = " and (ni.frequency_type = 'Instant'
  1436. or (ni.frequency_type = 'Daily'
  1437. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1438. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1439. else
  1440. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1441. end))
  1442. or (ni.frequency_type = 'Weekly'
  1443. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1444. 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)
  1445. 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
  1446. else
  1447. 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
  1448. end)))";
  1449. } elseif($frequency_type == "Daily"){
  1450. $sql_where = " and (ni.frequency_type = 'Daily'
  1451. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1452. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1453. else
  1454. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1455. end))";
  1456. } elseif($frequency_type == "Weekly"){
  1457. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1458. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1459. // 如今天是4-14,最小边界值是4.8- 4.14
  1460. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1461. // 当 前时间是 4.15时,但到规定的time,取4.15
  1462. $sql_where = " and (ni.frequency_type = 'Weekly'
  1463. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1464. 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)
  1465. 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
  1466. else
  1467. 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
  1468. end))";
  1469. }
  1470. if (!empty($_REQUEST['current_time'])){
  1471. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1472. // and ni.is_send_message is null";
  1473. //这里都以服务器时间,检查标准
  1474. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
  1475. }
  1476. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1477. $sql_where .= " and ni.is_send_message is null";
  1478. }
  1479. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  1480. $aa_where = "";
  1481. if (!empty($insert_date_format)){
  1482. $aa_where = " where insert_date_format = '$insert_date_format'";
  1483. }
  1484. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1485. $sql = "select *
  1486. from (select ni.*,
  1487. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1488. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1489. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1490. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1491. else 0
  1492. end as _delay_diff,
  1493. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1494. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1495. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1496. 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')
  1497. || ' - ' ||
  1498. 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')
  1499. else ''
  1500. end as insert_date_format,
  1501. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1502. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1503. when COALESCE(ni.frequency_type,'') = 'Daily'
  1504. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1505. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1506. 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
  1507. else ''
  1508. end as first_notifiation_date,
  1509. case when ni.notifiation_type ='Milestone_Update'
  1510. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1511. else ''
  1512. end as milestone_previous_json,
  1513. case when ni.notifiation_type ='Container_Status_Update'
  1514. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1515. else ''
  1516. end as ctnr_previous_json,
  1517. case when ni.notifiation_type ='Container_Status_Update'
  1518. then (select description
  1519. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1520. else ''
  1521. end as ctnr_desc,
  1522. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  1523. from public.kln_notifiation_info ni
  1524. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1525. from public.kln_ocean oo
  1526. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1527. 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
  1528. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1529. and ni.insert_date > NOW() - INTERVAL '3 months'
  1530. and lower(ni.notifiation_type) in ($more_param)
  1531. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
  1532. error_log($sql);
  1533. $data_all_type = common::excuteListSql($sql);
  1534. $data_group = array();
  1535. $data_group_uniqe = array();
  1536. foreach($data_all_type as $dat){
  1537. $uniqe_group_str = $dat['notifiation_type'];
  1538. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  1539. $tempArr = $data_group[$uniqe_group_str];
  1540. $tempArr[] = $dat;
  1541. $data_group[$uniqe_group_str] = $tempArr;
  1542. } else {
  1543. $data_group[$uniqe_group_str] = array($dat);
  1544. $data_group_uniqe[] = $uniqe_group_str;
  1545. }
  1546. }
  1547. $retData = array();
  1548. foreach($data_group as $key => $data){
  1549. $notifiation_type_db = $key;
  1550. //统一处理数据Instant Daily weekly_week 先分开在处理
  1551. $instant = array();
  1552. $daily = array();
  1553. $daily_uniqe = array();
  1554. $weekly = array();
  1555. $weekly_uniqe = array();
  1556. foreach($data as $d){
  1557. if ($d['frequency_type'] == "Instant"){
  1558. $instant[] = $d;
  1559. }
  1560. //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  1561. $uniqe_str = $d['serial_no'];
  1562. if ($notifiation_type_db == "Milestone_Update"){
  1563. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
  1564. }else if ($notifiation_type_db == "Container_Status_Update"){
  1565. $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
  1566. }else if($notifiation_type_db == "Departure/Arrival_Delay"){
  1567. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
  1568. }else if($notifiation_type_db == "ETD/ETA_Change"){
  1569. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
  1570. }
  1571. if ($d['frequency_type'] == "Daily"){
  1572. if(!utils::in_array($uniqe_str,$daily_uniqe)){
  1573. $daily[$uniqe_str] = $d;
  1574. $daily_uniqe[] = $uniqe_str;
  1575. }
  1576. }
  1577. if ($d['frequency_type'] == "Weekly"){
  1578. if(!utils::in_array($uniqe_str,$weekly_uniqe)){
  1579. $weekly[$uniqe_str] = $d;
  1580. $weekly_uniqe[] = $uniqe_str;
  1581. }
  1582. }
  1583. }
  1584. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
  1585. }
  1586. return $retData;
  1587. }
  1588. public function getNotificationsNew($notifiation_type,$frequency_type,$insert_date_format = null){
  1589. if ($frequency_type == "all"){
  1590. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1591. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1592. $sql_where = " and (ni.frequency_type = 'Instant'
  1593. or (ni.frequency_type = 'Daily'
  1594. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1595. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1596. else
  1597. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1598. end))
  1599. or (ni.frequency_type = 'Weekly'
  1600. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1601. 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)
  1602. 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
  1603. else
  1604. 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
  1605. end)))";
  1606. } elseif($frequency_type == "Daily"){
  1607. $sql_where = " and (ni.frequency_type = 'Daily'
  1608. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1609. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1610. else
  1611. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1612. end))";
  1613. } elseif($frequency_type == "Weekly"){
  1614. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1615. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1616. // 如今天是4-14,最小边界值是4.8- 4.14
  1617. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1618. // 当 前时间是 4.15时,但到规定的time,取4.15
  1619. $sql_where = " and (ni.frequency_type = 'Weekly'
  1620. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1621. 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)
  1622. 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
  1623. else
  1624. 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
  1625. end))";
  1626. }
  1627. if (!empty($_REQUEST['current_time'])){
  1628. // $sql_where .= " and ni.insert_date >= TO_TIMESTAMP('".$_REQUEST['current_time']."', 'MM/DD/YYYY HH24:MI:SS') - interval '5 minutes'
  1629. // and ni.is_send_message is null";
  1630. //这里都以服务器时间,检查标准
  1631. $sql_where .= " and ni.insert_date >= now() - interval '5 minutes' and ni.is_send_message is null";
  1632. }
  1633. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
  1634. $sql_where .= " and ni.is_send_message is null";
  1635. }
  1636. if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'false'){
  1637. $sql_where .= " and ni.is_send_message is not null";
  1638. }
  1639. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1640. $cp = common::check_input($_REQUEST['cp']); //current_page
  1641. $ps = common::check_input($_REQUEST['ps']); //ps
  1642. if (empty($ps) || empty($cp)){
  1643. $limit_param = " ";
  1644. } else {
  1645. $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
  1646. }
  1647. $sql = "WITH base_data AS (
  1648. SELECT
  1649. id,
  1650. notifiation_type,
  1651. frequency_type,
  1652. insert_date,
  1653. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1654. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1655. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1656. 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')
  1657. || ' - ' ||
  1658. 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')
  1659. else ''
  1660. end as insert_date_format,
  1661. -- 提取用于去重的字段
  1662. serial_no,
  1663. milestone_code,
  1664. ctnr,
  1665. ctnr_status_code,
  1666. delay_name,
  1667. date_change_name
  1668. FROM public.kln_notifiation_info ni
  1669. WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1670. AND ni.insert_date > NOW() - INTERVAL '3 months'
  1671. and lower(ni.notifiation_type) in ($more_param)
  1672. AND frequency_type IN ('Daily', 'Weekly')
  1673. ".$sql_where." and ni.notifications_method = true
  1674. ),
  1675. base_instant_data AS (
  1676. SELECT id,insert_date FROM public.kln_notifiation_info ni
  1677. WHERE lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1678. AND ni.insert_date > NOW() - INTERVAL '3 months'
  1679. and lower(ni.notifiation_type) in ($more_param)
  1680. AND frequency_type = 'Instant'
  1681. ".$sql_where." and ni.notifications_method = true
  1682. ),
  1683. -- Step 1: 按 insert_date_format + notifiation_type 分组,统计去重数量
  1684. grouped_stats AS (
  1685. SELECT
  1686. insert_date_format,
  1687. notifiation_type,
  1688. COUNT(DISTINCT
  1689. CASE WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  1690. WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  1691. WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  1692. WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  1693. END
  1694. ) AS total_count,
  1695. -- Departure / Arrival 单独统计
  1696. COUNT(DISTINCT
  1697. CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Departure%' THEN (serial_no || '_' || delay_name) END
  1698. ) AS departure_count,
  1699. COUNT(DISTINCT
  1700. CASE WHEN notifiation_type = 'Departure/Arrival_Delay' AND delay_name LIKE '%Arrival%' THEN (serial_no || '_' || delay_name) END
  1701. ) AS arrival_count,
  1702. -- ETD / ETA 单独统计
  1703. COUNT(DISTINCT
  1704. CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETD%' THEN (serial_no || '_' || date_change_name) END
  1705. ) AS etd_count,
  1706. COUNT(DISTINCT
  1707. CASE WHEN notifiation_type = 'ETD/ETA_Change' AND date_change_name LIKE '%ETA%' THEN (serial_no || '_' || date_change_name) END
  1708. ) AS eta_count
  1709. FROM base_data
  1710. where notifiation_type in ('Milestone_Update','Container_Status_Update','Departure/Arrival_Delay','ETD/ETA_Change')
  1711. GROUP BY insert_date_format, notifiation_type
  1712. ),
  1713. -- Step 2: 找出每个 insert_date_format + notifiation_type 组内的最新一条记录
  1714. latest_records AS (
  1715. SELECT DISTINCT ON (insert_date_format, notifiation_type)
  1716. ni.id,
  1717. ni.notifiation_type,
  1718. ni.insert_date,
  1719. bd.insert_date_format
  1720. FROM public.kln_notifiation_info ni
  1721. INNER JOIN base_data bd
  1722. ON ni.id = bd.id
  1723. ORDER BY insert_date_format, notifiation_type, ni.insert_date DESC
  1724. ),
  1725. daily_weekly_summary AS (
  1726. SELECT
  1727. lr.id,
  1728. lr.insert_date,
  1729. gs.total_count,
  1730. gs.departure_count,
  1731. gs.arrival_count,
  1732. gs.etd_count,
  1733. gs.eta_count
  1734. FROM latest_records lr
  1735. LEFT JOIN grouped_stats gs
  1736. ON lr.insert_date_format = gs.insert_date_format
  1737. AND lr.notifiation_type = gs.notifiation_type
  1738. UNION ALL
  1739. SELECT
  1740. id,
  1741. insert_date,
  1742. NULL::INT AS total_count,
  1743. NULL::INT AS departure_count,
  1744. NULL::INT AS arrival_count,
  1745. NULL::INT AS etd_count,
  1746. NULL::INT AS eta_count
  1747. FROM base_instant_data
  1748. ),
  1749. summary AS (
  1750. SELECT id ,
  1751. insert_date,
  1752. total_count,
  1753. departure_count,
  1754. arrival_count,
  1755. etd_count,
  1756. eta_count
  1757. FROM daily_weekly_summary order by insert_date desc ".$limit_param."
  1758. )
  1759. select *
  1760. from (select ni.*,
  1761. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1762. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1763. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1764. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1765. else 0
  1766. end as _delay_diff,
  1767. case when COALESCE(ni.frequency_type,'') = 'Daily'
  1768. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1769. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1770. 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')
  1771. || ' - ' ||
  1772. 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')
  1773. else ''
  1774. end as insert_date_format,
  1775. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1776. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1777. when COALESCE(ni.frequency_type,'') = 'Daily'
  1778. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1779. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1780. 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
  1781. else ''
  1782. end as first_notifiation_date,
  1783. case when ni.notifiation_type ='Milestone_Update'
  1784. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1785. else ''
  1786. end as milestone_previous_json,
  1787. case when ni.notifiation_type ='Container_Status_Update'
  1788. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1789. else ''
  1790. end as ctnr_previous_json,
  1791. case when ni.notifiation_type ='Container_Status_Update'
  1792. then (select description
  1793. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1794. else ''
  1795. end as ctnr_desc,
  1796. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
  1797. from public.kln_notifiation_info ni
  1798. left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1799. from public.kln_ocean oo
  1800. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1801. inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
  1802. from summary
  1803. where id = ni.id ) eee on true
  1804. 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
  1805. order by ni.insert_date desc) aa";
  1806. error_log($sql);
  1807. $retData = common::excuteListSql($sql);
  1808. return $retData;
  1809. }
  1810. public function getNotificationsSeeAll($notifiation_type,$frequency_type,$insert_date_format = null){
  1811. if ($frequency_type == "all"){
  1812. //Daily 频率:超过昨天的数据,不在限制提醒的daily_time,全部应该查出来
  1813. //比如今天周四 17号, 上第一周截止是10号, 10号以后的数据,不在做weekly_time和weekly_week 的限制,直接查出来
  1814. $sql_where = " and (ni.frequency_type = 'Instant'
  1815. or (ni.frequency_type = 'Daily'
  1816. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1817. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1818. else
  1819. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1820. end))
  1821. or (ni.frequency_type = 'Weekly'
  1822. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1823. 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)
  1824. 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
  1825. else
  1826. 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
  1827. end)))";
  1828. } elseif($frequency_type == "Daily"){
  1829. $sql_where = " and (ni.frequency_type = 'Daily'
  1830. and (case when (timezone(ni.daily_time_zone, NOW())::time > ni.daily_time::time)
  1831. then timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date
  1832. else
  1833. timezone(ni.daily_time_zone,ni.insert_date)::date < timezone(ni.daily_time_zone, NOW())::date - '1 days'::INTERVAL
  1834. end))";
  1835. } elseif($frequency_type == "Weekly"){
  1836. //当前now()的配置是周2。 如今天是4-17,最小边界值是4.15- 4.21
  1837. // 如今天是4-15(这个是周二),最小边界值是4.15- 4.21
  1838. // 如今天是4-14,最小边界值是4.8- 4.14
  1839. // 当 前时间是 4.15时,但没到规定的time,取4.8,但此时的边界值4.15- 4.21(这个是一个例外,除此之外,可以直接用当前now的最小边界值);
  1840. // 当 前时间是 4.15时,但到规定的time,取4.15
  1841. $sql_where = " and (ni.frequency_type = 'Weekly'
  1842. and (case when (timezone(ni.weekly_time_zone, NOW())::time < ni.weekly_time::time
  1843. 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)
  1844. 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
  1845. else
  1846. 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
  1847. end))";
  1848. }
  1849. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  1850. if (!empty($insert_date_format)){
  1851. $sql_where = " and eee.insert_date_format = '$insert_date_format'";
  1852. }
  1853. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  1854. $cp = common::check_input($_REQUEST['cp']); //current_page
  1855. $ps = common::check_input($_REQUEST['ps']); //ps
  1856. if (empty($ps) || empty($cp)){
  1857. $limit_param = " ";
  1858. } else {
  1859. $limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
  1860. }
  1861. $sql = "select *
  1862. from (select ni.*,
  1863. ROW_NUMBER() OVER (
  1864. PARTITION BY
  1865. CASE
  1866. WHEN notifiation_type = 'Milestone_Update' THEN (serial_no || '_' || milestone_code)
  1867. WHEN notifiation_type = 'Container_Status_Update' THEN (ctnr || '_' || ctnr_status_code)
  1868. WHEN notifiation_type = 'Departure/Arrival_Delay' THEN (serial_no || '_' || delay_name)
  1869. WHEN notifiation_type = 'ETD/ETA_Change' THEN (serial_no || '_' || date_change_name)
  1870. END
  1871. ORDER BY insert_date DESC
  1872. ) AS rn,
  1873. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  1874. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  1875. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  1876. then (FLOOR(EXTRACT(epoch FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp))/3600))
  1877. else 0
  1878. end as _delay_diff,
  1879. eee.insert_date_format,
  1880. case when COALESCE(ni.frequency_type,'') = 'Instant'
  1881. then to_char(timezone(ddd.default_time_zone, ni.insert_date),'YYYY-mm-dd HH24:MI:SS')
  1882. when COALESCE(ni.frequency_type,'') = 'Daily'
  1883. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'YYYY-mm-dd')||' '||ni.daily_time
  1884. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1885. 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
  1886. else ''
  1887. end as first_notifiation_date,
  1888. case when ni.notifiation_type ='Milestone_Update'
  1889. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  1890. else ''
  1891. end as milestone_previous_json,
  1892. case when ni.notifiation_type ='Container_Status_Update'
  1893. then public.getPreviousCtnrStatus(ni.serial_no,ni.ctnr,ni.ctnr_status_code)
  1894. else ''
  1895. end as ctnr_previous_json,
  1896. case when ni.notifiation_type ='Container_Status_Update'
  1897. then (select description
  1898. from public.ra_online_edi_event e where e.ra_name = ni.ctnr_status_code limit 1)
  1899. else ''
  1900. end as ctnr_desc,
  1901. ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol
  1902. from public.kln_notifiation_info ni
  1903. inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol
  1904. from public.kln_ocean oo
  1905. where oo.serial_no = ni.serial_no limit 1) ccc on true
  1906. 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
  1907. left join LATERAL (select case when COALESCE(ni.frequency_type,'') = 'Daily'
  1908. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  1909. when COALESCE(ni.frequency_type,'') = 'Weekly'
  1910. 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')
  1911. || ' - ' ||
  1912. 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')
  1913. else ''
  1914. end as insert_date_format) eee on true
  1915. where lower(ni.user_login) in ('".strtolower(_getLoginName())."','all_user')
  1916. and ni.insert_date > NOW() - INTERVAL '3 months'
  1917. and lower(ni.notifiation_type) in ($more_param)
  1918. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa
  1919. WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
  1920. error_log($sql);
  1921. $retData = common::excuteListSql($sql);
  1922. return $retData;
  1923. }
  1924. public function getEventCard($mInfo){
  1925. $eventCard = array();
  1926. $notifiation_type = $mInfo['notifiation_type'];
  1927. if($notifiation_type == "Milestone_Update"){
  1928. $eventCard = array("type" =>'milestone',
  1929. "numericRecords"=>0,
  1930. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1931. "title"=>"Milestone Update",
  1932. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1933. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  1934. "tag"=>$mInfo["milestone_description"],
  1935. "location"=>$mInfo["milestone_locations"],
  1936. "timezone"=>$mInfo["milestone_timezone"],
  1937. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  1938. "timeLabel"=>"",
  1939. "previous"=>"",
  1940. "frequency_type"=>$mInfo["frequency_type"],
  1941. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1942. "order_from"=>$mInfo["order_from"],
  1943. "id"=>$mInfo["id"],
  1944. "insert_date_format"=>'',
  1945. "rules_type"=>$mInfo["notifiation_type"],
  1946. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  1947. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1948. "info"=>new stdClass());
  1949. if ($mInfo["frequency_type"] == "Daily"){
  1950. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1951. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  1952. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1953. //seeall 的时候,前端不需要id
  1954. $eventCard["id"] = '';
  1955. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1956. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1957. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1958. "date" => $milestone_previous['milestone']['milestone_date'],
  1959. "time" => $milestone_previous['milestone']['milestone_time'],
  1960. "timezone" =>$milestone_previous['milestone']['timezone']);
  1961. }
  1962. } else if($mInfo["frequency_type"] == "Weekly"){
  1963. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1964. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1965. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1966. //seeall 的时候,前端不需要id
  1967. $eventCard["id"] = '';
  1968. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  1969. if(!empty($milestone_previous['milestone']['milestone_date'])){
  1970. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1971. "date" => $milestone_previous['milestone']['milestone_date'],
  1972. "time" => $milestone_previous['milestone']['milestone_time'],
  1973. "timezone" =>$milestone_previous['milestone']['timezone']);
  1974. }
  1975. }
  1976. }
  1977. if($notifiation_type == "Container_Status_Update"){
  1978. //当前状态的描述ctnr_desc
  1979. //$ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  1980. $eventCard = array("type" =>'container',
  1981. "numericRecords"=>0,
  1982. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  1983. "title"=>"Container_Status_Update",
  1984. "mode"=>"Ocean Freight",
  1985. "no"=>$mInfo["ctnr"],
  1986. "tag"=>$mInfo["ctnr_desc"],
  1987. "location"=>$mInfo["ctnr_status_locations"],
  1988. "timezone"=>$mInfo["ctnr_status_timezone"],
  1989. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  1990. "timeLabel"=>"",
  1991. "previous"=>"",
  1992. "frequency_type"=>$mInfo["frequency_type"],
  1993. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  1994. "order_from"=>$mInfo["order_from"],
  1995. "id"=>$mInfo["id"],
  1996. "insert_date_format"=>'',
  1997. "rules_type"=>$mInfo["notifiation_type"],
  1998. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  1999. "info"=>new stdClass());
  2000. if ($mInfo["frequency_type"] == "Daily"){
  2001. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2002. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  2003. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2004. //seeall 的时候,前端不需要id
  2005. $eventCard["id"] = '';
  2006. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  2007. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  2008. //当前状态 前一个的描述
  2009. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  2010. "date" => $ctnr_previous["ctnrStatus"]["date"],
  2011. "time" => $ctnr_previous["ctnrStatus"]["time"],
  2012. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  2013. }
  2014. } else if($mInfo["frequency_type"] == "Weekly"){
  2015. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2016. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  2017. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2018. //seeall 的时候,前端不需要id
  2019. $eventCard["id"] = '';
  2020. $ctnr_previous = json_decode($mInfo["ctnr_previous_json"],true);
  2021. if(!empty($ctnr_previous["ctnrStatus"]["date"])){
  2022. //当前状态 前一个的描述
  2023. $eventCard["previous"] = array("tag" =>"Previous:" .$ctnr_previous["ctnrStatus"]["description"]. " from " .$ctnr_previous["ctnrStatus"]["locations"],
  2024. "date" => $ctnr_previous["ctnrStatus"]["date"],
  2025. "time" => $ctnr_previous["ctnrStatus"]["time"],
  2026. "timezone" =>$ctnr_previous["ctnrStatus"]["timezone"]);
  2027. }
  2028. }
  2029. }
  2030. if($notifiation_type == "Departure/Arrival_Delay"){
  2031. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  2032. $title = $mInfo["delay_name"];
  2033. $outsideLocation = "";
  2034. $outsideTimezone = "";
  2035. $outsideTimeLabel= "";
  2036. $insideTimeLabel= "";
  2037. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  2038. $outsideTimeLabel = "ETD";
  2039. $insideTimeLabel = "ATD";
  2040. }
  2041. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  2042. $outsideTimeLabel = "ETA";
  2043. $insideTimeLabel = "ATA";
  2044. }
  2045. //直航的的
  2046. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  2047. $outsideLocation = $mInfo["delay_locations_from"];
  2048. }
  2049. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  2050. $outsideLocation = $mInfo["delay_locations_to"];
  2051. }
  2052. $route = array();
  2053. $leg = array();
  2054. if($mInfo["delay_is_direct"] <>'t'){
  2055. $title = substr($mInfo["delay_name"],8);
  2056. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  2057. //当前current Leg
  2058. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  2059. if($mInfo["delay_current"] == "2"){
  2060. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  2061. }
  2062. }
  2063. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  2064. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  2065. $delay_diff = $mInfo["_delay_diff"];
  2066. $delay_unit = $mInfo["delay_unit"];
  2067. $eventCard = array("type" =>'delay',
  2068. "numericRecords"=>0,
  2069. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2070. "title"=>$title,
  2071. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  2072. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  2073. //第一个字母大写
  2074. "tag"=>ucfirst($mInfo["delay_name"]),
  2075. "location"=>$outsideLocation,
  2076. "timezone"=>$mInfo["delay_timezone"],
  2077. "time"=>$est_date,
  2078. "timeLabel"=>$outsideTimeLabel,
  2079. "previous"=>"",
  2080. "frequency_type"=>$mInfo["frequency_type"],
  2081. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2082. "order_from"=>$mInfo["order_from"],
  2083. "id"=>$mInfo["id"],
  2084. "insert_date_format"=>'',
  2085. "rules_type"=>$mInfo["notifiation_type"],
  2086. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  2087. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2088. "info"=>array("route"=>$route,
  2089. "leg"=>$leg,
  2090. "etdOrdeparturNum"=>0,
  2091. "etaOrarrivalNum"=>0,
  2092. "time"=>$act_date,
  2093. "timeLabel"=>$insideTimeLabel,
  2094. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  2095. "timezone"=>$mInfo["delay_timezone"]
  2096. ));
  2097. if ($mInfo["frequency_type"] == "Daily"){
  2098. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2099. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2100. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2101. $eventCard["title"] = "Delay Daily Summary(".$mInfo["insert_date_format"].")";
  2102. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2103. //seeall 的时候,前端不需要id
  2104. $eventCard["id"] = '';
  2105. } else if($mInfo["frequency_type"] == "Weekly"){
  2106. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2107. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2108. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2109. $eventCard["title"] = "Delay Weekly Summary(".$mInfo["insert_date_format"].")";
  2110. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2111. //seeall 的时候,前端不需要id
  2112. $eventCard["id"] = '';
  2113. }
  2114. }
  2115. if($notifiation_type == "ETD/ETA_Change"){
  2116. $title = $mInfo["date_change_name"];
  2117. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  2118. $outsideTimeLabel = "Original ETD";
  2119. $insideTimeLabel = "Updated ETD";
  2120. }
  2121. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  2122. $outsideTimeLabel = "Original ETA";
  2123. $insideTimeLabel = "Updated ETA";
  2124. }
  2125. if($mInfo["date_change_is_direct"] <>'t'){
  2126. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  2127. $title = substr($mInfo["date_change_name"],8);
  2128. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  2129. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  2130. if($mInfo["date_change_current"] == "2"){
  2131. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  2132. }
  2133. }
  2134. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  2135. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  2136. $eventCard = array("type" =>'change',
  2137. "numericRecords"=>0,
  2138. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2139. "title"=>$title,
  2140. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  2141. "no"=>!empty($mInfo["h_bol"]) ? $mInfo["h_bol"] : $mInfo["m_bol"],
  2142. "tag"=>ucfirst($mInfo["date_change_name"]),
  2143. "location"=>"",
  2144. "timezone"=>$mInfo["date_change_timezone"],
  2145. "time"=>$original_date,
  2146. "timeLabel"=>$outsideTimeLabel,
  2147. "previous"=>"",
  2148. "frequency_type"=>$mInfo["frequency_type"],
  2149. "serial_no"=>common::deCode($mInfo["serial_no"], 'E'),
  2150. "order_from"=>$mInfo["order_from"],
  2151. "id"=>$mInfo["id"],
  2152. "insert_date_format"=>'',
  2153. "rules_type"=>$mInfo["notifiation_type"],
  2154. "is_display_hbol"=>!empty($mInfo["h_bol"]),
  2155. "first_notifiation_date"=>$mInfo["first_notifiation_date"],
  2156. "info"=>array("route"=>$route,
  2157. "leg"=>$leg,
  2158. "etdOrdeparturNum"=>0,
  2159. "etaOrarrivalNum"=>0,
  2160. "time"=>$updated_date,
  2161. "timeLabel"=>$insideTimeLabel,
  2162. "delayTimeTip"=>"",
  2163. "timezone"=>$mInfo["date_change_timezone"]
  2164. ));
  2165. if ($mInfo["frequency_type"] == "Daily"){
  2166. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2167. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2168. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2169. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  2170. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2171. $eventCard["id"] = "";
  2172. } else if($mInfo["frequency_type"] == "Weekly"){
  2173. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  2174. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  2175. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  2176. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  2177. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  2178. $eventCard["id"] = "";
  2179. }
  2180. }
  2181. if($notifiation_type == "Feature_Update" || $notifiation_type == "Passwond_Notifcations"){
  2182. $title = $mInfo["other_type"] == "password" ? "Password Notifications" : "Feature Update";
  2183. $isExpiration = false;
  2184. if($title == "Password Notifications" and $mInfo["other_pnum"] <= 3){
  2185. $isExpiration = true;
  2186. }
  2187. $path = $mInfo["id"];
  2188. if(!empty($mInfo["serial_no"])){
  2189. $path =$mInfo["serial_no"];
  2190. }
  2191. $eventCard = array(
  2192. "title" => $title,
  2193. "id"=> $mInfo["id"],
  2194. "header"=> $mInfo["other_name"],
  2195. "content"=>$mInfo["other_desc"],
  2196. "content_two"=>$mInfo["other_desc_two"],
  2197. "isRead"=>!empty($mInfo["is_send_message"]) ? true : false,
  2198. "isExpiration"=> $isExpiration,
  2199. "rules_type"=>$mInfo["notifiation_type"],
  2200. "imgSrc"=>SERVER_PAHT.FILE_UPLOAD_PAHT."feature_update_".$path.".png",
  2201. "view_more_link" =>"main_new_version.php?action=feature_update&id=".$path
  2202. );
  2203. }
  2204. return $eventCard;
  2205. }
  2206. /**
  2207. * 返回当前柜子的status信息描述,目前作废
  2208. */
  2209. public static function getContainerStatusDesc($ctnr_status_code){
  2210. $event =common::getEDICtnrEvent();
  2211. $ctnrStatusdesc = "";
  2212. foreach($event as $e){
  2213. if($e['event_name'] == $ctnr_status_code){
  2214. $ctnrStatusdesc = $e['description'];
  2215. }
  2216. }
  2217. return $ctnrStatusdesc;
  2218. }
  2219. }
  2220. ?>