Admin.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class Admin extends BaseModel
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. /**
  16. * 管理注册写入
  17. * @param $post
  18. */
  19. public static function saveAdmin($post) {
  20. $save = ['name' => $post['name'],
  21. 'role_id' => $post['role_id'],
  22. 'avatar' => $post['avatar'],
  23. 'status' => $post['status'],
  24. 'sassid' => $post['sassId']
  25. ];
  26. //是否密码写入
  27. if(!empty($post['password'])) {
  28. $save['password'] = password_hash($post['password'],PASSWORD_BCRYPT);
  29. }
  30. if($post['id']) {
  31. //
  32. $info = self::where("username",$post['username'])->where('sassid',$save['sassid'])->find();
  33. if(!empty($info) && $info['id'] != $post['id'] ) {
  34. return self::setErrorInfo('登录的账号已存在');
  35. }
  36. //判断密码
  37. if(empty($save['password'])) {
  38. unset($post['password']);
  39. }
  40. self::where('id',$post['id'])->save($save);
  41. } else {
  42. $save['time'] = time();
  43. $save['last_time'] = time();
  44. $save['username'] = $post['username'];
  45. $count = self::where("username",$post['username'])->where('sassid',$save['sassid'])->count();
  46. if($count > 0) {
  47. return self::setErrorInfo('登录的账号已存在');
  48. }
  49. if(empty($save['password'])) {
  50. return self::setErrorInfo('请输入登录密码');
  51. }
  52. self::insert($save);
  53. }
  54. return true;
  55. }
  56. }