浏览代码

dashboaed search

ShuanghongS 1 年之前
父节点
当前提交
f7856784da
共有 5 个文件被更改,包括 223 次插入67 次删除
  1. 46 42
      main_new_version.php
  2. 3 3
      service/login.class.php
  3. 102 2
      service/ocean_order.class.php
  4. 71 20
      utils/common.class.php
  5. 1 0
      utils/utils.class.php

+ 46 - 42
main_new_version.php

@@ -68,15 +68,15 @@ switch ($action) {
             $edate = $_REQUEST["e_date"];
             $edate = "'$edate'";
         }
-        //Demo测试数据 日期全为空 
+        //Demo测试数据 日期全为空 :前端是由日期过来来的
         $edate = "null";
         $bdate = "null";
 
         $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = common::check_input($sqlWhere);
         $sqlWhere = " " . $sqlWhere;
-
-        $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
+        //online_order_status_date_new 与本地的区分,发布上去这去掉new
+        $list = common::excuteListSql("select * from public.online_order_status_date_new('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
                         . "r (c bigint, e integer, b integer, d text)");              
         $key = "[";
         $value = "[";
@@ -103,8 +103,6 @@ switch ($action) {
         }
         $key .= "]";
         $value .= "]";
-        
-        //$data = array($key, $value, $totalValue);
         //处理返回原表数据格式
         $data = common::mian_repot_do($value,$type,$totalValue);
         common::echo_json_encode(200, $data);
@@ -133,10 +131,8 @@ switch ($action) {
         $sqlWhere = common::check_input($sqlWhere);
         $sqlWhere = " " . $sqlWhere;
 
-        $list = common::excuteListSql("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
-                        . "r (c bigint, d text)");    
-        error_log("select * from public.online_order_status_date_kpi('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
-                        . "r (c bigint, d text)");         
+        $list = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere'::text) "
+                        . "r (c bigint, d text)");            
         $key = "[";
         $value = "[";
         $totalValue = 0;
@@ -191,14 +187,12 @@ switch ($action) {
                 $edate = $_REQUEST["e_date"];
                 $edate = "'$edate'";
             }
-            //Demo测试数据 日期全为空 
-            $edate = "null";
-            $bdate = "null";
             $list= array();
             //all 查询所有
             $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
             $sqlWhere = common::check_input($sqlWhere);
             $sqlWhere = " " . $sqlWhere;
+            //如果页面查询的是ALL 这个20  40  45都查询出来。否则值查询都对应的size,其他的不查询
             if(strtolower($container_type_param) == "all"){
                 $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
                                 . "r (c bigint, e integer, b integer, d text)");
