RoleDataLogic.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\RoleData;
  12. use support\think\Db;
  13. /**
  14. * 角色查询逻辑层
  15. */
  16. class RoleDataLogic extends BaseLogic
  17. {
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct()
  22. {
  23. $this->model = new RoleData();
  24. }
  25. /**
  26. * 获取角色查询列表
  27. */
  28. public function getRoleList($query)
  29. {
  30. // 获取android数据
  31. $table_and = Db::connect('db_game_log')->table('role_data_and')->field('* , "android" as platform')->where($query)->select()->toArray();
  32. // 获取ios数据
  33. $table_ios = Db::connect('db_game_log')->table('role_data_ios')->field('* , "ios" as platform')->where($query)->select()->toArray();
  34. // 合并两个表的数据
  35. $data = array_merge($table_and, $table_ios);
  36. // 1. 根据game_id 查找 main_id
  37. $game_ids = array_unique(array_column($data, 'game_id'));
  38. $main_id_arr = Db::connect('db_center')->table('pf_game')->whereIn('id', $game_ids)->column('main_id','id');
  39. $data = array_map(function($item) use ($main_id_arr){
  40. // 最后登录时间
  41. $item['login_time'] = Db::connect('db_origin')->table('agent_reg_'.$item['uid']%10)->where('main_id', $main_id_arr[$item['game_id']])->where('uid', $item['uid'])->value('login_time');
  42. $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
  43. // 支付记录
  44. $pay_data = Db::connect('db_game_log')->table('sdk_order_success')->where('game_id', $item['game_id'])->where('uid', $item['uid'])->where('role_id', $item['role_id'])->order('pay_date', 'desc');
  45. // 最新的一条支付记录时间
  46. $item['last_recharge_time'] = $pay_data->value('pay_date');
  47. // 累计充值
  48. $item['total_recharge'] = $pay_data->sum('money');
  49. return $item;
  50. }, $data);
  51. $data = $this->trandformListColumn($data,['game','media','site', 'agent']);
  52. return $data;
  53. }
  54. /**
  55. * 更新
  56. */
  57. public function update($id, $data)
  58. {
  59. $platform = $data['platform'];
  60. $table = $platform === 'android' ? 'role_data_and' : 'role_data_ios';
  61. // 移除platform字段,避免更新到数据库
  62. unset($data['platform']);
  63. // 直接使用Db更新指定表的数据
  64. $result = Db::connect('db_game_log')
  65. ->table($table)
  66. ->where('id', $id)
  67. ->update($data);
  68. if ($result === false) {
  69. throw new ApiException('更新失败');
  70. }
  71. return $result;
  72. }
  73. }