| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- 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\Redis;
- use support\think\Db;
- /**
- * 账号信息逻辑层
- */
- class AccountLogic extends BaseLogic
- {
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new Account();
- }
-
- /**
- * 列表
- */
- 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();
- }
- $data = array_map(function($item){
- $item['login_ip'] = $item['login_ip'].getIpLocation($item['login_ip']);
- $item['reg_ip'] = $item['reg_ip'].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']);
- $item['pay_time'] = $item['pay_time'] == 0 ? '' : date('Y-m-d H:i:s', $item['pay_time']);
- $item['id_card'] = $item['id_card'] == '' ? '' : substr($item['id_card'], 0, 4).'****'.substr($item['id_card'], -4);
- unset($item['user_pwd']);
- return $item;
- }, $data);
- return $data;
- }
- /**
- * 修改密码
- */
- public function updatePwd($data)
- {
- $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
- return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
- }
- /**
- * 修改手机
- */
- public function updateMobile($data)
- {
- return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
- }
- /**
- * 修改真实名
- */
- public function updateReal($data)
- {
- return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['real_name' => $data['real_name'], 'id_card' => $data['id_card']]);
- }
- /**
- * 封禁列表
- */
- public function getBanList($where)
- {
- $saiType = request()->input('saiType', 'list');
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $orderBy = request()->input('orderBy', '');
- $orderType = request()->input('orderType', $this->orderType);
-
- if(empty($orderBy)) {
- $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
- }
-
- // 处理查询条件,特别是处理逗号分隔的value值
- $query = Db::connect('db_game_log')->table('ban_log');
-
- // 处理where条件
- foreach ($where as $key => $val) {
- if ($val !== '' && $key !== 'value') {
- $query->where($key, $val);
- }
- }
-
- // 特殊处理value字段
- if (isset($where['value']) && !empty($where['value'])) {
- $value = trim($where['value']);
-
- // 如果输入的值包含逗号,说明要搜索多个值
- if (strpos($value, ',') !== false) {
- $values = explode(',', $value);
- $values = array_map('trim', $values);
-
- // 构建FIND_IN_SET查询条件
- $findInSetConditions = [];
- foreach ($values as $val) {
- if (!empty($val)) {
- $findInSetConditions[] = "FIND_IN_SET('" . addslashes($val) . "', value) > 0";
- }
- }
-
- if (!empty($findInSetConditions)) {
- $query->whereRaw('(' . implode(' OR ', $findInSetConditions) . ')');
- }
- } else {
- // 如果输入的是单个值,需要同时考虑两种情况:
- // 1. 数据库中存储的是单个值(精确匹配)
- // 2. 数据库中存储的是逗号分隔的值(使用FIND_IN_SET)
- $query->where(function($q) use ($value) {
- $q->where('value', $value) // 精确匹配
- ->whereOr('value', 'like', '%' . $value . '%') // 模糊匹配
- ->whereOrRaw("FIND_IN_SET('" . addslashes($value) . "', value) > 0"); // FIND_IN_SET匹配
- });
- }
- }
-
- // 执行查询
- if ($saiType === 'all') {
- $data = $query->order($orderBy, $orderType)->select()->toArray();
- } else {
- $data = $query->order($orderBy, $orderType)->paginate($limit)->toArray();
- }
- $data['data'] = array_map(function($item) {
- $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
- $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
- return $item;
- }, $data['data']);
-
- $data['data'] = $this->trandformListColumn($data['data'],['auth']);
- return $data;
- }
- /**
- * 添加/解除封禁
- */
- public function saveBan($data)
- {
- $type = $data['type']; // 封禁类型
- $value = $data['value']; // 封禁值
- $action = $data['action']; // 操作
- $reason = $data['reason']; // 理由
- $auth_id = $data['auth_id']; // 操作人
- $data = Db::connect('db_game_log')->table('ban_log')->insert([
- 'type' => $type,
- 'value' => $value,
- 'action' => $action,
- 'reason' => $reason,
- 'auth_id' => $auth_id,
- ]);
- // 如果成功插入,则更新redis
- if($data){
- $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
- $value = explode(',', $value);
- $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
- }
- return $data;
- }
- }
|