WasteScale.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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($data['scale_sn']){
  21. $deviceLog = Db::name('device_log')->where('sn',$data['scale_sn'])->where('type',1)->where('del',0)->find();
  22. $txt = '添加';
  23. if($id > 0){
  24. $txt = '修改';
  25. }
  26. if(!$deviceLog){
  27. $this->error = '该设备无法'.$txt.',请联系管理员';
  28. return false;
  29. }
  30. }
  31. if($data['printer_sn']){
  32. $deviceLog = Db::name('device_log')->where('sn',$data['printer_sn'])->where('type',6)->where('del',0)->find();
  33. $txt = '添加';
  34. if($id > 0){
  35. $txt = '修改';
  36. }
  37. if(!$deviceLog){
  38. $this->error = '该设备无法'.$txt.',请联系管理员';
  39. return false;
  40. }
  41. }
  42. if($id > 0){
  43. $check = Db::name('waste_scale')
  44. ->where('del',0)
  45. ->where('user_id',$data['user_id'])
  46. ->where('enable',1)
  47. ->where('id','<>',$id)
  48. ->where('org_id',$data['org_id'])
  49. ->find();
  50. if($check){
  51. $this->error = '当前人员已绑定过';
  52. return false;
  53. }
  54. $data['update_time'] = date('Y-m-d H:i:s');
  55. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  56. }else{
  57. $check = Db::name('waste_scale')
  58. ->where('del',0)
  59. ->where('user_id',$data['user_id'])
  60. ->where('enable',1)
  61. ->where('org_id',$data['org_id'])
  62. ->find();
  63. if($check){
  64. $this->error = '当前人员已绑定过';
  65. return false;
  66. }
  67. $data['create_time'] = date('Y-m-d H:i:s');
  68. $ret = $this->allowField(true)->save($data);
  69. }
  70. if(!$ret){
  71. $this->error = '操作失败';
  72. return false;
  73. }
  74. return true;
  75. }
  76. public function getList(){
  77. $list =$this
  78. ->where('org_id',cur_org_id())
  79. ->where('del',0)
  80. ->where('enable',1)
  81. ->select()
  82. ->toArray();
  83. return $list;
  84. }
  85. //获取绑定人员打印机
  86. public function list($orgId,$userId){
  87. $list =$this
  88. ->where('org_id',$orgId)
  89. ->where('user_id',$userId)
  90. ->where('del',0)
  91. ->where('enable',1)
  92. ->select()
  93. ->toArray();
  94. return $list;
  95. }
  96. }