0
0

Feedback.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller;
  3. class Feedback extends Auth
  4. {
  5. public function index(){
  6. if(request()->isAjax()){
  7. //分页参数
  8. $length = input('rows',10,'intval'); //每页条数
  9. $page = input('page',1,'intval'); //第几页
  10. $start = ($page - 1) * $length; //分页开始位置
  11. //排序
  12. $sortRow = input('sidx','id','trim'); //排序列
  13. $sort = input('sord','desc','trim'); //排序方式
  14. $order = $sortRow.' '.$sort;
  15. $title = input('user_name','','trim');
  16. if($title){
  17. $map[] = ['u.real_name','like','%'.$title.'%'];
  18. }
  19. // $map[] = ['org_id','=',cur_org_id()];
  20. $map= empty($map) ? true: $map;
  21. //数据查询
  22. $lists = db('feedback')
  23. ->alias('f')
  24. ->field('f.*,u.real_name')
  25. ->join('user u','u.id=f.user_id')
  26. ->limit($start,$length)
  27. ->where($map)
  28. ->order($order)
  29. ->select();
  30. //数据返回
  31. $totalCount = db('feedback')
  32. ->alias('f')
  33. ->field('f.*,u.real_name')
  34. ->join('user u','u.id=f.user_id')
  35. ->where($map)
  36. ->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 opinion($id=0){
  51. if(request()->isPost()){
  52. $res = model('Feedback')->updates();
  53. if($res){
  54. $this->success('操作成功',url('index'));
  55. }else{
  56. $this->error(model('Feedback')->getError());
  57. }
  58. }else{
  59. if($id){
  60. $info = db('feedback')->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 details($id=0){
  71. if(!$id){
  72. $this->error('参数错误');
  73. }
  74. $info = db('feedback')->where('id',$id)->find();
  75. $info['real_name'] = db('user')->where('id',$info['user_id'])->value('real_name');
  76. $info['to_user'] = db('user')->where('id',$info['to_user_id'])->value('real_name');
  77. $this->assign('info',$info);
  78. return $this->fetch();
  79. }
  80. /**
  81. * 删除记录
  82. * @param int $id
  83. */
  84. public function del($id=0){
  85. if(!$id){
  86. $this->error('参数错误');
  87. }
  88. $res = db('feedback')->where('id',$id)->delete();
  89. if($res){
  90. $this->success('删除成功');
  91. }else{
  92. $this->error('删除失败');
  93. }
  94. }
  95. /**
  96. * 改变字段值
  97. * @param int $fv
  98. * @param string $fn
  99. * @param int $fv
  100. */
  101. public function changeField($id=0,$fn='',$fv=0){
  102. if(!$fn||!$id){
  103. $this->error('参数错误');
  104. }
  105. $res = db('feedback')->where('id',$id)->setField($fn,$fv);
  106. if($res){
  107. $this->success('操作成功');
  108. }else{
  109. $this->error('操作失败');
  110. }
  111. }
  112. }