AccountLogic.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: your name
  6. // +----------------------------------------------------------------------
  7. namespace app\v1\logic\customer;
  8. use plugin\saiadmin\basic\BaseLogic;
  9. use plugin\saiadmin\exception\ApiException;
  10. use plugin\saiadmin\utils\Helper;
  11. use app\v1\model\customer\Account;
  12. use support\think\Db;
  13. /**
  14. * 账号信息逻辑层
  15. */
  16. class AccountLogic extends BaseLogic
  17. {
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct()
  22. {
  23. $this->model = new Account();
  24. }
  25. /**
  26. * 获取IP地理位置
  27. */
  28. public function getIpLocation($ip): string
  29. {
  30. $ip2region = new \Ip2Region();
  31. try {
  32. $region = $ip2region->memorySearch($ip);
  33. } catch (\Exception $e) {
  34. return '未知';
  35. }
  36. list($country, $number, $province, $city, $network) = explode('|', $region['region']);
  37. if ($network === '内网IP') {
  38. return $network;
  39. }
  40. if ($country == '中国') {
  41. return $province.'-'.$city.':'.$network;
  42. } else if ($country == '0') {
  43. return '未知';
  44. } else {
  45. return $country;
  46. }
  47. }
  48. /**
  49. * 列表
  50. */
  51. public function list($query)
  52. {
  53. if($query['type'] == '1'){
  54. $uid = Db::connect('db_origin')->table('users')->where('user_name', $query['val'])->value('uid');
  55. $data = Db::connect('db_origin')->table('user_'.$uid%10)->where('uid', $uid)->select()->toArray();
  56. }else{
  57. $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray();
  58. }
  59. print_r($data);
  60. $data = array_map(function($item){
  61. $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']);
  62. $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']);
  63. $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
  64. $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
  65. unset($item['user_pwd']);
  66. return $item;
  67. }, $data);
  68. return $data;
  69. }
  70. /**
  71. * 修改密码
  72. */
  73. public function updatePwd($data)
  74. {
  75. $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
  76. print_r($data);
  77. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
  78. return $result;
  79. }
  80. /**
  81. * 修改手机
  82. */
  83. public function updateMobile($data)
  84. {
  85. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
  86. return $result;
  87. }
  88. /**
  89. * 修改真实名
  90. */
  91. public function updateReal($data)
  92. {
  93. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['real_name' => $data['real_name'], 'id_card' => $data['id_card']]);
  94. return $result;
  95. }
  96. }