CleanType.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class CleanType extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'clean_type';
  9. protected $validateName = 'CleanType';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['org_id'] = cur_org_id();
  13. $result = validate($this->validateName)->check($data,[],'');
  14. if(true !== $result){
  15. $this->error = validate($this->validateName)->getError();
  16. return false;
  17. }
  18. if($data['type']==1){
  19. if(empty($data['parent_id'])){
  20. $this->error = '请选择任务类型';
  21. return false;
  22. }
  23. }
  24. $id = $data['id'];
  25. unset($data['id']);
  26. unset($data['type']);
  27. if($id > 0){
  28. $data['update_time'] = date('Y-m-d H:i:s');
  29. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  30. }else{
  31. $data['create_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data);
  33. }
  34. if(!$ret){
  35. $this->error = '操作失败';
  36. return false;
  37. }
  38. return true;
  39. }
  40. //获取任务类型
  41. public function list(){
  42. $list =$this
  43. ->where('parent_id',0)
  44. ->where('enable',1)
  45. ->where('del',0)
  46. ->where('org_id',cur_org_id())
  47. ->select()
  48. ->toArray();
  49. return $list;
  50. }
  51. //获取任务项
  52. public function getList(){
  53. $list =$this
  54. ->where('parent_id','>',0)
  55. ->where('enable',1)
  56. ->where('del',0)
  57. ->where('org_id',cur_org_id())
  58. ->select()
  59. ->toArray();
  60. return $list?$list:[];
  61. }
  62. public function getGroupList(){
  63. $arr =[];
  64. $list = $this->list();
  65. foreach ($list as $k=>$v){
  66. $ids = $this
  67. ->where('enable',1)
  68. ->where('del',0)
  69. ->where('parent_id',$v['id'])->column('id');
  70. $a = [];
  71. $lists = Db::name('clean_form')
  72. ->whereIn('type_id',$ids)
  73. ->select();
  74. foreach ($lists as $v1){
  75. $a[] = $v1;
  76. }
  77. $arr[] = [
  78. 'label'=>$v['title'],
  79. 'options'=>$a
  80. ];
  81. }
  82. return $arr;
  83. }
  84. }