Transformer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CatchAdmin [Just Like ~ ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
  8. // +----------------------------------------------------------------------
  9. // | Author: JaguarJack [ njphper@gmail.com ]
  10. // +----------------------------------------------------------------------
  11. namespace catchAdmin\domain\support;
  12. use think\Paginator;
  13. class Transformer
  14. {
  15. /**
  16. * 分页展示
  17. *
  18. * @param array $data
  19. * @return mixed
  20. */
  21. public static function aliyunDomainPaginate(array $data)
  22. {
  23. $list = [];
  24. foreach ($data['Domains']['Domain'] as $item) {
  25. $list[] = [
  26. 'name' => $item['DomainName'],
  27. 'created_at' => date('Y-m-d', $item['CreateTimestamp']/1000),
  28. 'dns_server' => $item['DnsServers']['DnsServer'],
  29. 'from' => $item['VersionName'],
  30. 'free' => $item['VersionCode'] === 'mianfei',
  31. 'record_count' => $item['RecordCount'],
  32. 'tags' => $item['Tags']['Tag'],
  33. 'id' => $item['DomainId']
  34. ];
  35. }
  36. return Paginator::make($list, $data['PageSize'], $data['PageNumber'], $data['TotalCount']);
  37. }
  38. /**
  39. * 腾讯云域名列表
  40. *
  41. * @param array $data
  42. * @param $page
  43. * @param $limit
  44. * @return Paginator|\think\paginator\driver\Bootstrap
  45. */
  46. public static function qcloudDomainPaginate(array $data, $page, $limit)
  47. {
  48. $info = $data['data']['info'];
  49. $domains = $data['data']['domains'];
  50. $list = [];
  51. foreach ($domains as $item) {
  52. $list[] = [
  53. 'name' => $item['name'],
  54. 'created_at' => $item['created_on'],
  55. 'dns_server' => [],
  56. 'from' => 'qcloud',
  57. 'free' => $item['grade'] === 'DP_Free',
  58. 'record_count' => $item['records'],
  59. 'tags' => [],
  60. 'id' => $item['id']
  61. ];
  62. }
  63. return Paginator::make($list, $limit, $page + 1,$info['domain_total']);
  64. }
  65. /**
  66. * 阿里云域名解析
  67. *
  68. * @param array $data
  69. * @return mixed
  70. */
  71. public static function aliyunDomainRecordPaginate(array $data)
  72. {
  73. $list = [];
  74. foreach ($data['DomainRecords']['Record'] as &$item) {
  75. $list[] = array_change_key_case($item);
  76. }
  77. return Paginator::make($list, $data['PageSize'], $data['PageNumber'], $data['TotalCount']);
  78. }
  79. /**
  80. * DNS 记录
  81. *
  82. * @param array $data
  83. * @param $page
  84. * @param $limit
  85. * @return Paginator|\think\paginator\driver\Bootstrap
  86. */
  87. public static function qcloudDomainRecordPaginate(array $data, $page, $limit)
  88. {
  89. $list = [];
  90. foreach ($data['data']['records'] as &$item) {
  91. $item['status'] = $item['status'] === 'enabled' ? 'ENABLE' : 'DISABLE';
  92. $item['rr'] = $item['name'];
  93. $item['recordid'] = $item['id'];
  94. $list[] = array_change_key_case($item);
  95. }
  96. return Paginator::make($list, $limit, $page + 1, $data['data']['info']['record_total']);
  97. }
  98. }