Services.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_email = input("param.account_email/s");
  35. $phone = input("param.phone/s");
  36. $address = input("param.address/s");
  37. $remark = input("param.remark/s");
  38. $label_id = input("param.label_id/s");
  39. $nick_name = input("param.nick_name/s");
  40. $param = [
  41. 'account_email' => $account_email,
  42. 'account_phone' => $phone,
  43. 'address' => $address,
  44. 'label_id' => $label_id,
  45. 'nick_name' => $nick_name,
  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. return json(['code' => 1, 'data' => '', 'msg' => '保存成功']);
  53. }catch(\Exception $e){
  54. return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
  55. }
  56. }else{
  57. try{
  58. db('accounts')->insertGetId($param);
  59. return json(['code' => 1, 'data' => '', 'msg' => '保存成功']);
  60. }catch(\Exception $e){
  61. return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
  62. }
  63. }
  64. }
  65. }
  66. //获取用户信息
  67. public function accountInfo()
  68. {
  69. if(request()->isPost()) {
  70. $account_id = input("param.account_id/s");
  71. $account = db('accounts')->field('id,account_name,nick_name,account_email,account_phone,address,remark,label_id')->where('id', $account_id)->find();
  72. if(empty($account)){
  73. return json(['code' => -1, 'data' => '', 'msg' => '用户不存在']);
  74. }
  75. $label = db('accountslabel')->where('id', $account['label_id'])->find();
  76. if(!empty($label)){
  77. $account['label'] = $label['name'];
  78. }
  79. return json(['code' => 1, 'data' => $account, 'msg' => '成功']);
  80. }
  81. }
  82. // 客服信息修改
  83. public function updateinfo()
  84. {
  85. if(request()->isPost()){
  86. $token = input("param.token/s");
  87. $res = model('Services')->checktoken($token);
  88. if($res == -1){
  89. return $res;
  90. }
  91. $user_id = $res;
  92. //$user_id = input("param.user_id/s");
  93. $user_name = input("param.user_name/s");
  94. $user_email = input("param.user_email/s");
  95. $phone = input("param.phone/s");
  96. $signature = input("param.signature/s");
  97. $fullname = input("param.fullname/s");
  98. // $username = db('users')->where('user_name', $user_name)->where('id', '<>', $user_id)->find();
  99. // if(!empty($username)){
  100. // return json(['code' => -1, 'data' => '', 'msg' => '该客服已经存在']);
  101. // }
  102. // 更新客服信息
  103. $param = [
  104. 'user_name' => $user_name,
  105. 'user_email' => $user_email,
  106. 'signature' => $signature,
  107. 'fullname' => $fullname,
  108. 'phone' => $phone,
  109. 'expire_time' => time()
  110. ];
  111. db('users')->where('id', $user_id)->update($param);
  112. $user = db('users')->where('id', $user_id)->select();
  113. $group = db('groups')->where('id', $user[0]['group_id'])->find();
  114. $user[0]['group'] = $group['name'];
  115. return json(['code' => 1, 'data' => ['user' => $user[0]], 'msg' => '修改成功']);
  116. }
  117. }
  118. // 客服密码修改
  119. public function updatepwd()
  120. {
  121. if(request()->isPost()){
  122. $token = input("param.token/s");
  123. $res = model('Services')->checktoken($token);
  124. if($res == -1){
  125. return json(['code' => -1, 'data' => '', 'msg' => '请先登陆']);
  126. }
  127. $user_id = $res;
  128. //$user_id = input("param.user_id/s");
  129. $password = input("param.password/s");
  130. $new_password = input("param.new_password/s");
  131. $user = db('users')->where('id', $user_id)->find();
  132. if(empty($user)){
  133. return json(['code' => -1, 'data' => '', 'msg' => '客服不存在']);
  134. }else{
  135. if($user['user_pwd'] != md5($password . config('salt'))){
  136. return json(['code' => -2, 'data' => '', 'msg' => '原密码不正确']);
  137. }
  138. }
  139. // 更新密码
  140. $param = [
  141. 'user_pwd' => md5($new_password . config('salt'))
  142. ];
  143. db('users')->where('id', $user_id)->update($param);
  144. return json(['code' => 1, 'data' => '', 'msg' => '密码修改成功']);
  145. }
  146. }
  147. }