DinnerUser.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class DinnerUser extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->table='dinner_user';
  10. $this->model= new \app\common\model\DinnerUser();
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','id','trim'); //排序列
  20. $sort = input('sord','desc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort;
  22. $title = input('title','','trim');
  23. if($title){
  24. $map[] = ['name','like','%'.$title.'%'];
  25. }
  26. $enable = input('enable','','trim');
  27. if($enable != ''){
  28. $map[] = ['enable','=',$enable];
  29. }
  30. $map[] = ['del','=',0];
  31. $map[] = ['org_id','=',$this->orgId];
  32. $map= empty($map) ? true: $map;
  33. //数据查询
  34. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  35. //数据返回
  36. $totalCount = db($this->table)->where($map)->count();
  37. $totalPage = ceil($totalCount/$length);
  38. $result['page'] = $page;
  39. $result['total'] = $totalPage;
  40. $result['records'] = $totalCount;
  41. $result['rows'] = $lists;
  42. return json($result);
  43. }else{
  44. return $this->fetch();
  45. }
  46. }
  47. /**
  48. * 新增/编辑
  49. */
  50. public function add($id=0){
  51. if(request()->isPost()){
  52. $res = $this->model->updates();
  53. if($res){
  54. $this->success('操作成功',url('index'));
  55. }else{
  56. $this->error($this->model->getError());
  57. }
  58. }else{
  59. if($id){
  60. $info =db($this->table)->where('id',$id)->find();
  61. $this->assign('info',$info);
  62. }
  63. return $this->fetch();
  64. }
  65. }
  66. /**
  67. * 删除记录
  68. * @param int $id
  69. */
  70. public function del($id=0){
  71. if(!$id){
  72. $this->error('参数错误');
  73. }
  74. $res = db($this->table)->where('id',$id)->setField('del',1);
  75. if($res){
  76. $this->success('删除成功');
  77. }else{
  78. $this->error('删除失败');
  79. }
  80. }
  81. /**
  82. * 改变字段值
  83. * @param int $fv
  84. * @param string $fn
  85. * @param int $fv
  86. */
  87. public function changeField($id=0,$fn='',$fv=0){
  88. if(!$fn||!$id){
  89. $this->error('参数错误');
  90. }
  91. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  92. if($res){
  93. $this->success('操作成功');
  94. }else{
  95. $this->error('操作失败');
  96. }
  97. }
  98. }