<?php
namespace app\admin\model;

use think\Model;


class Accountsmessage extends Model
{

    /**
     * select数据筛选
     *
     * @access public
     * @param mixed $leftjoin 关联
     * @param mixed $where 条件
     * @param mixed $start 开始时间
     * @param mixed $end 结束时间
     * @param mixed $offset 分页开始
     * @param mixed $limit 分页大小
     * @param mixed $order 排序
     * @return array 返回类型
     */
    public function selectJoin($join,$leftjoin, $where=[],$start,$end, $offset='', $limit='', $order=['a.message_id'=>'desc'])
    {
        $result = $this;
        $result = $result->alias('a');
        $result = $result->field('a.message_id,a.name,a.email,a.content,a.add_time,a.message_status,a.user_id,a.dealWith_time,a.image,a.phone,a.qq,a.wechat,a.if_public,a.reply_content,b.name as type_name,c.user_name');
        if (empty($join) === false) {
            foreach ($join as $k => $v) {
                $result = $result->join($k, $v,'LEFT');
            }
        }

        if (empty($leftjoin) === false) {
            foreach ($leftjoin as $k => $v) {
                $result = $result->join('users c', 'a.user_id = c.id','LEFT');
            }
        }

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

        if (strlen($start) && strlen($end)) {
            $result = $result->whereBetween('add_time', [$start, $end]);
        }

        //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;

    }

}
