<?php

namespace loyalsoft;

/**
 * 邮件数据模型
 * @version
 *          1.0.0 Created at 2017-4-27. by --gwang
 * @author gwang (mail@wanggangzero.cn)
 * @copyright ? 2017-4-27, SJZ LoyalSoft Corporation & gwang. All rights reserved.
 */
class Ins_Email extends Object_ext {

    /**
     * 邮件编号
     * @var int
     */
    public $mailId;

    /**
     * 发件人uid
     * @var string
     */
    public $sender_uid;

    /**
     * 发件人昵称
     * @var string
     */
    public $sender_name;

    /**
     * 附件
     * @var string itemId,num;itemId,num;....
     */
    public $appendix;

    /**
     * 邮件类型
     * @var int
     */
    public $type;

    /**
     * 邮件标题
     * @var string
     */
    public $title;

    /**
     * 邮件正文
     * @var string[]
     */
    public $content;

    /**
     * 附加标签
     * @var obj
     */
    public $tag;

    /**
     * 打开/读取邮件 时间戳
     * @var ts
     */
    public $readts = 0;

    /**
     * 领取时间
     * @var ts
     */
    public $drawedts = 0;

    /**
     * 发送时间
     * @var ts
     */
    public $insertts = 0;

    /**
     * 邮件是否已经领取
     * true = 已读
     * @return bool
     */
    public function isDrawed() {
        return $this->drawedts > 0;
    }

    /**
     * 计算邮件的超时时间
     * @return type
     */
    public function ExpireTs() {
        return $this->insertts + EmailProc::MaxMailExpireTs;
    }

    /**
     * 邮件是否存在奖励内容
     * true = 有奖励
     * false =  无
     * @return bool
     */
    public function isExistReward() {
        return strlen($this->appendix) > 0;
    }

    function __construct($tag = null, $type = 1, $title = "", $content = "", $appendix = "", #
            $uid_sender = "系统", $name_sender = "系统") {
        if (1 == func_num_args() && $tag) {                                     # 默认的Object初始化方法
            parent::__construct($tag);
        } else {                                                                # 并非只有一个参数的情况下, tag还是tag
            $this->tag = $tag;
            $this->type = $type;
            $this->title = $title;
            $this->content = $content;
            $this->appendix = $appendix;
            $this->sender_uid = $uid_sender;
            $this->sender_name = $name_sender;
            $this->insertts = now();                                            # 初始化插入/创建时间
        }
    }

}
