// +---------------------------------------------------------------------- namespace Admin\Model; use Think\Model; /** * 分类模型 */ class SpendCountModel extends Model{ /** * 构造函数 * @param string $name 模型名称 * @param string $tablePrefix 表前缀 * @param mixed $connection 数据库连接信息 */ public function __construct($name = '', $tablePrefix = '', $connection = '') { /* 设置默认的表前缀 */ $this->tablePrefix ='tab_'; /* 执行构造方法 */ parent::__construct($name, $tablePrefix, $connection); } /** * 获取统计 $map,$page,$row */ public function getSpendCountData($map=[],$field='',$group='',$order='',$page = 0,$row = 0) { if ($row == 0) { $data = $this->field($field)->where($map)->group($group)->order($order)->select(); } else { $data = $this->field($field)->where($map)->page($page,$row)->group($group)->order($order)->select(); } return $data; } /** * 获取某个字段的总和 $map,$field */ public function sumSpendCountField($map,$field) { $sum = $this->where($map)->sum($field); return $sum; } }