DepositSearch.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace backend\models\searches;
  3. use backend\models\DepositApi;
  4. use common\helpers\ExcelHelper;
  5. use common\helpers\UserAgentHelper;
  6. use Yii;
  7. use yii\data\ArrayDataProvider;
  8. use yii\data\Pagination;
  9. use yii\helpers\Url;
  10. class DepositSearch extends DataTable
  11. {
  12. public $sTime;
  13. public $eTime;
  14. public $name;
  15. public $type;
  16. /**
  17. * @inheritdoc
  18. */
  19. public function rules()
  20. {
  21. $rules = parent::rules();
  22. $rules[] = [['sTime', 'eTime', 'name', 'type'], 'safe'];
  23. return $rules;
  24. }
  25. /**
  26. * @param array $params
  27. * @param null|string $from
  28. * @return ArrayDataProvider
  29. */
  30. public function search($params, $from = null)
  31. {
  32. $this->setAttributes($params);
  33. // 初始化DataTable查询参数
  34. $this->initSearchParams();
  35. $pagination = new Pagination();
  36. $pagination->setPageSize($this->pageSize);
  37. $data['pageSize'] = $pagination->getPageSize();
  38. $data['page'] = $this->page;
  39. if ($this->orderBy) {
  40. $data['orderBy'] = $this->orderBy;
  41. }
  42. if (!empty($this->search['value']) && trim($this->search['value']) !== '') {
  43. $data['search'] = trim($this->search['value']);
  44. }
  45. if ($from == 'admin') {
  46. $data['from'] = $from;
  47. if ($this->sTime && ($inTimeStart = strtotime($this->sTime))) {
  48. $data['inTimeStart'] = $inTimeStart * 1000;
  49. }
  50. if ($this->eTime && ($inTimeEnd = strtotime($this->eTime))) {
  51. $data['inTimeEnd'] = $inTimeEnd * 1000;
  52. }
  53. $this->name && $data['name'] = $this->name;
  54. is_numeric($this->type) && $data['type'] = $this->type;
  55. } else {
  56. $data['memberId'] = Yii::$app->getUser()->getId();
  57. }
  58. if ($this->pageSize > 5000) {
  59. if (Yii::$app->getRequest()->getIsAjax()) {
  60. Yii::$app->getResponse()->redirect(Url::current(), UserAgentHelper::isIE() ? 200 : 302);
  61. } else {
  62. $this->exportXls($data);
  63. }
  64. Yii::$app->end();
  65. }
  66. $api = new DepositApi();
  67. $result = $api->getDepositList($data);
  68. $models = [];
  69. if ($result['code'] == 1) {
  70. $models = (array)$result['data']['dataList'];
  71. $pagination->totalCount = $result['data']['totalCount'];
  72. }
  73. $dataProvider = new ArrayDataProvider([
  74. 'models' => $models,
  75. 'pagination' => $pagination,
  76. 'totalCount' => $pagination->totalCount,
  77. ]);
  78. return $dataProvider;
  79. }
  80. /**
  81. * @param array $data
  82. */
  83. private function exportXls($data)
  84. {
  85. ExcelHelper::init();
  86. $attachmentName = "入金管理_" . date('Y-m-d') . '.xlsx';
  87. $header = ['交易编号', '状态', '代理商', '账户', '姓名', '手机', '金额', '人民币', '汇率', '入金方式', '入金时间', '操作人'];
  88. $source = [];
  89. $api = new DepositApi();
  90. $data['pageSize'] = 5000;
  91. $data['page'] = 1;
  92. while (true) {
  93. $result = $api->getDepositList($data);
  94. if ($result['code'] == 1 && !empty($result['data']['dataList'])) {
  95. foreach ((array)$result['data']['dataList'] as $key => $row) {
  96. $arr = [];
  97. $arr[] = "SN{$row['id']}";
  98. if ($row['type'] == 1) {
  99. $arr[] = "成功";
  100. } else {
  101. $arr[] = "等待";
  102. }
  103. $arr[] = $row['IBNAME'];
  104. $arr[] = $row['login'];
  105. $arr[] = $row['name'];
  106. $arr[] = $row['mobile'];
  107. $arr[] = $row['amount'];
  108. $arr[] = $row['rmb'];
  109. $arr[] = $row['rate'];
  110. $arr[] = $row['pay_name'];
  111. $arr[] = date('Y-m-d H:i:s', intval($row['in_time'] / 1000));
  112. $arr[] = $row['admin_name'];
  113. $source[] = $arr;
  114. }
  115. } else {
  116. break;
  117. }
  118. if ($data['page'] * $data['pageSize'] >= $result['data']['totalCount']) {
  119. break;
  120. }
  121. $data['page']++;
  122. }
  123. ExcelHelper::output($source, $header, $attachmentName);
  124. }
  125. }