AccountLogic.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. $item['pay_time'] = $item['pay_time'] == 0 ? '' : date('Y-m-d H:i:s', $item['pay_time']);
  38. $item['id_card'] = $item['id_card'] == '' ? '' : substr($item['id_card'], 0, 4).'****'.substr($item['id_card'], -4);
  39. unset($item['user_pwd']);
  40. return $item;
  41. }, $data);
  42. return $data;
  43. }
  44. /**
  45. * 修改密码
  46. */
  47. public function updatePwd($data)
  48. {
  49. $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
  50. return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
  51. }
  52. /**
  53. * 修改手机
  54. */
  55. public function updateMobile($data)
  56. {
  57. return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
  58. }
  59. /**
  60. * 修改真实名
  61. */
  62. public function updateReal($data)
  63. {
  64. 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']]);
  65. }
  66. /**
  67. * 封禁列表
  68. */
  69. public function getBanList($query)
  70. {
  71. $saiType = request()->input('saiType', 'list');
  72. $page = request()->input('page', 1);
  73. $limit = request()->input('limit', 10);
  74. $orderBy = request()->input('orderBy', '');
  75. $orderType = request()->input('orderType', $this->orderType);
  76. if(empty($orderBy)) {
  77. $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
  78. }
  79. if ($saiType === 'all') {
  80. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray();
  81. }else{
  82. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit)->toArray();
  83. }
  84. $data['data'] = array_map(function($item) {
  85. $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
  86. $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
  87. return $item;
  88. }, $data['data']);
  89. $data['data'] = $this->trandformListColumn($data['data'],['auth']);
  90. return $data;
  91. }
  92. /**
  93. * 添加/解除封禁
  94. */
  95. public function saveBan($data)
  96. {
  97. $type = $data['type']; // 封禁类型
  98. $value = $data['value']; // 封禁值
  99. $action = $data['action']; // 操作
  100. $reason = $data['reason']; // 理由
  101. $auth_id = $data['auth_id']; // 操作人
  102. $data = Db::connect('db_game_log')->table('ban_log')->insert([
  103. 'type' => $type,
  104. 'value' => $value,
  105. 'action' => $action,
  106. 'reason' => $reason,
  107. 'auth_id' => $auth_id,
  108. ]);
  109. // 如果成功插入,则更新redis
  110. if($data){
  111. $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
  112. $value = explode(',', $value);
  113. $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
  114. }
  115. return $data;
  116. }
  117. }