<?php

class OFare{
    public static function getExpress($src,$dest){
        $sql = "select * from fare where source='".$src."' and destination like '%".$dest."%'";
        $express = DB::GetQueryResult($sql,false);
        if(count($express)==0){
            $sql = "select * from fare where source='".$src."' and destination like '%%'";
            $express = DB::GetQueryResult($sql,false);
        }
        return $express;
    }
    public static function getName($id){
        $fare = Table::Fetch('fare',$id);
        return $fare['name'];
    }
    public static function add(){
        if(!($_POST['name'] || $_POST['source'] || $_POST['destination'] || $_POST['base'] || $_POST['add'])){
            Session::Set('error','信息填写不完整！');
            redirect(WEB_ROOT."/manage/fare.php");
        }
        $tb = new Table('fare',$_POST);
        $re = $tb->Insert(array_keys($_POST));
        if($re==false){
            Session::Set('error','操作失败，请检查添加的数据！');
            redirect(WEB_ROOT."/manage/fare.php");
        }else{
            Session::Set('success','运费添加成功！');
            redirect(WEB_ROOT."/manage/fare.php");
        }
    }
    public static function modi(){
        if(!($_POST['id']||$_POST['name'] || $_POST['source'] || $_POST['destination'] || $_POST['base'] || $_POST['add'])){
            Session::Set('error','信息填写不完整！');
            redirect(WEB_ROOT."/manage/fare.php");
        }
        $re = Table::UpdateCache('fare', $_POST['id'], $_POST);
        if($re==false){
            Session::Set('error','操作失败，请检查填写的数据！');
            redirect(WEB_ROOT."/manage/fare.php");
        }else{
            Session::Set('success','运费编辑成功！');
            redirect(WEB_ROOT."/manage/fare.php");
        }
    }

}
?>