@@ -236,8 +230,11 @@ switch ($action) {
             $value .= "]";
             $key_arr = json_decode($key,true);
             $value_arr = json_decode($value,true);
+
             $data = array();
+            //每一个size 的所有月份总计
             $total = 0;
+            //每一个size 对应的最大值
             $max = 0;
             foreach($value_arr as $arr){
                 $data[] = intval($arr['value']);
@@ -249,18 +246,22 @@ switch ($action) {
         
         //处理返回时数据格式
         $ContainerCounSeries_return = array();
+        //横坐标栏位
         $ContainerCount_Title = $key_arr;
+
+        //所查的所有模式计算总和
         $total = 0;
+        //所有size下的最大值,方便标注计算最长的Y坐标
         $max_all = 0;
         foreach($ContainerCounSeries as $k =>$v){
-            //这个type 是页面传过来的
+            //这个type 是页面传过来的。这个固定r2
             $color = common::getItemStyle($type,$k);
             $total = $total + $v['total'];
             $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
                 "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));
             $max_all = $max_all +  $v['max'];
         }
-        //处理返回原表数据格式
+        //计算Y坐标的间隔
         $interval = utils::calculateTicks(0,$max_all,5);
         if($interval == 0){
             //处理返回默认值
@@ -365,40 +366,43 @@ switch ($action) {
         exit();
         break;
     case 'main_map_new':
-
+        //修改添加port_of_transshipment 和port_of_transshipment_name的坐标获取(有为空的可能)
         $serial_no = $_POST["serial_no"];
         $sql = "with ss as (select '$serial_no' as sn)
-            , aa as (
-            select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp from public.online_ocean oo where serial_no=(select sn from ss) limit 1
-            )
-            , v1 as (select public.get_vessel_position(sn::text) bbb from ss)
-            , t1 as (select tl.upload_time, tl.by_pickup, split_part(g.consignee_exp,'\n',1) as consignee_exp, split_part(g.pickup_from_exp,'\n',1) as pickup_from_exp, c.ctnr, split_part(g.deliveryto_exp,'\n',1) as deliveryto_exp, g.serial_no, tl.location, tl.type, tl.id, 
-                        to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime 
-                        from public.tk_general g, public.tk_commodity c left join public.tk_location tl on c.serial_no=tl.serial_no 
+                , aa as (
+                    select place_of_receipt_un, place_of_delivery_un, fport_of_loading_un, mport_of_discharge_un, port_of_loading, port_of_discharge, place_of_delivery_exp, place_of_receipt_exp,dd.*
+                        from public.online_ocean oo 
+                        left join LATERAL (
+                            select (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un,
+                                    port_of_transshipment_name
+                                from  ocean o where o.serial_no=oo.serial_no order by id desc limit 1
+                        ) dd on true
+                        where serial_no=(select sn from ss) limit 1
+                )
+                , v1 as (select public.get_vessel_position(sn::text) bbb from ss)
+                , t1 as (
+                    select tl.upload_time, tl.by_pickup, split_part(g.consignee_exp,'\n',1) as consignee_exp, split_part(g.pickup_from_exp,'\n',1) as pickup_from_exp,
+                            c.ctnr, split_part(g.deliveryto_exp,'\n',1) as deliveryto_exp,g.serial_no, tl.location, tl.type, tl.id, 
+                            to_char(tl.upload_time, 'MM/DD/YYYY HH24:MI:SS') as utime 
+                        from public.tk_general g, public.tk_commodity c 
+                            left join public.tk_location tl on c.serial_no=tl.serial_no 
                         where g.serial_no=c.serial_no and g.bol=(select m_bol from public.ocean where serial_no=(select sn from ss)) order by tl.order_id)
-            , vv as (select split_part(split_part(bbb, '|', 2), ',', 1)::numeric  as lng, split_part(split_part(bbb, '|', 2), ',', 2)::numeric  as lat, 'Vessel: '||split_part(bbb, '|', 3) as infor, 5 as sort, null::timestamp without time zone as stime, 'vessel'::text as ptype from v1 where bbb is not null and bbb<>'')
-            , tt as (select split_part(location, ',', 2)::numeric  as lng, split_part(location, ',', 1)::numeric  as lat, (
-                                case when type='26' then ctnr||': Pick up: '||utime||', '||(case when by_pickup=true then pickup_from_exp else consignee_exp end)
-                                         else ctnr||': Delivery: '||utime||', '||(case when by_pickup=true then consignee_exp else deliveryto_exp end)
-                                    end 
-                            ) as infor, 6 as sort, upload_time as stime, case when type='26' then 'pickup'::text else 'delivery'::text end as ptype from t1 where location is not null and location<>'')
-            , rr as (
-            select lon as lng, lat as lat, 'Place of receipt: '||place_of_receipt_exp as infor, 0 as sort, null::timestamp without time zone as stime, 'por'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_receipt_un
-            union all
-            select lon as lng, lat as lat, 'POL: '||port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=fport_of_loading_un
-            union all
-            select lon as lng, lat as lat, 'POD: '||port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=mport_of_discharge_un
-            union all
-            select lon as lng, lat as lat, 'Place of delivery: '||place_of_delivery_exp as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=place_of_delivery_un
-            union all
-            select * from vv
-            union all
-            select * from tt
-            )
+                , rr as (
+                        select lon as lng, lat as lat, 'Origin' as label, port_of_loading as infor, 1 as sort, null::timestamp without time zone as stime, 'pol'::text as ptype 
+                            from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=fport_of_loading_un
+                        union all
+                        select lon as lng, lat as lat, 'Destination' as label, port_of_discharge as infor, 2 as sort, null::timestamp without time zone as stime, 'pod'::text as ptype 
+                            from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=mport_of_discharge_un
+                        union all
+                        select lon as lng, lat as lat,  'Transfer' as label, port_of_transshipment_name as infor, 3 as sort, null::timestamp without time zone as stime, 'poe'::text as ptype 
+                            from vessel.vt_unlocode, aa where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode=port_of_transshipment_un
+                    )
             select * from rr order by sort, stime";
         $rss = common::excuteListSql($sql);
         //先固定死
-        $json = '[{"lng":"100.78594000","lat":"13.68521000","infor":"Place of receipt: LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},{"lng":"100.88333333","lat":"13.08333333","infor":"POL: LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},{"lng":"-122.28640000","lat":"37.79784000","infor":"POD: OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"},{"lng":"93.78333333","lat":"37.68333333","infor":"Place of delivery: STOCKTON, CA, USA","sort":"3","stime":null,"ptype":"poe"}]';
+        $json = '[{"lng":"100.78594000","lat":"13.68521000","label":"Origin","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"},
+                  {"lng":"100.88333333","lat":"13.08333333","label":"Destination","infor":"LAEM CHABANG PORT,THAILAND","sort":"1","stime":null,"ptype":"pol"},
+                  {"lng":"-122.28640000","lat":"37.79784000","label":"Transfer","infor":"OAKLAND, CA, USA","sort":"2","stime":null,"ptype":"pod"}]';
         $rss = json_decode($json,true);
         common::echo_json_encode(200, $rss);
         exit();

+ 3 - 3
service/login.class.php

@@ -995,7 +995,7 @@ class login {
                 'msg' => $str,
                 'data' => ''
             );
-            common::echo_json_encode(200, $data);
+            common::echo_json_encode(400, $data);
             exit();
         }
 
@@ -1013,7 +1013,7 @@ class login {
                 'msg' => $msg,
                 'data' => ''
             );
-            common::echo_json_encode(200, $data);
+            common::echo_json_encode(400, $data);
             exit();
         }
     }
@@ -1249,7 +1249,7 @@ class login {
         //Milestones info  列名固定
         $Milestones_column = array();
         $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
-        $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
+        $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"dateTime");
         $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
         $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
 

+ 102 - 2
service/ocean_order.class.php

@@ -264,10 +264,108 @@ class ocean_order {
         $ps = common::check_input($_POST ['ps']); //ps
         if (empty($ps))
             $ps = 50;
+        if (empty($cp))
+            $cp = 1;
 
         $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
 
+        if (!empty($_REQUEST["_reportRef"])) {
+            $_reportType = $_REQUEST["_reportType"];
+            $_reportRef = $_REQUEST["_reportRef"];
+            if ($_reportType == "r3") {
+                if ($_reportRef == "Previous 7 Days") {
+                    $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
+                } else if ($_reportRef == "0 Day") {
+                    $sqlWhere .= " and eta=current_date";
+                } else if ($_reportRef == "1-2 Days") {
+                    $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
+                } else if ($_reportRef == "3-6 Days") {
+                    $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
+                } else if ($_reportRef == "7 Days") {
+                    $sqlWhere .= " and eta>(current_date+interval '6 days')";
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else if ($_reportType == "r4") {
+                if ($_reportRef == "Previous 7 Days") {
+                    $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
+                } else if ($_reportRef == "0 Day") {
+                    $sqlWhere .= " and etd=current_date";
+                } else if ($_reportRef == "1-2 Days") {
+                    $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
+                }  else if ($_reportRef == "3-6 Days") {
+                    $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
+                } else if ($_reportRef == "7 Days") {
+                    $sqlWhere .= " and etd>(current_date+interval '6 days')";
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else if ($_reportType == "ata_r3") {
+                if ($_reportRef == "0 Day") {
+                    $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
+                } else if ($_reportRef == "1-2 Days") {
+                    $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
+                }  else if ($_reportRef == "3-6 Days") {
+                    $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
+                } else if ($_reportRef == "7 Days") {
+                    $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else if ($_reportType == "atd_r4") {
+                if ($_reportRef == "0 Day") {
+                    $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
+                } else if ($_reportRef == "1-2 Days") {
+                    $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
+                }  else if ($_reportRef == "3-6 Days") {
+                    $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
+                } else if ($_reportRef == "7 Days") {
+                    $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else if ($_reportType == "top") {
+                if (!empty($_reportRef)) {
+                    $_reportStationType = $_REQUEST["_reportStationType"];
+                    if($_reportStationType == 'origin'){
+                        $sqlWhere .= " and  origin = '$_reportRef'";
+                    }else{
+                        $sqlWhere .= " and  agent = '$_reportRef'";
+                    }
+                    
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else if ($_reportType == "co2e") {
+                $_reportDataType = $_REQUEST["_reportDataType"];
+                //查询sea 其他的为空
+                if (!empty($_reportRef) && $_reportDataType == "sea") {
+                    $_reportStationType = $_REQUEST["_reportStationType"];
+                    if($_reportStationType == 'origin'){
+                        $sqlWhere .= " and  origin = '$_reportRef'";
+                    }else{
+                        $sqlWhere .= " and  agent = '$_reportRef'";
+                    }
+                    
+                } else {
+                    $sqlWhere .= " and 1<>1";
+                }
+            } else {
+                $_reportRef = explode("-", $_REQUEST["_reportRef"]);
+                $_reportRefb_date = $_REQUEST["_reportRefb_date"];
+                $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
+                $_reportRefe_date = $_REQUEST["_reportRefe_date"];
+                $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
+                //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
+                if ($_REQUEST["_reportRef"] == "Over 80 Days") {
+                    $sqlWhere .= " and (eta-etd)>80";
+                } else {
+                    $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
+                }
+            }
+        }
+
         //查询tag
         // IFFBCF;Booking Confirmation
         // IFFREC;Cargo Arrived at Origin
@@ -341,7 +439,7 @@ class ocean_order {
 						select regexp_split_to_table('Booking Confirmation,Cargo Pickup,Cargo Arrived at Origin,Departure,Arrived at Final Destination Port,Arrived at Final Destination', ','))
 				 order by id desc limit 1) dd on true" . $sqlWhere;
             $rc = common::excuteOneSql($sql);
-            error_log($sql);
+            error_log("sss:".$sql);
 
             //Booked
             $sql = $this->getOcanOrderSearchSql("Booked",$sqlWhere);
@@ -419,6 +517,8 @@ class ocean_order {
 		            END AS new_status, ".
                     column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean $ocean_ref_sql $ocean_status_sql" . $sqlWhere . 
                 " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
+
+             $sss =  " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;   
             
             $rs = common::excuteListSql($sql);
             
@@ -1158,7 +1258,7 @@ class ocean_order {
         //Milestones info  列名固定
         $Milestones_column = array();
         $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
-        $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
+        $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"dateTime");
         $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
         $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
 

+ 71 - 20
utils/common.class.php

@@ -1117,6 +1117,7 @@ class common {
     public static function mian_repot_do($value,$type,$totalValue){
         $data = array();
         $value_arr = json_decode($value,true);
+        //r1 是 ETD to ETA (Days)圆形图表数据结构返回
         if($type == 'r1'){
             $ETDList = array();
             foreach($value_arr as $arr){
@@ -1179,23 +1180,39 @@ class common {
         //新UI air sea road 目前只有sea
         $type = $_REQUEST["r_type"];
         $container_type_arr = array("air","sea","road");
-        $container_type_param = 'sea';
+
+        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = common::check_input($sqlWhere);
+        $sqlWhere = " " . $sqlWhere;
+
         $ContainerCounSeries = array();
-        $ContainerCount_Title = array("HKHKG","DKHKG","EKHKG","FKHKG","KKHKG","GKHKG","MKHKG","LKHKG","NKHKG","OKHKG"); 
+
         foreach($container_type_arr as $_container_type){
-            //查询逻辑需要问,目前暂时写死ssh-keygen -t rsa -b 4096 -C "shuanghong.shuai@united-cn.net"
+            //类型有 sea air road,目前之类只查询sea的,其他为空
             $container_type = $_container_type;
-            $data = array(1500, 1500, 2100, 1500, 2450, 1900, 1900, 900, 600, 500);
+            if ($type == "co2e_orgin"){
+                $co2e_orgin_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum ,origin as station from online_ocean  where 1=1 $sqlWhere group by origin order by catnum desc limit 10";
+                $co2e = common::excuteListSql($co2e_orgin_sql);
+            }
+            if ($type == "co2e_desination"){
+                $co2e_agent_sql = "select SUM(COALESCE(carbon_emission,0)::numeric(12,10)) as catnum,agent as station from online_ocean  where 1=1 $sqlWhere group by agent order by catnum desc limit 10";
+                $co2e = common::excuteListSql($co2e_agent_sql);
+            }
+
             $total = 0;
             $max = 0;
-            // foreach($value_arr as $arr){
-            //     $data[] = intval($arr['value']);
-            //     $total = $total + intval($arr['value']);
-            // }
-            foreach($data as $arr){
-                $total = $total + $arr;
-                $max = $max < $arr ? $arr : $max;
-             }
+            $ContainerCount_Title = array();
+            $data = array();
+            foreach($co2e as $val){
+                $ContainerCount_Title[] = $val['station'];
+                $data[] = $val['catnum'];
+                $total = $total + $val['catnum'];
+                $max = $max < $val['catnum'] ? $val['catnum'] : $max;
+            }
+            //这里处理为空,目前没有数据
+            if($container_type == "air" || $container_type == "road"){
+                $data = array();
+            }
             $ContainerCounSeries[$container_type] = array("data"=>$data,"total"=>$total,"max"=>$max);
         }
         
@@ -1206,7 +1223,8 @@ class common {
             $color = common::getItemStyle($type,$k);
             $ContainerCounSeries_return[] = array("name"=>$k,"type"=>"bar","emphasis" => array("focus" =>"none"),
                 "stack" =>"总计","data" =>$v['data'],"itemStyle" =>array("color" =>$color));  
-            $max = $max + $v['max'];
+            //$max = $max + $v['max'];
+            $max = $max < $v['max'] ? $v['max'] : $max;
             
         }
         //处理返回原表数据格式
@@ -1222,20 +1240,53 @@ class common {
     }
 
     public static function getTopBar(){
+
+        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = common::check_input($sqlWhere);
+        $sqlWhere = " " . $sqlWhere;
+
+        $orgin10_sql = "select count(origin) as num,origin from online_ocean  where 1=1 $sqlWhere group by origin order by num desc limit 10";
+        $orgin10 = common::excuteListSql($orgin10_sql);
+
+        $agent10_sql = "select count(agent) as num,agent from online_ocean  where 1=1 $sqlWhere group by agent order by num desc limit 10";
+        $agent10 = common::excuteListSql($agent10_sql);
+
+
         $toporigin = array();
-        for($i = 0; $i<10; $i++){
-            $num = $i + 1;
-            $toporigin[] = array("name"=>"CNSGH$num","value"=>$num,"color"=>common::getItemStyle("top",$num));
+        $i = 0;
+        $origiNunMax = 0;
+        foreach($orgin10 as $orgin){
+            $i = $i + 1;
+            $map_sql = "select lon as lng, lat as lat,
+                    '' as label, '' as infor, 3 as sort,
+                    null::timestamp without time zone as stime,''::text as ptype 
+				from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode='".$orgin['origin']."'";
+            $map = common::excuteObjectSql($map_sql);   
+            $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$orgin['origin'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
+            $map = json_decode($json,true); 
+            $toporigin[] = array("name"=>$orgin['origin'],"value"=>$orgin['num'],"color"=>common::getItemStyle("top",$i),"map"=>$map);
+            $origiNunMax = $origiNunMax < $orgin['num'] ? $orgin['num'] : $origiNunMax;
         }
 
         $topdestination = array();
-        for($i = 0; $i<10; $i++){
-            $num = $i + 1;
-            $topdestination[] = array("name"=>"CNSGH$num","value"=>$num,"color"=>common::getItemStyle("top",$num));
+        $i = 0;
+        $agentiNunMax = 0;
+        foreach($agent10 as $agent){
+            $i = $i + 1;
+            $map_sql = "select lon as lng, lat as lat,
+                    '' as label, '' as infor, 3 as sort,
+                    null::timestamp without time zone as stime,''::text as ptype 
+				from vessel.vt_unlocode where lon<>0 and lat<>0 and lon is not null and lat is not null and uncode='".$agent['agent']."'";
+            $map = common::excuteObjectSql($map_sql);  
+
+            $json = '{"lng":"100.78594000","lat":"13.68521000","label":"'.$agent['agent'].'","infor":"LAT KRABANG, THAILAND","sort":"0","stime":null,"ptype":"por"}';
+            $map = json_decode($json,true);
+            $topdestination[] = array("name"=>$agent['agent'],"value"=>$agent['num'],"color"=>common::getItemStyle("top",$i),"map"=>$map);
+            $agentiNunMax = $agentiNunMax < $agent['num'] ? $agent['num'] : $agentiNunMax;
         }
 
         //处理返回原表数据格式
-        $interval = utils::calculateTicks(0,10,10);
+        $interval = utils::calculateTicks(0,$origiNunMax,10);
         if($interval == 0){
             //处理返回默认值
             $interval = 1;

+ 1 - 0
utils/utils.class.php

@@ -382,6 +382,7 @@ class utils {
 
     public static function calculateTicks($minValue, $maxValue, $targetTickCount = 10) {
         $tickSpacing = ($maxValue - $minValue);
+        $tickSpacing = intval($tickSpacing);
         $len = strlen($tickSpacing);
         if($len >=2 ){
             $interval = ceil($tickSpacing/pow(10,$len-2)/10) *pow(10,$len-2);