<?php

namespace app\admin\model;

use support\Db;
use support\Model;

/**
 * 角色模型
 * Class Users
 * @package app\admin\model
 */
class PackageGoodsCategory extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'package_goods_category';

    public $timestamps = false;

    /**
     * Notes:获取产品分类
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: QJF
     * Date: 2022/9/20
     */
    public static function getPackageGoodsCategoryList(int $page, int $limit, $keywords)
    {
        $list = static::select('*')
            ->where(['category_delete_time'=>0])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('category_name', 'like', '%' . $keywords . '%');
            })
            ->orderBy('category_update_time','DESC')
            ->forPage($page, $limit)
            ->get();

        $count = static::where(['category_delete_time'=>0])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('category_name', 'like', '%' . $keywords . '%');
            })->count();
        return [$list, $count];
    }
    public function getCategoryCreateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }
    public function getCategoryUpdateTimeAttribute($value)
    {
        return date('Y-m-d H:i:s', $value);
    }
}
