<?php

namespace app\admin\model;

use support\Db;
use support\Model;

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

    public $timestamps = false;

    /**
     * Notes:获取智能产品列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: ZQ
     * Date: 2022/9/13
     */
    public static function getProductList(int $page, int $limit, string $keywords)
    {
        $list = static::select(['intelligence_products.*','intelligence_category.category_name'])
            ->where(['product_del'=>0])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('product_name', 'like', '%' . $keywords . '%');
            })
            ->leftJoin('intelligence_category', 'category_id', '=', 'intelligence_products.product_category_id')
            ->orderBy('product_create_time','DESC')
            ->forPage($page, $limit)
            ->get();
        $count = static::where(['product_del'=>0])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('product_name',  'like', '%' . $keywords . '%');
            })
            ->count();
        return [$list, $count];
    }

    /**
     * Notes:获取角色列表
     * @return array
     * User: ZQ
     * Date: 2022/9/19`
     */
    public static function getRoleAll()
    {
        $list = static::select(['role_id','role_name'])
            ->where(['role_status'=>1])
            ->orderBy('role_create_time','DESC')
            ->get();
        return $list;
    }

}
