DinnerApply.php 3.2 KB

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