<?php
/**
 * Created by PhpStorm.
 * User: chenkuan
 * Date: 2017/11/6
 * Time: 上午10:15
 */

namespace backend\models;


class NoticeApi extends BaseApi
{
    public $apiUrl = 'notice';

    public function getNoticeList($data = [])
    {
        $result = $this->get($this->apiUrl.'/index', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取公告记录成功');
        } else {
            return $this->returnArray(0, [], '获取公告记录失败');
        }
    }

    public function findNotReadCount($member_id = '', $type)
    {
        $result = $this->get($this->apiUrl.'/not-read-count', [
            'member_id' => $member_id,
            'type' => $type,
        ]);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取未读数成功');
        } else {
            return $this->returnArray(0, [], '获取未读数失败');
        }
    }

    public function view($data = [])
    {
        $result = $this->get($this->apiUrl.'/view', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取详情成功');
        } else {
            return $this->returnArray(0, [], '获取详情失败');
        }
    }

    public function getHelpList($member_id = '', $type)
    {
        $result = $this->get($this->apiUrl.'/get-help-list', [
            'member_id' => $member_id,
            'type' => $type,
        ]);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取常见问题成功');
        } else {
            return $this->returnArray(0, [], '获取常见问题失败');
        }
    }
    
    public function saveNotice($data = [])
    {
        $result = $this->post($this->apiUrl.'/create', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '保存成功');
        } else {
            return $this->returnArray(0, [], '保存失败');
        }
    }

    public function updateNotice($data = [])
    {
        $result = $this->post($this->apiUrl.'/update', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '更新成功');
        } else {
            return $this->returnArray(0, [], '更新失败');
        }
    }

    public function deleteNotice($data = [])
    {
        $result = $this->post($this->apiUrl.'/delete', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '删除成功');
        } else {
            return $this->returnArray(0, [], '删除失败');
        }
    }

    public function lastUnreadNotice($data = [])
    {
        $result = $this->get($this->apiUrl.'/last-unread-notice', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取成功');
        } else {
            return $this->returnArray(0, [], '获取失败');
        }
    }
}

