BaseModel.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Common\Model;
  3. use Think\Model;
  4. use Common\Common\util\Page;
  5. use Common\Common\util\PageB;
  6. class BaseModel extends Model {
  7. public function __construct($name = '') {
  8. parent::__construct($name);
  9. }
  10. /**
  11. * @param type $where 条件
  12. * @param type $page 分页
  13. * @param type $pageSize 每页几条记录
  14. * @param type $field 查询字段
  15. * @param type $order 排序
  16. * @return type
  17. */
  18. public function x_get_list($where = '', $page, $pageSize = 20, $field = '*', $order='') {
  19. if (!empty($where)) {
  20. $this->where($where);
  21. }
  22. if(empty($order)){
  23. $order['id']='desc';
  24. }
  25. $res = $this->field($field)->page($page)->limit($pageSize)->order($order)->select();
  26. return $res;
  27. }
  28. /**
  29. * @param type $where
  30. * @return type
  31. */
  32. public function x_count($where) {
  33. $res = $this->where($where)->count();
  34. return $res;
  35. }
  36. /**
  37. * @author 545 16.4.14 插入
  38. * @param type $data 要插入的字段
  39. * @return type
  40. */
  41. public function x_set_add($data) {
  42. if ($this->create($data)) {
  43. $res = $this->add(); // 写入数据到数据库
  44. // 如果主键是自动增长型 成功后返回值就是最新插入的值
  45. return $res;
  46. }
  47. }
  48. /**
  49. * @author 545 16.4.14 更新
  50. * @param type $data
  51. * @param type $where
  52. */
  53. public function x_save($data, $where) {
  54. if (!empty($where)) {
  55. $this->where($where);
  56. }
  57. $res = $this->save($data);
  58. return $res;
  59. }
  60. /**
  61. * @param type $where 更新条件
  62. * @param type $field 查询字段
  63. * @return type
  64. */
  65. public function x_get_one($where, $field = '*',$order='') {
  66. $res = $this->where($where)->field($field)->order($order)->find();
  67. return $res;
  68. }
  69. /**
  70. * @param type $where 删除条件
  71. * @return type
  72. */
  73. public function x_del($where) {
  74. $res = $this->where($where)->delete();
  75. return $res;
  76. }
  77. /**
  78. * @author 545 16.4.14 分页
  79. * @param type $count 统计数值
  80. * @param type $pageSize 行数
  81. * @return type
  82. */
  83. public function x_show($count, $pageSize,$params = []) {
  84. $Page = new Page($count, $pageSize,$params);
  85. $pager = $Page->show();
  86. return $pager;
  87. }
  88. /**
  89. * @param type $where 条件
  90. * @param type $sum 求和字段
  91. * @return type
  92. */
  93. public function x_sum($where,$sum) {
  94. $res = $this->where($where)->sum($sum);
  95. return $res;
  96. }
  97. }