示例#1
0
<?php

if (Tools::P('saveCoupon') == 'add') {
    $coupon = new Coupon();
    $coupon->copyFromPost();
    $coupon->add();
    if (is_array($coupon->_errors) and count($coupon->_errors) > 0) {
        $errors = $coupon->_errors;
    } else {
        $_GET['id'] = $coupon->id;
        UIAdminAlerts::conf('优惠码已添加');
    }
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $obj = new Coupon($id);
}
if (Tools::P('saveCoupon') == 'edit') {
    if (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        $obj->update();
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
        $errors = $obj->_errors;
    } else {
        UIAdminAlerts::conf('优惠码已更新');
    }
}
if (isset($errors)) {
    UIAdminAlerts::MError($errors);
}