<?php
/**
 * Created by PhpStorm.
 * User: fuju
 * Date: 2018/1/20
 * Time: 17:52
 */

namespace app\model;
use think\Db;

class AAgents extends BaseModel
{

public function saveList(){

}

    //分页列表
    public function getList($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '',$join='', $where = '')
    {
        $data = $this->field($field)
            ->alias('a')
            ->join($join)
            ->where($where)
            ->order($order_)
            ->limit($pageSize)
            ->page($p)
            ->select();
        return $data;
    }

    /**
     *检查重复
     *
     */
    public function repetition($name,$key){
        $r=$this->field($name)
            ->where($name,'=',$key)
            ->select();
        //$this->getLastSql();
        if($r){
            return true;
        }else{
            return false;
        }
    }
    //更新数据
    public function saveStatus($name,$key,$ids){
      $r = $this->save([$name,$key],["id",'in',$ids]);
       return $r;
    }
//删除数据
    public function  delUid($name,$ids){
        $this->where($name,'in',$ids)->delete();
    }
    //通过ids批量添加数据
    public  function addAllAccess($ids,$data){
        $idarr=explode($ids);
        if(is_array($idarr)){
            $arr=array();
            foreach ($idarr as $v){
                $data['uid']=$v;
                 $arr[]=$data;
            }
           $r= $this->saveAll($arr);
          }else{
            $data['uid']=$ids;
           $r= $this->save($data);
        }
        return $r;
    }

    /**
     * 记录总数
     *
     * @param $params
     * @return int|string
     */
    public function getTotal2($params)
    {
        return  $this->alias('a')->where($params)->count();
    }

    /**
     * 操作盘方记录
     *
     * @param int $pageNo
     * @param int $pageSize
     * @param string $order_
     * @param string $field
     * @param string $params
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getRecords($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
    {
        $data = Db::table('g_operating_records')
            ->field($field)
            ->where($params)
            ->limit($pageSize)
            ->order($order_)
            ->page($pageNo)
            ->select();
        return $data;
    }

}