tools.class.php 145 KB

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