0
0

AttendanceMachine.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class AttendanceMachine extends Base{
  5. public function updates(){
  6. $data = request()->post();
  7. $data['org_id'] = cur_org_id();
  8. $result = validate('AttendanceMachine')->check($data,[],'');
  9. if(true !== $result){
  10. $this->error = validate('AttendanceMachine')->getError();
  11. return false;
  12. }
  13. $id = $data['id'];
  14. unset($data['id']);
  15. if($data['sn']){
  16. $deviceLog = Db::name('device_log')->where('sn',$data['sn'])->where('type',3)->where('del',0)->find();
  17. $txt = '添加';
  18. if($id > 0){
  19. $txt = '修改';
  20. }
  21. if(!$deviceLog){
  22. $this->error = '该设备无法'.$txt.',请联系管理员';
  23. return false;
  24. }
  25. }
  26. Db::startTrans();
  27. try{
  28. $mid = 0;
  29. if($id > 0){
  30. $data['update_time'] = date('Y-m-d H:i:s');
  31. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  32. }else{
  33. $data['create_time'] = date('Y-m-d H:i:s');
  34. $ret = $this->allowField(true)->save($data);
  35. $mid = $this->id;
  36. }
  37. if(!$ret){
  38. \exception('操作失败');
  39. }
  40. if($mid){
  41. // 导入超级管理员
  42. $admin = config('app.machine_admin');
  43. $ret = model('AttendanceMachineCmd')->updateAdminInfo($mid,$admin['id'],$admin['name'],$admin['card']);
  44. if(!$ret){
  45. exception('操作失败');
  46. }
  47. }
  48. Db::commit();
  49. return true;
  50. }catch (Exception $e){
  51. $this->error = $e->getMessage();
  52. Db::rollback();
  53. return false;
  54. }
  55. }
  56. public function info($id){
  57. $info = db('AttendanceMachine')->where('id',$id)->find();
  58. return $info;
  59. }
  60. }