<?php

/** ==============================================================

 * 用户关注论坛版块功能.

 * @param: uid 用户id 

 * @param: fid 版块id 不区分父级版块子版块

 * @param：focus 0=取消关注 1=关注(参数类型 必须是int)

 * Author: Allen zhang

 * modify: zlc

 * Date: 2015-07-28

 */



//未登录跳到登录页面

if(!$_G['uid']){



        odz_error('token_expire', -1000);     

}



$focus = isset($_GET['focus'])?$_GET['focus']:null;

$fid   = isset($_GET['fid'])?$_GET['fid']:null;



if( $focus === null || $fid === null ){

        //参数传递错误提示

        odz_error('parameters_error', -112);

}



//查询关注记录

$f      = DB::fetch_all('SELECT * FROM '.DB::table('mocuz_member_focus')."  WHERE fid = {$fid} AND uid = {$_G['uid']}");



//取消关注



if($focus == 0){

        //无关注数据

        if(empty($f)){



           odz_error('focus_no', -1001);         

        }



        $res    = DB::query('DELETE FROM '.DB::table('mocuz_member_focus')." WHERE fid = {$fid} AND uid = {$_G['uid']}");

        $res ? odz_success('focus_cancel'): odz_error('focus_failed', -1003); 

}



//关注

if($focus == 1){

        //已经关注

        if(!empty($f)){

                odz_error('focus_already', -1002) ;        

        }



        $res    = DB::query('INSERT INTO '.DB::table('mocuz_member_focus')." SET fid = {$fid} , uid = {$_G['uid']}");

        $res ? odz_success('focus_add'): odz_error('focus_failed', -1003);

}







?>



