0
0

PatrolAddrForm.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class PatrolAddrForm extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model= new \app\common\model\PatrolAddrForm();
  10. $this->table= $this->model->table;
  11. }
  12. public function index($mode=1){
  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[] = ['title','like','%'.$title.'%'];
  25. }
  26. $enable = input('enable','','trim');
  27. if($enable != ''){
  28. $map[] = ['enable','=',$enable];
  29. }
  30. $cate_id = input('cate_id','','trim');
  31. if($cate_id != ''){
  32. $map[] = ['cate_id','=',$cate_id];
  33. }
  34. $map[] = ['del','=',0];
  35. $map[] = ['patrol_mode','=',$mode];
  36. $map[] = ['org_id','=',$this->orgId];
  37. $map= empty($map) ? true: $map;
  38. //数据查询
  39. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  40. foreach ($lists as $k=>$v){
  41. // $lists[$k]['address'] = db('address')
  42. // ->where('id',$v['patrol_addr_id'])
  43. // ->value('title');
  44. $lists[$k]['cateName'] = $v['cate_id']?implode(',',Db::name('patrol_cate')
  45. ->where('id','in',explode(',',$v['cate_id']))
  46. ->column('title')):'';
  47. }
  48. //数据返回
  49. $totalCount = db($this->table)->where($map)->count();
  50. $totalPage = ceil($totalCount/$length);
  51. $result['page'] = $page;
  52. $result['total'] = $totalPage;
  53. $result['records'] = $totalCount;
  54. $result['rows'] = $lists;
  55. return json($result);
  56. }else{
  57. $this->assign('m_name',(new \app\common\model\PatrolAddrForm())->getModeTitle($mode).'任务内容');
  58. $this->assign('mode',$mode);
  59. $cate = model('PatrolCate')->getByModeList($mode);
  60. $this->assign('cate',$cate);
  61. return $this->fetch();
  62. }
  63. }
  64. /**
  65. * 新增/编辑
  66. */
  67. public function add($id=0){
  68. $mode = input('mode',1,'trim');
  69. if(request()->isPost()){
  70. $res = $this->model->updates();
  71. if($res){
  72. $this->success('操作成功',url('index',['mode'=>$mode]));
  73. }else{
  74. $this->error($this->model->getError());
  75. }
  76. }else{
  77. $patrol_form = [];
  78. if($id){
  79. $info =db($this->table)->where('id',$id)->find();
  80. if($info){
  81. $info['cate_id'] = $info['cate_id']?explode(',',$info['cate_id']):[];
  82. $info['patrol_form'] = explode(',',$info['patrol_form']);
  83. }
  84. if($mode==4){
  85. $patrol_form = (new \app\common\model\PatrolForm())->getByCateList($info['cate_id']);
  86. }
  87. $this->assign('info',$info);
  88. }
  89. // $this->assign('address',(new \app\common\model\Address())->getListByType($mode+2));
  90. if($mode==4){
  91. $this->assign('patrol_form',$patrol_form);
  92. }else{
  93. $this->assign('patrol_form',(new \app\common\model\PatrolForm())->getByModeList($mode));
  94. }
  95. $this->assign('mode',$mode);
  96. $cate = model('PatrolCate')->getByModeList($mode);
  97. $this->assign('cate',$cate);
  98. return $this->fetch();
  99. }
  100. }
  101. /**
  102. * 删除记录
  103. * @param int $id
  104. */
  105. public function del($id=0){
  106. if(!$id){
  107. $this->error('参数错误');
  108. }
  109. $res = db($this->table)->where('id',$id)->setField('del',1);
  110. if($res){
  111. $this->success('删除成功');
  112. }else{
  113. $this->error('删除失败');
  114. }
  115. }
  116. /**
  117. * 改变字段值
  118. * @param int $fv
  119. * @param string $fn
  120. * @param int $fv
  121. */
  122. public function changeField($id=0,$fn='',$fv=0){
  123. if(!$fn||!$id){
  124. $this->error('参数错误');
  125. }
  126. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  127. if($res){
  128. $this->success('操作成功');
  129. }else{
  130. $this->error('操作失败');
  131. }
  132. }
  133. }