<?php

namespace app\admin\model;

use support\Db;
use support\Model;

/**
 * 医疗产品
 * Class Users
 * @package app\admin\model
 */
class Appointment extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'medical_care_appointment';

    public $timestamps = false;

    /**
     * Notes:获取产品列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: QJF
     * Date: 2022/9/23
     */
    public static function geMentList(int $page, int $limit,$keywords)
    {
        $list = static::select('*')
            ->with(['Category','Shop'])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('appointment_name', 'like', '%' . $keywords . '%');
            })
            ->where('appointment_del',0)
            ->orderBy('appointment_create_time','DESC')
            ->forPage($page, $limit)
            ->get();

        $count = static::when($keywords != '', function ($query) use ($keywords){
            $query->where('appointment_name', 'like', '%' . $keywords . '%');
        }) ->where('appointment_del',0)->count();
        return [$list, $count];
    }

    public function getAppointmentCreateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }
    public function Category(){
        return $this->belongsTo(Category::class,'appointment_category_id','category_id');
    }
    //关联店铺
    public function Shop(){
        return $this->belongsTo(MerchantShop::class,'appointment_shop_id','shop_id');
    }
}