QualityForm.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class QualityForm extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model= new \app\common\model\QualityForm();
  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]['type'] = $this->model->type[$v['type']];
  37. }
  38. //数据返回
  39. $totalCount = db($this->table)->where($map)->count();
  40. $totalPage = ceil($totalCount/$length);
  41. $result['page'] = $page;
  42. $result['total'] = $totalPage;
  43. $result['records'] = $totalCount;
  44. $result['rows'] = $lists;
  45. return json($result);
  46. }else{
  47. $this->assign('m_name','品控检查项');
  48. return $this->fetch();
  49. }
  50. }
  51. /**
  52. * 新增/编辑
  53. */
  54. public function add($id=0){
  55. if(request()->isPost()){
  56. $res = $this->model->updates();
  57. if($res){
  58. $this->success('操作成功',url('index'));
  59. }else{
  60. $this->error($this->model->getError());
  61. }
  62. }else{
  63. if($id){
  64. $info =db($this->table)->where('id',$id)->find();
  65. $this->assign('info',$info);
  66. }
  67. $this->assign('type',$this->model->type);
  68. return $this->fetch();
  69. }
  70. }
  71. /**
  72. * 删除记录
  73. * @param int $id
  74. */
  75. public function del($id=0){
  76. if(!$id){
  77. $this->error('参数错误');
  78. }
  79. $res = db($this->table)->where('id',$id)->setField('del',1);
  80. if($res){
  81. $this->success('删除成功');
  82. }else{
  83. $this->error('删除失败');
  84. }
  85. }
  86. /**
  87. * 改变字段值
  88. * @param int $fv
  89. * @param string $fn
  90. * @param int $fv
  91. */
  92. public function changeField($id=0,$fn='',$fv=0){
  93. if(!$fn||!$id){
  94. $this->error('参数错误');
  95. }
  96. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  97. if($res){
  98. $this->success('操作成功');
  99. }else{
  100. $this->error('操作失败');
  101. }
  102. }
  103. public function selectforms($idx=0){
  104. $this->assign('idx',$idx);
  105. $this->assign('m_name','品控检查项');
  106. $quality_cate = Db::name('quality_cate')
  107. ->where('org_id',$this->orgId)
  108. ->where('del',0)
  109. ->where('enable',1)
  110. ->where('pid',0)
  111. ->field('id as value,title as label')
  112. ->select();
  113. foreach ($quality_cate as $k=>$v) {
  114. $child =Db::name('quality_cate')
  115. ->where('org_id',$this->orgId)
  116. ->where('del',0)
  117. ->where('enable',1)
  118. ->where('pid',$v['value'])
  119. ->field('id as value,title as label')
  120. ->select();
  121. $quality_cate[$k]['children'] = $child;
  122. foreach ($child as $k1=>$v1){
  123. $child1 =Db::name('quality_cate')
  124. ->where('org_id',$this->orgId)
  125. ->where('del',0)
  126. ->where('enable',1)
  127. ->where('pid',$v1['value'])
  128. ->field('id as value,title as label')
  129. ->select();
  130. $quality_cate[$k]['children'][$k1]['children'] = $child1;
  131. }
  132. }
  133. $this->assign('quality_cate',$quality_cate);
  134. return $this->fetch();
  135. }
  136. public function selectforms_id($idx=0){
  137. if(request()->isAjax()){
  138. //分页参数
  139. $length = input('rows',10,'intval'); //每页条数
  140. $page = input('page',1,'intval'); //第几页
  141. $start = ($page - 1) * $length; //分页开始位置
  142. //排序
  143. $sortRow = input('sidx','id','trim'); //排序列
  144. $sort = input('sord','desc','trim'); //排序方式
  145. $order = $sortRow.' '.$sort;
  146. $title = input('title','','trim');
  147. if($title){
  148. $map[] = ['title','like','%'.$title.'%'];
  149. }
  150. $map[] = ['enable','=',1];
  151. $map[] = ['del','=',0];
  152. $map[] = ['org_id','=',$this->orgId];
  153. $map= empty($map) ? true: $map;
  154. //数据查询
  155. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  156. foreach ($lists as $k=>$v){
  157. $lists[$k]['type_text'] = $this->model->type[$v['type']];
  158. }
  159. //数据返回
  160. $totalCount = db($this->table)->where($map)->count();
  161. $totalPage = ceil($totalCount/$length);
  162. $result['page'] = $page;
  163. $result['total'] = $totalPage;
  164. $result['records'] = $totalCount;
  165. $result['rows'] = $lists;
  166. return json($result);
  167. }else{
  168. $this->assign('idx',$idx);
  169. $this->assign('m_name','品控检查项');
  170. return $this->fetch();
  171. }
  172. }
  173. public function getCate(){
  174. $id = input('id','');
  175. $ids = explode(',',$id);
  176. $list = Db::name('quality_cate')
  177. ->where('id','in',$ids)
  178. ->field('id,title')
  179. ->select();
  180. foreach ($list as $k=>$v){
  181. $list[$k]['type']=1;
  182. }
  183. $this->success('操作成功','',$list);
  184. }
  185. }