public function index()
 {
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         //分页
         $page = intval($_REQUEST['p']);
         if ($page == 0) {
             $page = 1;
         }
         $limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
         $condition = " brand_promote = 1 and (end_time = 0 or end_time > " . get_gmtime() . ") ";
         $brand_list = $GLOBALS['db']->getAll("select * from " . DB_PREFIX . "brand where " . $condition . " order by time_status asc,sort desc limit " . $limit);
         $brand_total = $GLOBALS['db']->getOne("select count(*) from " . DB_PREFIX . "brand where " . $condition);
         foreach ($brand_list as $k => $v) {
             $brand_list[$k]['url'] = url("shop", "discount#index", array("id" => $v['id']));
             $brand_list[$k]['time_status'] = syn_brand_status($v['id']);
         }
         $page = new Page($brand_total, app_conf("DEAL_PAGE_SIZE"));
         //初始化分页对象
         $p = $page->show();
         $GLOBALS['tmpl']->assign('pages', $p);
         //开始输出当前的site_nav
         $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => APP_ROOT . "/");
         $site_nav[] = array('name' => $GLOBALS['lang']['BRAND_DISCOUNT'], 'url' => url("shop", "discount#index"));
         $GLOBALS['tmpl']->assign("site_nav", $site_nav);
         //输出当前的site_nav
         $GLOBALS['tmpl']->assign("brand_list", $brand_list);
         $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['BRAND_DISCOUNT']);
         $GLOBALS['tmpl']->assign("page_keyword", $GLOBALS['lang']['BRAND_DISCOUNT']);
         $GLOBALS['tmpl']->assign("page_description", $GLOBALS['lang']['BRAND_DISCOUNT']);
         //输出右侧的推荐
         $condition_rec = "buy_type <> 1 and is_effect =1 and is_delete = 0 and is_shop =1 and brand_promote = 1 and (begin_time = 0 or begin_time <= " . get_gmtime() . ") and (end_time = 0 or end_time > " . get_gmtime() . ") ";
         $rec_list = get_goods_list(intval(app_conf("REC_CATE_GOODS_LIMIT")), 0, $condition_rec);
         $GLOBALS['tmpl']->assign("rec_list", $rec_list['list']);
         $GLOBALS['tmpl']->display("discount_index.html", $cache_id);
     } else {
         $GLOBALS['tmpl']->caching = true;
         $cache_id = md5(MODULE_NAME . "show" . trim($_REQUEST['id']) . $GLOBALS['deal_city']['id']);
         if (!$GLOBALS['tmpl']->is_cached('brand_info.html', $cache_id)) {
             $condition = " brand_promote = 1 and (end_time = 0 or end_time > " . get_gmtime() . ") ";
             $brand_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "brand where id = " . $id . " and " . $condition);
             if ($brand_info) {
                 //开始输出当前的site_nav
                 $site_nav[] = array('name' => $GLOBALS['lang']['HOME_PAGE'], 'url' => APP_ROOT . "/");
                 $site_nav[] = array('name' => $GLOBALS['lang']['BRAND_DISCOUNT'], 'url' => url("shop", "discount#index"));
                 $site_nav[] = array('name' => $brand_info['name'], 'url' => url("shop", "discount#index", array("id" => $brand_info['id'])));
                 $GLOBALS['tmpl']->assign("site_nav", $site_nav);
                 //输出当前的site_nav
                 $GLOBALS['tmpl']->assign("page_title", $brand_info['name']);
                 $GLOBALS['tmpl']->assign("page_keyword", $brand_info['name']);
                 $GLOBALS['tmpl']->assign("page_description", $brand_info['name']);
             } else {
                 app_redirect(APP_ROOT . "/");
             }
         }
         $GLOBALS['tmpl']->display("brand_info.html", $cache_id);
     }
 }
 public function update()
 {
     B('FilterString');
     $data = M(MODULE_NAME)->create();
     $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name");
     //开始验证有效性
     $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
     if (!check_empty($data['name'])) {
         $this->error(L("BRAND_NAME_EMPTY_TIP"));
     }
     $data['begin_time'] = trim($data['begin_time']) == '' ? 0 : to_timespan($data['begin_time']);
     $data['end_time'] = trim($data['end_time']) == '' ? 0 : to_timespan($data['end_time']);
     // 更新数据
     $list = M(MODULE_NAME)->save($data);
     if (false !== $list) {
         //同步更新所有的产品
         M("Deal")->where("brand_id=" . $data['id'] . " and brand_promote = 1")->setField("begin_time", $data['begin_time']);
         M("Deal")->where("brand_id=" . $data['id'] . " and brand_promote = 1")->setField("end_time", $data['end_time']);
         //成功提示
         syn_brand_status($data['id']);
         clear_auto_cache("static_goods_info");
         save_log($log_info . L("UPDATE_SUCCESS"), 1);
         $this->success(L("UPDATE_SUCCESS"));
     } else {
         //错误提示
         save_log($log_info . L("UPDATE_FAILED"), 0);
         $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
     }
 }
function get_brand_time_status($status, $brand_id)
{
    $status = syn_brand_status($brand_id);
    return l("BRAND_TIME_STATUS_" . $status);
}