<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id ac_index.php 1 2008-08-15  08:46 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

$pcd = isset($pcd) ? (preg_match("/^[0-9]{2}$/",$pcd) ? $pcd : '') : '';
$where .= " a.available=1 AND b.status=1 ".($pcd ? " AND b.classcode like '{$pcd}__' " : '');

$result = $db->get_one("SELECT COUNT(*) as total FROM {$dbpre}carddiscounts a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid) WHERE $where");
$total = $result['total'];

if($total > 0) {
    $offset = 20;
    $limit = get_limit($page, $offset);
    $query = $db->query("SELECT a.shopid,a.cardsort,a.discount,a.largess,a.exception,b.classcode,b.areacode,b.shopname,b.subname FROM {$dbpre}carddiscounts a LEFT JOIN {$dbpre}shops b ON(a.shopid=b.sid) WHERE $where ORDER BY b.reviews DESC LIMIT $limit");
    while($shop = $db->fetch_array($query)) {
        $shop['shopname'] .= $shop['subname'] ? "({$shop['subname']})" : '';
        $shop['membercard'] = $_membercard['enable'] && $shop['membercard_available'];
        if($shop['cardsort'] == 'both') {
            $shop['membercard_msg'] = $shop['discount'].'折, '.$shop['largess'];
        } elseif($shop['cardsort'] == 'discount') {
            $shop['membercard_msg'] = $shop['discount'].'折';
        } else {
            $shop['membercard_msg'] = $shop['largess'];
        }
        $shops[] = $shop;
    }
    $multipage = multi($total, $offset, $page, 'index.php?ac=index&pcd='.$pcd);
}

$tpl_name = 'card_index';
$subtitle = $MOD['name'].' - 最优惠的消费折扣卡';
require_once MUDDER_ROOT.'header.php';
require_once template($tpl_name);
footer();
?>