SmsLog.php 3.9 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:系统-短信 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\System
 * @package   App\Models\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年1月26日17:53:22
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\System;

use App\Models\BaseModel;
use App\Models\Traits\MorphMapTrait;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Class SmsLog
 *
 * @category  App\Models\System
 * @package   App\Models\System
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年1月26日17:53:22
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class SmsLog extends BaseModel
{
    use MorphMapTrait;

    // 指定数据库表
    const TABLE = 'system_sms_logs';

    protected $table = self::TABLE ;

    const REGISTER_SMS          = 1;// 注册短信
    const LOGIN_SMS             = 2;// 登录短信
    const RETRIEVE_PASSWORD_SMS  = 3;// 找回密码短信
    const RESET_PASSWORD_SMS     = 4;// 重置密码短信
    const UPDATE_LOCK_PASSWORD_SMS = 5;// 修改智能门锁密码
    const AUTHORIZATION_BIND    = 6;// 授权绑定
    const WARNING_USER    = 'warning_user';// 火警短信

    const TYPE_OPTIONS = [
        self::REGISTER_SMS          => '注册短信',
        self::LOGIN_SMS             => '登录短信',
        self::RETRIEVE_PASSWORD_SMS => '找回密码短信',
        self::RESET_PASSWORD_SMS        => '重置密码短信',
        self::UPDATE_LOCK_PASSWORD_SMS  => '修改智能门锁密码',
        self::AUTHORIZATION_BIND        => '授权绑定',
        self::WARNING_USER              => '火警短信',
    ];

    const INTERVALS  = 60 ;// 短信发送间隔时间
    const INVALID_TIME = 60 * 10 ;// 短信失效时间

    const SENDING       = 1;
    const SEND_SUCCESS  = 2;
    const SEND_FAIL     = 3;
    const SEND_UNKNOWN  = 4;
    const STATUS_OPTIONS = [
        self::SENDING       => '发送中',
        self::SEND_SUCCESS  => '发送成功',
        self::SEND_FAIL     => '发送失败',
        self::SEND_UNKNOWN  => '未知',
    ];

    /**
     * 可以批量赋值的属性
     *
     * @var array
     */
    protected $fillable = [
        'loggable_id', 'loggable_type', 'mobile','sent_at','sent_body','received_body','received_at',
        'noticed_body','noticed_at','out_id','type','status','result'
    ];

    /**
     * 多态关联
     *
     * @return MorphTo
     */
    public function loggable(): MorphTo
    {
        return $this->morphTo()->withTrashed();
    }

    public function getSentBodyAttribute($value)
    {
        return json_decode($value, true) ?: null;
    }

    public function setSentBodyAttribute($value)
    {
        $this->attributes['sent_body'] = my_json_encode($value);
    }

    public function getReceivedBodyAttribute($value)
    {
        return json_decode($value, true) ?: null;
    }

    public function setReceivedBodyAttribute($value)
    {
        $this->attributes['received_body'] = my_json_encode($value);
    }

    public function getNoticedBodyAttribute($value)
    {
        return json_decode($value, true) ?: null;
    }

    public function setNoticedBodyAttribute($value)
    {
        $this->attributes['noticed_body'] = my_json_encode($value);
    }

//    public function getResultAttribute($value)
//    {
//        return json_decode($value, true) ?: null;
//    }
//
//    public function setResultAttribute($value)
//    {
//        $this->attributes['result'] = my_json_encode($value);
//    }
}