Services.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\service\controller;
  3. class Services extends Base
  4. {
  5. //客服信息
  6. public function index()
  7. {
  8. $token = input("param.token/s");
  9. $res = model('Services')->checktoken($token);
  10. if($res == -1){
  11. return $res;
  12. }
  13. $user_id = $res;
  14. //客服信息
  15. $service = db('users')->where('id',$user_id )->select();
  16. //print_r($service);exit;
  17. return $service;
  18. }
  19. //用户信息
  20. public function account()
  21. {
  22. if(request()->isPost()) {
  23. $account_id = input("param.account_id/s");
  24. //客服信息
  25. $account = db('accounts')->where('id', $account_id)->select();
  26. return $account;
  27. }
  28. }
  29. //修改/新增用户信息
  30. public function update()
  31. {
  32. if(request()->isPost()) {
  33. $account_id = input("param.account_id/s");
  34. $account_name = input("param.account_name/s");
  35. $account_email = input("param.account_email/s");
  36. $phone = input("param.phone/s");
  37. $address = input("param.address/s");
  38. $label = input("param.label/s");
  39. $remark = input("param.remark/s");
  40. $param = [
  41. 'account_name' => $account_name,
  42. 'account_email' => $account_email,
  43. 'phone' => $phone,
  44. 'address' => $address,
  45. 'label' => $label,
  46. 'remark' => $remark
  47. ];
  48. $account = db('accounts')->where('id', $account_id)->select();
  49. if(!empty($account)){
  50. try{
  51. db('accounts')->where('id', $account_id)->update($param);
  52. }catch(\Exception $e){
  53. return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
  54. }
  55. }else{
  56. try{
  57. db('accounts')->insertGetId($param);
  58. }catch(\Exception $e){
  59. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  60. }
  61. }
  62. return json(['code' => 1, 'data' => '', 'msg' => '保存成功']);
  63. }
  64. }
  65. // 客服信息修改
  66. public function updateinfo()
  67. {
  68. if(request()->isPost()){
  69. $token = input("param.token/s");
  70. $res = model('Services')->checktoken($token);
  71. if($res == -1){
  72. return $res;
  73. }
  74. $user_id = $res;
  75. //$user_id = input("param.user_id/s");
  76. $user_name = input("param.user_name/s");
  77. $user_job_number = input("param.user_job_number/s");
  78. $user_email = input("param.user_email/s");
  79. $phone = input("param.phone/s");
  80. $user_avatar = input("param.user_avatar/s");
  81. $username = db('users')->where('user_name', $user_name)->where('id', '<>', $user_id)->find();
  82. if(!empty($username)){
  83. return json(['code' => -1, 'data' => '', 'msg' => '该客服已经存在']);
  84. }
  85. $userjobnumber = db('users')->where('user_job_number', $user_job_number)->where('id', '<>', $user_id)->find();
  86. if(!empty($userjobnumber)){
  87. return json(['code' => -2, 'data' => '', 'msg' => '该工号已经存在']);
  88. }
  89. $useremail = db('users')->where('user_email', $user_email)->where('id', '<>', $user_id)->find();
  90. if(!empty($useremail)){
  91. return json(['code' => -3, 'data' => '', 'msg' => '该邮箱已经存在']);
  92. }
  93. // 更新客服信息
  94. $param = [
  95. 'user_name' => $user_name,
  96. 'user_job_number' => $user_job_number,
  97. 'user_email' => $user_email,
  98. 'user_avatar' => $user_avatar,
  99. 'phone' => $phone
  100. ];
  101. db('users')->where('id', $user_id)->update($param);
  102. return json(['code' => 1, 'data' => url('service/index'), 'msg' => '修改成功']);
  103. }
  104. }
  105. // 客服密码修改
  106. public function updatepwd()
  107. {
  108. if(request()->isPost()){
  109. $token = input("param.token/s");
  110. $res = model('Services')->checktoken($token);
  111. if($res == -1){
  112. return json(['code' => -1, 'data' => '', 'msg' => '请先登陆']);
  113. }
  114. $user_id = $res;
  115. //$user_id = input("param.user_id/s");
  116. $password = input("param.password/s");
  117. $new_password = input("param.new_password/s");
  118. $user = db('users')->where('id', $user_id)->find();
  119. if(empty($user)){
  120. return json(['code' => -1, 'data' => '', 'msg' => '客服不存在']);
  121. }else{
  122. if($user['user_pwd'] != md5($password . config('salt'))){
  123. return json(['code' => -2, 'data' => '', 'msg' => '原密码不正确']);
  124. }
  125. }
  126. // 更新密码
  127. $param = [
  128. 'user_pwd' => md5($new_password . config('salt'))
  129. ];
  130. db('users')->where('id', $user_id)->update($param);
  131. return json(['code' => 1, 'data' => '', 'msg' => '密码修改成功']);
  132. }
  133. }
  134. }