| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of operation_log
- *
- * @author Administrator
- */
- class destination_delivery {
- private static $_destination_delivery;
- public static function getInstance() {
- if (!self::$_destination_delivery) {
- $c = __CLASS__;
- self::$_destination_delivery = new $c;
- }
- return self::$_destination_delivery;
- }
- /**
- * 关于destination_delivery 页面的所有的静态加载数据查询
- */
- public function destination_delivery_load(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- /**
- * select country
- */
- if ($operate == "country") {
- $term = $_POST['term'];
- $term = trim($term);
- $sql = "select DISTINCT SUBSTRING(c.country FROM 1 FOR 2) AS country_code
- from public.contract_region_mapping crm
- left join ocean.contacts c on c.contact_id = crm.overeas and crm.ksmart_station_new ilike 'ksmart%'
- where coalesce(c.country,'')<> ''
- and SUBSTRING(c.country FROM 1 FOR 2) ilike '" . common::check_input($term) . "%'";
- $sql .= " order by country_code";
- $rs = common::excuteListSql($sql);
- //前端要加上id 从1开始
- $retData = array();
- foreach($rs as $key => $val){
- if(!empty($val['country_code'])){
- $retData[] = array("value" =>$val['country_code'] ,"label"=>$val['country_code']);
- }
- }
- common::echo_json_encode(200,$retData);
- exit();
- }
- /**
- * select station 选择国家后再展示 station list数据
- */
- if ($operate == "station") {
- $country = common::check_input($_REQUEST['country']);
- $sql = "select crm.overeas from public.contract_region_mapping crm
- left join ocean.contacts c on c.contact_id = crm.overeas and crm.ksmart_station_new ilike 'ksmart%'
- where SUBSTRING(c.country FROM 1 FOR 2) = '".$country."'";
- $rs = common::excuteListSql($sql);
- foreach($rs as $key => $val){
- if(!empty($val['overeas'])){
- $retData[] = array("value" =>$val['overeas'] ,"label"=>$val['overeas']);
- }
- }
- common::echo_json_encode(200,$retData);
- exit();
- }
- /**
- * select KLN PIC 下拉可供选择的employee帐号,且帐号权限站点包含选中的station
- */
- if ($operate == "employee_account") {
- $term = $_POST['term'];
- $term = trim($term);
- $station = $_REQUEST['station'];
- $more_param = common::getInNotInSqlForSearch(utils::implode(';',$station));
- $sql = "select email from employee where contact_id in ($more_param) and email ilike '" . common::check_input($term) . "%' limit 20";
- $rs = common::excuteListSql($sql);
- foreach($rs as $key => $val){
- if(!empty($val['email'])){
- $retData[] = array("value" =>$val['email'] ,"label"=>$val['email']);
- }
- }
- common::echo_json_encode(200,$retData);
- exit();
- }
- /**
- * 下拉可供选择的ports
- */
- if ($operate == "ports") {
-
- $mode = $_POST['mode'];
- $term = $_POST['term'];
- $term = trim($term);
- if ($mode == 'sea'){
- $sql = "select DISTINCT uncode from public.ports
- where coalesce(uncode,'')<> '' and uncode ilike '" . common::check_input($term) . "%'";
- } else {
- $sql = "select DISTINCT coalesce(airport.country_abb,'')||airport.airport_code as uncode from sfs.airport
- where coalesce(country_abb,'')<>''
- and coalesce(airport.country_abb,'')||airport.airport_code ilike '" . common::check_input($term) . "%'";
- }
- $sql .= " order by uncode limit 20";
- $rs = common::excuteListSql($sql);
- //前端要加上id 从1开始
- $retData = array();
- foreach($rs as $key => $val){
- if(!empty($val['uncode'])){
- $retData[] = array("value" =>$val['uncode'] ,"label"=>$val['uncode']);
- }
- }
- common::echo_json_encode(200,$retData);
- exit();
-
- }
- /**
- * 下拉可供选择的carrier
- */
- if ($operate == "carrier") {
- $term = $_POST['term'];
- $term = trim($term);
- $sql = "select DISTINCT scac from public.vessel_company
- where coalesce(scac,'')<> '' and scac ilike '" . common::check_input($term) . "%'";
- $sql .= " order by scac limit 20";
- $rs = common::excuteListSql($sql);
- //前端要加上id 从1开始
- $retData = array();
- foreach($rs as $key => $val){
- if(!empty($val['scac'])){
- $retData[] = array("value" =>$val['scac'] ,"label"=>$val['scac']);
- }
- }
- common::echo_json_encode(200,$retData);
- exit();
- }
- }
- /**
- * destination_delivery 配置
- */
- public function destination_delivery_config(){
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- /**
- * 这个是嵌套在destination_delivery的配置查询,
- */
- if ($operate == "search"){
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 100;
- if (empty($cp))
- $cp = 1;
- $rc = $_POST ['rc'];
- if ($rc == - 1) {
- $sql = "select count(*) from public.kln_destination_delivery_config";
- $rc = common::excuteOneSql($sql);
- }
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "select * from public.kln_destination_delivery_config";
- $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
- $rs = common::excuteListSql($sql);
- foreach($rs as $key => $val){
- $rs[$key]["_serial_no"] = common::deCode($val['serial_no'], 'E');
- }
- $arrTmp = array('searchData' => $rs,
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp);
- common::echo_json_encode(200,$arrTmp);
- exit();
- }else{
- $arrTmp = array('searchData' => array());
- common::echo_json_encode(200, $arrTmp);
- exit();
- }
- }
- if ($operate == "add"){
- $serial_no = common::deCode($_GET['a'], 'D');
- $data = array();
- $rule = array();
- if (!empty($serial_no)){
- $sql = "select * from public.kln_destination_delivery_config where serial_no = '$serial_no'";
- $data = common::excuteObjectSql($sql);
- if ($data['recommended_delivery'] == 'delivery_eta_ata') {
- $sql = "select * from public.kln_destination_delivery_rule where recommended_delivery_serial_no = '$serial_no'";
- $rule = common::excuteObjectSql($sql);
- }
- }
- //处理组装返回格式
- //RcommendDeliveryDate
- $RecommendCheckedAirList = array();
- $RecommendCheckedSeaList = array();
- $RecommendCheckedList = array();
- foreach($rule as $item){
- if ($item['mode_type'] == 'sea'){
- $RecommendCheckedSeaList[] = array("Priority"=>$item['priority'],"RuleType"=>$item['rule_type'],
- "Port"=>explode(";", $item['ports']),
- "Carrier"=>explode(";", $item['carrier']),
- "FromDate"=>$item['recommended_delivery_from'],
- "ToDate"=>$item['recommended_delivery_to']);
- }
- if ($item['mode_type'] == 'air'){
- $RecommendCheckedAirList[] = array("Priority"=>$item['priority'],"RuleType"=>$item['rule_type'],
- "Port"=>explode(";", $item['ports']),
- "Carrier"=>explode(";", $item['carrier']),
- "FromDate"=>$item['recommended_delivery_from'],
- "ToDate"=>$item['recommended_delivery_to']);
- }
- if (!utils::in_array($item['mode_type'], $RecommendCheckedList)) {
- $RecommendCheckedList[] = $item['mode_type'];
- }
- }
- $returnData = $data;
- if (!empty($data['booking_window'])) {
- $returnData["SetBookingWindow"] = array("windowradio" =>$data['booking_window'],
- "windowBeforeDays"=>$data['booking_window'],
- "windowAfterDays"=>$data['booking_window']);
- } else {
- $returnData["SetBookingWindow"] = array();
- }
- if ($data['recommended_delivery'] == 'Delivery_ETA_ATA') {
- $returnData["RcommendDeliveryDate"] = array("Recommendradio" =>$data['recommended_delivery'],
- "RecommendCheckedList"=>$RecommendCheckedList,
- "RecommendCheckedAirList"=>$RecommendCheckedAirList,
- "RecommendCheckedSeaList"=>$RecommendCheckedSeaList);
- } else {
- $returnData["RcommendDeliveryDate"] = array();
- }
- $returnData["KLNPLCvalue"] = explode(";", $data['kln_pic']);
- global $_COPYRIGHT;
- $data = array('copyright' =>$_COPYRIGHT,
- 'returnData' =>$returnData);
- common::echo_json_encode(200,$data);
- exit();
- }
- if ($operate == "save"){
- $serial_no = common::deCode($_POST['a'], 'D');
- $country = common::check_input($_POST['country']);
- $station = empty($_POST['station']) ? "" :explode(";", $_POST['station']);
- $booking_window = common::check_input($_POST['booking_window']);
- $booking_window_date_start = common::check_input($_POST['booking_window_date_start']);
- $booking_window_date_end = common::check_input($_POST['booking_window_date_end']);
- $recommended_delivery = common::check_input($_POST['recommended_delivery']);
- $kln_pic = empty($_POST['kln_pic']) ? "" :explode(";", $_POST['kln_pic']);
- //rule
- $_mode_type = $_POST['mode_type'];
- $_priority = $_POST['priority'];
- $_rule_type = $_POST['rule_type'];
- $_ports = $_POST['ports'];
- $_carrier = $_POST['carrier'];
- $_recommended_delivery_from = $_POST['recommended_delivery_from'];
- $_recommended_delivery_to = $_POST['recommended_delivery_to'];
- $errmsg = "";
- $sql = "";
- if (!empty($serial_no)){
- $updateSqlSet = " modify_by = '"._getLoginName()."',update_time = now()";
- if (!empty($country)) {
- $updateSqlSet.= ", country = '$country' ";
- }
- if (!empty($station)) {
- $updateSqlSet.= ", station = '$station' ";
- }
- if (!empty($booking_window)) {
- $updateSqlSet.= ", booking_window = '$booking_window' ";
- }
- if (!empty($booking_window_date_start)) {
- $updateSqlSet.= ", booking_window_date_start = '$booking_window_date_start' ";
- }
- if (!empty($booking_window_date_end)) {
- $updateSqlSet.= ", booking_window_date_end = '$booking_window_date_end' ";
- }
- if (!empty($recommended_delivery)) {
- $updateSqlSet.= ", recommended_delivery = '$recommended_delivery' ";
- }
- if (!empty($kln_pic)) {
- $updateSqlSet.= ", kln_pic = '$kln_pic' ";
- }
- //代表update
- $sql .= "update public.kln_destination_delivery_config set ".$updateSqlSet."
- where serial_no = '$serial_no';";
- } else {
- //代表更新
- $serial_no = common::uuid();
- $sql .="INSERT INTO public.kln_destination_delivery_config(
- serial_no, country, station, booking_window, booking_window_date_start,
- booking_window_date_end, recommended_delivery, kln_pic, create_by,
- created_time, modify_by, update_time)
- VALUES ('$serial_no', '$country', '$station', '$booking_window', '$booking_window_date_start',
- '$booking_window_date_end', '$recommended_delivery', '$kln_pic',
- '"._getLoginName()."', now(), '"._getLoginName()."', now());";
- }
- if ($recommended_delivery == "delivery_eta_ata"){
- // 用于统计每种类型是否存在,以及是否满足 rule_type = 'all'
- $typeExists = ['air' => false, 'sea' => false];
- $typeHasAllRule = ['air' => false, 'sea' => false];
- foreach($_mode_type as $key => $v){
- $mode_type = $v;
- $priority = $_priority[$key];
- $rule_type = $_rule_type[$key];
- $ports = empty($_ports[$key]) ? "" :explode(";", $_ports[$key]);
- $carrier = empty($_carrier[$key]) ? "" :explode(";", $_carrier[$key]);
- $recommended_delivery_from = $_recommended_delivery_from[$key];
- $recommended_delivery_to = $_recommended_delivery_to[$key];
- // 只处理 air 和 sea
- if ($mode_type == 'air' || $mode_type == 'sea') {
- $typeExists[$mode_type] = true;
- if ($rule_type == 'all') {
- $typeHasAllRule[$mode_type] = true;
- }
- }
- //先删除,后添加
- $sql .= "delete from public.kln_destination_delivery_rule where recommended_delivery_serial_no = '$serial_no';";
- $sql .= "INSERT INTO public.kln_destination_delivery_rule(
- serial_no, recommended_delivery_serial_no, mode_type, priority,
- rule_type, ports, carrier, recommended_delivery_from, recommended_delivery_to,
- create_by, created_time, modify_by, update_time)
- VALUES ('$serial_no', '$mode_type', '$priority',
- '$rule_type', '$ports', '$carrier', '$recommended_delivery_from', '$recommended_delivery_to',
- '"._getLoginName()."', now(), '"._getLoginName()."', now());";
- }
- // 检查缺失的 rule_type = 'all'
- $missingTypes = [];
- foreach (['air', 'sea'] as $type) {
- if ($typeExists[$type] && !$typeHasAllRule[$type]) {
- $missingTypes[] = $type;
- }
- }
- if (!empty($missingTypes)) {
- $errmsg = "The Default Rule must exist.";
- }
- }
- if (empty($errmsg) && !empty($sql)){
- common::excuteUpdateSql($sql);
- $data = array("msg" =>"success");
- } else {
- $data = array("msg" =>$errmsg);
- }
- common::echo_json_encode(200,$data);
- exit();
- }
- }
- /**
- * booking
- */
- public function destination_delivery(){
- }
- }
- ?>
|