PhUser.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use tools\Idcard;
  7. class PhUser extends Base
  8. {
  9. public function updates($orgId){
  10. $data = request()->post();
  11. if(!$data['user']){
  12. $this->error = '请选择负责人';
  13. return false;
  14. }
  15. if(!$data['dep']){
  16. $this->error = '请选择负责部门';
  17. return false;
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. Db::startTrans();
  22. try{
  23. if($id > 0){
  24. $res = $this->where('id',$id)
  25. ->update($data);
  26. if(!$res){
  27. \exception('更新失败');
  28. }
  29. }else{
  30. $data['org_id'] = $orgId;
  31. $data['create_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->insert($data);
  33. if(!$ret){
  34. \exception('操作失败');
  35. }
  36. }
  37. Db::commit();
  38. return true;
  39. }catch (Exception $e){
  40. Db::rollback();
  41. $this->error = $e->getMessage();
  42. return false;
  43. }
  44. }
  45. }