<?php
declare (strict_types = 1);

namespace app\model\api;

use library\basic\BaseModel;
use think\Model;

/**
 * @mixin \think\Model
 */
class UserWorkType extends Model
{
    /**
     * 获取列表
     * @param type $post
     * @param type $field
     * @return type
     */
    public function getList($post,$field="*"){
        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
        $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
        $where=[];
        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
            $where[]=["status","=",(int)$post["status"]];
        }
        if(!empty($post["title"])){
            $where[]=["title","like","%{$post["title"]}%"];
        }
        $totalCount = $this->where($where)->count();
        $data=null;
        if($totalCount>0){
            $data = $this
                ->field($field)
                ->where($where)
                ->order("seq", "desc")
                ->page($post["page"], $post["pageSize"])
                ->select();
            if(!empty($data)){
                $data = $data->toArray();
            }
        }
        $data = empty($data)?[]:$data;
        return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
    }
}
