| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: your name
- // +----------------------------------------------------------------------
- namespace app\v1\logic\customer;
- use plugin\saiadmin\basic\BaseLogic;
- use plugin\saiadmin\exception\ApiException;
- use plugin\saiadmin\utils\Helper;
- use app\v1\model\customer\Account;
- use support\think\Db;
- /**
- * 账号信息逻辑层
- */
- class AccountLogic extends BaseLogic
- {
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new Account();
- }
- /**
- * 获取IP地理位置
- */
- public function getIpLocation($ip): string
- {
- $ip2region = new \Ip2Region();
- try {
- $region = $ip2region->memorySearch($ip);
- } catch (\Exception $e) {
- return '未知';
- }
- list($country, $number, $province, $city, $network) = explode('|', $region['region']);
- if ($network === '内网IP') {
- return $network;
- }
- if ($country == '中国') {
- return $province.'-'.$city.':'.$network;
- } else if ($country == '0') {
- return '未知';
- } else {
- return $country;
- }
- }
-
- /**
- * 列表
- */
- public function list($query)
- {
- if($query['type'] == '1'){
- $uid = Db::connect('db_origin')->table('users')->where('user_name', $query['val'])->value('uid');
- $data = Db::connect('db_origin')->table('user_'.$uid%10)->where('uid', $uid)->select()->toArray();
- }else{
- $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray();
- }
- print_r($data);
- $data = array_map(function($item){
- $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']);
- $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']);
- $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
- $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
- unset($item['user_pwd']);
- return $item;
- }, $data);
- return $data;
- }
- /**
- * 修改密码
- */
- public function updatePwd($data)
- {
- $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
- print_r($data);
- $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
- return $result;
- }
- /**
- * 修改手机
- */
- public function updateMobile($data)
- {
- $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
- return $result;
- }
- /**
- * 修改真实名
- */
- public function updateReal($data)
- {
- $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']]);
- return $result;
- }
- }
|