Services.php 6.5 KB

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