<?php
/**
 * 消息相关
 */
defined( 'IN_WEB') or die( 'Include Error!');

class News {

    private $_config = ''; //公共配置文件

    function __construct(){
        if( is_file( PATH_CFG.'config.usernews.php') ){
            $this->_config = include( PATH_CFG.'config.usernews.php' );
        }
    }

    /**
     * 获取玩家消息接口
     * @param $param
     */
    public function getUserNews($param){
        $data = array( 'code' => -1, 'data' => array() );
        $uid = oo::functions()->uint($param['uid']);
        $p = oo::functions()->uint($param['p']);//查询页数
        $newstype = oo::functions()->uint($param['newstype']);//消息类型
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        $data = oo::commonOprModel('usernews')->getUserMsg($uid, $p, $newstype);
        return json_encode($data);
    }

    /**
     * 玩家领奖接口
     * @param $param
     */
    public function userReward($param){
        $data = array( 'code' => -1 );
        $uid = oo::functions()->uint($param['uid']);
        $newsid = oo::functions()->uint($param['newsid']);
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        $data = oo::commonOprModel('usernews')->userReward($uid, $newsid);
        return json_encode($data);
    }

    /**
     * 删除消息
     * @param $param
     */
    public function delNews($param){
        $data = array( 'code' => -1 );
        $uid = oo::functions()->uint($param['uid']);
        $newsid = oo::functions()->uint($param['newsid']);
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        //$data = oo::usernews()->delNews($uid, $newsid);
        $data = oo::commonOprModel('usernews')->delNews($uid, $newsid);
        return json_encode($data);
    }

    /**
     * 已读修改状态
     * @param $param
     */
    public function read($param){
        $data = array( 'code' => -1 );
        $uid = oo::functions()->uint($param['uid']);
        $newsid = oo::functions()->uint($param['newsid']);
        $newsidList = $param['newsidList'];
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        if ($newsidList) {
            $newsIdArr = explode(',', $newsidList);
            $data = oo::commonOprModel('usernews')->readMult($uid, $newsIdArr);
        }else{
            $data = oo::commonOprModel('usernews')->read($uid, $newsid);
        }
        return json_encode($data);
    }

    /**
     * 检查是否有新消息
     * @param $param
     */
    public function checkNew($param){
        $data = array( 'code' => -1 );
        $uid = oo::functions()->uint($param['uid']);
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        $data = oo::commonOprModel("usernews")->checkNew($uid);
        return json_encode($data);
    }

    /**
    *   一键领取,和回赠功能
    */
    public function getNewsReward($param)
    {
        $data = array( 'code' => -1 );
        $uid = oo::functions()->uint($param['uid']);
        $newstype = oo::functions()->uint($param['newstype']);//消息类型
        if( empty($uid) ){ //基本验证
            return json_encode($data);
        }
        $data = oo::commonOprModel("usernews")->getNewsReward($uid, $newstype);
        return json_encode($data);
    }

}