User.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @author huwhois<huwhois@163.com>
  4. */
  5. namespace app\admin\controller;
  6. use daswork\Controller;
  7. use app\admin\model\User as UserModel;
  8. class User extends Base
  9. {
  10. protected $model;
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. $this->model = new UserModel();
  15. }
  16. public function index()
  17. {
  18. $data = $this->model->dataList();
  19. $this->assign('data', $data);
  20. $this->fetch();
  21. }
  22. public function info()
  23. {
  24. $id = $_GET['id'];
  25. if (!$id) {
  26. echo json_encode(['code' => 1, 'msg'=>'id不能为空']);
  27. return false;
  28. }
  29. $data = $this->model->getOneById($id);
  30. echo json_encode(['code'=>0, 'data'=>$data]);
  31. return false;
  32. }
  33. public function save()
  34. {
  35. $params = escapeString($_POST);
  36. $data = [
  37. 'truename' => $params['truename'],
  38. 'organization' => $params['organization'],
  39. 'phone' => $params['phone'],
  40. 'fee_type' => intval($params['feeType']),
  41. 'is_pay' => intval($params['isPay']),
  42. 'money' =>intval($params['money']),
  43. 'remark' => $params['remark'],
  44. 'member_type'=> intval($params['memberType']),
  45. 'receipt_number'=> intval($params['receipt_number'])
  46. ];
  47. $id = $params['id'];
  48. if ($id) {
  49. $data['id'] = $id;
  50. $res = $this->model->updateById($data);
  51. } else {
  52. $res = $this->model->save($data);
  53. }
  54. if (!$res) {
  55. echo json_encode(['code' => 2, 'msg'=>$this->model->lastErrorMsg()]);
  56. return false;
  57. } else {
  58. echo json_encode(['code' => 0]);
  59. return false;
  60. }
  61. }
  62. public function delete()
  63. {
  64. $id = escapeString($_POST['id']);
  65. if (!$id) {
  66. echo json_encode(['code' => 1, 'msg'=>'id不能为空']);
  67. return false;
  68. }
  69. if (is_array($id)) {
  70. if (in_array(1, $id)) {
  71. echo json_encode(['code' => 1, 'msg'=>'超级管理员不可删除']);
  72. return false;
  73. }
  74. } elseif ($id == 1) {
  75. echo json_encode(['code' => 1, 'msg'=>'超级管理员不可删除']);
  76. return false;
  77. }
  78. $res = $this->model->deleteById($id);
  79. if (!$res) {
  80. echo json_encode(['code' => 2, 'msg'=>$this->model->lastErrorMsg()]);
  81. return false;
  82. } else {
  83. echo json_encode(['code' => 0]);
  84. return false;
  85. }
  86. }
  87. public function repassword()
  88. {
  89. $params = escapeString($_POST);
  90. $id = $_SESSION['userid'];
  91. $user = $this->model->getOneById($id);
  92. if ($user['password'] != md5($params['oldpassword'])) {
  93. echo json_encode(['code' => 2, 'msg'=>'原密码不正确']);
  94. return false;
  95. }
  96. $user['password'] = md5($params['newpassword']);
  97. $res = $this->model->updateById($user);
  98. echo json_encode(['code' => 0, 'msg'=>'修改成功, 请重新登录']);
  99. return false;
  100. }
  101. }