QualityGroup.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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])){
  52. $lists = (new \app\common\model\Address())->getListByType($type+2,$orgId);
  53. foreach ($lists as $k=>$v){
  54. $ll[] = [
  55. 'id' => $v['id'],
  56. 'title' => $v['title'],
  57. 'sn' => $v['sn'],
  58. 'qrcode' => get_qrcode_str('address',$v['id'])
  59. ];
  60. }
  61. }else if($type == 5){ // 日常工作
  62. $lists = Db::name('daily')
  63. ->where('del',0)
  64. ->where('enable',1)
  65. ->where('org_id',$orgId)
  66. ->field('id,title')
  67. ->select();
  68. $lists = $lists?$lists:[];
  69. foreach ($lists as $k=>$v){
  70. $ll[] = [
  71. 'id' => $v['id'],
  72. 'title' => $v['title'],
  73. 'sn' => '',
  74. 'qrcode' => get_qrcode_str('daily',$v['id'])
  75. ];
  76. }
  77. }else if($type == 6){ // 设备台账
  78. $lists = Db::name('device')
  79. ->where('del',0)
  80. ->where('enable',1)
  81. ->where('org_id',$orgId)
  82. ->field('id,title')
  83. ->select();
  84. $lists = $lists?$lists:[];
  85. foreach ($lists as $k=>$v){
  86. $ll[] = [
  87. 'id' => $v['id'],
  88. 'title' => $v['title'],
  89. 'sn' => '',
  90. 'qrcode' => get_qrcode_str('device',$v['id'])
  91. ];
  92. }
  93. }
  94. return $ll?$ll:[];
  95. }
  96. }