Example #1
0
function userFollowUpdate($user_code, $follow_type, $follow_code, $update_type)
{
    // 生成动态目标表名
    $table = constant('TB_BAS_USER_FOLLOW_' . strtoupper($follow_type));
    // 必须用户编码和对象编码都有效才能执行更新操作
    if ($user_code && $follow_code) {
        // 根据不同的更新类型执行不同的操作
        switch ($update_type) {
            case 'add':
                if (!userFollowQuery($follow_type, 'count', array('user_code' => $user_code, 'follow_code' => $follow_code))) {
                    $data = array('user_code' => $user_code, 'follow_code' => $follow_code, 'follow_time' => date('Y-m-d H:i:s'), 'follow_state' => 1);
                    $flag = insertTable($table, $data);
                } else {
                    $flag = 1;
                }
                break;
            case 'del':
                $condition = array('user_code' => $user_code, 'follow_code' => $follow_code);
                $flag = deleteTable($table, $condition);
                break;
        }
    } else {
        return false;
    }
    return $flag;
    // // 更新完成返回最新的关注/收藏查询数据
    // if($flag){
    //     return userFollowQuery($follow_type , 'count', array('user_code'=>$user_code)) ;
    // }else{
    //     return false ;
    // }
}
Example #2
0
function api_user_follow_query()
{
    $follow_type = func_get_args()[0]['follow_type'];
    // 取参数:查询类型
    $query_type = func_get_args()[0]['query_type'];
    // 取参数:查询方式类型
    $user_code = func_get_args()[0]['user_code'];
    // 取参数:用户编码
    $follow_code = func_get_args()[0]['follow_code'];
    // 取参数:查询对象编码
    $tbBasSurveyInfo = M(TB_BAS_SURVEY_INFO)->getTableName();
    $tbDetSurveyState = M(TB_DET_SURVEY_STATE)->getTableName();
    $tbBasSurveyFollow = M(TB_BAS_USER_FOLLOW_SURVEY)->getTableName();
    switch ($query_type) {
        case 'select':
            $sql = "select " . "    a.survey_code, a.survey_name, a.state_time, a.survey_state, c.state_desc_sketch survey_state_desc, " . "    date(a.start_time) start_date, concat('{$url_action}?code=', a.survey_code) url_action " . "from {$tbBasSurveyInfo} a , {$tbBasSurveyFollow} b , {$tbDetSurveyState} c " . "where a.survey_code = b.follow_code " . "and a.survey_state = c.survey_state_code " . "and a.survey_state >= 3 " . "and b.user_code = {$user_code} " . "order by a.end_time desc";
            $data = M()->query($sql);
            break;
        case 'count':
            $data = userFollowQuery($follow_type, $query_type, array('user_code' => $user_code, 'follow_code' => $follow_code));
            break;
    }
    // 返回数据
    if ($data) {
        return array('data' => $data, 'info' => "success:api_user_follow_query", 'status' => 1, 'type' => 'json');
    } else {
        return array('data' => 0, 'info' => "failed:api_user_follow_query", 'status' => 0);
    }
}