2019-09-06 23:53:10 +08:00

121 lines
3.4 KiB
PHP
Executable File

<?php
namespace wstmart\common\model;
use think\Db;
/**
* ============================================================================
* 验证处理类
*/
class Table extends Base{
protected $table = '';
public function __construct(){
parent::__construct();
}
public function setTable($tableName){
$this->table = Db::name($tableName);
}
/**
* 获取单条信息
* @param [type] $where [description]
* @param string $field [description]
* @return [type] [description]
*/
public function getInfo($where,$field='*'){
return $this->table->where($where)->field($field)->find();
}
/**
* 获取单条信息
* @param [type] $where [description]
* @param string $field [description]
* @return [type] [description]
*/
public function getField($where,$field='id'){
return $this->table->where($where)->value($field);
}
/**
* 插入单条信息
* @param string $data [description]
* @return [type] [description]
*/
public function insertInfo($data){
return $this->table->insert($data);
}
/**
* 加数
* @param string $data [description]
* @return [type] [description]
*/
public function incNum($where,$field,$num){
return $this->table->where($where)->setInc($field,$num);
}
/**
* 减数
* @param string $data [description]
* @return [type] [description]
*/
public function decNum($where,$field,$num){
return $this->table->where($where)->setDec($field,$num);
}
/**
* 更新单条信息
* @param [type] $where [description]
* @param string $data [description]
* @return [type] [description]
*/
public function updateInfo($where,$data){
return $this->table->where($where)->update($data);
}
/**
* 获取多条信息分页
* @param [type] $where [description]
* @param string $field [description]
* @return [type] [description]
*/
public function getSelect($where,$field='id',$order=''){
return $this->table->where($where)->field($field)->order($order)->paginate(input('pageSize/d',10))->toArray();
}
/**
* 获取多条信息不分页
* @param [type] $where [description]
* @param string $field [description]
* @return [type] [description]
*/
public function getList($where,$field='id',$order=''){
return $this->table->where($where)->field($field)->order($order)->select();
}
/**
* 获取合计值
* @param [type] $where [description]
* @param [type] $field [description]
* @return [type] [description]
*/
public function getSum($where,$field){
return $this->table->where($where)->sum($field);
}
/**
* 获取最大值
* @param [type] $where [description]
* @param [type] $field [description]
* @return [type] [description]
*/
public function getMax($where,$field){
return $this->table->where($where)->max($field);
}
/**
* 获取符合条件数量
* @param [type] $where [description]
* @return [type] [description]
*/
public function getCount($where){
return $this->table->where($where)->count();
}
/**
* 获取某一字段列表
* @param [type] $where [description]
* @param [type] $field [description]
* @return [type] [description]
*/
public function getColumn($where,$field){
return $this->table->where($where)->column($field);
}
}