Supervise.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace app\admin\controller;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class Supervise extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sort','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $map[] = ['del','=',0];
  18. $map= empty($map) ? true: $map;
  19. //数据查询
  20. $lists = Db::name('supervise')->where($map)->limit($start,$length)->order('id desc')->select();
  21. //数据返回
  22. $totalCount = Db::name('supervise')->where($map)->count();
  23. $totalPage = ceil($totalCount/$length);
  24. $result['page'] = $page;
  25. $result['total'] = $totalPage;
  26. $result['records'] = $totalCount;
  27. $result['rows'] = $lists;
  28. return json($result);
  29. }else{
  30. return $this->fetch();
  31. }
  32. }
  33. /**
  34. * 新增/编辑
  35. */
  36. public function add($id=0){
  37. if(request()->isPost()){
  38. $res = model('Supervise')->updates();
  39. if($res){
  40. $this->success('操作成功',url('index'));
  41. }else{
  42. $this->error(model('Supervise')->getError());
  43. }
  44. }else{
  45. $meta_title = '添加品质督察标准';
  46. if($id){
  47. $meta_title = '编辑品质督察标准';
  48. $info = db('supervise')->where('id',$id)->find();
  49. $this->assign('info',$info);
  50. }
  51. $this->assign('meta_title',$meta_title);
  52. if($id > 0){
  53. return $this->fetch('edit');
  54. }else{
  55. return $this->fetch();
  56. }
  57. }
  58. }
  59. /**
  60. * 删除记录
  61. * @param int $id
  62. */
  63. public function del($id=0){
  64. if(!$id){
  65. $this->error('参数错误');
  66. }
  67. $info = Db::name('supervise_record')->where('supervise_id',$id)->where('del',0)->find();
  68. if($info){
  69. $this->error('该类下面有记录不能删除');
  70. }
  71. $res = Db::name('supervise')->where('id',$id)->setField('del',1);
  72. if($res){
  73. $this->success('删除成功');
  74. }else{
  75. $this->error('删除失败');
  76. }
  77. }
  78. /**
  79. * 改变字段值
  80. * @param int $fv
  81. * @param string $fn
  82. * @param int $fv
  83. */
  84. public function changeField($id=0,$fn='',$fv=0){
  85. if(!$fn||!$id){
  86. $this->error('参数错误');
  87. }
  88. $res = db('supervise')->where('id',$id)->setField($fn,$fv);
  89. if($res){
  90. $this->success('操作成功');
  91. }else{
  92. $this->error('操作失败');
  93. }
  94. }
  95. public function record($id=0){
  96. if(request()->isAjax()){
  97. //分页参数
  98. $length = input('rows',20,'intval'); //每页条数
  99. $page = input('page',1,'intval'); //第几页
  100. $start = ($page - 1) * $length; //分页开始位置
  101. //排序
  102. $sortRow = input('sidx','id','trim'); //排序列
  103. $sort = input('sord','desc','trim'); //排序方式
  104. $order = $sortRow.' '.$sort;
  105. $st = input('start','','trim');
  106. if($st){
  107. $map[] = ['create_time','>=',date('Y-m-d 00:00:00',strtotime($st))];
  108. }
  109. $et = input('end','','trim');
  110. if($et){
  111. $map[] = ['create_time','<=',date('Y-m-d 23:59:59',strtotime($et))];
  112. }
  113. $map[] = ['supervise_id','=',$id];
  114. $map[] = ['del','=',0];
  115. $map= empty($map) ? true: $map;
  116. //数据查询
  117. $lists = Db::name('supervise_record')->where($map)->limit($start,$length)->order('score desc')->select();
  118. foreach ($lists as $k=>$v){
  119. $lists[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  120. $lists[$k]['org_name'] = Db::name('org')->where('id',$v['org_id'])->value('name');
  121. }
  122. //数据返回
  123. $totalCount = Db::name('supervise_record')->where($map)->count();
  124. $totalPage = ceil($totalCount/$length);
  125. $result['page'] = $page;
  126. $result['total'] = $totalPage;
  127. $result['records'] = $totalCount;
  128. $result['rows'] = $lists;
  129. return json($result);
  130. }else{
  131. $this->assign('start',date('Y-m-d',strtotime('-1 months')));
  132. $this->assign('end',date('Y-m-d'));
  133. $this->assign('id',$id);
  134. return $this->fetch();
  135. }
  136. }
  137. /**
  138. * 删除记录
  139. * @param int $id
  140. */
  141. public function recordDel($id=0){
  142. if(!$id){
  143. $this->error('参数错误');
  144. }
  145. $data = [
  146. 'del'=>1,
  147. 'del_user'=>$this->userId,
  148. 'del_time'=>date('Y-m-d H:i:s'),
  149. ];
  150. $res = Db::name('supervise_record')->where('id',$id)->update($data);
  151. if($res){
  152. $this->success('删除成功');
  153. }else{
  154. $this->error('删除失败');
  155. }
  156. }
  157. public function recordDetail($id){
  158. $info = Db::name('supervise_record')->where('id',$id)->find();
  159. if(!$info){
  160. HelpHander::success('参数错误');
  161. }
  162. $info['supervise_title'] = Db::name('supervise')->where('id',$info['supervise_id'])->value('title');
  163. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  164. $info['content'] = json_decode($info['content'] ,true);
  165. foreach ($info['content'] as $k=>$v){
  166. $nums = $nums2= 0;
  167. foreach ($v['sub'] as $kk=>$vv){
  168. $nums2 = 0;
  169. foreach ($vv['sub'] as $kkk=>$vvv){
  170. if($vvv){
  171. $nums2 +=1;
  172. }
  173. }
  174. $nums +=$nums2;
  175. $info['content'][$k]['sub'][$kk]['nums'] = $nums2 >0 ? $nums2 :0;
  176. }
  177. $info['content'][$k]['nums'] = $nums;
  178. }
  179. $arr = [];
  180. $total = 0;
  181. foreach ($info['content'] as $k=>$v){
  182. foreach ($v['sub'] as $kk=>$vv){
  183. foreach ($vv['sub'] as $kkk=>$vvv){
  184. $arr[] = [
  185. 'num1' => $v['nums'],
  186. 'num2' => $vv['nums'],
  187. 'title1' => $kk==0&&$kkk==0?$v['title'].'('.$v['score'].'分)':'',
  188. 'title2' => $kkk==0?$vv['title'].'('.$vv['score'].'分)':'',
  189. 'standard' => $vv['standard'],
  190. 'title3' => $vvv['title'],
  191. 'score' => $vvv['score'],
  192. 'scored' => $vv['scored'],
  193. 'score_dec' => $vv['score']-$vv['scored'],
  194. 'reason' => isset($vv['reason'])&&!empty($vv['reason'])?$vv['reason']:'',
  195. 'img' => isset($vv['img'])&&!empty($vv['img'])? explode(',',$vv['img']):[],
  196. ];
  197. }
  198. }
  199. }
  200. $this->assign('info',$info);
  201. $this->assign('arr',$arr);
  202. return $this->fetch();
  203. }
  204. }