<?php

namespace app\admin\model;

use support\Db;
use support\Model;

/**
 * 商品模型
 * Class Users
 * @package app\admin\model
 */
class LifeCinema extends Model
{
    const ROLE_STATUS = 1;

    const IS_DEL_YES = 1;
    const IS_DEL_NO  = 0;
    const GOODS_IS_SHOW = [
        self::IS_DEL_YES => '已删除',
        self::IS_DEL_NO  => '未删除'
    ];
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'life_cinema';

    public $timestamps = false;

    /**
     * Notes:获取影片列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: ZQ
     * Date: 2022/9/13
     */
    public static function getCinemaList(int $page, int $limit, string $keywords)
    {
        $list = static::select('*')
            ->where(['cinema_is_del'=>static::IS_DEL_NO])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('cinema_name', 'like', '%' . $keywords . '%');
            })
            ->orderBy('cinema_create_time','DESC')
            ->forPage($page, $limit)
            ->get();
        $count = static::where(['cinema_is_del'=>static::IS_DEL_NO])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('cinema_name', 'like', '%' . $keywords . '%');
            })
            ->count();
        return [$list, $count];
    }

    /**
     * Notes:获取商品列表
     * @return array
     * User: ZQ
     * Date: 2022/9/19`
     */
    public static function getCinemaAll()
    {
        $list = static::select(['cinema_id','cinema_name'])
            ->where(['cinema_is_del'=>static::IS_DEL_NO])
            ->orderBy('goods_create_time','DESC')
            ->get();
        return $list;
    }

    /**
     * Notes:获取商品名称
     * @param string $account
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     * User: ZQ
     * Date: 2022/9/19
     */
    public static function cinemaMation($admin_cinema)
    {
        $where = [];
        $where['cinema_is_del'] = static::IS_DEL_NO;
        $mation = static::where($where)
            ->when($admin_cinema != '', function ($query) use ($admin_cinema){
                $query->whereIn('cinema_id', $admin_cinema);
            })
            ->get('cinema_name');
        return $mation;
    }

}
