WasteScale.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class WasteScale extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'waste_scale';
  9. protected $validateName = 'WasteScale';
  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. $check = Db::name('waste_scale')
  22. ->where('del',0)
  23. ->where('user_id',$data['user_id'])
  24. ->where('enable',1)
  25. ->where('id','<>',$id)
  26. ->where('org_id',$data['org_id'])
  27. ->find();
  28. if($check){
  29. $this->error = '当前人员已绑定过';
  30. return false;
  31. }
  32. $data['update_time'] = date('Y-m-d H:i:s');
  33. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  34. }else{
  35. $check = Db::name('waste_scale')
  36. ->where('del',0)
  37. ->where('user_id',$data['user_id'])
  38. ->where('enable',1)
  39. ->where('org_id',$data['org_id'])
  40. ->find();
  41. if($check){
  42. $this->error = '当前人员已绑定过';
  43. return false;
  44. }
  45. $data['create_time'] = date('Y-m-d H:i:s');
  46. $ret = $this->allowField(true)->save($data);
  47. }
  48. if(!$ret){
  49. $this->error = '操作失败';
  50. return false;
  51. }
  52. return true;
  53. }
  54. public function getList(){
  55. $list =$this
  56. ->where('org_id',cur_org_id())
  57. ->where('del',0)
  58. ->where('enable',1)
  59. ->select()
  60. ->toArray();
  61. return $list;
  62. }
  63. //获取绑定人员打印机
  64. public function list($orgId,$userId){
  65. $list =$this
  66. ->where('org_id',$orgId)
  67. ->where('user_id',$userId)
  68. ->where('del',0)
  69. ->where('enable',1)
  70. ->select()
  71. ->toArray();
  72. return $list;
  73. }
  74. }