<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/1/001
 * Time: 15:30
 */

namespace backend\models;


class MailApi extends BaseApi
{
    public $apiUrl = 'mail';

    public function getMailList($data = [])
    {
        $result = $this->get($this->apiUrl.'/get-mail-list', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取列表成功');
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }

    public function getMailRecordList($data = [])
    {
        $result = $this->get($this->apiUrl.'/get-mail-record-list', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取列表成功');
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }

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

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

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

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

    public function sendMail($data = [])
    {
        $result = $this->post($this->apiUrl.'/send-mail', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '发送成功');
        } else {
            return $this->returnArray(0, [], '发送失败');
        }
    }

    public function sendMailRecord($data = [])
    {
        $result = $this->post($this->apiUrl.'/send-mail-record', $data);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '发送成功');
        } else {
            return $this->returnArray(0, [], '发送失败');
        }
    }

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

    public function sendMailCode($email)
    {
        $result = $this->post($this->apiUrl.'/send-mail-code', ['email' => $email]);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '发送成功');
        } else {
            return $this->returnArray(0, [], $result['message']);
        }
    }

    /**
     * @param string $email
     * @return array
     */
    public function getMailCode($email)
    {
        $result = $this->get($this->apiUrl . '/get-mail-code', ['email' => $email]);
        if ($result['code'] == 1) {
            return $this->returnArray(1, $result['data'], '获取验证码成功');
        } else {
            return $this->returnArray(0, $result, '获取验证码失败');
        }
    }

}
