tools.class.php 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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 ra_online_user u
  128. left join 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_init") {
  158. $subscribur_data =array();
  159. //查询用户对应的Rule
  160. $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  161. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
  162. from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
  163. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  164. $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
  165. foreach($all_rules as $rule_name){
  166. $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
  167. $subscribur_data[$rule_name] = $rules;
  168. }
  169. //整合拼接addedRules
  170. $addedRules = array();
  171. foreach($subscribe_rules as $addedRule){
  172. $addedRules[] = array(
  173. "visible" => false,
  174. "id" =>$addedRule['id'],
  175. "Event" =>$addedRule['rules_type'],
  176. "Event Details" =>$addedRule['event_details'],
  177. "Frequency" =>$addedRule['frequency_display'],
  178. "Methods" =>$addedRule['method_display']);
  179. }
  180. $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
  181. //获取subscribe shipment 当前页数cp,每页ps
  182. $subscribeShipmentWithPage = $this->getSubscribeShipment(1,15);
  183. $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
  184. common::echo_json_encode(200,$subscribur_data);
  185. exit();
  186. }
  187. if ($operate == "subscribe_notification_event_update"){
  188. $rules_type = common::check_input($_POST["rules_type"]);
  189. //判断该规则是否存在
  190. $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
  191. and lower(user_login) = '".strtolower(_getLoginName())."'");
  192. $updateOrInsert = empty($exist) ? "insert" : "update";
  193. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
  194. $rs = common::excuteUpdateSql($sql);
  195. if ($rs === FALSE){
  196. $data = array("msg" => "Update Error");
  197. } else{
  198. $data = array("msg" => "Update Successful");
  199. //返回addedRules 全部列表
  200. $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
  201. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  202. //整合拼接addedRules
  203. $addedRules = array();
  204. foreach($subscribe_rules as $addedRule){
  205. $addedRules[] = array(
  206. "id" =>$addedRule['id'],
  207. "Event" =>$addedRule['rules_type'],
  208. "Event Details" =>$addedRule['event_details'],
  209. "Frequency" =>$addedRule['frequency_display'],
  210. "Methods" =>$addedRule['method_display']);
  211. }
  212. $data['addedRules'] = array("tableData"=>$addedRules);
  213. }
  214. common::echo_json_encode(200,$data);
  215. exit();
  216. }
  217. if ($operate == "subscribe_notification_rules_delete"){
  218. $rules_type = common::check_input($_POST['rules_type']);
  219. $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
  220. and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
  221. common::excuteUpdateSql($sql);
  222. $data = array("msg" => "Delete Successful");
  223. common::echo_json_encode(200,$data);
  224. exit();
  225. }
  226. if ($operate == "subscribe_shipment"){
  227. $serial_no = common::deCode($_POST['serial_no'], 'D');
  228. $is_subscribe = common::check_input($_POST['is_subscribe']);
  229. if($is_subscribe == "true"){
  230. $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
  231. if(!empty($exist)){
  232. $data = array("msg" => "Subscribe exist,Please check");
  233. common::echo_json_encode(200,$data);
  234. exit();
  235. }
  236. $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
  237. VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
  238. common::excuteUpdateSql($sql);
  239. $data = array("msg" => "Subscribe Successful");
  240. common::echo_json_encode(200,$data);
  241. exit();
  242. }else{
  243. //取消订阅
  244. $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
  245. common::excuteUpdateSql($sql);
  246. $data = array("msg" => "Cancel Subscribe successfully");
  247. common::echo_json_encode(200,$data);
  248. exit();
  249. }
  250. }
  251. if ($operate == "subscribe_shipment_search"){
  252. $cp = common::check_input($_POST ['cp']); //current_page
  253. $ps = common::check_input($_POST ['ps']); //ps
  254. $arrTmp = $this->getSubscribeShipment($cp,$ps);
  255. common::echo_json_encode(200,$arrTmp);
  256. exit();
  257. }
  258. }
  259. public function user_monitoring_setting(){
  260. $operate = utils::_get('operate');
  261. $operate = strtolower($operate);
  262. if ($operate == "monitoring_rules_init"){
  263. $ret = array();
  264. //Milestone Update的页面配置数据
  265. $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
  266. $oceanMilestone = array();
  267. $airMilestone = array();
  268. foreach($milestones as $milestone){
  269. if($milestone['type'] == "air"){
  270. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  271. }
  272. if($milestone['type'] == "sea"){
  273. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  274. }
  275. }
  276. $ret["OceanCheckBoxList"] = $oceanMilestone;
  277. $ret["AirCheckBoxList"] = $airMilestone;
  278. //Milestone Update的结构处理
  279. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  280. $event =common::getEDICtnrEvent();
  281. $ctnrStatus = array();
  282. foreach($event as $e){
  283. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  284. }
  285. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  286. common::echo_json_encode(200,$ret);
  287. exit();
  288. }
  289. if ($operate == "monitoring_rules_search") {
  290. $cp = common::check_input($_POST ['cp']); //current_page
  291. $ps = common::check_input($_POST ['ps']); //ps
  292. if (empty($ps))
  293. $ps = 15;
  294. $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
  295. $rc = common::excuteOneSql($sql);
  296. $tp = ceil($rc / $ps);
  297. if ($rc > 0) {
  298. $sql = "select *,replace(rules_type, '_', ' ') AS _rules_type_display,
  299. case when rules_type = 'Milestone_Update' then 'Milestone'
  300. when rules_type = 'Container_Status_Update' then 'Container'
  301. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  302. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  303. else '' end as notifications_option
  304. from public.notifications_rules
  305. where lower(user_login) = '".strtolower(_getLoginName())."'
  306. and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  307. $monitoringRules = common::excuteListSql($sql);
  308. $arrTmp = array('monitoringRules' => $monitoringRules,
  309. 'rc' => intval($rc),
  310. 'ps' => intval($ps),
  311. 'cp' => intval($cp),
  312. 'tp' => intval($tp)
  313. );
  314. } else {
  315. $arrTmp = array('searchData' => array(),
  316. 'rc' => intval($rc),
  317. 'ps' => intval($ps),
  318. 'cp' => intval($cp),
  319. 'tp' => intval($tp)
  320. );
  321. }
  322. common::echo_json_encode(200,$arrTmp);
  323. exit();
  324. }
  325. if ($operate == "monitoring_rules_edit"){
  326. $id = $_POST['id'];
  327. $rules_type = common::check_input($_POST['rules_type']);
  328. $subscribe_rule_sql = "select *,
  329. TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
  330. TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time,
  331. case when rules_type = 'Milestone_Update' then 'Milestone'
  332. when rules_type = 'Container_Status_Update' then 'Container'
  333. when rules_type = 'Departure/Arrival_Delay' then 'Departure'
  334. when rules_type = 'ETD/ETA_Change' then 'ETDChange'
  335. else '' end as notifications_option
  336. from public.notifications_rules where notifications_type = 'Monitoring' and lower(user_login) = '".strtolower(_getLoginName())."'
  337. and id = '$id' order by id";
  338. $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
  339. $rules = $this->getSubscribeRules($rules_type,$subscribe_rules);
  340. //数据转换前端需要的显示的格式
  341. $rules["shipment_transport_mode"] = utils::converModeToDisplay($rules["shipment_transport_mode"]);
  342. $monitoring_data[$rules_type] = $rules;
  343. common::echo_json_encode(200,$monitoring_data);
  344. exit();
  345. }
  346. if ($operate == "monitoring_rules_do") {
  347. $rules_type = common::check_input($_POST["rules_type"]);
  348. //检查编辑提交的Monitoring规则,是否允许保存
  349. $msg = $this->checkedMonitoringRulesSave($rules_type);
  350. if(!empty($msg)){
  351. $data = array("msg" =>$msg);
  352. common::echo_json_encode(200,$data);
  353. exit();
  354. }
  355. $updateOrInsert = "insert";
  356. if(isset($_POST['id']) && !empty($_POST['id'])){
  357. $updateOrInsert = "update";
  358. }
  359. $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
  360. $rs = common::excuteUpdateSql($sql);
  361. if ($rs === FALSE){
  362. $data = array("msg" => "Update Error");
  363. } else{
  364. $data = array("msg" => "Update Successful");
  365. }
  366. common::echo_json_encode(200,$data);
  367. exit();
  368. }
  369. if ($operate == "monitoring_rules_delete"){
  370. $id = common::check_input($_POST['id']);
  371. $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
  372. and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id'";
  373. common::excuteUpdateSql($sql);
  374. $data = array("msg" => "Delete Successful");
  375. common::echo_json_encode(200,$data);
  376. exit();
  377. }
  378. }
  379. public function notifications_rules(){
  380. $operate = utils::_get('operate');
  381. $operate = strtolower($operate);
  382. if ($operate == "notifications_init"){
  383. $rules_type = common::check_input($_REQUEST['rules_type']);
  384. $milestoneData = array();
  385. $containerData = array();
  386. $delayData = array();
  387. $changeData = array();
  388. if ($rules_type == "all"){
  389. $rules_type = "Milestone_Update;Container_Status_Update;Departure/Arrival_Delay;ETD/ETA_Change";
  390. $allData = $this->getNotifications($rules_type,"all");
  391. $milestoneData = $allData['Milestone_Update'];
  392. $containerData = $allData['Container_Status_Update'];
  393. $delayData = $allData['Departure/Arrival_Delay'];
  394. $changeData = $allData['ETD/ETA_Change'];
  395. } else {
  396. $data = $this->getNotifications($rules_type,"all");
  397. if($rules_type == "Milestone_Update"){
  398. $milestoneData = $data['Milestone_Update'];
  399. }elseif($rules_type == "Container_Status_Update"){
  400. $containerData = $data['Container_Status_Update'];
  401. }elseif($rules_type == "Departure/Arrival_Delay"){
  402. $delayData = $data['Departure/Arrival_Delay'];
  403. }elseif($rules_type == "ETD/ETA_Change"){
  404. $changeData = $data['ETD/ETA_Change'];
  405. }
  406. }
  407. $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,"changeData"=>$changeData);
  408. $instant_sum = array();
  409. foreach($data as $v){
  410. if(!empty($v['instant'])){
  411. foreach($v['instant'] as $instant){
  412. $instant_sum[] = $instant;
  413. }
  414. }
  415. if(!empty($v['daily'])){
  416. //取第一组的第一个显示
  417. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($v['daily']);
  418. $instant_sum[]= $dailyFristAndFrist;
  419. }
  420. if(!empty($v['weekly'])){
  421. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($v['weekly']);
  422. $instant_sum[]= $weeklyFristAndFrist;
  423. }
  424. }
  425. //根据时间顺序排序
  426. $insert_dates = array_column($instant_sum, 'insert_date');
  427. array_multisort($insert_dates, SORT_ASC, $instant_sum);
  428. $info = array();
  429. foreach($instant_sum as $mInfo){
  430. $eventCard = $this->getEventCard($mInfo);
  431. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  432. }
  433. $returnData = $info;
  434. common::echo_json_encode(200,$returnData);
  435. exit();
  436. }
  437. if($operate == "notifications_see_all"){
  438. $rules_type = common::check_input($_REQUEST['rules_type']);
  439. $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
  440. $notificationsData = $this->getNotifications($rules_type,$frequency_type);
  441. $moreData = $notificationsData[$rules_type][strtolower($frequency_type)];
  442. //这个函数里面带有分开计数的信息
  443. $dataInfo =utils::getDailyAndweeklyFrist($moreData);
  444. $returnData = array();
  445. $notificationList = array();
  446. foreach($moreData as $key => $data){
  447. $eventCard = $this->getEventCard($data);
  448. //sea all的数据格式和查询全部的格式有区别
  449. if($key == 0){
  450. $returnData["title"] = $eventCard["title"];
  451. if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
  452. $returnData["numericRecords_one"] = $dataInfo["numericRecords_one"];
  453. $returnData["numericRecords_two"] =$dataInfo["numericRecords_two"];
  454. }else{
  455. $returnData["numericRecords"] = $dataInfo["numericRecords"];
  456. }
  457. }
  458. //移除不需要的字段
  459. unset($eventCard["title"]);
  460. $notificationList[] = $eventCard;
  461. }
  462. if(!empty($notificationList)){
  463. $returnData["notificationList"] = $notificationList;
  464. }
  465. //点击seall会默认全部标记为已读
  466. $all_id = $notificationsData[$rules_type][strtolower($frequency_type."_all_id")];
  467. $returnData["all_id"] = $all_id;
  468. if(!empty($all_id)){
  469. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$all_id)));
  470. $markReadSql = "update public.kln_notifiation_info set is_send_message = true where id in ($more_param)";
  471. //common::excuteUpdateSql($markReadSql);
  472. }
  473. common::echo_json_encode(200,$returnData);
  474. exit();
  475. }
  476. if($operate == "notifications_read"){
  477. $read_type = common::check_input($_POST["read_type"]);
  478. $id = $_POST["id"];
  479. //代表改用户下的所有信息全部标记为已读
  480. if ($read_type == "true"){
  481. $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = true where lower(user_login) = '".strtolower(_getLoginName())."'");
  482. }else{
  483. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$id)));
  484. $markReadSql = "update public.kln_notifiation_info set is_send_message = true where id in ($more_param)";
  485. $rs = common::excuteUpdateSql($markReadSql);
  486. }
  487. if ($rs === FALSE){
  488. $returnData = array("msg" =>"Error");
  489. common::echo_json_encode(500,$returnData);
  490. }else{
  491. $returnData = array("msg" =>"Success");
  492. common::echo_json_encode(200,$returnData);
  493. }
  494. exit();
  495. }
  496. if ($operate == "notifications_message_init"){
  497. $rules_type = common::check_input($_REQUEST['rules_type']);
  498. //查询所有情况得未读情况 查询最近一年的情况
  499. //"select * from public.kln_notifiation_info where ";
  500. }
  501. }
  502. /**
  503. * 遍历查找对应的rule。
  504. */
  505. public function getSubscribeRules($rule_name,$subscribe_rules){
  506. //初始是不显示,没有值的情况
  507. $ret = array("is_display" => false);
  508. foreach($subscribe_rules as $rules){
  509. if($rules['rules_type'] == $rule_name){
  510. $rules["is_display"] = true;
  511. $rules["daily_time"] = $rules["_daily_time"];
  512. $rules["weekly_time"] = $rules["_weekly_time"];
  513. $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
  514. $ret = $rules;
  515. }
  516. }
  517. //Milestone Update的结构处理,处理init page load
  518. if($rule_name == "Milestone_Update"){
  519. //Milestone Update的页面配置数据
  520. $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
  521. $oceanMilestone = array();
  522. $airMilestone = array();
  523. foreach($milestones as $milestone){
  524. if($milestone['type'] == "air"){
  525. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  526. }
  527. if($milestone['type'] == "sea"){
  528. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  529. }
  530. }
  531. $ret["OceanCheckBoxList"] = $oceanMilestone;
  532. $ret["AirCheckBoxList"] = $airMilestone;
  533. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  534. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  535. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  536. $ret["AirCheckedList"] = $airMilestoneSetting;
  537. }
  538. //Milestone Update的结构处理
  539. if($rule_name == "Container_Status_Update"){
  540. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  541. $event =common::getEDICtnrEvent();
  542. $ctnrStatus = array();
  543. foreach($event as $e){
  544. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  545. }
  546. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  547. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  548. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  549. }
  550. return $ret;
  551. }
  552. /**
  553. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  554. * cp current_page
  555. */
  556. public function getSubscribeShipment($cp,$ps){
  557. if (empty($cp)){
  558. $cp = 1;
  559. }
  560. if (empty($ps)){
  561. $ps = 15;
  562. }
  563. $sql = "select count(1) from public.kln_user_subscribed u
  564. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  565. where lower(user_login) = '".strtolower(_getLoginName())."'";
  566. $rc = common::excuteOneSql($sql);
  567. $tp = ceil($rc / $ps);
  568. if ($rc > 0) {
  569. $sql = "select o.h_bol,
  570. o.shipper,o.consignee,o.etd,o.eta,
  571. case when transport_mode = 'sea'
  572. then (select sn.description
  573. from public.ocean_milestone a
  574. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  575. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  576. when transport_mode = 'air' and order_from = 'public'
  577. then (select sn.description
  578. from public.air_milestone a
  579. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  580. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  581. when transport_mode = 'air' and order_from = 'sfs'
  582. then (select sn.description
  583. from sfs.air_milestone a
  584. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  585. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  586. else '' end as recent_milestone
  587. from public.kln_user_subscribed u
  588. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  589. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  590. $subscribeShipment = common::excuteListSql($sql);
  591. $arrTmp = array('tableData' => $subscribeShipment,
  592. 'rc' => intval($rc),
  593. 'ps' => $ps,
  594. 'cp' => $cp,
  595. 'tp' => $tp
  596. );
  597. } else {
  598. $arrTmp = array('tableData' => array(),
  599. 'rc' => $rc,
  600. 'ps' => $ps,
  601. 'cp' => $cp,
  602. 'tp' => $tp,
  603. );
  604. }
  605. return $arrTmp;
  606. }
  607. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  608. $sql = "";
  609. //先删后加
  610. if($updateOrInsert == "update"){
  611. $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  612. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  613. and id = '$id';";
  614. }
  615. //这个几个参数是所有规则都有的参数
  616. $frequency_type = common::check_input($_POST['frequency_type']);
  617. $daily_time = "null";
  618. $daily_time_zone = "";
  619. $weekly_week = "";
  620. $weekly_time = "null";
  621. $weekly_time_zone = "";
  622. if(strtolower($frequency_type) == "daily"){
  623. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  624. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  625. } elseif (strtolower($frequency_type) == "weekly"){
  626. $weekly_week = common::check_input($_POST['weekly_week']);
  627. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  628. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  629. }
  630. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  631. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  632. $event_details = common::check_input($_POST['event_details']);
  633. $frequency_display = common::check_input($_POST['frequency_display']);
  634. $method_display = common::check_input($_POST['method_display']);
  635. $shipment_detail = common::check_input($_POST['shipment_details']);
  636. //当规则是 Monitoring类型是,需要配置的range
  637. $shipment_transport_mode = "";
  638. $shipment_etd_limit = "";
  639. $shipment_eta_limit = "";
  640. if($notifications_type == "Monitoring"){
  641. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  642. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  643. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  644. }
  645. if ($rules_type == "Milestone_Update"){
  646. //提交的description 的转换code
  647. $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
  648. $oceanMilestone = array();
  649. $airMilestone = array();
  650. foreach($milestones as $milestone){
  651. if($milestone['type'] == "air"){
  652. $airMilestone[] = $milestone;
  653. }
  654. if($milestone['type'] == "sea"){
  655. $oceanMilestone[] = $milestone;
  656. }
  657. }
  658. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  659. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  660. $sql.="INSERT INTO public.notifications_rules(
  661. user_login, notifications_type, rules_type, ocean_milestone,
  662. air_milestone, frequency_type, daily_time, daily_time_zone,
  663. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  664. event_details, frequency_display, method_display,shipment_details,
  665. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  666. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
  667. '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
  668. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  669. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  670. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  671. }
  672. if ($rules_type == "Container_Status_Update"){
  673. $event = common::getEDICtnrEvent();
  674. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  675. $sql.="INSERT INTO public.notifications_rules(
  676. user_login, notifications_type, rules_type, ocean_ctnr_status,
  677. frequency_type, daily_time, daily_time_zone,
  678. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  679. event_details, frequency_display, method_display,shipment_details,
  680. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  681. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  682. '$frequency_type', $daily_time, '$daily_time_zone',
  683. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  684. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  685. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  686. }
  687. if ($rules_type == "Departure/Arrival_Delay"){
  688. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  689. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  690. if(!empty($ocean_atd_sub_etd_unit)){
  691. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  692. }
  693. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  694. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  695. if(!empty($ocean_ata_sub_eta_unit)){
  696. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  697. }
  698. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  699. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  700. if(!empty($air_atd_sub_etd_unit)){
  701. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  702. }
  703. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  704. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  705. if(!empty($air_ata_sub_eta_unit)){
  706. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  707. }
  708. $sql.="INSERT INTO public.notifications_rules(
  709. user_login, notifications_type, rules_type,
  710. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  711. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  712. frequency_type, daily_time, daily_time_zone,
  713. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  714. event_details, frequency_display, method_display,shipment_details,
  715. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  716. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  717. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  718. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  719. '$frequency_type', $daily_time, '$daily_time_zone',
  720. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  721. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  722. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  723. }
  724. if ($rules_type == "ETD/ETA_Change"){
  725. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  726. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  727. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  728. if(!empty($ocean_etd_old_sub_new_unit)){
  729. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  730. }
  731. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  732. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  733. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  734. if(!empty($ocean_eta_old_sub_new_unit)){
  735. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  736. }
  737. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  738. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  739. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  740. if(!empty($air_etd_old_sub_new_unit)){
  741. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  742. }
  743. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  744. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  745. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  746. if(!empty($air_eta_old_sub_new_unit)){
  747. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  748. }
  749. $sql.="INSERT INTO public.notifications_rules(
  750. user_login, notifications_type, rules_type,
  751. 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,
  752. 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,
  753. frequency_type, daily_time, daily_time_zone,
  754. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  755. event_details, frequency_display, method_display,shipment_details,
  756. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  757. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  758. '$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',
  759. '$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',
  760. '$frequency_type', $daily_time, '$daily_time_zone',
  761. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  762. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  763. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  764. }
  765. return $sql;
  766. }
  767. /**
  768. * 检查编辑提交的Monitoring规则,是否允许保存
  769. */
  770. public function checkedMonitoringRulesSave($rules_type){
  771. $sql_where = "";
  772. if(isset($_POST['id']) && !empty($_POST['id'])){
  773. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  774. }
  775. $rules = common::excuteListSql("select * from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  776. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  777. foreach($rules as $rule){
  778. //判断range 是否一样
  779. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit");
  780. $range_flag = true;
  781. foreach($checkRangeFiled as $filed){
  782. if($filed == "shipment_transport_mode"){
  783. $postValue = utils::converModeToDB($_POST[$filed]);
  784. $rule_mode_arr = explode(";", $rule[$filed]);
  785. $post_mode_arr = explode(";", $postValue);
  786. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  787. $range_flag = false;
  788. }
  789. }else{
  790. //正常字段直接比较就行
  791. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  792. if($postValue != $rule[$filed]){
  793. $range_flag = false;
  794. }
  795. }
  796. }
  797. //判断details 是否一样
  798. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  799. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  800. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  801. "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",
  802. "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");
  803. $details_flag = true;
  804. foreach($checkDetailsFiled as $filed){
  805. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  806. $rule_mode_arr = explode(";", $rule[$filed]);
  807. $post_mode_arr = explode(";", $_POST[$filed]);
  808. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  809. $details_flag = false;
  810. }
  811. $postValue = utils::implode(";",$_POST[$filed]);
  812. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  813. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  814. if($post_boolean != $rule[$filed]){
  815. $details_flag = false;
  816. }
  817. } else {
  818. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  819. if($postValue != $rule[$filed]){
  820. $details_flag = false;
  821. }
  822. }
  823. }
  824. //判断frequency 是否一样
  825. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  826. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  827. $frequency_flag = true;
  828. foreach($checkFrequencyFiled as $filed){
  829. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  830. if($postValue != $rule[$filed]){
  831. $frequency_flag = false;
  832. }
  833. }
  834. //判断通知方式是否一样
  835. $checkMethodFiled = array("method_by_email","method_by_message");
  836. $method_flag = true;
  837. foreach($checkMethodFiled as $filed){
  838. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  839. if($postValue != $rule[$filed]){
  840. $method_flag = false;
  841. }
  842. }
  843. //五个条件一样,不允许保存
  844. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  845. $msg = "Unable to Save";
  846. continue;
  847. }
  848. //前三个重回,后面不重合,提示但允许保存
  849. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  850. $msg = "Similar Rule Detected";
  851. continue;
  852. }
  853. }
  854. return $msg;
  855. }
  856. public function getNotifications($notifiation_type,$frequency_type){
  857. if ($frequency_type == "all"){
  858. $sql_where = " and (ni.frequency_type = 'Instant'
  859. or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
  860. or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  861. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
  862. } elseif($frequency_type == "Daily"){
  863. $sql_where = " and (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
  864. } elseif($frequency_type == "Weekly"){
  865. $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  866. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
  867. }
  868. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  869. $sql = "select ni.*,
  870. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  871. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  872. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  873. then (EXTRACT(HOUR FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  874. else 0
  875. end as delay_diff,
  876. case when COALESCE(ni.frequency_type,'') = 'Daily'
  877. then to_char(timezone(ni.daily_time_zone, now()),'Mon DD, YYYY')
  878. when COALESCE(ni.frequency_type,'') = 'Weekly'
  879. then to_char(timezone(ni.weekly_time_zone, now()),'Mon DD, YYYY')
  880. else ''
  881. end as insert_date_format,
  882. ccc.order_from,ccc.h_bol,ccc.transport_mode
  883. from public.kln_notifiation_info ni
  884. left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from
  885. from public.kln_ocean oo
  886. where oo.serial_no = ni.serial_no limit 1) ccc on true
  887. where lower(ni.user_login) = '".strtolower(_getLoginName())."'
  888. and lower(ni.notifiation_type) in ($more_param)
  889. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc";
  890. error_log($sql);
  891. $data_all_type = common::excuteListSql($sql);
  892. $data_group = array();
  893. $data_group_uniqe = array();
  894. foreach($data_all_type as $dat){
  895. $uniqe_group_str = $dat['notifiation_type'];
  896. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  897. $tempArr = $data_group[$uniqe_group_str];
  898. $tempArr[] = $dat;
  899. $data_group[$uniqe_group_str] = $tempArr;
  900. } else {
  901. $data_group[$uniqe_group_str] = array($dat);
  902. $data_group_uniqe[] = $uniqe_group_str;
  903. }
  904. }
  905. $retData = array();
  906. foreach($data_group as $key => $data){
  907. $notifiation_type_db = $key;
  908. //统一处理数据Instant Daily weekly_week 先分开在处理
  909. $instant = array();
  910. $daily = array();
  911. $daily_uniqe = array();
  912. $daily_all_id = array();
  913. $weekly = array();
  914. $weekly_uniqe = array();
  915. $weekly_all_id = array();
  916. foreach($data as $d){
  917. if ($d['frequency_type'] == "Instant"){
  918. $instant[] = $d;
  919. }
  920. //类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  921. $uniqe_str = $d['serial_no'];
  922. if ($notifiation_type_db == "Departure/Arrival_Delay"){
  923. $uniqe_str = $d['serial_no']."_".$d['delay_name'];
  924. } else if($notifiation_type_db == "ETD/ETA_Change"){
  925. $uniqe_str = $d['serial_no']."_".$d['date_change_name'];
  926. }
  927. if ($d['frequency_type'] == "Daily"){
  928. if($d["is_send_message"] <> 't'){
  929. $daily_all_id[] = $d["id"];
  930. }
  931. if(utils::in_array($uniqe_str,$daily_uniqe)){
  932. $temp = $daily[$uniqe_str];
  933. //previous只更新最近的一次,并且是需要查询详细的时候,才放开previous的查询
  934. if(empty($temp['previous']) && $frequency_type <> "all"){
  935. $temp['previous'] = $d;
  936. }
  937. $daily[$uniqe_str] = $temp;
  938. } else {
  939. $daily[$uniqe_str] = $d;
  940. $daily_uniqe[] = $uniqe_str;
  941. }
  942. }
  943. if ($d['frequency_type'] == "Weekly"){
  944. if($d["is_send_message"] <> 't'){
  945. $weekly_all_id[] = $d["id"];
  946. }
  947. if(utils::in_array($uniqe_str,$weekly_uniqe)){
  948. $temp = $weekly[$uniqe_str];
  949. //previous只更新最近的一次,并且是需要查询详细的时候,才放开previous的查询
  950. if(empty($temp['previous']) && $frequency_type <> "all"){
  951. $temp['previous'] = $d;
  952. }
  953. $weekly[$uniqe_str] = $temp;
  954. } else {
  955. $weekly[$uniqe_str] = $d;
  956. $weekly_uniqe[] = $uniqe_str;
  957. }
  958. }
  959. }
  960. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly),
  961. "daily_all_id" =>$daily_all_id,"weekly_all_id"=>$weekly_all_id);
  962. }
  963. return $retData;
  964. }
  965. public function getEventCard($mInfo){
  966. $eventCard = array();
  967. $notifiation_type = $mInfo['notifiation_type'];
  968. if($notifiation_type == "Milestone_Update"){
  969. $eventCard = array("type" =>'milestone',
  970. "numericRecords"=>0,
  971. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  972. "title"=>"Milestone Update",
  973. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  974. "no"=>$mInfo["h_bol"],
  975. "tag"=>$mInfo["milestone_description"],
  976. "location"=>$mInfo["milestone_locations"],
  977. "timezone"=>$mInfo["milestone_timezone"],
  978. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  979. "timeLabel"=>"",
  980. "previous"=>"",
  981. "frequency_type"=>$mInfo["frequency_type"],
  982. "serial_no"=>$mInfo["serial_no"],
  983. "order_from"=>$mInfo["order_from"],
  984. "id"=>$mInfo["id"],
  985. "info"=>new stdClass());
  986. if ($mInfo["frequency_type"] == "Daily"){
  987. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  988. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  989. if(!empty($mInfo["previous"])){
  990. $eventCard["previous"] = array("tag" =>"Previous:".$mInfo["previous"]["milestone_description"]." from ".$mInfo["previous"]["milestone_locations"],
  991. "time" => $mInfo["previous"]["milestone_time"],
  992. "timezone" =>$mInfo["previous"]["milestone_timezone"]);
  993. }
  994. } else if($mInfo["frequency_type"] == "Weekly"){
  995. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  996. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  997. if(!empty($mInfo["previous"])){
  998. $eventCard["previous"] = array("tag" =>"Previous:".$mInfo["previous"]["milestone_desc"]." from ".$mInfo["previous"]["milestone_description"],
  999. "time" => $mInfo["previous"]["milestone_time"],
  1000. "timezone" =>$mInfo["previous"]["milestone_timezone"]);
  1001. }
  1002. }
  1003. }
  1004. if($notifiation_type == "Container_Status_Update"){
  1005. //当前状态的描述
  1006. $ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  1007. $eventCard = array("type" =>'container',
  1008. "numericRecords"=>0,
  1009. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1010. "title"=>"Container_Status_Update",
  1011. "mode"=>"Ocean Freight",
  1012. "no"=>$mInfo["ctnr"],
  1013. "tag"=>$ctnrStatusdesc,
  1014. "location"=>$mInfo["ctnr_status_locations"],
  1015. "timezone"=>$mInfo["ctnr_status_timezone"],
  1016. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  1017. "timeLabel"=>"",
  1018. "previous"=>"",
  1019. "frequency_type"=>$mInfo["frequency_type"],
  1020. "serial_no"=>$mInfo["serial_no"],
  1021. "order_from"=>$mInfo["order_from"],
  1022. "id"=>$mInfo["id"],
  1023. "info"=>new stdClass());
  1024. if ($mInfo["frequency_type"] == "Daily"){
  1025. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1026. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1027. if(!empty($mInfo["previous"])){
  1028. //当前状态 前一个的描述
  1029. $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
  1030. $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
  1031. "time" => $mInfo["previous"]["ctnr_status_time"],
  1032. "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
  1033. }
  1034. } else if($mInfo["frequency_type"] == "Weekly"){
  1035. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1036. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1037. if(!empty($mInfo["previous"])){
  1038. //当前状态 前一个的描述
  1039. $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
  1040. $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
  1041. "time" => $mInfo["previous"]["ctnr_status_time"],
  1042. "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
  1043. }
  1044. }
  1045. }
  1046. if($notifiation_type == "Departure/Arrival_Delay"){
  1047. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  1048. $title = $mInfo["delay_name"];
  1049. $outsideLocation = "";
  1050. $outsideTimezone = "";
  1051. $outsideTimeLabel= "";
  1052. $insideTimeLabel= "";
  1053. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  1054. $outsideTimeLabel = "ETD";
  1055. $insideTimeLabel = "ATD";
  1056. }
  1057. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  1058. $outsideTimeLabel = "ETA";
  1059. $insideTimeLabel = "ATA";
  1060. }
  1061. //直航的的
  1062. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  1063. $outsideLocation = $mInfo["delay_locations_from"];
  1064. }
  1065. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  1066. $outsideLocation = $mInfo["delay_locations_to"];
  1067. }
  1068. $route = array();
  1069. $leg = array();
  1070. if($mInfo["delay_is_direct"] <>'t'){
  1071. $title = substr($mInfo["delay_name"],8);
  1072. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1073. //当前current Leg
  1074. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  1075. if($mInfo["delay_current"] == "2"){
  1076. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1077. }
  1078. }
  1079. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  1080. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  1081. $delay_diff = $mInfo["delay_diff"];
  1082. $delay_unit = $mInfo["delay_unit"];
  1083. $eventCard = array("type" =>'delay',
  1084. "numericRecords"=>0,
  1085. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1086. "title"=>$title,
  1087. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1088. "no"=>$mInfo["h_bol"],
  1089. "tag"=>$mInfo["delay_name"],
  1090. "location"=>$outsideLocation,
  1091. "timezone"=>$mInfo["delay_timezone"],
  1092. "time"=>$est_date,
  1093. "timeLabel"=>$outsideTimeLabel,
  1094. "previous"=>"",
  1095. "frequency_type"=>$mInfo["frequency_type"],
  1096. "serial_no"=>$mInfo["serial_no"],
  1097. "order_from"=>$mInfo["order_from"],
  1098. "id"=>$mInfo["id"],
  1099. "info"=>array("route"=>$route,
  1100. "leg"=>$leg,
  1101. "etdOrdeparturNum"=>0,
  1102. "etaOrarrivalNum"=>0,
  1103. "time"=>$act_date,
  1104. "timeLabel"=>$insideTimeLabel,
  1105. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  1106. "timezone"=>$mInfo["delay_timezone"]
  1107. ));
  1108. if ($mInfo["frequency_type"] == "Daily"){
  1109. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1110. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1111. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1112. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1113. } else if($mInfo["frequency_type"] == "Weekly"){
  1114. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1115. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1116. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1117. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1118. }
  1119. }
  1120. if($notifiation_type == "ETD/ETA_Change"){
  1121. $title = $mInfo["date_change_name"];
  1122. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  1123. $outsideTimeLabel = "Original ETD";
  1124. $insideTimeLabel = "Upoated ETD";
  1125. }
  1126. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  1127. $outsideTimeLabel = "Original ETA";
  1128. $insideTimeLabel = "Upoated ETA";
  1129. }
  1130. if($mInfo["date_change_is_direct"] <>'t'){
  1131. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  1132. $title = substr($mInfo["date_change_name"],8);
  1133. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1134. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  1135. if($mInfo["delay_current"] == "2"){
  1136. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1137. }
  1138. }
  1139. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  1140. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  1141. $eventCard = array("type" =>'change',
  1142. "numericRecords"=>0,
  1143. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1144. "title"=>$title,
  1145. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1146. "no"=>$mInfo["h_bol"],
  1147. "tag"=>$mInfo["date_change_name"],
  1148. "location"=>"",
  1149. "timezone"=>$mInfo["date_change_timezone"],
  1150. "time"=>$original_date,
  1151. "timeLabel"=>$outsideTimeLabel,
  1152. "previous"=>"",
  1153. "frequency_type"=>$mInfo["frequency_type"],
  1154. "serial_no"=>$mInfo["serial_no"],
  1155. "order_from"=>$mInfo["order_from"],
  1156. "id"=>$mInfo["id"],
  1157. "info"=>array("route"=>$route,
  1158. "leg"=>$leg,
  1159. "etdOrdeparturNum"=>0,
  1160. "etaOrarrivalNum"=>0,
  1161. "time"=>$updated_date,
  1162. "timeLabel"=>$insideTimeLabel,
  1163. "delayTimeTip"=>"",
  1164. "timezone"=>$mInfo["date_change_timezone"]
  1165. ));
  1166. if ($mInfo["frequency_type"] == "Daily"){
  1167. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1168. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1169. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1170. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  1171. } else if($mInfo["frequency_type"] == "Weekly"){
  1172. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1173. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1174. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1175. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  1176. }
  1177. }
  1178. return $eventCard;
  1179. }
  1180. /**
  1181. * 返回当前柜子的status信息描述
  1182. */
  1183. public static function getContainerStatusDesc($ctnr_status_code){
  1184. $event =common::getEDICtnrEvent();
  1185. $ctnrStatusdesc = "";
  1186. foreach($event as $e){
  1187. if($e['event_name'] == $ctnr_status_code){
  1188. $ctnrStatusdesc = $e['description'];
  1189. }
  1190. }
  1191. return $ctnrStatusdesc;
  1192. }
  1193. }
  1194. ?>