<?php

namespace app\admin\model;

use support\Model;

/**
 * 业务控制器模型
 * Class SystemAdmin
 * @package app\admin\model
 */
class SystemBusiness extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'system_business';

    public $timestamps = false;

    /**
     * Notes:获取业务控制器列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     * User: ZQ
     * Date: 2022/11/17
     */
    public static function businessList(string $keywords, int $page, int $limit)
    {
        $list = static::select('*')
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('business_name', 'like', '%' . $keywords . '%');
            })
            ->orderBy('business_time','DESC')
            ->forPage($page, $limit)
            ->get();
        $count = static::
            when($keywords != '', function ($query) use ($keywords){
                $query->where('business_name', 'like', '%' . $keywords . '%');
            })
            ->count();
        return [$list, $count];
    }

    public static function businessUpdate($business)
    {
        return static::where('uid', '>', 0)->update($business);
    }

}
