123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\common\model;
- use think\Db;
- class AttendanceMachine extends Base{
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $result = validate('AttendanceMachine')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('AttendanceMachine')->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- if($data['sn']){
- $deviceLog = Db::name('device_log')->where('sn',$data['sn'])->where('type',3)->where('del',0)->find();
- $txt = '添加';
- if($id > 0){
- $txt = '修改';
- }
- if(!$deviceLog){
- $this->error = '该设备无法'.$txt.',请联系管理员';
- return false;
- }
- }
- Db::startTrans();
- try{
- $mid = 0;
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- $mid = $this->id;
- }
- if(!$ret){
- \exception('操作失败');
- }
- if($mid){
- // 导入超级管理员
- $admin = config('app.machine_admin');
- $ret = model('AttendanceMachineCmd')->updateAdminInfo($mid,$admin['id'],$admin['name'],$admin['card']);
- if(!$ret){
- exception('操作失败');
- }
- }
- Db::commit();
- return true;
- }catch (Exception $e){
- $this->error = $e->getMessage();
- Db::rollback();
- return false;
- }
- }
- public function info($id){
- $info = db('AttendanceMachine')->where('id',$id)->find();
- return $info;
- }
- }
|