0
0

Security.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Security extends Base
  5. {
  6. public function updates(){
  7. $data = request()->post();
  8. $data['org_id'] = cur_org_id();
  9. $result = validate('Security')->check($data,[],'');
  10. if(true !== $result){
  11. $this->error = validate('Security')->getError();
  12. return false;
  13. }
  14. $id = $data['id'];
  15. unset($data['id']);
  16. if($data['sn']){
  17. $deviceLog = Db::name('device_log')->where('sn',$data['sn'])->where('type',4)->where('del',0)->find();
  18. $txt = '添加';
  19. if($id > 0){
  20. $txt = '修改';
  21. }
  22. if(!$deviceLog){
  23. $this->error = '该设备无法'.$txt.',请联系管理员';
  24. return false;
  25. }
  26. }
  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. }