| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of operation_log
- *
- * @author Administrator
- */
- class tools {
- private static $_tools;
- public static function getInstance() {
- if (!self::$_tools) {
- $c = __CLASS__;
- self::$_tools = new $c;
- }
- return self::$_tools;
- }
- /*
- * update password when login success
- */
- public function updatePassword() {
- if ($_SESSION['ONLINE_USER']['is_demo'] == "t") {
- $str = "DEMO cannot update password.";
- } else {
- $opsw = common::check_input($_POST ['opsw']);
- $npsw = common::check_input($_POST ['npsw']);
- $username = _getLoginName();
- $msg = common::checkPasswordRule($username, $npsw);
- //为空代表验证通过
- if (empty($msg)) {
- $sql = "select ra_password as password from ra_online_user where lower(user_login) = '" . strtolower($username) . "'";
- $rs = common::excuteObjectSql($sql);
- $str = '';
- if (!empty($rs)) {
- if ($rs['password'] == $opsw) {
- $sql = "UPDATE ra_online_user SET ra_password = '" . $npsw . "', last_pwd_change = now() WHERE lower(user_login) = '" . strtolower($username) . "'";
- $rls = common::excuteUpdateSql($sql);
- if (!$rls) {
- $str = "Password modification failed!";
- } else {
- $str = " Your password has been modified!";
- }
- } else {
- $str = "Old password is incorrect!";
- }
- } else {
- $str = "Old password is incorrect!";
- }
- } else {
- $str = $msg;
- }
- }
- $returnData = array("msg" => $str);
- common::echo_json_encode(200, $returnData);
- exit();
- }
- public function markSystem(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "mark_save") {
- $suggestion = utils::implode(",",$_POST['suggestion']);
- $proposal = common::check_input($_POST['proposal']);
- $expression = common::check_input($_POST['expression']);
- $complete_funtionality = common::check_input($_POST['Complete_funtionality']);
- $accurate_data = common::check_input($_POST['Accurate_data']);
- $clear_information = common::check_input($_POST['Clear_information']);
- $easy_to_use = common::check_input($_POST['Easy_to_use']);
- $system_Performance = common::check_input($_POST['System_Performance']);
- $username = common::check_input($_POST['username']);
- $user_type = _isApexLogin() ? "employee" : "customer";
- if(!isset($_SESSION['ONLINE_USER'])){
- $user_type = "other";
- }
- $loginName = _getLoginName();
- $loginEamil = _getLoginEamil();
- //如果在没有登录前,没有登录信息,指定用户-- 这里逻辑取消,没有登录相当于匿名用户的评价,无法获取用户名
- // if(!isset($_SESSION['ONLINE_USER'])){
- // $user_type = "Customer";
- // if(!empty($username)){
- // $loginName = $username;
- // $loginEamil = common::excuteOneSql("select email from public.ra_online_user u where lower(user_login) = '" . strtolower($username) . "'");
- // }
- // }
- $sql = "INSERT INTO public.customer_service_user_mark(user_type, user_name, suggestion, proposal, expression, complete_funtionality,
- accurate_data, clear_information, easy_to_use, system_performance,
- created_time,email)
- VALUES ('$user_type', '$loginName', '$suggestion', '$proposal', '$expression', '$complete_funtionality',
- '$accurate_data', '$clear_information', '$easy_to_use', '$system_Performance', now(),'$loginEamil')";
- common::excuteUpdateSql($sql);
- $data = array("msg" =>"success");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- public function user_system_setting(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "personal_profile_init") {
- // get system config
- $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')";
- $rs1s = common::excuteListSql($sql);
- foreach ($rs1s as $rs1) {
- if ($rs1['ra_name'] == 'employee_password_change_cycle')
- $EMPLOYEE_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- if ($rs1['ra_name'] == 'customer_password_change_cycle')
- $CUSTOMER_PASSWORD_CHANGE_CYCLE = $rs1['ra_value'];
- }
- $sql="select item_value from config where item='passwordChangePeriod'";
- $pcp = common::excuteObjectSql($sql);
- $passwordChangePeriod = json_decode($pcp["item_value"],true);
- if (_isApexLogin()) {
- $PASSWORD_CHANGE_CYCLE = $EMPLOYEE_PASSWORD_CHANGE_CYCLE;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Employee"]["days"];
- }
- } else {
- $PASSWORD_CHANGE_CYCLE = $CUSTOMER_PASSWORD_CHANGE_CYCLE;
- //如果有新配置,则采用新配置
- if (!empty($pcp)) {
- $PASSWORD_CHANGE_CYCLE = $passwordChangePeriod["Customer"]["days"];
- }
- }
-
- $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,
- ue.date_format,ue.numbers_format
- from ra_online_user u
- left join kln_user_extend ue on u.user_login = ue.user_login
- where lower(u.user_login) = '".strtolower(_getLoginName())."' ";
- $data = common::excuteObjectSql($sql);
- $data["expire_day"] = $PASSWORD_CHANGE_CYCLE - $data['last_pwd_change_date'];
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "personal_profile_save") {
- $save_model = common::check_input($_POST['save_model']);
- if ($save_model == "profile"){
- $first_name = common::check_input($_POST['first_name']);
- $last_name = common::check_input($_POST['last_name']);
- $sql = "update public.ra_online_user set first_name = '$first_name',last_name = '$last_name' where lower(user_login) = '".strtolower(_getLoginName())."'";
- }else{
- $date_fromat = common::check_input($_POST['date_fromat']);
- $numbers_format = common::check_input($_POST['numbers_format']);
- $exist_kln_user = common::excuteObjectSql("select user_login from public.kln_user_extend where lower(user_login) = '".strtolower(_getLoginName())."'");
- if (!empty($exist_kln_user['user_login'])){
- $sql = "update public.kln_user_extend set date_fromat = '$date_fromat',numbers_format = '$numbers_format' where lower(user_login) = '".strtolower(_getLoginName())."'";
- } else {
- $sql = "INSERT INTO public.kln_user_extend(user_login, date_format, numbers_format, subscribe_hbol)
- VALUES ('"._getLoginName()."', '$date_fromat', '$numbers_format', null);";
- }
- }
- common::excuteUpdateSql($sql);
- $data = array("msg" => "save Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_notification_init") {
- $subscribur_data =array();
- //查询用户对应的Rule
- $subscribe_rule_sql = "select *,TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
- TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time
- from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- $all_rules = array("Milestone_Update","Container_Status_Update","Departure/Arrival_Delay","ETD/ETA_Change");
- foreach($all_rules as $rule_name){
- $rules = $this->getSubscribeRules($rule_name,$subscribe_rules);
- $subscribur_data[$rule_name] = $rules;
- }
- //整合拼接addedRules
- $addedRules = array();
- foreach($subscribe_rules as $addedRule){
- $addedRules[] = array(
- "visible" => false,
- "id" =>$addedRule['id'],
- "Event" =>$addedRule['rules_type'],
- "Event Details" =>$addedRule['event_details'],
- "Frequency" =>$addedRule['frequency_display'],
- "Methods" =>$addedRule['method_display']);
- }
- $subscribur_data['addedRules'] = array("tableData"=>$addedRules);
- //获取subscribe shipment 当前页数cp,每页ps
- $subscribeShipmentWithPage = $this->getSubscribeShipment(1,15);
- $subscribur_data['subscribeShipmentWithPage'] = $subscribeShipmentWithPage;
- common::echo_json_encode(200,$subscribur_data);
- exit();
- }
- if ($operate == "subscribe_notification_event_update"){
- $rules_type = common::check_input($_POST["rules_type"]);
- //判断该规则是否存在
- $exist = common::excuteObjectSql("select user_login,id from public.notifications_rules where notifications_type = 'Subscribe' and rules_type = '".$rules_type."'
- and lower(user_login) = '".strtolower(_getLoginName())."'");
- $updateOrInsert = empty($exist) ? "insert" : "update";
- $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Subscribe",$exist['id']);
- $rs = common::excuteUpdateSql($sql);
- if ($rs === FALSE){
- $data = array("msg" => "Update Error");
- } else{
- $data = array("msg" => "Update Successful");
- //返回addedRules 全部列表
- $subscribe_rule_sql = "select * from public.notifications_rules where notifications_type = 'Subscribe' and lower(user_login) = '".strtolower(_getLoginName())."' order by id";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- //整合拼接addedRules
- $addedRules = array();
- foreach($subscribe_rules as $addedRule){
- $addedRules[] = array(
- "id" =>$addedRule['id'],
- "Event" =>$addedRule['rules_type'],
- "Event Details" =>$addedRule['event_details'],
- "Frequency" =>$addedRule['frequency_display'],
- "Methods" =>$addedRule['method_display']);
- }
- $data['addedRules'] = array("tableData"=>$addedRules);
- }
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_notification_rules_delete"){
- $rules_type = common::check_input($_POST['rules_type']);
- $sql = "delete from notifications_rules where notifications_type = 'Subscribe'
- and rules_type = '$rules_type' and lower(user_login) = '".strtolower(_getLoginName())."'";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Delete Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "subscribe_shipment"){
- $serial_no = common::deCode($_POST['serial_no'], 'D');
- $is_subscribe = common::check_input($_POST['is_subscribe']);
- if($is_subscribe == "true"){
- $exist = common::excuteOneSql("select user_login from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no'");
- if(!empty($exist)){
- $data = array("msg" => "Subscribe exist,Please check");
- common::echo_json_encode(200,$data);
- exit();
- }
-
- $sql = "INSERT INTO public.kln_user_subscribed(user_login, subscribed_serial_no, create_user, create_time)
- VALUES ('"._getLoginName()."', '$serial_no', '"._getLoginName()."', now());";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Subscribe Successful");
- common::echo_json_encode(200,$data);
- exit();
- }else{
- //取消订阅
- $sql = "delete from public.kln_user_subscribed where lower(user_login) = '".strtolower(_getLoginName())."' and subscribed_serial_no = '$serial_no';";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Cancel Subscribe successfully");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- if ($operate == "subscribe_shipment_search"){
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- $arrTmp = $this->getSubscribeShipment($cp,$ps);
- common::echo_json_encode(200,$arrTmp);
- exit();
- }
- }
- public function user_monitoring_setting(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "monitoring_rules_init"){
- $ret = array();
- //Milestone Update的页面配置数据
- $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
- $oceanMilestone = array();
- $airMilestone = array();
- foreach($milestones as $milestone){
- if($milestone['type'] == "air"){
- $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
- "code"=>$milestone['code'],"description"=>$milestone['description']);
- }
- if($milestone['type'] == "sea"){
- $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
- "code"=>$milestone['code'],"description"=>$milestone['description']);
- }
- }
- $ret["OceanCheckBoxList"] = $oceanMilestone;
- $ret["AirCheckBoxList"] = $airMilestone;
- //Milestone Update的结构处理
- //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
- $event =common::getEDICtnrEvent();
- $ctnrStatus = array();
- foreach($event as $e){
- $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['description']);
- }
- $ret["CtnrCheckBoxList"] = $ctnrStatus;
- common::echo_json_encode(200,$ret);
- exit();
- }
- if ($operate == "monitoring_rules_search") {
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 15;
- $sql = "select count(1) from public.notifications_rules where lower(user_login) = '".strtolower(_getLoginName())."' and notifications_type = 'Monitoring'";
- $rc = common::excuteOneSql($sql);
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "select *,replace(rules_type, '_', ' ') AS _rules_type_display,
- case when rules_type = 'Milestone_Update' then 'Milestone'
- when rules_type = 'Container_Status_Update' then 'Container'
- when rules_type = 'Departure/Arrival_Delay' then 'Departure'
- when rules_type = 'ETD/ETA_Change' then 'ETDChange'
- else '' end as notifications_option
- from public.notifications_rules
- where lower(user_login) = '".strtolower(_getLoginName())."'
- and notifications_type = 'Monitoring' order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
- $monitoringRules = common::excuteListSql($sql);
- $arrTmp = array('monitoringRules' => $monitoringRules,
- 'rc' => intval($rc),
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp
- );
- } else {
- $arrTmp = array('searchData' => array(),
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp,
- );
- }
- common::echo_json_encode(200,$arrTmp);
- exit();
- }
- if ($operate == "monitoring_rules_edit"){
- $id = $_POST['id'];
- $rules_type = common::check_input($_POST['rules_type']);
- $subscribe_rule_sql = "select *,
- TO_CHAR(daily_time, 'HH24:MI') as _daily_time,
- TO_CHAR(weekly_time, 'HH24:MI') as _weekly_time,
- case when rules_type = 'Milestone_Update' then 'Milestone'
- when rules_type = 'Container_Status_Update' then 'Container'
- when rules_type = 'Departure/Arrival_Delay' then 'Departure'
- when rules_type = 'ETD/ETA_Change' then 'ETDChange'
- else '' end as notifications_option
- from public.notifications_rules where notifications_type = 'Monitoring' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id' order by id";
- $subscribe_rules = common::excuteListSql($subscribe_rule_sql);
- $rules = $this->getSubscribeRules($rules_type,$subscribe_rules);
-
- //数据转换前端需要的
- $converMode = array();
- $shipment_transport_mode_arr = explode(";", $rules["shipment_transport_mode"]);
- foreach($shipment_transport_mode_arr as $model){
- if (strtolower($model) == "sea"){
- $converMode[] = 'Ocean';
- }else{
- $converMode[] = ucfirst($model);
- }
- }
- $rules["shipment_transport_mode"] = utils::implode(";",$converMode);
- $monitoring_data[$rules_type] = $rules;
- common::echo_json_encode(200,$monitoring_data);
- exit();
- }
- if ($operate == "monitoring_rules_do") {
- $rules_type = common::check_input($_POST["rules_type"]);
- //检查编辑提交的Monitoring规则,是否允许保存
- $msg = $this->checkedMonitoringRulesSave($rules_type);
- if(!empty($msg)){
- $data = array("msg" =>$msg);
- common::echo_json_encode(200,$data);
- exit();
- }
- $updateOrInsert = "insert";
- if(isset($_POST['id']) && !empty($_POST['id'])){
- $updateOrInsert = "update";
- }
- $sql = $this->getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,"Monitoring",$_POST['id']);
- $rs = common::excuteUpdateSql($sql);
- if ($rs === FALSE){
- $data = array("msg" => "Update Error");
- } else{
- $data = array("msg" => "Update Successful");
- }
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "monitoring_rules_delete"){
- $id = common::check_input($_POST['id']);
- $sql = "delete from notifications_rules where notifications_type = 'Monitoring'
- and lower(user_login) = '".strtolower(_getLoginName())."' and id = '$id'";
- common::excuteUpdateSql($sql);
- $data = array("msg" => "Delete Successful");
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- public function notifications_rules(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- if ($operate == "notifications_init"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $milestoneData = array();
- $containerData = array();
- $delayData = array();
- $changeData = array();
- if ($rules_type == "all"){
- $milestoneData = $this->getNotifications("Milestone_Update","all");
- $containerData = $this->getNotifications("Container_Status_Update","all");
- $delayData = $this->getNotifications("Departure/Arrival_Delay","all");
- $changeData = $this->getNotifications("ETD/ETA_Change","all");
- } else {
- $data = $this->getNotifications($rules_type,"all");
- if($rules_type == "Milestone_Update"){
- $milestoneData = $data;
- }elseif($rules_type == "Container_Status_Update"){
- $containerData = $data;
- }elseif($rules_type == "Departure/Arrival_Delay"){
- $delayData = $data;
- }elseif($rules_type == "ETD/ETA_Change"){
- $changeData = $data;
- }
- }
- $data = array("milestoneData"=>$milestoneData,"containerData"=>$containerData,"delayData"=>$delayData,"changeData"=>$changeData);
- $instant_sum = array();
- foreach($data as $v){
- if(!empty($v['instant'])){
- foreach($v['instant'] as $instant){
- $instant_sum[] = $instant;
- }
- }
- if(!empty($v['daily'])){
- //取第一组的第一个显示
- $dailyFristAndFrist = utils::getDailyAndweeklyFrist($v['daily']);
- $instant_sum[]= $dailyFristAndFrist;
- }
- if(!empty($v['weekly'])){
- $weeklyFristAndFrist = utils::getDailyAndweeklyFrist($v['weekly']);
- $instant_sum[]= $weeklyFristAndFrist;
- }
- }
- //根据时间顺序排序
- $insert_dates = array_column($instant_sum, 'insert_date');
- array_multisort($insert_dates, SORT_ASC, $instant_sum);
- $info = array();
- foreach($instant_sum as $mInfo){
- $eventCard = $this->getEventCard($mInfo);
- $info[] = array("notificationType"=>"event","info" =>$eventCard);
- }
- $returnData = $info;
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if($operate == "notifications_see_all"){
- $rules_type = common::check_input($_REQUEST['rules_type']);
- $frequency_type = common::check_input($_REQUEST['frequency_type']); //这个只会传daily 和weekly
- $data = $this->getNotifications($rules_type,$frequency_type);
- $moreData = $data[strtolower($frequency_type)];
- //这个函数里面带有分开计数的信息
- $dataInfo =utils::getDailyAndweeklyFrist($moreData);
- $returnData = array();
- $notificationList = array();
- foreach($moreData as $key => $data){
- $eventCard = $this->getEventCard($data);
- //sea all的数据格式和查询全部的格式有区别
- if($key == 0){
- $returnData["title"] = $eventCard["title"];
- if($eventCard["type"] == "change" || $eventCard["type"] == "delay"){
- $returnData["numericRecords_one"] = $dataInfo["numericRecords_one"];
- $returnData["numericRecords_two"] =$dataInfo["numericRecords_two"];
- }else{
- $returnData["numericRecords"] = $dataInfo["numericRecords"];
- }
- }
- //移除不需要的字段
- unset($eventCard["title"]);
- $notificationList[] = $eventCard;
- }
- if(!empty($notificationList)){
- $returnData["notificationList"] = $notificationList;
- }
- //点击seall会默认全部标记为已读
-
- common::echo_json_encode(200,$returnData);
- exit();
- }
- if($operate == "notifications_read"){
-
-
- exit();
- }
- }
- /**
- * 遍历查找对应的rule。
- */
- public function getSubscribeRules($rule_name,$subscribe_rules){
- //初始是不显示,没有值的情况
- $ret = array("is_display" => false);
- foreach($subscribe_rules as $rules){
- if($rules['rules_type'] == $rule_name){
- $rules["is_display"] = true;
- $rules["daily_time"] = $rules["_daily_time"];
- $rules["weekly_time"] = $rules["_weekly_time"];
- $rules["weekly_week"] = common::getWeek($rules["weekly_week"]);
- $ret = $rules;
- }
- }
- //Milestone Update的结构处理,处理init page load
- if($rule_name == "Milestone_Update"){
- //Milestone Update的页面配置数据
- $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
- $oceanMilestone = array();
- $airMilestone = array();
- foreach($milestones as $milestone){
- if($milestone['type'] == "air"){
- $airMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
- "code"=>$milestone['code'],"description"=>$milestone['description']);
- }
- if($milestone['type'] == "sea"){
- $oceanMilestone[] = array("label"=>$milestone['description'],"value"=>$milestone['description'],
- "code"=>$milestone['code'],"description"=>$milestone['description']);
- }
- }
- $ret["OceanCheckBoxList"] = $oceanMilestone;
- $ret["AirCheckBoxList"] = $airMilestone;
- $oceanMilestoneSetting = !empty($ret['ocean_milestone']) ? explode(";",$ret['ocean_milestone']) : array();
- $airMilestoneSetting = !empty($ret['air_milestone']) ? explode(";",$ret['air_milestone']): array();
- //转换描述,因为前端支持description,没有code的对应
- $oceanMilestoneDescription = $this->convertDescriptionForMilestoneAndCtnr("Milestone_Update",$oceanMilestoneSetting,$oceanMilestone);
- //转换描述,因为前端支持description,没有code的对应
- $airMilestoneDescription = $this->convertDescriptionForMilestoneAndCtnr("Milestone_Update",$airMilestoneSetting,$airMilestone);
- $ret["OceanCheckedList"] = $oceanMilestoneDescription;
- $ret["AirCheckedList"] = $airMilestoneDescription;
- }
- //Milestone Update的结构处理
- if($rule_name == "Container_Status_Update"){
- //这里基准event 写死, 根据online查询页面的通用的来, 这里需提问确定
- $event =common::getEDICtnrEvent();
- $ctnrStatus = array();
- foreach($event as $e){
- $ctnrStatus[] = array("label"=>$e['description'],"value"=>$e['description']);
- }
- $ret["CtnrCheckBoxList"] = $ctnrStatus;
-
- $ctnrStatusSetting = !empty($ret['ocean_ctnr_status']) ? explode(";",$ret['ocean_ctnr_status']) : array();
- //转换描述,因为前端支持description,没有code的对应
- $ctnrStatusDescription = $this->convertDescriptionForMilestoneAndCtnr("Container_Status_Update",$ctnrStatusSetting,$event);
- $ret["CtnrCheckedList"] = $ctnrStatusDescription;
-
- }
- return $ret;
- }
- /**
- * 查询对应用户订阅的shipment信息.可能存在分页查询,如果有需要就改正
- * cp current_page
- */
- public function getSubscribeShipment($cp,$ps){
- if (empty($cp)){
- $cp = 1;
- }
- if (empty($ps)){
- $ps = 15;
- }
- $sql = "select count(1) from public.kln_user_subscribed u
- left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
- where lower(user_login) = '".strtolower(_getLoginName())."'";
- $rc = common::excuteOneSql($sql);
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "select o.h_bol,
- o.shipper,o.consignee,o.etd,o.eta,
- case when transport_mode = 'sea'
- then (select sn.description
- from public.ocean_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'sea'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- when transport_mode = 'air' and order_from = 'public'
- then (select sn.description
- from public.air_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- when transport_mode = 'air' and order_from = 'sfs'
- then (select sn.description
- from sfs.air_milestone a
- inner join public.customer_service_milestone_sno sn on sn.code=a.code and sn.type = 'air'
- where a.serial_no=o.serial_no and act_date is not null order by sn.sno desc limit 1)
- else '' end as recent_milestone
- from public.kln_user_subscribed u
- left join public.kln_ocean o on o.serial_no = u.subscribed_serial_no
- where lower(user_login) = '".strtolower(_getLoginName())."' order by u.id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
- $subscribeShipment = common::excuteListSql($sql);
- $arrTmp = array('tableData' => $subscribeShipment,
- 'rc' => intval($rc),
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp
- );
- } else {
- $arrTmp = array('tableData' => array(),
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp,
- );
- }
- return $arrTmp;
- }
- /**
- * 转换描述,因为前端支持description,没有code的对应
- */
- public function convertDescriptionForMilestoneAndCtnr($type,$codeArr,$mappingData){
- $descriptions = array();
- $key = $type == "Milestone_Update" ? "code" : "event_name";
- foreach($codeArr as $code){
- foreach($mappingData as $md){
- if($md[$key] == $code){
- $descriptions[] = common::check_input($md['description']);
- }
- }
- }
- return $descriptions;
- }
- /**
- * 转换code,因为前端提交的是description,没有code的
- */
- public function convertCodeForMilestoneAndCtnr($type,$descriptionArr,$mappingData){
- $codes = array();
- $key = $type == "Milestone_Update" ? "code" : "event_name";
- foreach($descriptionArr as $description){
- foreach($mappingData as $md){
- if($md['description'] == $description){
- $codes[] = common::check_input($md[$key]);
- }
- }
- }
- return $codes;
- }
- public function getNotificationsRulesUpdateSql($updateOrInsert,$rules_type,$notifications_type,$id){
- $sql = "";
- //先删后加
- if($updateOrInsert == "update"){
- $sql.="delete from public.notifications_rules where rules_type = '$rules_type'
- and notifications_type = '$notifications_type' and lower(user_login) = '".strtolower(_getLoginName())."'
- and id = '$id';";
- }
- //这个几个参数是所有规则都有的参数
- $frequency_type = common::check_input($_POST['frequency_type']);
- $daily_time = "null";
- $daily_time_zone = "";
- $weekly_week = "";
- $weekly_time = "null";
- $weekly_time_zone = "";
- if(strtolower($frequency_type) == "daily"){
- $daily_time = "'".common::check_input($_POST['daily_time'])."'";
- $daily_time_zone = common::check_input($_POST['daily_time_zone']);
- } elseif (strtolower($frequency_type) == "weekly"){
- $weekly_week = common::check_input($_POST['weekly_week']);
- $weekly_time = "'".common::check_input($_POST['weekly_time'])."'";
- $weekly_time_zone = common::check_input($_POST['weekly_time_zone']);
- }
- $method_by_email = common::check_input($_POST['method_by_email']);
- $method_by_message = common::check_input($_POST['method_by_message']);
- $event_details = common::check_input($_POST['event_details']);
- $frequency_display = common::check_input($_POST['frequency_display']);
- $method_display = common::check_input($_POST['method_display']);
- $shipment_detail = common::check_input($_POST['shipment_details']);
- //当规则是 Monitoring类型是,需要配置的range
- $shipment_transport_mode = "";
- $shipment_etd_limit = "";
- $shipment_eta_limit = "";
- if($notifications_type == "Monitoring"){
- $converMode = array();
- foreach($_POST['shipment_transport_mode'] as $model){
- if (strtolower($model) == "ocean"){
- $converMode[] = 'sea';
- }else{
- $converMode[] = strtolower($model);
- }
- }
- $shipment_transport_mode = utils::implode(";",$converMode);
- $shipment_etd_limit = common::check_input($_POST['shipment_etd_limit']);
- $shipment_eta_limit = common::check_input($_POST['shipment_eta_limit']);
- }
- if ($rules_type == "Milestone_Update"){
- //提交的description 的转换code
- $milestones = common::excuteListSql("select * from customer_service_milestone_sno order by type, sno");
- $oceanMilestone = array();
- $airMilestone = array();
- foreach($milestones as $milestone){
- if($milestone['type'] == "air"){
- $airMilestone[] = $milestone;
- }
- if($milestone['type'] == "ocean"){
- $oceanMilestone[] = $milestone;
- }
- }
- $ocean_milestone = $this->convertCodeForMilestoneAndCtnr("Milestone_Update",$_POST['ocean_milestone'],$oceanMilestone);
- $air_milestone = $this->convertCodeForMilestoneAndCtnr("Milestone_Update",$_POST['air_milestone'],$airMilestone);
- $ocean_milestone = utils::implode(";",$ocean_milestone);
- $air_milestone = utils::implode(";",$air_milestone);
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type, ocean_milestone,
- air_milestone, frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_milestone',
- '$air_milestone', '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
- }
- if ($rules_type == "Container_Status_Update"){
- $event = common::getEDICtnrEvent();
- $ocean_ctnr_status = $this->convertCodeForMilestoneAndCtnr("Container_Status_Update",$_POST['ocean_ctnr_status'],$event);
- $ocean_ctnr_status = utils::implode(";",$ocean_ctnr_status);
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type, ocean_ctnr_status,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type', '$ocean_ctnr_status',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
- }
- if ($rules_type == "Departure/Arrival_Delay"){
- $ocean_atd_sub_etd = common::check_input($_POST['ocean_atd_sub_etd']);
- $ocean_atd_sub_etd_unit = common::check_input($_POST['ocean_atd_sub_etd_unit']);
- if(!empty($ocean_atd_sub_etd_unit)){
- $ocean_atd_sub_etd_unit = $ocean_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
- }
- $ocean_ata_sub_eta = common::check_input($_POST['ocean_ata_sub_eta']);
- $ocean_ata_sub_eta_unit = common::check_input($_POST['ocean_ata_sub_eta_unit']);
- if(!empty($ocean_ata_sub_eta_unit)){
- $ocean_ata_sub_eta_unit = $ocean_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
- }
- $air_atd_sub_etd = common::check_input($_POST['air_atd_sub_etd']);
- $air_atd_sub_etd_unit = common::check_input($_POST['air_atd_sub_etd_unit']);
- if(!empty($air_atd_sub_etd_unit)){
- $air_atd_sub_etd_unit = $air_atd_sub_etd_unit=="Day(s)" ? "days":"hours";
- }
- $air_ata_sub_eta = common::check_input($_POST['air_ata_sub_eta']);
- $air_ata_sub_eta_unit = common::check_input($_POST['air_ata_sub_eta_unit']);
- if(!empty($air_ata_sub_eta_unit)){
- $air_ata_sub_eta_unit = $air_ata_sub_eta_unit=="Day(s)" ? "days":"hours";
- }
-
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type,
- ocean_atd_sub_etd, ocean_atd_sub_etd_unit,ocean_ata_sub_eta,ocean_ata_sub_eta_unit,
- air_atd_sub_etd, air_atd_sub_etd_unit,air_ata_sub_eta,air_ata_sub_eta_unit,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
- '$ocean_atd_sub_etd','$ocean_atd_sub_etd_unit','$ocean_ata_sub_eta','$ocean_ata_sub_eta_unit',
- '$air_atd_sub_etd','$air_atd_sub_etd_unit','$air_ata_sub_eta','$air_ata_sub_eta_unit',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
- }
- if ($rules_type == "ETD/ETA_Change"){
- $ocean_etd_change = common::check_input($_POST['ocean_etd_change']);
- $ocean_etd_old_sub_new = common::check_input($_POST['ocean_etd_old_sub_new']);
- $ocean_etd_old_sub_new_unit = common::check_input($_POST['ocean_etd_old_sub_new_unit']);
- if(!empty($ocean_etd_old_sub_new_unit)){
- $ocean_etd_old_sub_new_unit = $ocean_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $ocean_eta_change = common::check_input($_POST['ocean_eta_change']);
- $ocean_eta_old_sub_new = common::check_input($_POST['ocean_eta_old_sub_new']);
- $ocean_eta_old_sub_new_unit = common::check_input($_POST['ocean_eta_old_sub_new_unit']);
- if(!empty($ocean_eta_old_sub_new_unit)){
- $ocean_eta_old_sub_new_unit = $ocean_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $air_etd_change = common::check_input($_POST['air_etd_change']);
- $air_etd_old_sub_new = common::check_input($_POST['air_etd_old_sub_new']);
- $air_etd_old_sub_new_unit = common::check_input($_POST['air_etd_old_sub_new_unit']);
- if(!empty($air_etd_old_sub_new_unit)){
- $air_etd_old_sub_new_unit = $air_etd_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
- $air_eta_change = common::check_input($_POST['air_eta_change']);
- $air_eta_old_sub_new = common::check_input($_POST['air_eta_old_sub_new']);
- $air_eta_old_sub_new_unit = common::check_input($_POST['air_eta_old_sub_new_unit']);
- if(!empty($air_eta_old_sub_new_unit)){
- $air_eta_old_sub_new_unit = $air_eta_old_sub_new_unit=="Day(s)" ? "days":"hours";
- }
-
- $sql.="INSERT INTO public.notifications_rules(
- user_login, notifications_type, rules_type,
- 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,
- 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,
- frequency_type, daily_time, daily_time_zone,
- weekly_week, weekly_time, weekly_time_zone, method_by_email, method_by_message,
- event_details, frequency_display, method_display,shipment_details,
- shipment_transport_mode,shipment_etd_limit,shipment_eta_limit)
- VALUES ('".strtolower(_getLoginName())."', '$notifications_type', '$rules_type',
- '$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',
- '$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',
- '$frequency_type', $daily_time, '$daily_time_zone',
- '$weekly_week', $weekly_time, '$weekly_time_zone', '$method_by_email', '$method_by_message',
- '$event_details', '$frequency_display', '$method_display','$shipment_detail',
- '$shipment_transport_mode','$shipment_etd_limit','$shipment_eta_limit');";
- }
- return $sql;
- }
- /**
- * 检查编辑提交的Monitoring规则,是否允许保存
- */
- public function checkedMonitoringRulesSave($rules_type){
- $sql_where = "";
- if(isset($_POST['id']) && !empty($_POST['id'])){
- $sql_where = " and id <> '".common::check_input($_POST['id'])."'";
- }
- $rules = common::excuteOneSql("select * from public.notifications_rules where notifications_type = 'Monitoring' and rules_type = '".$rules_type."'
- and lower(user_login) = '".strtolower(_getLoginName())."' $sql_where");
- foreach($rules as $rule){
- //判断range 是否一样
- $checkRangeFiled = array("shipment_transport_mode","shipment_etd_limit","shipment_eta_limit");
- $range_flag = true;
- foreach($checkRangeFiled as $filed){
- if($filed == "shipment_transport_mode"){
- $postValue = utils::implode(";",$_POST[$filed]);
- }else{
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- }
- if($postValue != $rule[$filed]){
- $range_flag = false;
- }
- }
- //判断details 是否一样
- $checkDetailsFiled = array("ocean_milestone","air_milestone","ocean_ctnr_status",
- "ocean_atd_sub_etd","ocean_atd_sub_etd_unit","ocean_ata_sub_eta","ocean_ata_sub_eta_unit",
- "air_atd_sub_etd","air_atd_sub_etd_unit","air_ata_sub_eta","air_ata_sub_eta_unit",
- "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",
- "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");
- $details_flag = true;
- foreach($checkDetailsFiled as $filed){
- if($filed == "ocean_milestone" || $filed == "air_milestone" || $filed == "ocean_ctnr_status"){
- $postValue = utils::implode(";",$_POST[$filed]);
- }else{
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- }
- if($postValue != $rule[$filed]){
- $details_flag = false;
- }
- }
-
- //判断frequency 是否一样
- $checkFrequencyFiled = array("frequency_type","daily_time","daily_time_zone",
- "weekly_week","weekly_time","weekly_time_zone","daily_time_zone");
- $frequency_flag = true;
- foreach($checkFrequencyFiled as $filed){
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- if($postValue != $rule[$filed]){
- $frequency_flag = false;
- }
- }
-
- //判断通知方式是否一样
- $checkMethodFiled = array("method_by_email","method_by_message");
- $method_flag = true;
- foreach($checkMethodFiled as $filed){
- $postValue = !empty($_POST[$filed]) ? $_POST[$filed] : "";
- if($postValue != $rule[$filed]){
- $method_flag = false;
- }
- }
- //五个条件一样,不允许保存
- if($range_flag && $details_flag && $frequency_flag && $method_flag){
- $msg = "Unable to Save";
- continue;
- }
- //前三个重回,后面不重合,提示但允许保存
- if($range_flag && $details_flag){
- $msg = "Similar Rule Detected";
- continue;
- }
- }
- return $msg;
- }
- public function getNotifications($notifiation_type,$frequency_type){
- if ($frequency_type == "all"){
- $sql_where = " and (ni.frequency_type = 'Instant'
- or (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)
- or (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
- and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%'))";
- } elseif($frequency_type == "Daily"){
- $sql_where = " and (ni.frequency_type = 'Daily' and timezone(ni.daily_time_zone, NOW()::time) > ni.daily_time::time)";
- } elseif($frequency_type == "Weekly"){
- $sql_where = " and (ni.frequency_type = 'Weekly' and timezone(ni.weekly_time_zone, NOW()::time) > ni.weekly_time::time
- and ni.weekly_week ilike '%'|| EXTRACT(dow FROM timezone(ni.weekly_time_zone, NOW())) ||'%')";
- }
-
- $sql = "select ni.*,
- case when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'days'
- then (EXTRACT(DAY FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- when ni.notifiation_type = 'Departure/Arrival_Delay' and ni.delay_unit = 'hours'
- then (EXTRACT(HOUR FROM ((delay_act_date||' '||delay_act_time)::timestamp - (delay_est_date||' '||delay_est_time)::timestamp)))
- else 0
- end as delay_diff,
- case when COALESCE(ni.frequency_type,'') = 'Daily'
- then to_char(timezone(ni.daily_time_zone, now()),'Mon DD, YYYY')
- when COALESCE(ni.frequency_type,'') = 'Weekly'
- then to_char(timezone(ni.weekly_time_zone, now()),'Mon DD, YYYY')
- else ''
- end as insert_date_format,
- ccc.order_from,ccc.h_bol,ccc.transport_mode
- from public.kln_notifiation_info ni
- left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from
- from public.kln_ocean oo
- where oo.serial_no = ni.serial_no limit 1) ccc on true
- where lower(ni.user_login) = '"._getLoginName()."'
- and ni.notifiation_type = '".$notifiation_type."'
- ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc";
- error_log($sql);
- $data = common::excuteListSql($sql);
- //统一处理数据Instant Daily weekly_week 先分开在处理
- $instant = array();
- $daily = array();
- $daily_uniqe = array();
- $daily_all_id = array();
- $weekly = array();
- $weekly_uniqe = array();
- $weekly_all_id = array();
- foreach($data as $d){
- if ($d['frequency_type'] == "Instant"){
- $instant[] = $d;
- }
- //类型为这个时才用这个去重,否则要加上描述(转船的情况,会让相同的HBOL显示)
- $uniqe_str = $d['serial_no'];
- if ($notifiation_type == "Departure/Arrival_Delay"){
- $uniqe_str = $d['serial_no']."_".$d['delay_name'];
- } else if($notifiation_type == "ETD/ETA_Change"){
- $uniqe_str = $d['serial_no']."_".$d['date_change_name'];
- }
- if ($d['frequency_type'] == "Daily"){
- $daily_all_id[] = $d["id"];
- if(utils::in_array($uniqe_str,$daily_uniqe)){
- $temp = $daily[$uniqe_str];
- //previous只更新最近的一次,并且是需要查询详细的时候,才放开previous的查询
- if(empty($temp['previous']) && $frequency_type <> "all"){
- $temp['previous'] = $d;
- }
- $daily[$uniqe_str] = $temp;
- } else {
- $daily[$uniqe_str] = $d;
- $daily_uniqe[] = $uniqe_str;
- }
- }
- if ($d['frequency_type'] == "Weekly"){
- $weekly_all_id[] = $d["id"];
- if(utils::in_array($uniqe_str,$weekly_uniqe)){
- $temp = $weekly[$uniqe_str];
- //previous只更新最近的一次,并且是需要查询详细的时候,才放开previous的查询
- if(empty($temp['previous']) && $frequency_type <> "all"){
- $temp['previous'] = $d;
- }
- $weekly[$uniqe_str] = $temp;
- } else {
- $weekly[$uniqe_str] = $d;
- $weekly_uniqe[] = $uniqe_str;
- }
- }
- }
- return array("instant" =>$instant,"daily" =>utils::arrayKeyToInt($daily),"weekly"=>utils::arrayKeyToInt($weekly),
- "daily_all_id" =>$daily_all_id,"weekly_all_id"=>$weekly_all_id);
- }
- public function getEventCard($mInfo){
- $eventCard = array();
- $notifiation_type = $mInfo['notifiation_type'];
- if($notifiation_type == "Milestone_Update"){
- $eventCard = array("type" =>'milestone',
- "numericRecords"=>0,
- "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
- "title"=>"Milestone Update",
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>$mInfo["h_bol"],
- "tag"=>$mInfo["milestone_description"],
- "location"=>$mInfo["milestone_locations"],
- "timezone"=>$mInfo["milestone_timezone"],
- "time"=>$mInfo["milestone_date"]." ".$mInfo["milestone_time"],
- "timeLabel"=>"",
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>$mInfo["serial_no"],
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "info"=>new stdClass());
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Milestone Update Daily Summary(".$mInfo["insert_date_format"].")";
- if(!empty($mInfo["previous"])){
- $eventCard["previous"] = array("tag" =>"Previous:".$mInfo["previous"]["milestone_description"]." from ".$mInfo["previous"]["milestone_locations"],
- "time" => $mInfo["previous"]["milestone_time"],
- "timezone" =>$mInfo["previous"]["milestone_timezone"]);
- }
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Milestone Update Weekly Summary(".$mInfo["insert_date_format"].")";
- if(!empty($mInfo["previous"])){
- $eventCard["previous"] = array("tag" =>"Previous:".$mInfo["previous"]["milestone_desc"]." from ".$mInfo["previous"]["milestone_description"],
- "time" => $mInfo["previous"]["milestone_time"],
- "timezone" =>$mInfo["previous"]["milestone_timezone"]);
- }
- }
- }
- if($notifiation_type == "Container_Status_Update"){
- //当前状态的描述
- $ctnrStatusdesc = $this->getContainerStatusDesc($mInfo["ctnr_status_code"]);
- $eventCard = array("type" =>'container',
- "numericRecords"=>0,
- "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
- "title"=>"Container_Status_Update",
- "mode"=>"Ocean Freight",
- "no"=>$mInfo["ctnr"],
- "tag"=>$ctnrStatusdesc,
- "location"=>$mInfo["ctnr_status_locations"],
- "timezone"=>$mInfo["ctnr_status_timezone"],
- "time"=>$mInfo["ctnr_status_date"]." ".$mInfo["ctnr_status_time"],
- "timeLabel"=>"",
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>$mInfo["serial_no"],
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "info"=>new stdClass());
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
- if(!empty($mInfo["previous"])){
- //当前状态 前一个的描述
- $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
- $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
- "time" => $mInfo["previous"]["ctnr_status_time"],
- "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
- }
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
- if(!empty($mInfo["previous"])){
- //当前状态 前一个的描述
- $previousCtnrStatusdesc = $this->getContainerStatusDesc($mInfo["previous"]["ctnr_status_code"]);
- $eventCard["previous"] = array("tag" =>"Previous:" .$previousCtnrStatusdesc. " from " .$mInfo["previous"]["ctnr_status_locations"],
- "time" => $mInfo["previous"]["ctnr_status_time"],
- "timezone" =>$mInfo["previous"]["ctnr_status_timezone"]);
- }
- }
- }
- if($notifiation_type == "Departure/Arrival_Delay"){
- //代表信息为转船信息,title要处理一下: leg 2/3 Departure_Delay => Departure_Delay
- $title = $mInfo["delay_name"];
- $outsideLocation = "";
- $outsideTimezone = "";
- $outsideTimeLabel= "";
- $insideTimeLabel= "";
- if(utils::checkExist($mInfo["delay_name"],"Departure_Delay")){
- $outsideTimeLabel = "ETD";
- $insideTimeLabel = "ATD";
- }
- if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay")){
- $outsideTimeLabel = "ETA";
- $insideTimeLabel = "ATA";
- }
- //直航的的
- if(utils::checkExist($mInfo["delay_name"],"Departure_Delay") and $mInfo["delay_is_direct"] == 't'){
- $outsideLocation = $mInfo["delay_locations_from"];
- }
- if(utils::checkExist($mInfo["delay_name"],"Arrival_Delay") and $mInfo["delay_is_direct"] == 't'){
- $outsideLocation = $mInfo["delay_locations_to"];
- }
- $route = array();
- $leg = array();
- if($mInfo["delay_is_direct"] <>'t'){
- $title = substr($mInfo["delay_name"],8);
- $route = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
- //当前current Leg
- $leg = array($mInfo["delay_locations_from"],$mInfo["delay_locations_transshipment"]);
- if($mInfo["delay_current"] == "2"){
- $leg = array($mInfo["delay_locations_transshipment"],$mInfo["delay_locations_to"]);
- }
- }
- $act_date = $mInfo["delay_act_date"]." ".$mInfo["delay_act_time"];
- $est_date = $mInfo["delay_est_date"]." ".$mInfo["delay_est_time"];
- $delay_diff = $mInfo["delay_diff"];
- $delay_unit = $mInfo["delay_unit"];
- $eventCard = array("type" =>'delay',
- "numericRecords"=>0,
- "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
- "title"=>$title,
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>$mInfo["h_bol"],
- "tag"=>$mInfo["delay_name"],
- "location"=>$outsideLocation,
- "timezone"=>$mInfo["delay_timezone"],
- "time"=>$est_date,
- "timeLabel"=>$outsideTimeLabel,
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>$mInfo["serial_no"],
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "info"=>array("route"=>$route,
- "leg"=>$leg,
- "etdOrdeparturNum"=>0,
- "etaOrarrivalNum"=>0,
- "time"=>$act_date,
- "timeLabel"=>$insideTimeLabel,
- "delayTimeTip"=>"+".$delay_diff." ".$delay_unit." delay",
- "timezone"=>$mInfo["delay_timezone"]
- ));
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "Container Status Update Daily Summary(".$mInfo["insert_date_format"].")";
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "Container Status Update Weekly Summary(".$mInfo["insert_date_format"].")";
- }
- }
- if($notifiation_type == "ETD/ETA_Change"){
- $title = $mInfo["date_change_name"];
- if(utils::checkExist($mInfo["date_change_name"],"ETD Change")){
- $outsideTimeLabel = "Original ETD";
- $insideTimeLabel = "Upoated ETD";
- }
- if(utils::checkExist($mInfo["date_change_name"],"ETA Change")){
- $outsideTimeLabel = "Original ETA";
- $insideTimeLabel = "Upoated ETA";
- }
-
- if($mInfo["date_change_is_direct"] <>'t'){
- //代表信息为转船信息,title要处理一下: leg 1/3 ETD Change
- $title = substr($mInfo["date_change_name"],8);
- $route = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
- $leg = array($mInfo["date_change_locations_from"],$mInfo["date_change_locations_transshipment"]);
- if($mInfo["delay_current"] == "2"){
- $leg = array($mInfo["date_change_locations_transshipment"],$mInfo["date_change_locations_to"]);
- }
- }
- $updated_date = $mInfo["date_change_updated_date"]." ".$mInfo["date_change_updated_time"];
- $original_date = $mInfo["date_change_original_date"]." ".$mInfo["date_change_original_time"];
- $eventCard = array("type" =>'change',
- "numericRecords"=>0,
- "isRead"=>$mInfo["is_send_message"] == 't' ? true : false,
- "title"=>$title,
- "mode"=>$mInfo["transport_mode"] == 'sea' ? "Ocean Freight": "Air Freight",
- "no"=>$mInfo["h_bol"],
- "tag"=>$mInfo["date_change_name"],
- "location"=>"",
- "timezone"=>$mInfo["date_change_timezone"],
- "time"=>$original_date,
- "timeLabel"=>$outsideTimeLabel,
- "previous"=>"",
- "frequency_type"=>$mInfo["frequency_type"],
- "serial_no"=>$mInfo["serial_no"],
- "order_from"=>$mInfo["order_from"],
- "id"=>$mInfo["id"],
- "info"=>array("route"=>$route,
- "leg"=>$leg,
- "etdOrdeparturNum"=>0,
- "etaOrarrivalNum"=>0,
- "time"=>$updated_date,
- "timeLabel"=>$insideTimeLabel,
- "delayTimeTip"=>"",
- "timezone"=>$mInfo["date_change_timezone"]
- ));
- if ($mInfo["frequency_type"] == "Daily"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "ETD/ETA Change Daily Summary(".$mInfo["insert_date_format"].")";
- } else if($mInfo["frequency_type"] == "Weekly"){
- $eventCard["numericRecords"] = !empty($mInfo["numericRecords"]) ? $mInfo["numericRecords"] : 0;
- $eventCard["info"]["etdOrdeparturNum"] = !empty($mInfo["numericRecords_one"]) ? $mInfo["numericRecords_one"] : 0;
- $eventCard["info"]["etaOrarrivalNum"] = !empty($mInfo["numericRecords_two"]) ? $mInfo["numericRecords_two"] : 0;
- $eventCard["title"] = "ETD/ETA Change Weekly Summary(".$mInfo["insert_date_format"].")";
- }
- }
- return $eventCard;
- }
- /**
- * 返回当前柜子的status信息描述
- */
- public static function getContainerStatusDesc($ctnr_status_code){
- $event =common::getEDICtnrEvent();
- $ctnrStatusdesc = "";
- foreach($event as $e){
- if($e['event_name'] == $ctnr_status_code){
- $ctnrStatusdesc = $e['description'];
- }
- }
- return $ctnrStatusdesc;
- }
- }
- ?>
|