| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?php/** * Message.php UTF-8 * 消息类 * * @date    : 2017/11/24 18:20 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\controller\message;use huo\controller\common\Base;use huo\logic\message\MessageLogic;class Message extends Base {    protected $msg_logic;    public function __construct(MessageLogic $msg_logic = null) {        if (null === $msg_logic) {            $this->msg_logic = new MessageLogic();        } else {            $this->msg_logic = $msg_logic;        }    }    /**     * 获取消息数量     *     * @param     $param     * @param int $mem_id     *     * @return int     */    public function getCnt($param, $mem_id = 0) {        if (empty($mem_id)) {            return 0;        }        // TODO: wuyonghong 2018/4/24 添加消息数量函数        return rand(0, 2);    }    /**     * 获取文章列表     *     * @param array  $param     * @param string $page     *     * @param int    $mem_id     *     * @internal param $where     * @return array     */    public function getList($param = [], $page, $mem_id = 0) {        $_map['gameid'] = $this->getVal($param, 'gameid', 0);        $_map['type'] = $this->getVal($param, 'type', 0);        $_map['mem_id'] = $mem_id;        $_data = [            'count' => 0,            'list'  => []        ];        $_cnt = $this->msg_logic->getCnt($_map);        if (empty($_cnt)) {            return $this->huoSuccess(200, '', $_data);        }        $_data['count'] = $_cnt;        $_order = '-create_time';        $_data['list'] = $this->msg_logic->getList($_map, $page, $_order);        return $this->huoSuccess(200, '', $_data);    }    /**     * 获取消息详情     *     * @param int $msg_id     * @param int $mem_id     *     * @return array     */    public function getDetail($msg_id = 0, $mem_id = 0) {        if (empty($msg_id)) {            return $this->huoError(400);        }        $_data = $this->msg_logic->getDetail($msg_id, $mem_id);        if (false === $_data) {            return $this->huoError(1000);        }        if (is_numeric($_data)) {            return $this->huoError($_data);        }        return $this->huoSuccess(200, '', $_data);    }    /**     * 添加消息     *     * @param $_param     * @param $mem_id     *     * @return array     */    public function addMessage($_param, $mem_id) {        $title = $this->getVal($_param, 'title', '');        $content = $this->getVal($_param, 'content', '');        $type = $this->getVal($_param, 'type', 2);        $app_id = $this->getVal($_param, 'app_id', 0);        $_rs = $this->msg_logic->addMessage($mem_id, $title, $content, $type, $app_id);        if ($_rs) {            return $this->huoSuccess(200);        } else {            return $this->huoError(1000);        }    }}
 |