Services.php 6.1 KB

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