<?php

namespace app\admin\model;

use support\Model;

/**
 * 影片类型模型
 * Class Users
 * @package app\admin\model
 */
class LifeCinemaMold 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_mold';

    public $timestamps = false;

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

    /**
     * Notes:获取列表
     * @return array
     * User: ZQ
     * Date: 2022/9/19`
     */
    public static function getMoldAll()
    {
        $list = static::select(['mold_id','mold_name'])
            ->where(['mold_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 moldMation($admin_mold)
    {
        $where = [];
        $where['mold_is_del'] = static::IS_DEL_NO;
        $mation = static::where($where)
            ->when($admin_mold != '', function ($query) use ($admin_mold){
                $query->whereIn('mold_id', $admin_mold);
            })
            ->get('mold_name');
        return $mation;
    }

}
