123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Common\Model;
- use Think\Model;
- use Common\Common\util\Page;
- use Common\Common\util\PageB;
- class BaseModel extends Model {
- public function __construct($name = '') {
- parent::__construct($name);
- }
- /**
- * @param type $where 条件
- * @param type $page 分页
- * @param type $pageSize 每页几条记录
- * @param type $field 查询字段
- * @param type $order 排序
- * @return type
- */
- public function x_get_list($where = '', $page, $pageSize = 20, $field = '*', $order='') {
- if (!empty($where)) {
- $this->where($where);
- }
- if(empty($order)){
- $order['id']='desc';
- }
- $res = $this->field($field)->page($page)->limit($pageSize)->order($order)->select();
- return $res;
- }
- /**
- * @param type $where
- * @return type
- */
- public function x_count($where) {
- $res = $this->where($where)->count();
- return $res;
- }
- /**
- * @author 545 16.4.14 插入
- * @param type $data 要插入的字段
- * @return type
- */
- public function x_set_add($data) {
- if ($this->create($data)) {
- $res = $this->add(); // 写入数据到数据库
- // 如果主键是自动增长型 成功后返回值就是最新插入的值
- return $res;
- }
- }
- /**
- * @author 545 16.4.14 更新
- * @param type $data
- * @param type $where
- */
- public function x_save($data, $where) {
- if (!empty($where)) {
- $this->where($where);
- }
- $res = $this->save($data);
- return $res;
- }
- /**
- * @param type $where 更新条件
- * @param type $field 查询字段
- * @return type
- */
- public function x_get_one($where, $field = '*',$order='') {
- $res = $this->where($where)->field($field)->order($order)->find();
- return $res;
- }
- /**
- * @param type $where 删除条件
- * @return type
- */
- public function x_del($where) {
- $res = $this->where($where)->delete();
- return $res;
- }
- /**
- * @author 545 16.4.14 分页
- * @param type $count 统计数值
- * @param type $pageSize 行数
- * @return type
- */
- public function x_show($count, $pageSize,$params = []) {
- $Page = new Page($count, $pageSize,$params);
- $pager = $Page->show();
- return $pager;
- }
- /**
- * @param type $where 条件
- * @param type $sum 求和字段
- * @return type
- */
- public function x_sum($where,$sum) {
- $res = $this->where($where)->sum($sum);
- return $res;
- }
- }
|