tools.class.php 66 KB

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