Notice.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. class Notice extends Model{
  5. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  6. protected $createTime = 'create_time'; // 创建时间
  7. protected $updateTime = 'update_time'; // 每次更新时间
  8. public function initialize(){
  9. parent::initialize();
  10. }
  11. /**
  12. * 获取数据信息
  13. * @param int $page 页码
  14. * @param array $where 查询条件
  15. */
  16. public function getInfo($page = 0, $where = array()){
  17. return $this->db()
  18. ->where($where)
  19. ->page($page, config('paginate.list_rows'))
  20. ->select();
  21. }
  22. /**
  23. * 获取分页信息
  24. * @param array $where 查询条件
  25. */
  26. public function getPage($where = array()){
  27. $total = $this->db()->count();
  28. $paginate = $this->db()->where($where)->paginate(config('paginate.list_rows'), $total);
  29. return $paginate->render();
  30. }
  31. /**
  32. * 根据id找到对象
  33. * @param int $id
  34. */
  35. public function getNoticeById($id){
  36. return $this->db()->where(['id'=>$id])->find();
  37. }
  38. /**
  39. * 添加和更新的方法
  40. */
  41. public function addAndSave(){
  42. $data = request()->post();
  43. return $this->allowField(true)->isUpdate(isset($data['id']) && $data['id']?true:false)->save($data);
  44. }
  45. }