<?php


class OCategory{
    public static function add(){
        if(!isset($_POST['name']) || !isset($_POST['cost_discount']) || !isset($_POST['user_discount'])){
            Session::Set('error','信息填写不完整！');
            redirect(WEB_ROOT."/manage/category.php");
        }
        $insert['name'] = $_POST['name'];
        $insert['cost_discount'] = $_POST['cost_discount'];
        $insert['user_discount'] = $_POST['user_discount'];
        (isset($_POST['zone'])) ? $insert['zone'] = $_POST['zone'] : $insert['zone'] = "一般";
        (isset($_POST['remark'])) ? $insert['remark'] = $_POST['remark'] : $insert['remark'] = "";
        (isset($_POST['sort_order']) && $_POST['sort_order']!="") ? $insert['sort_order'] = $_POST['sort_order'] : $insert['sort_order'] = 0;

        $tb = new Table('category',$insert);
        $re = $tb->Insert(array_keys($insert));
        if($re==false){
            Session::Set('error','操作失败，请检查添加的数据！');
            redirect(WEB_ROOT."/manage/category.php");
        }else{
            Session::Set('success','类别添加成功！');
            redirect(WEB_ROOT."/manage/category.php");
        }
    }
    public static function modi(){
        if(empty($_POST['id']) || empty($_POST['name']) || empty($_POST['cost_discount']) || empty($_POST['user_discount'])){
            Session::Set('error','信息填写不完整！');
            redirect(WEB_ROOT."/manage/category.php");
        }
        $id = $_POST['id'];
        $update['name'] = $_POST['name'];
        $update['cost_discount'] = $_POST['cost_discount'];
        $update['user_discount'] = $_POST['user_discount'];
        (isset($_POST['zone'])) ? $update['zone'] = $_POST['zone'] : $insert['zone'] = "一般";
        (isset($_POST['remark'])) ? $update['remark'] = $_POST['remark'] : $update['remark'] = "";
        (isset($_POST['sort_order']) && $_POST['sort_order']!="") ? $update['sort_order'] = $_POST['sort_order'] : $update['sort_order'] = 0;

        $re = Table::UpdateCache('category', $id, $update);
        if($re==false){
            Session::Set('error','操作失败，请检查填写的数据！');
            redirect(WEB_ROOT."/manage/category.php");
        }else{
            Session::Set('success','类别编辑成功！');
            redirect(WEB_ROOT."/manage/category.php");
        }
    }
}



?>
