QualityGroup.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class QualityGroup extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'quality_group';
  9. protected $validateName = 'QualityGroup';
  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. $id = $data['id'];
  19. unset($data['id']);
  20. if($id > 0){
  21. $data['update_time'] = date('Y-m-d H:i:s');
  22. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  23. }else{
  24. $data['create_time'] = date('Y-m-d H:i:s');
  25. $ret = $this->allowField(true)->save($data);
  26. }
  27. if(!$ret){
  28. $this->error = '操作失败';
  29. return false;
  30. }
  31. return true;
  32. }
  33. /**
  34. * 获取指定mode检查项
  35. *
  36. * @author wst
  37. * @date 2021/9/7 15:15
  38. * @return array
  39. */
  40. public function getByModeList(){
  41. $list =$this
  42. ->where('org_id',cur_org_id())
  43. ->where('del',0)
  44. ->where('enable',1)
  45. ->select()
  46. ->toArray();
  47. return $list?$list:[];
  48. }
  49. public function getListByType($type,$orgId){
  50. $ll = [];
  51. if(in_array($type,[1,2,3,4,5])){
  52. $ctype = $type;
  53. if(in_array($type,[1,2,3,4])){
  54. $ctype = $type+2;
  55. }
  56. if($type == 5){
  57. $ctype = 10;
  58. }
  59. $lists = (new \app\common\model\Address())->getListByType($ctype,$orgId);
  60. foreach ($lists as $k=>$v){
  61. $ll[] = [
  62. 'id' => $v['id'],
  63. 'title' => $v['title'],
  64. 'sn' => $v['sn'],
  65. 'qrcode' => get_qrcode_str('address',$v['id'])
  66. ];
  67. }
  68. }
  69. // else if($type == 5){ // 日常工作
  70. // $lists = Db::name('daily')
  71. // ->where('del',0)
  72. // ->where('enable',1)
  73. // ->where('org_id',$orgId)
  74. // ->field('id,title')
  75. // ->select();
  76. // $lists = $lists?$lists:[];
  77. // foreach ($lists as $k=>$v){
  78. // $ll[] = [
  79. // 'id' => $v['id'],
  80. // 'title' => $v['title'],
  81. // 'sn' => '',
  82. // 'qrcode' => get_qrcode_str('daily',$v['id'])
  83. // ];
  84. // }
  85. // }
  86. else if($type == 6){ // 设备台账
  87. $lists = Db::name('device')
  88. ->where('del',0)
  89. ->where('enable',1)
  90. ->where('org_id',$orgId)
  91. ->field('id,title')
  92. ->select();
  93. $lists = $lists?$lists:[];
  94. foreach ($lists as $k=>$v){
  95. $ll[] = [
  96. 'id' => $v['id'],
  97. 'title' => $v['title'],
  98. 'sn' => '',
  99. 'qrcode' => get_qrcode_str('device',$v['id'])
  100. ];
  101. }
  102. }
  103. return $ll?$ll:[];
  104. }
  105. }