CleanForm.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. class CleanForm extends Auth
  5. {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->model= new \app\common\model\CleanForm();
  9. $this->table= $this->model->table;
  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[] = ['title','like','%'.$title.'%'];
  24. }
  25. $enable = input('enable','','trim');
  26. if($enable != ''){
  27. $map[] = ['enable','=',$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. foreach ($lists as $k=>$v){
  35. $lists[$k]['type_name'] = db('clean_type')
  36. ->where('id',$v['type_id'])
  37. ->value('title');
  38. }
  39. //数据返回
  40. $totalCount = db($this->table)->where($map)->count();
  41. $totalPage = ceil($totalCount/$length);
  42. $result['page'] = $page;
  43. $result['total'] = $totalPage;
  44. $result['records'] = $totalCount;
  45. $result['rows'] = $lists;
  46. return json($result);
  47. }else{
  48. $this->assign('m_name','任务内容');
  49. return $this->fetch();
  50. }
  51. }
  52. /**
  53. * 新增/编辑
  54. */
  55. public function add($id=0){
  56. if(request()->isPost()){
  57. $res = $this->model->updates();
  58. if($res){
  59. $this->success('操作成功',url('index'));
  60. }else{
  61. $this->error($this->model->getError());
  62. }
  63. }else{
  64. if($id){
  65. $info = db($this->table)->where('id',$id)->find();
  66. if(!empty($info) && !empty($info['address_ids'])){
  67. $info['address_ids'] = explode(',',$info['address_ids']);
  68. }
  69. $this->assign('info',$info);
  70. }
  71. $this->assign('type',(new \app\common\model\CleanType())->getList());
  72. $this->assign('address',(new \app\common\model\Address())->getListByType(8));
  73. return $this->fetch();
  74. }
  75. }
  76. /**
  77. * 删除记录
  78. * @param int $id
  79. */
  80. public function del($id=0){
  81. if(!$id){
  82. $this->error('参数错误');
  83. }
  84. $res = db($this->table)->where('id',$id)->setField('del',1);
  85. if($res){
  86. $this->success('删除成功');
  87. }else{
  88. $this->error('删除失败');
  89. }
  90. }
  91. /**
  92. * 改变字段值
  93. * @param int $fv
  94. * @param string $fn
  95. * @param int $fv
  96. */
  97. public function changeField($id=0,$fn='',$fv=0){
  98. if(!$fn||!$id){
  99. $this->error('参数错误');
  100. }
  101. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  102. if($res){
  103. $this->success('操作成功');
  104. }else{
  105. $this->error('操作失败');
  106. }
  107. }
  108. }