QualityGroup.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class QualityGroup extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model= new \app\common\model\QualityGroup();
  10. $this->table= $this->model->table;
  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[] = ['title','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. foreach ($lists as $k=>$v){
  36. // $lists[$k]['address'] = db('address')
  37. // ->where('id',$v['patrol_addr_id'])
  38. // ->value('title');
  39. }
  40. //数据返回
  41. $totalCount = db($this->table)->where($map)->count();
  42. $totalPage = ceil($totalCount/$length);
  43. $result['page'] = $page;
  44. $result['total'] = $totalPage;
  45. $result['records'] = $totalCount;
  46. $result['rows'] = $lists;
  47. return json($result);
  48. }else{
  49. $this->assign('m_name','检查内容列表');
  50. return $this->fetch();
  51. }
  52. }
  53. /**
  54. * 新增/编辑
  55. */
  56. public function add($id=0){
  57. if(request()->isPost()){
  58. $res = $this->model->updates();
  59. if($res){
  60. $this->success('操作成功',url('index'));
  61. }else{
  62. $this->error($this->model->getError());
  63. }
  64. }else{
  65. if($id){
  66. $info =db($this->table)->where('id',$id)->find();
  67. // if($info){
  68. // $info['forms'] = $info['forms']?explode(',',$info['forms']):[];
  69. // $info['busids'] = $info['busids']?explode(',',$info['busids']):[];
  70. // }
  71. $this->assign('info',$info);
  72. }
  73. $this->assign('patrol_form',(new \app\common\model\QualityForm())->getByModeList());
  74. $glarr = [
  75. ['id' => 0,'type' => 0, 'lists' => []],
  76. ['id' => 1,'type' => 3, 'lists' => []],
  77. ['id' => 2,'type' => 4, 'lists' => []],
  78. ['id' => 3,'type' => 5, 'lists' => []],
  79. ['id' => 4,'type' => 6, 'lists' => []],
  80. ['id' => 5,'type' => 0, 'lists' => []],
  81. ['id' => 6,'type' => 0, 'lists' => []],
  82. ];
  83. foreach ($glarr as $k=>$v){
  84. $ll = (new \app\common\model\QualityGroup())->getListByType($v['id'],$this->orgId);
  85. $glarr[$k]['lists'] = $ll?$ll:[];
  86. }
  87. $this->assign('glarr',$glarr);
  88. return $this->fetch();
  89. }
  90. }
  91. /**
  92. * 删除记录
  93. * @param int $id
  94. */
  95. public function del($id=0){
  96. if(!$id){
  97. $this->error('参数错误');
  98. }
  99. $res = db($this->table)->where('id',$id)->setField('del',1);
  100. if($res){
  101. $this->success('删除成功');
  102. }else{
  103. $this->error('删除失败');
  104. }
  105. }
  106. /**
  107. * 改变字段值
  108. * @param int $fv
  109. * @param string $fn
  110. * @param int $fv
  111. */
  112. public function changeField($id=0,$fn='',$fv=0){
  113. if(!$fn||!$id){
  114. $this->error('参数错误');
  115. }
  116. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  117. if($res){
  118. $this->success('操作成功');
  119. }else{
  120. $this->error('操作失败');
  121. }
  122. }
  123. }