<?php
namespace app\admin\model;

use think\Model;

/**
 * 智能问答模型
 */
class Robot extends Model
{


    /**
     * select数据筛选
     *
     * @access public
     * @param mixed $field 字段
     * @param mixed $join 关联
     * @param mixed $where 条件
     * @param mixed $offset 分页开始
     * @param mixed $limit 分页大小
     * @param mixed $order 排序
     * @return array 返回类型
     */
    public function selectJoin($field, $join, $where=[], $offset='', $limit='', $order=['robot_updateTime'=>'desc'])
    {
        $result = $this->field($field);
        if (empty($join) === false) {
            $result = $result->alias('a');
            foreach ($join as $k => $v) {
                $result = $result->join($k, $v,'left');
            }
        }

        if (empty($where) === false) {
            $result = $result->where($where);
        }

        if (empty($offset) === false && empty($limit) === false) {
            $result = $result->limit($offset, $limit);
        }

        if (empty($order) === false) {
            foreach ($order as $k => $v) {
                $result = $result->order($k, $v);
            }
        }

        $result = $result->select();
        return $result;

    }//end selectJoin()


    /**
     * select数据筛选
     *
     * @access public
     * @param mixed $where 条件
     * @return array 返回类型
     */
    public function count($where=[])
    {
        $result = $this;
        if (empty($where) === false) {
            $result = $result->where($where)->count();
        }else{
            $result = $result->where($where)->count();
        }
        return $result;

    }//end count()


}
