<?php
namespace app\api\controller\user;

use app\models\user\UserNotice;
use app\Request;
use crmeb\services\UtilService;

/**
 *
 * 消息协议 参看文档 docs/messages.md
 *
 * Class UserNoticeController
 * @package app\api\controller\user
 */
class UserNoticeController {

    // 获取用户所有消息(分页)
    public function messages(Request $request) {
        [$page, $limit] = UtilService::getMore([
            ['page', 1],
            ['limit', 20]
        ], $request, true);

        $uid = $request->uid();
        return app('json')->successful(UserNotice::getNoticeList($uid, intval($page), intval($limit)));
    }

    // 标记已读
    public function read(Request $request) {
        list($ids, $read) = UtilService::postMore([
            ['ids', []],
            ['read', 1]
        ], $request, true);

        if (count($ids) <= 0) {
            return app('json')->fail('未选择');
        }
        if ($read == 0 ) {
            return app('json')->fail('暂不支持');
        }
        $uid = $request->uid();
        UserNotice::seeNotice($uid, $ids);

        return app('json')->successful([]);
    }

    // 删除
    public function del(Request $request) {
        list($ids) = UtilService::postMore([
            ['ids', []]
        ], $request, true);

        $uid =  $request->uid();
        UserNotice::delNotice($uid, $ids);

        return app('json')->successful([]);
    }
}