<?php
declare (strict_types = 1);

namespace app\admin\model\v1;

use app\common\model\LeaveMessageBaseModel;

/**
 * 留言记录（联系我们）模型
 * @mixin \think\Model
 */
class LeaveMessageModel extends LeaveMessageBaseModel
{
    // 根据语言查询
    public function scopeLanguage($query, $value)
    {
        $query->where('language_id', '=', $value);
    }

    // 按添加时间搜索
    public function searchCreatedAtAttr($query, $value, $data)
    {
        if (is_null($value)) return;
        if (is_array($value)) {
            if (count($value) > 1) {
                if ($value[0] == $value[1]) {
                    $value[1] = date("Y-m-d 23:59:59", strtotime($value[1]));
                }
                $query->whereBetweenTime('created_at', $value[0], $value[1]);
            } else {
                $query->whereTime('created_at', '>=', $value[0]);
            }
        }
    }
}
