项目实战篇-餐馆管理系统—MFC,PHP,MySql:6.订单管理模块

此模块基于一个订单管理员类,该类拥有一下权限:
1、创建订单
2、获取菜单及价格
3、删除订单
4、完成订单

C++ 声明如下

struct FOOD
{
    size_t food_index; // 菜索引
    CString food_name;
    CString image_url;
    CString food_price;
};

struct ORDER
{
    size_t order_index; // 订单索引
    CString food_name;
    CString food_price;
    CString create_user;
    CString create_time;
    CString isOver; // 订单状态,如果为 “0” 代表为未完成,如果为 “1” 代表已经完成
    CString finish_time;
};

class OrderAdmin :
    public Person
{
public:
    OrderAdmin(CString strUser, CString strSession);
    ~OrderAdmin();
    void getFoodsList(size_t nStart, size_t nLength, bool isClear = false);
    CString createOrder(size_t food_index);
    void getOrdersList(size_t nStart, size_t nLength, bool isClear = false);
    std::vector m_foodLists; // 保存菜单列表
    CString delOrder(size_t order_index);
    CString finishOrder(size_t order_index);
    std::vector m_orderLists; // 保存订单列表
private:
    WinHttp::IWinHttpRequestPtr m_ptrHttp; // 网络访问WinHttp智能指针

};

接下来就是数据库订单列表的创建
项目实战篇-餐馆管理系统—MFC,PHP,MySql:6.订单管理模块_第1张图片
PHP 端代码:

创建订单:



require_once("../db_info.php");

//index|name|url|Price

$rightstr = $_SESSION['rightstr'];
$user = $_SESSION['user'];

if( $rightstr == 'administrator' or $rightstr == 'order_admin') {
    $food_index = $_POST['food_index'];
    $isExit_sql = "SELECT * FROM menu WHERE food_index = '$food_index'";
    $query = mysqli_query($con, $isExit_sql);
    $row = mysqli_fetch_array($query);
    $row_nums = mysqli_num_rows($query);
    if ($row_nums != 1) {
        echo 'error:菜不存在!';
        exit;
    }

    $sql = "insert into order_list (food_name, create_user, food_price, create_time) values('".$row['food_name']."','".$user."','".$row['food_price']."', now())";

    $rs = mysqli_query($con,$sql);

    if(!$rs){
        echo 'error:订单添加失败!';
    }else{
        echo 'success:订单添加成功!';
    }

}else{
    echo 'error:您的权限不足!';
    exit();
}





?>

删除订单:



require("../db_info.php");

$rightstr = $_SESSION['rightstr'];


if( $rightstr == 'administrator' or $rightstr == 'order_admin') {

    $index = $_POST['order_index'];


    $sql = "delete from order_list where order_index=$index";

    $rs = mysqli_query($con,$sql);

    if(!$rs){
        echo 'error:订单删除失败!';
    }else{
        echo 'success:订单删除成功!';
    }

}else{
    echo 'error:您的权限不足!';
    exit();
}

?>

完成订单:



require("../db_info.php");

//index|name|url|Price

$rightstr = $_SESSION['rightstr'];


if( $rightstr == 'administrator' or $rightstr == 'order_admin') {

    $index = $_POST['order_index'];

    $sql = "UPDATE order_list SET isOver = 1, finish_time = now() WHERE order_index = $index";
    $rs = mysqli_query($con,$sql);

    if(!$rs){
        echo 'error:完成订单失败!';
    }else{
        echo 'success:完成订单成功!';
    }

}else{
    echo 'error:您的权限不足!';
    exit();
}

?>

查询订单:



require("../db_info.php");

$start = $_GET['start'];
$limit = $_GET['limit'];

$rightstr = $_SESSION['rightstr'];

if( $rightstr == 'administrator' or $rightstr == 'order_admin') {
    if(!is_numeric($start) or !is_numeric($limit)){
        echo 'error :请输入数字!';
        exit();
    }

    $tmp = ($start-1) * $limit;

    $sql = "select * from  order_list limit $tmp, $limit";

    $rs = mysqli_query($con,$sql);

    if(!$rs){
        echo 'error:找不到订单!';
        exit();
    }

    $info = array();

    while($row = mysqli_fetch_assoc($rs)){
        $info[] = $row;
    }


    foreach ($info as $key) {
        echo $key['order_index'].'|'.$key['food_name'].'|'.$key['food_price'].'|'.$key['create_user'].'|'.$key['create_time'].'|'.$key['isOver'].'|'.$key['finish_time']."\n";
    }
} else {
    echo 'error:您的权限不足!';
    exit;
}

?>

订单管理模块窗口布局:

项目实战篇-餐馆管理系统—MFC,PHP,MySql:6.订单管理模块_第2张图片

最后效果:
项目实战篇-餐馆管理系统—MFC,PHP,MySql:6.订单管理模块_第3张图片

你可能感兴趣的:(项目实战篇)