AttendanceMachine.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. Db::startTrans();
  16. try{
  17. $mid = 0;
  18. if($id > 0){
  19. $data['update_time'] = date('Y-m-d H:i:s');
  20. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  21. }else{
  22. $data['create_time'] = date('Y-m-d H:i:s');
  23. $ret = $this->allowField(true)->save($data);
  24. $mid = $this->id;
  25. }
  26. if(!$ret){
  27. \exception('操作失败');
  28. }
  29. if($mid){
  30. // 导入超级管理员
  31. $admin = config('app.machine_admin');
  32. $ret = model('AttendanceMachineCmd')->updateAdminInfo($mid,$admin['id'],$admin['name'],$admin['card']);
  33. if(!$ret){
  34. exception('操作失败');
  35. }
  36. }
  37. Db::commit();
  38. return true;
  39. }catch (Exception $e){
  40. $this->error = $e->getMessage();
  41. Db::rollback();
  42. return false;
  43. }
  44. }
  45. public function info($id){
  46. $info = db('AttendanceMachine')->where('id',$id)->find();
  47. return $info;
  48. }
  49. }