注册用户名中的分四种,1,个人用户。2,免费中介,3,高级中介,4,待审中介。
个人用户每天可以发布4条信息,免费中介可以每天发布10条信息,高级中介不限,
请问怎么实现?

解决方案 »

  1.   

    系统预设常量
    $max_records = array('a' => 4, 'b' => 10);用户信息:
    $uid #用户标识
    $type #用户类型以使用缓存Memcache为例
    $default_host = '127.0.0.1';
    $default_port = 11211;
    function getCache($host, $port) {
        $cache = new Memcache();
        $cache->connect($host, $port);
        return $cache;
    }
    function canRelease($uid, $type, $cache = NULL) {
        static $max_records = array('a' => 4, 'b' => 10);
        global $default_host, $default_port;
        if(!isset($max_records[$type])) return true;
        $max_record = $max_records[$type];
        $cache or ($cache = getCache($default_host, $default_port));
        $today = date('Ymd');
        $current_record = $cache->get("$uid/releasecount/$today");
        return $current_record < $max_record;
    }
    function incrementCount($uid, $cache = NULL) {
        $today = date('Ymd');
        $now = time();
        $today_last_time = strtotime(date('Ymd'));
        $life_cycle = $today_last_time - $now;
        $cache or ($cache = getCache($default_host, $default_port));
        $original_record = $cache->get("$uid/releasecount/$today");
        return $cache->set("$uid/releasecount/$today", ++ $original_record);
    }在发布信息的时候 
    首先用canRelease检测一下
    发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
      

  2.   


    #mail: [email protected]
    #blog: http://blog.csdn.net/lgg201
    #有不足之处欢迎交流, 谢谢系统预设常量
    $max_records = array('a' => 4, 'b' => 10);用户信息:
    $uid #用户标识
    $type #用户类型以使用缓存Memcache为例
    $default_host = '127.0.0.1';
    $default_port = 11211;
    function getCache($host, $port) {
        $cache = new Memcache();
        $cache->connect($host, $port);
        return $cache;
    }
    function canRelease($uid, $type, $cache = NULL) {
        static $max_records = array('a' => 4, 'b' => 10);
        global $default_host, $default_port;
        if(!isset($max_records[$type])) return true;
        $max_record = $max_records[$type];
        $cache or ($cache = getCache($default_host, $default_port));
        $today = date('Ymd');
        $current_record = $cache->get("$uid/releasecount/$today");
        return $current_record < $max_record;
    }
    function incrementCount($uid, $cache = NULL) {
        $today = date('Ymd');
        $now = time();
        $today_last_time = strtotime(date('Ymd'));
        $life_cycle = $today_last_time - $now;
        $cache or ($cache = getCache($default_host, $default_port));
        $original_record = $cache->get("$uid/releasecount/$today");
        return $cache->set("$uid/releasecount/$today", ++ $original_record);
    }在发布信息的时候 
    首先用canRelease检测一下
    发布完信息之后, 调用incrementCount增加一下计数Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
      

  3.   


    #mail: [email protected]
    #blog: http://blog.csdn.net/lgg201
    #有不足之处欢迎交流, 谢谢
    #不好意思, 上面的少了设置值的失效时间#系统预设常量
    $max_records = array('a' => 4, 'b' => 10);#用户信息:
    $uid #用户标识
    $type #用户类型#以使用缓存Memcache为例
    $default_host = '127.0.0.1';
    $default_port = 11211;
    function getCache($host, $port) {
        $cache = new Memcache();
        $cache->connect($host, $port);
        return $cache;
    }
    function canRelease($uid, $type, $cache = NULL) {
        static $max_records = array('a' => 4, 'b' => 10);
        global $default_host, $default_port;
        if(!isset($max_records[$type])) return true;
        $max_record = $max_records[$type];
        $cache or ($cache = getCache($default_host, $default_port));
        $today = date('Ymd');
        $current_record = $cache->get("$uid/releasecount/$today");
        return $current_record < $max_record;
    }
    function incrementCount($uid, $cache = NULL) {
        $today = date('Ymd');
        $now = time();
        $today_last_time = strtotime(date('Ymd'));
        $life_cycle = $today_last_time - $now;
        $cache or ($cache = getCache($default_host, $default_port));
        $original_record = $cache->get("$uid/releasecount/$today");
        #下面增加life_cycle是为了到第二天时候把数据给清理了, 这个时间可以根据需求设长点, 因为第二天key不一样了, 不会影响正确性
        return $cache->set("$uid/releasecount/$today", ++ $original_record, NULL, $life_cycle);
    }#在发布信息的时候 
    #首先用canRelease检测一下
    #发布完信息之后, 调用incrementCount增加一下计数#Memcache的increment接口是否支持没有值的时候自动设置不记得了, 如果支持, 可以把设置值换成该接口.
      

  4.   

    各位能给个简单的方法吗?比如根据用户ID统计用户一天的发帖量  如果达到一定数量 就提示一下 
    比如 
    select count(*) as title from table 
    where addtime = 当天的时间 and uid=当前登录用户id
    根据统计出来的title的来计算