LeaderShip.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class LeaderShip extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'content' =>input('content','','trim'),
  12. 'enable' =>input('enable',1),
  13. ];
  14. $result = validate('LeaderShip')->check($data,[],'');
  15. if(true !== $result){
  16. HelpHander::error(validate('LeaderShip')->getError());
  17. }
  18. $id = $data['id'];
  19. unset($data['id']);
  20. if($id > 0){
  21. $data['update_time'] = date("Y-m-d H:i:s");
  22. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  23. }else{
  24. $data['create_time'] = date("Y-m-d H:i:s");
  25. $ret = $this->allowField(true)->save($data);
  26. }
  27. if(!$ret){
  28. HelpHander::error('操作失败');
  29. }
  30. return true;
  31. }
  32. public function info($id){
  33. $info = $this->where('id',$id)->find();
  34. if(!$info){
  35. HelpHander::error('数据不存在');
  36. }
  37. return $info->toArray();
  38. }
  39. public function del($id){
  40. $ret = $this->where('id',$id)->update(['del'=>1]);
  41. if(!$ret){
  42. HelpHander::error('删除失败');
  43. }
  44. return true;
  45. }
  46. public function lists($page,$size,$content){
  47. $map[] = ['enable','=',1];
  48. $map[] = ['del','=',0];
  49. if($content){
  50. $map[] = ['content','like','%'.$content.'%'];
  51. }
  52. $lists = $this
  53. ->where($map)
  54. ->page($page,$size)
  55. ->order('id desc')
  56. ->select();
  57. $total = $this->where($map)->count();
  58. $data = [
  59. 'total' => $total,
  60. 'list' => $lists?$lists->toArray():[]
  61. ];
  62. return $data;
  63. }
  64. public function all(){
  65. $lists = $this
  66. ->where(['enable'=>1,'del'=>0])
  67. ->order('id desc')
  68. ->select();
  69. return $lists?$lists->toArray():[];
  70. }
  71. }