AccountLogic.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\v1\logic\customer;
  3. use plugin\saiadmin\basic\BaseLogic;
  4. use plugin\saiadmin\exception\ApiException;
  5. use plugin\saiadmin\utils\Helper;
  6. use app\v1\model\customer\Account;
  7. use support\Redis;
  8. use support\think\Db;
  9. /**
  10. * 账号信息逻辑层
  11. */
  12. class AccountLogic extends BaseLogic
  13. {
  14. /**
  15. * 构造函数
  16. */
  17. public function __construct()
  18. {
  19. $this->model = new Account();
  20. }
  21. /**
  22. * 列表
  23. */
  24. public function list($query)
  25. {
  26. if($query['type'] == '1'){
  27. $uid = Db::connect('db_origin')->table('users')->where('user_name', $query['val'])->value('uid');
  28. $data = Db::connect('db_origin')->table('user_'.$uid%10)->where('uid', $uid)->select()->toArray();
  29. }else{
  30. $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray();
  31. }
  32. $data = array_map(function($item){
  33. $item['login_ip'] = $item['login_ip'].getIpLocation($item['login_ip']);
  34. $item['reg_ip'] = $item['reg_ip'].getIpLocation($item['reg_ip']);
  35. $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
  36. $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
  37. unset($item['user_pwd']);
  38. return $item;
  39. }, $data);
  40. return $data;
  41. }
  42. /**
  43. * 修改密码
  44. */
  45. public function updatePwd($data)
  46. {
  47. $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
  48. return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
  49. }
  50. /**
  51. * 修改手机
  52. */
  53. public function updateMobile($data)
  54. {
  55. return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
  56. }
  57. /**
  58. * 修改真实名
  59. */
  60. public function updateReal($data)
  61. {
  62. 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']]);
  63. }
  64. /**
  65. * 封禁列表
  66. */
  67. public function getBanList($query)
  68. {
  69. $saiType = request()->input('saiType', 'list');
  70. $page = request()->input('page', 1);
  71. $limit = request()->input('limit', 10);
  72. $orderBy = request()->input('orderBy', '');
  73. $orderType = request()->input('orderType', $this->orderType);
  74. if(empty($orderBy)) {
  75. $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
  76. }
  77. if ($saiType === 'all') {
  78. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray();
  79. }else{
  80. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit)->toArray();
  81. }
  82. $data['data'] = array_map(function($item) {
  83. $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
  84. $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
  85. return $item;
  86. }, $data['data']);
  87. $data['data'] = $this->trandformListColumn($data['data'],['auth']);
  88. return $data;
  89. }
  90. /**
  91. * 添加/解除封禁
  92. */
  93. public function saveBan($data)
  94. {
  95. $type = $data['type']; // 封禁类型
  96. $value = $data['value']; // 封禁值
  97. $action = $data['action']; // 操作
  98. $reason = $data['reason']; // 理由
  99. $auth_id = $data['auth_id']; // 操作人
  100. $data = Db::connect('db_game_log')->table('ban_log')->insert([
  101. 'type' => $type,
  102. 'value' => $value,
  103. 'action' => $action,
  104. 'reason' => $reason,
  105. 'auth_id' => $auth_id,
  106. ]);
  107. // 如果成功插入,则更新redis
  108. if($data){
  109. $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
  110. $value = explode(',', $value);
  111. $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
  112. }
  113. return $data;
  114. }
  115. }