tools.class.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of operation_log
  7. *
  8. * @author Administrator
  9. */
  10. class tools {
  11. private static $_tools;
  12. public static function getInstance() {
  13. if (!self::$_tools) {
  14. $c = __CLASS__;
  15. self::$_tools = new $c;
  16. }
  17. return self::$_tools;
  18. }
  19. /*
  20. * update password when login success
  21. */
  22. public function updatePassword() {
  23. if ($_SESSION['ONLINE_USER']['is_demo'] == "t") {
  24. $str = "DEMO cannot update password.";
  25. } else {
  26. $opsw = common::check_input($_POST ['opsw']);
  27. $npsw = common::check_input($_POST ['npsw']);
  28. $username = _getLoginName();
  29. $msg = common::checkPasswordRule($username, $npsw);
  30. //为空代表验证通过
  31. if (empty($msg)) {
  32. $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($username) . "'";
  33. $rs = common::excuteObjectSql($sql);
  34. $str = '';
  35. if (!empty($rs)) {
  36. if ($rs['password'] == $opsw) {
  37. $sql = "UPDATE ra_online_user SET ra_password = '" . $npsw . "', last_pwd_change = now() WHERE lower(user_login) = '" . strtolower($username) . "'";
  38. $rls = common::excuteUpdateSql($sql);
  39. if (!$rls) {
  40. $str = "Password modification failed!";
  41. } else {
  42. $str = " Your password has been modified!";
  43. }
  44. } else {
  45. $str = "Old password is incorrect!";
  46. }
  47. } else {
  48. $str = "Old password is incorrect!";
  49. }
  50. } else {
  51. $str = $msg;
  52. }
  53. }
  54. $returnData = array("msg" => $str);
  55. common::echo_json_encode(200, $returnData);
  56. exit();
  57. }
  58. public function markSystem(){
  59. $operate = utils::_get('operate');
  60. $operate = strtolower($operate);
  61. if ($operate == "mark_save") {
  62. $suggestion = utils::implode(",",$_POST['suggestion']);
  63. $proposal = common::check_input($_POST['proposal']);
  64. $expression = common::check_input($_POST['expression']);
  65. $complete_funtionality = common::check_input($_POST['Complete_funtionality']);
  66. $accurate_data = common::check_input($_POST['Accurate_data']);
  67. $clear_information = common::check_input($_POST['Clear_information']);
  68. $easy_to_use = common::check_input($_POST['Easy_to_use']);
  69. $system_Performance = common::check_input($_POST['System_Performance']);
  70. $username = common::check_input($_POST['username']);
  71. $user_type = _isApexLogin() ? "employee" : "customer";
  72. if(!isset($_SESSION['ONLINE_USER'])){
  73. $user_type = "other";
  74. }
  75. $loginName = _getLoginName();
  76. $loginEamil = _getLoginEamil();
  77. //如果在没有登录前,没有登录信息,指定用户-- 这里逻辑取消,没有登录相当于匿名用户的评价,无法获取用户名
  78. // if(!isset($_SESSION['ONLINE_USER'])){
  79. // $user_type = "Customer";
  80. // if(!empty($username)){
  81. // $loginName = $username;
  82. // $loginEamil = common::excuteOneSql("select email from public.ra_online_user u where lower(user_login) = '" . strtolower($username) . "'");
  83. // }
  84. // }
  85. $sql = "INSERT INTO public.customer_service_user_mark(user_type, user_name, suggestion, proposal, expression, complete_funtionality,
  86. accurate_data, clear_information, easy_to_use, system_performance,
  87. created_time,email)
  88. VALUES ('$user_type', '$loginName', '$suggestion', '$proposal', '$expression', '$complete_funtionality',
  89. '$accurate_data', '$clear_information', '$easy_to_use', '$system_Performance', now(),'$loginEamil')";
  90. common::excuteUpdateSql($sql);
  91. $data = array("msg" =>"success");
  92. common::echo_json_encode(200,$data);
  93. exit();
  94. }
  95. }
  96. public function user_system_setting(){
  97. $operate = utils::_get('operate');
  98. $operate = strtolower($operate);
  99. if ($operate == "personal_profile_init") {
  100. // get system config
  101. $sql = "SELECT lower(ra_name) as ra_name, ra_value from ra_online_config where lower(ra_name) in ('employee_password_change_cycle', 'customer_password_change_cycle')";
  102. $rs1s = common::excuteListSql($sql);
  103. foreach ($rs1s as $rs1) {
  104. if ($rs1['ra_name'] == 'employee_password_change_cycle')
  105. $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  106. if ($rs1['ra_name'] == 'customer_password_change_cycle')
  107. $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
  108. }
  109. $sql="select item_value from config where item='passwordChangePeriod'";
  110. $pcp = common::excuteObjectSql($sql);
  111. $passwordChangePeriod = json_decode($pcp["item_value"],true);
  112. if (_isApexLogin()) {
  113. $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
  114. //如果有新配置,则采用新配置
  115. if (!empty($pcp)) {
  116. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
  117. }
  118. } else {
  119. $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
  120. //如果有新配置,则采用新配置
  121. if (!empty($pcp)) {
  122. $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
  123. }
  124. }
  125. $sql = "select u.first_name,u.last_name,u.user_login,u.email,EXTRACT(DAY from (now() - u.last_pwd_change)) as last_pwd_change_date,
  126. ue.date_format,ue.numbers_format
  127. from public.ra_online_user u
  128. left join public.kln_user_extend ue on u.user_login = ue.user_login
  129. where lower(u.user_login) = '".strtolower(_getLoginName())."' ";
  130. $data = common::excuteObjectSql($sql);
  131. $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
  132. common::echo_json_encode(200,$data);
  133. exit();
  134. }
  135. if ($operate == "personal_profile_save") {
  136. $save_model = common::check_input($_POST['save_model']);
  137. if ($save_model == "profile"){
  138. $first_name = common::check_input($_POST['first_name']);
  139. $last_name = common::check_input($_POST['last_name']);
  140. $sql = "update public.ra_online_user set first_name = '$first_name',last_name = '$last_name' where lower(user_login) = '".strtolower(_getLoginName())."'";
  141. }else{
  142. $date_format = common::check_input($_REQUEST['date_format']);
  143. $numbers_format = common::check_input($_REQUEST['numbers_format']);
  144. $exist_kln_user = common::excuteObjectSql("select user_login from public.kln_user_extend where lower(user_login) = '".strtolower(_getLoginName())."'");
  145. if (!empty($exist_kln_user['user_login'])){
  146. $sql = "update public.kln_user_extend set date_format = '$date_format',numbers_format = '$numbers_format' where lower(user_login) = '".strtolower(_getLoginName())."'";
  147. } else {
  148. $sql = "INSERT INTO public.kln_user_extend(user_login, date_format, numbers_format, subscribe_hbol)
  149. VALUES ('"._getLoginName()."', '$date_format', '$numbers_format', null);";
  150. }
  151. }
  152. common::excuteUpdateSql($sql);
  153. $data = array("msg" => "save Successful");
  154. common::echo_json_encode(200,$data);
  155. exit();
  156. }
  157. if ($operate == "subscribe_notification_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 public.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. $dailys = common::handleDailyWeekedData($v['daily']);
  417. foreach($dailys as $dailyArr){
  418. //取第一组的第一个显示
  419. $dailyFristAndFrist = utils::getDailyAndweeklyFrist($dailyArr);
  420. $instant_sum[]= $dailyFristAndFrist;
  421. }
  422. }
  423. if(!empty($v['weekly'])){
  424. $weeklys = common::handleDailyWeekedData($v['weekly']);
  425. foreach($weeklys as $weeklyArr){
  426. $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($weeklyArr);
  427. $instant_sum[]= $weeklyFristAndFrist;
  428. }
  429. }
  430. }
  431. //根据时间顺序排序
  432. $insert_dates = array_column($instant_sum, 'insert_date');
  433. array_multisort($insert_dates, SORT_ASC, $instant_sum);
  434. $info = array();
  435. foreach($instant_sum as $mInfo){
  436. $eventCard = $this->getEventCard($mInfo);
  437. $info[] = array("notificationType"=>"event","info" =>$eventCard);
  438. }
  439. $returnData = $info;
  440. common::echo_json_encode(200,$returnData);
  441. exit();
  442. }
  443. if($operate == "notifications_see_all"){
  444. $rules_type = common::check_input($_REQUEST['rules_type']);
  445. $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
  446. $insert_date_format = common::check_input($_REQUEST['insert_date_format']);
  447. $notificationsData = $this->getNotifications($rules_type,$frequency_type,$insert_date_format);
  448. $moreData = $notificationsData[$rules_type][strtolower($frequency_type)];
  449. //这个函数里面带有分开计数的信息
  450. $dataInfo =utils::getDailyAndweeklyFrist($moreData);
  451. $returnData = array();
  452. $notificationList = array();
  453. $ids = array();
  454. foreach($moreData as $key => $data){
  455. $eventCard = $this->getEventCard($data);
  456. //sea all的数据格式和查询全部的格式有区别
  457. if($key == 0){
  458. $returnData["title"] = $eventCard["title"];
  459. if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
  460. $returnData["numericRecords_one"] = $dataInfo["numericRecords_one"];
  461. $returnData["numericRecords_two"] =$dataInfo["numericRecords_two"];
  462. }else{
  463. $returnData["numericRecords"] = $dataInfo["numericRecords"];
  464. }
  465. }
  466. //移除不需要的字段
  467. unset($eventCard["title"]);
  468. $notificationList[] = $eventCard;
  469. $ids[] = $data['id'];
  470. }
  471. if(!empty($notificationList)){
  472. $returnData["notificationList"] = $notificationList;
  473. }
  474. //点击seall会默认全部标记为已读
  475. if(!empty($ids)){
  476. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$ids)));
  477. $markReadSql = "update public.kln_notifiation_info set is_send_message = true where id in ($more_param)";
  478. //common::excuteUpdateSql($markReadSql);
  479. }
  480. common::echo_json_encode(200,$returnData);
  481. exit();
  482. }
  483. if($operate == "notifications_read"){
  484. $read_type = common::check_input($_POST["read_type"]);
  485. $id = $_POST["id"];
  486. //代表改用户下的所有信息全部标记为已读
  487. if ($read_type == "true"){
  488. $rs = common::excuteUpdateSql("update public.kln_notifiation_info set is_send_message = true where lower(user_login) = '".strtolower(_getLoginName())."'");
  489. }else{
  490. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$id)));
  491. $markReadSql = "update public.kln_notifiation_info set is_send_message = true where id in ($more_param)";
  492. $rs = common::excuteUpdateSql($markReadSql);
  493. }
  494. if ($rs === FALSE){
  495. $returnData = array("msg" =>"Error");
  496. common::echo_json_encode(500,$returnData);
  497. }else{
  498. $returnData = array("msg" =>"Success");
  499. common::echo_json_encode(200,$returnData);
  500. }
  501. exit();
  502. }
  503. if ($operate == "notifications_message_init"){
  504. $rules_type = common::check_input($_REQUEST['rules_type']);
  505. //查询所有情况得未读情况 查询最近一年的情况
  506. "select
  507. sum(case when (1<>1 or (notifiation_type='Milestone_Update')) then 1 else 0 end) as sea_rc,
  508. sum(case when (1<>1 or (notifiation_type='sea')) then 1 else 0 end) as sea_rc,
  509. sum(case when (1<>1 or (notifiation_type='sea')) then 1 else 0 end) as sea_rc,
  510. sum(case when (1<>1 or (notifiation_type='sea')) then 1 else 0 end) as sea_rc,
  511. sum(case when (1<>1 or (notifiation_type='sea')) then 1 else 0 end) as sea_rc
  512. from public.kln_notifiation_info
  513. where insert_date > NOW() - INTERVAL '1 year'
  514. and notifications_method = 'true' and is_send_message = 'false'";
  515. }
  516. }
  517. /**
  518. * 遍历查找对应的rule。
  519. */
  520. public function getSubscribeRules($rule_name,$subscribe_rules){
  521. //初始是不显示,没有值的情况
  522. $ret = array("is_display" => false);
  523. foreach($subscribe_rules as $rules){
  524. if($rules['rules_type'] == $rule_name){
  525. $rules["is_display"] = true;
  526. $rules["daily_time"] = $rules["_daily_time"];
  527. $rules["weekly_time"] = $rules["_weekly_time"];
  528. $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
  529. $ret = $rules;
  530. }
  531. }
  532. //Milestone Update的结构处理,处理init page load
  533. if($rule_name == "Milestone_Update"){
  534. //Milestone Update的页面配置数据
  535. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  536. $oceanMilestone = array();
  537. $airMilestone = array();
  538. foreach($milestones as $milestone){
  539. if($milestone['type'] == "air"){
  540. $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  541. }
  542. if($milestone['type'] == "sea"){
  543. $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['code']);
  544. }
  545. }
  546. $ret["OceanCheckBoxList"] = $oceanMilestone;
  547. $ret["AirCheckBoxList"] = $airMilestone;
  548. $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
  549. $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
  550. $ret["OceanCheckedList"] = $oceanMilestoneSetting;
  551. $ret["AirCheckedList"] = $airMilestoneSetting;
  552. }
  553. //Milestone Update的结构处理
  554. if($rule_name == "Container_Status_Update"){
  555. //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
  556. $event =common::getEDICtnrEvent();
  557. $ctnrStatus = array();
  558. foreach($event as $e){
  559. $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['event_name']);
  560. }
  561. $ret["CtnrCheckBoxList"] = $ctnrStatus;
  562. $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
  563. $ret["CtnrCheckedList"] = $ctnrStatusSetting;
  564. }
  565. return $ret;
  566. }
  567. /**
  568. * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
  569. * cp current_page
  570. */
  571. public function getSubscribeShipment($cp,$ps){
  572. if (empty($cp)){
  573. $cp = 1;
  574. }
  575. if (empty($ps)){
  576. $ps = 15;
  577. }
  578. $sql = "select count(1) from public.kln_user_subscribed u
  579. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  580. where lower(user_login) = '".strtolower(_getLoginName())."'";
  581. $rc = common::excuteOneSql($sql);
  582. $tp = ceil($rc / $ps);
  583. if ($rc > 0) {
  584. $sql = "select o.h_bol,
  585. o.shipper,o.consignee,o.etd,o.eta,
  586. case when transport_mode = 'sea'
  587. then (select sn.description
  588. from public.ocean_milestone a
  589. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
  590. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  591. when transport_mode = 'air' and order_from = 'public'
  592. then (select sn.description
  593. from public.air_milestone a
  594. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  595. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  596. when transport_mode = 'air' and order_from = 'sfs'
  597. then (select sn.description
  598. from sfs.air_milestone a
  599. inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
  600. where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
  601. else '' end as recent_milestone
  602. from public.kln_user_subscribed u
  603. left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
  604. where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
  605. $subscribeShipment = common::excuteListSql($sql);
  606. $arrTmp = array('tableData' => $subscribeShipment,
  607. 'rc' => intval($rc),
  608. 'ps' => $ps,
  609. 'cp' => $cp,
  610. 'tp' => $tp
  611. );
  612. } else {
  613. $arrTmp = array('tableData' => array(),
  614. 'rc' => $rc,
  615. 'ps' => $ps,
  616. 'cp' => $cp,
  617. 'tp' => $tp,
  618. );
  619. }
  620. return $arrTmp;
  621. }
  622. public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
  623. $sql = "";
  624. //先删后加
  625. if($updateOrInsert == "update"){
  626. $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
  627. and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
  628. and id = '$id';";
  629. }
  630. //这个几个参数是所有规则都有的参数
  631. $frequency_type = common::check_input($_POST['frequency_type']);
  632. $daily_time = "null";
  633. $daily_time_zone = "";
  634. $weekly_week = "";
  635. $weekly_time = "null";
  636. $weekly_time_zone = "";
  637. if(strtolower($frequency_type) == "daily"){
  638. $daily_time = "'".common::check_input($_POST['daily_time'])."'";
  639. $daily_time_zone = common::check_input($_POST['daily_time_zone']);
  640. } elseif (strtolower($frequency_type) == "weekly"){
  641. $weekly_week = common::check_input($_POST['weekly_week']);
  642. $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
  643. $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
  644. }
  645. $method_by_email = !empty($_POST['method_by_email']) ? common::check_input($_POST['method_by_email']) : 'false';
  646. $method_by_message = !empty($_POST['method_by_message']) ? common::check_input($_POST['method_by_message']) : 'false';
  647. $event_details = common::check_input($_POST['event_details']);
  648. $frequency_display = common::check_input($_POST['frequency_display']);
  649. $method_display = common::check_input($_POST['method_display']);
  650. $shipment_detail = common::check_input($_POST['shipment_details']);
  651. //当规则是 Monitoring类型是,需要配置的range
  652. $shipment_transport_mode = "";
  653. $shipment_etd_limit = "";
  654. $shipment_eta_limit = "";
  655. if($notifications_type == "Monitoring"){
  656. $shipment_transport_mode = utils::converModeToDB($_POST['shipment_transport_mode']);
  657. $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
  658. $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
  659. }
  660. if ($rules_type == "Milestone_Update"){
  661. //提交的description 的转换code
  662. $milestones = common::excuteListSql("select * from public.customer_service_milestone_sno order by type, sno");
  663. $oceanMilestone = array();
  664. $airMilestone = array();
  665. foreach($milestones as $milestone){
  666. if($milestone['type'] == "air"){
  667. $airMilestone[] = $milestone;
  668. }
  669. if($milestone['type'] == "sea"){
  670. $oceanMilestone[] = $milestone;
  671. }
  672. }
  673. $ocean_milestone = utils::implode(";",$_POST['ocean_milestone']);
  674. $air_milestone = utils::implode(";",$_POST['air_milestone']);
  675. $sql.="INSERT INTO public.notifications_rules(
  676. user_login, notifications_type, rules_type, ocean_milestone,
  677. air_milestone, 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_milestone',
  682. '$air_milestone', '$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 == "Container_Status_Update"){
  688. $event = common::getEDICtnrEvent();
  689. $ocean_ctnr_status = utils::implode(";",$_POST['ocean_ctnr_status']);
  690. $sql.="INSERT INTO public.notifications_rules(
  691. user_login, notifications_type, rules_type, ocean_ctnr_status,
  692. frequency_type, daily_time, daily_time_zone,
  693. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  694. event_details, frequency_display, method_display,shipment_details,
  695. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  696. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
  697. '$frequency_type', $daily_time, '$daily_time_zone',
  698. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  699. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  700. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  701. }
  702. if ($rules_type == "Departure/Arrival_Delay"){
  703. $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
  704. $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
  705. if(!empty($ocean_atd_sub_etd_unit)){
  706. $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  707. }
  708. $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
  709. $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
  710. if(!empty($ocean_ata_sub_eta_unit)){
  711. $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  712. }
  713. $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
  714. $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
  715. if(!empty($air_atd_sub_etd_unit)){
  716. $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
  717. }
  718. $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
  719. $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
  720. if(!empty($air_ata_sub_eta_unit)){
  721. $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
  722. }
  723. $sql.="INSERT INTO public.notifications_rules(
  724. user_login, notifications_type, rules_type,
  725. ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
  726. air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
  727. frequency_type, daily_time, daily_time_zone,
  728. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  729. event_details, frequency_display, method_display,shipment_details,
  730. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  731. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  732. '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
  733. '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
  734. '$frequency_type', $daily_time, '$daily_time_zone',
  735. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  736. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  737. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  738. }
  739. if ($rules_type == "ETD/ETA_Change"){
  740. $ocean_etd_change = !empty($_POST['ocean_etd_change']) ? common::check_input($_POST['ocean_etd_change']) : 'false';
  741. $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
  742. $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
  743. if(!empty($ocean_etd_old_sub_new_unit)){
  744. $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  745. }
  746. $ocean_eta_change = !empty($_POST['ocean_eta_change']) ? common::check_input($_POST['ocean_eta_change']) : 'false';
  747. $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
  748. $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
  749. if(!empty($ocean_eta_old_sub_new_unit)){
  750. $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  751. }
  752. $air_etd_change = !empty($_POST['air_etd_change']) ? common::check_input($_POST['air_etd_change']) : 'false';
  753. $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
  754. $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
  755. if(!empty($air_etd_old_sub_new_unit)){
  756. $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
  757. }
  758. $air_eta_change = !empty($_POST['air_eta_change']) ? common::check_input($_POST['air_eta_change']): 'false';
  759. $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
  760. $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
  761. if(!empty($air_eta_old_sub_new_unit)){
  762. $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
  763. }
  764. $sql.="INSERT INTO public.notifications_rules(
  765. user_login, notifications_type, rules_type,
  766. 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,
  767. 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,
  768. frequency_type, daily_time, daily_time_zone,
  769. weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
  770. event_details, frequency_display, method_display,shipment_details,
  771. shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
  772. VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
  773. '$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',
  774. '$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',
  775. '$frequency_type', $daily_time, '$daily_time_zone',
  776. '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
  777. '$event_details', '$frequency_display', '$method_display','$shipment_detail',
  778. '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
  779. }
  780. return $sql;
  781. }
  782. /**
  783. * 检查编辑提交的Monitoring规则,是否允许保存
  784. */
  785. public function checkedMonitoringRulesSave($rules_type){
  786. $sql_where = "";
  787. if(isset($_POST['id']) && !empty($_POST['id'])){
  788. $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
  789. }
  790. $rules = common::excuteListSql("select * from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
  791. and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
  792. foreach($rules as $rule){
  793. //判断range 是否一样
  794. $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit");
  795. $range_flag = true;
  796. foreach($checkRangeFiled as $filed){
  797. if($filed == "shipment_transport_mode"){
  798. $postValue = utils::converModeToDB($_POST[$filed]);
  799. $rule_mode_arr = explode(";", $rule[$filed]);
  800. $post_mode_arr = explode(";", $postValue);
  801. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  802. $range_flag = false;
  803. }
  804. }else{
  805. //正常字段直接比较就行
  806. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  807. if($postValue != $rule[$filed]){
  808. $range_flag = false;
  809. }
  810. }
  811. }
  812. //判断details 是否一样
  813. $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
  814. "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
  815. "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
  816. "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",
  817. "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");
  818. $details_flag = true;
  819. foreach($checkDetailsFiled as $filed){
  820. if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
  821. $rule_mode_arr = explode(";", $rule[$filed]);
  822. $post_mode_arr = explode(";", $_POST[$filed]);
  823. if(!utils::compareArrayEq($post_mode_arr,$rule_mode_arr)){
  824. $details_flag = false;
  825. }
  826. $postValue = utils::implode(";",$_POST[$filed]);
  827. } elseif ($filed == "ocean_etd_change" || $filed == "ocean_eta_change" || $filed == "air_etd_change" || $filed == "air_eta_change"){
  828. $post_boolean = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f":"t";
  829. if($post_boolean != $rule[$filed]){
  830. $details_flag = false;
  831. }
  832. } else {
  833. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  834. if($postValue != $rule[$filed]){
  835. $details_flag = false;
  836. }
  837. }
  838. }
  839. //判断frequency 是否一样
  840. $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
  841. "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
  842. $frequency_flag = true;
  843. foreach($checkFrequencyFiled as $filed){
  844. $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
  845. if($postValue != $rule[$filed]){
  846. $frequency_flag = false;
  847. }
  848. }
  849. //判断通知方式是否一样
  850. $checkMethodFiled = array("method_by_email","method_by_message");
  851. $method_flag = true;
  852. foreach($checkMethodFiled as $filed){
  853. $postValue = (empty($_POST[$filed]) || $_POST[$filed] == "false") ? "f" : "t";
  854. if($postValue != $rule[$filed]){
  855. $method_flag = false;
  856. }
  857. }
  858. //五个条件一样,不允许保存
  859. if($range_flag && $details_flag && $frequency_flag && $method_flag){
  860. $msg = "Unable to Save";
  861. continue;
  862. }
  863. //前三个重回,后面不重合,提示但允许保存
  864. if($range_flag && $details_flag && $_POST['is_similar_rule'] <> 'true'){
  865. $msg = "Similar Rule Detected";
  866. continue;
  867. }
  868. }
  869. return $msg;
  870. }
  871. public function getNotifications($notifiation_type,$frequency_type,$insert_date_format = null){
  872. if ($frequency_type == "all"){
  873. $sql_where = " and (ni.frequency_type = 'Instant'
  874. or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
  875. or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  876. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
  877. } elseif($frequency_type == "Daily"){
  878. $sql_where = " and (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
  879. } elseif($frequency_type == "Weekly"){
  880. $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
  881. and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
  882. }
  883. //这里的查询会把不同日期的但hbol相同的信息,过滤掉只剩下最新的那一条。所以移除
  884. $aa_where = "";
  885. if (!empty($insert_date_format)){
  886. $aa_where = " where insert_date_format = '$insert_date_format'";
  887. }
  888. $more_param = common::getInNotInSqlForSearch($notifiation_type);
  889. $sql = "select *
  890. from (select ni.*,
  891. case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
  892. then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  893. when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
  894. then (EXTRACT(HOUR FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
  895. else 0
  896. end as delay_diff,
  897. case when COALESCE(ni.frequency_type,'') = 'Daily'
  898. then to_char(timezone(ni.daily_time_zone, ni.insert_date),'Mon DD, YYYY')
  899. when COALESCE(ni.frequency_type,'') = 'Weekly'
  900. then to_char(date_trunc('week', ni.insert_date),'Mon DD, YYYY')|| ' - ' ||to_char((date_trunc('week', ni.insert_date) + INTERVAL '6 days'),'Mon DD, YYYY')
  901. else ''
  902. end as insert_date_format,
  903. case when ni.notifiation_type ='Milestone_Update'
  904. then public.getPreviousMilestone(ni.serial_no,ni.milestone_code,ccc.transport_mode,ccc.order_from)
  905. else ''
  906. end as milestone_previous_json,
  907. ccc.order_from,ccc.h_bol,ccc.transport_mode
  908. from public.kln_notifiation_info ni
  909. left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from
  910. from public.kln_ocean oo
  911. where oo.serial_no = ni.serial_no limit 1) ccc on true
  912. where lower(ni.user_login) = '".strtolower(_getLoginName())."'
  913. and lower(ni.notifiation_type) in ($more_param)
  914. ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa $aa_where";
  915. error_log($sql);
  916. $data_all_type = common::excuteListSql($sql);
  917. $data_group = array();
  918. $data_group_uniqe = array();
  919. foreach($data_all_type as $dat){
  920. $uniqe_group_str = $dat['notifiation_type'];
  921. if(utils::in_array($uniqe_group_str,$data_group_uniqe)){
  922. $tempArr = $data_group[$uniqe_group_str];
  923. $tempArr[] = $dat;
  924. $data_group[$uniqe_group_str] = $tempArr;
  925. } else {
  926. $data_group[$uniqe_group_str] = array($dat);
  927. $data_group_uniqe[] = $uniqe_group_str;
  928. }
  929. }
  930. $retData = array();
  931. foreach($data_group as $key => $data){
  932. $notifiation_type_db = $key;
  933. //统一处理数据Instant Daily weekly_week 先分开在处理
  934. $instant = array();
  935. $daily = array();
  936. $daily_uniqe = array();
  937. $weekly = array();
  938. $weekly_uniqe = array();
  939. foreach($data as $d){
  940. if ($d['frequency_type'] == "Instant"){
  941. $instant[] = $d;
  942. }
  943. //Daily 或者 Weekly类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
  944. $uniqe_str = $d['serial_no'];
  945. if ($notifiation_type_db == "Milestone_Update"){
  946. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['milestone_code'];
  947. }else if ($notifiation_type_db == "Container_Status_Update"){
  948. $uniqe_str = $d['ctnr']."_".$d['insert_date_format']."_".$d['ctnr_status_code'];
  949. }else if($notifiation_type_db == "Departure/Arrival_Delay"){
  950. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['delay_name'];
  951. }else if($notifiation_type_db == "ETD/ETA_Change"){
  952. $uniqe_str = $d['serial_no']."_".$d['insert_date_format']."_".$d['date_change_name'];
  953. }
  954. if ($d['frequency_type'] == "Daily"){
  955. if(!utils::in_array($uniqe_str,$daily_uniqe)){
  956. $daily[$uniqe_str] = $d;
  957. $daily_uniqe[] = $uniqe_str;
  958. }
  959. }
  960. if ($d['frequency_type'] == "Weekly"){
  961. if(!utils::in_array($uniqe_str,$weekly_uniqe)){
  962. $weekly[$uniqe_str] = $d;
  963. $weekly_uniqe[] = $uniqe_str;
  964. }
  965. }
  966. }
  967. $retData[$key]= array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly));
  968. }
  969. return $retData;
  970. }
  971. public function getEventCard($mInfo){
  972. $eventCard = array();
  973. $notifiation_type = $mInfo['notifiation_type'];
  974. if($notifiation_type == "Milestone_Update"){
  975. $eventCard = array("type" =>'milestone',
  976. "numericRecords"=>0,
  977. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  978. "title"=>"Milestone Update",
  979. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  980. "no"=>$mInfo["h_bol"],
  981. "tag"=>$mInfo["milestone_description"],
  982. "location"=>$mInfo["milestone_locations"],
  983. "timezone"=>$mInfo["milestone_timezone"],
  984. "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
  985. "timeLabel"=>"",
  986. "previous"=>"",
  987. "frequency_type"=>$mInfo["frequency_type"],
  988. "serial_no"=>$mInfo["serial_no"],
  989. "order_from"=>$mInfo["order_from"],
  990. "id"=>$mInfo["id"],
  991. "insert_date_format"=>'',
  992. "info"=>new stdClass());
  993. if ($mInfo["frequency_type"] == "Daily"){
  994. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  995. $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
  996. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  997. $eventCard["previous"] = '';
  998. $milestone_previous = json_decode($mInfo["milestone_previous_json"],true);
  999. if(!empty($milestone_previous['milestone'])){
  1000. $eventCard["previous"] = array("tag" =>"Previous:".$milestone_previous['milestone']['milestone_description']." from ".$milestone_previous['milestone']['locations'],
  1001. "time" => $milestone_previous['milestone']['milestone_time'],
  1002. "timezone" =>$milestone_previous['milestone']['timezone']);
  1003. }
  1004. } else if($mInfo["frequency_type"] == "Weekly"){
  1005. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1006. $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1007. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1008. if(!empty($mInfo["previous"])){
  1009. $eventCard["previous"] = array("tag" =>"Previous:".$mInfo["previous"]["milestone_desc"]." from ".$mInfo["previous"]["milestone_description"],
  1010. "time" => $mInfo["previous"]["milestone_time"],
  1011. "timezone" =>$mInfo["previous"]["milestone_timezone"]);
  1012. }
  1013. }
  1014. }
  1015. if($notifiation_type == "Container_Status_Update"){
  1016. //当前状态的描述
  1017. $ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
  1018. $eventCard = array("type" =>'container',
  1019. "numericRecords"=>0,
  1020. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1021. "title"=>"Container_Status_Update",
  1022. "mode"=>"Ocean Freight",
  1023. "no"=>$mInfo["ctnr"],
  1024. "tag"=>$ctnrStatusdesc,
  1025. "location"=>$mInfo["ctnr_status_locations"],
  1026. "timezone"=>$mInfo["ctnr_status_timezone"],
  1027. "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
  1028. "timeLabel"=>"",
  1029. "previous"=>"",
  1030. "frequency_type"=>$mInfo["frequency_type"],
  1031. "serial_no"=>$mInfo["serial_no"],
  1032. "order_from"=>$mInfo["order_from"],
  1033. "id"=>$mInfo["id"],
  1034. "insert_date_format"=>'',
  1035. "info"=>new stdClass());
  1036. if ($mInfo["frequency_type"] == "Daily"){
  1037. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1038. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1039. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1040. if(!empty($mInfo["previous"])){
  1041. //当前状态 前一个的描述
  1042. $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
  1043. $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
  1044. "time" => $mInfo["previous"]["ctnr_status_time"],
  1045. "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
  1046. }
  1047. } else if($mInfo["frequency_type"] == "Weekly"){
  1048. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1049. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1050. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1051. if(!empty($mInfo["previous"])){
  1052. //当前状态 前一个的描述
  1053. $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
  1054. $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
  1055. "time" => $mInfo["previous"]["ctnr_status_time"],
  1056. "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
  1057. }
  1058. }
  1059. }
  1060. if($notifiation_type == "Departure/Arrival_Delay"){
  1061. //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
  1062. $title = $mInfo["delay_name"];
  1063. $outsideLocation = "";
  1064. $outsideTimezone = "";
  1065. $outsideTimeLabel= "";
  1066. $insideTimeLabel= "";
  1067. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
  1068. $outsideTimeLabel = "ETD";
  1069. $insideTimeLabel = "ATD";
  1070. }
  1071. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
  1072. $outsideTimeLabel = "ETA";
  1073. $insideTimeLabel = "ATA";
  1074. }
  1075. //直航的的
  1076. if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
  1077. $outsideLocation = $mInfo["delay_locations_from"];
  1078. }
  1079. if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
  1080. $outsideLocation = $mInfo["delay_locations_to"];
  1081. }
  1082. $route = array();
  1083. $leg = array();
  1084. if($mInfo["delay_is_direct"] <>'t'){
  1085. $title = substr($mInfo["delay_name"],8);
  1086. $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1087. //当前current Leg
  1088. $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
  1089. if($mInfo["delay_current"] == "2"){
  1090. $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
  1091. }
  1092. }
  1093. $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
  1094. $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
  1095. $delay_diff = $mInfo["delay_diff"];
  1096. $delay_unit = $mInfo["delay_unit"];
  1097. $eventCard = array("type" =>'delay',
  1098. "numericRecords"=>0,
  1099. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1100. "title"=>$title,
  1101. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1102. "no"=>$mInfo["h_bol"],
  1103. "tag"=>$mInfo["delay_name"],
  1104. "location"=>$outsideLocation,
  1105. "timezone"=>$mInfo["delay_timezone"],
  1106. "time"=>$est_date,
  1107. "timeLabel"=>$outsideTimeLabel,
  1108. "previous"=>"",
  1109. "frequency_type"=>$mInfo["frequency_type"],
  1110. "serial_no"=>$mInfo["serial_no"],
  1111. "order_from"=>$mInfo["order_from"],
  1112. "id"=>$mInfo["id"],
  1113. "insert_date_format"=>'',
  1114. "info"=>array("route"=>$route,
  1115. "leg"=>$leg,
  1116. "etdOrdeparturNum"=>0,
  1117. "etaOrarrivalNum"=>0,
  1118. "time"=>$act_date,
  1119. "timeLabel"=>$insideTimeLabel,
  1120. "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
  1121. "timezone"=>$mInfo["delay_timezone"]
  1122. ));
  1123. if ($mInfo["frequency_type"] == "Daily"){
  1124. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1125. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1126. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1127. $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
  1128. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1129. } else if($mInfo["frequency_type"] == "Weekly"){
  1130. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1131. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1132. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1133. $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
  1134. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1135. }
  1136. }
  1137. if($notifiation_type == "ETD/ETA_Change"){
  1138. $title = $mInfo["date_change_name"];
  1139. if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
  1140. $outsideTimeLabel = "Original ETD";
  1141. $insideTimeLabel = "Upoated ETD";
  1142. }
  1143. if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
  1144. $outsideTimeLabel = "Original ETA";
  1145. $insideTimeLabel = "Upoated ETA";
  1146. }
  1147. if($mInfo["date_change_is_direct"] <>'t'){
  1148. //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
  1149. $title = substr($mInfo["date_change_name"],8);
  1150. $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1151. $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
  1152. if($mInfo["delay_current"] == "2"){
  1153. $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
  1154. }
  1155. }
  1156. $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
  1157. $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
  1158. $eventCard = array("type" =>'change',
  1159. "numericRecords"=>0,
  1160. "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
  1161. "title"=>$title,
  1162. "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
  1163. "no"=>$mInfo["h_bol"],
  1164. "tag"=>$mInfo["date_change_name"],
  1165. "location"=>"",
  1166. "timezone"=>$mInfo["date_change_timezone"],
  1167. "time"=>$original_date,
  1168. "timeLabel"=>$outsideTimeLabel,
  1169. "previous"=>"",
  1170. "frequency_type"=>$mInfo["frequency_type"],
  1171. "serial_no"=>$mInfo["serial_no"],
  1172. "order_from"=>$mInfo["order_from"],
  1173. "id"=>$mInfo["id"],
  1174. "insert_date_format"=>'',
  1175. "info"=>array("route"=>$route,
  1176. "leg"=>$leg,
  1177. "etdOrdeparturNum"=>0,
  1178. "etaOrarrivalNum"=>0,
  1179. "time"=>$updated_date,
  1180. "timeLabel"=>$insideTimeLabel,
  1181. "delayTimeTip"=>"",
  1182. "timezone"=>$mInfo["date_change_timezone"]
  1183. ));
  1184. if ($mInfo["frequency_type"] == "Daily"){
  1185. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1186. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1187. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1188. $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
  1189. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1190. } else if($mInfo["frequency_type"] == "Weekly"){
  1191. $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
  1192. $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
  1193. $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
  1194. $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
  1195. $eventCard["insert_date_format"] = $mInfo["insert_date_format"];
  1196. }
  1197. }
  1198. return $eventCard;
  1199. }
  1200. /**
  1201. * 返回当前柜子的status信息描述
  1202. */
  1203. public static function getContainerStatusDesc($ctnr_status_code){
  1204. $event =common::getEDICtnrEvent();
  1205. $ctnrStatusdesc = "";
  1206. foreach($event as $e){
  1207. if($e['event_name'] == $ctnr_status_code){
  1208. $ctnrStatusdesc = $e['description'];
  1209. }
  1210. }
  1211. return $ctnrStatusdesc;
  1212. }
  1213. }
  1214. ?>