AgentCpaLogController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * AgentCpaLogController.php UTF-8
  4. * 渠道CPA记录
  5. *
  6. * @date : 2020/3/7 18:22
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOOA 1.0
  11. */
  12. namespace admin\admin\controller\financial;
  13. use cmf\controller\AdminBaseController;
  14. use cmf\view\Filter;
  15. use huo\logic\agent\AgentCpaLogLogic;
  16. use huolib\constant\AgentConst;
  17. use huolib\tool\Export;
  18. class AgentCpaLogController extends AdminBaseController {
  19. public function _initialize() {
  20. parent::_initialize();
  21. }
  22. /**
  23. * 列表
  24. */
  25. public function index() {
  26. if ('1' == $this->request->param('export/d', 0)) {
  27. return $this->export();
  28. }
  29. $_param = $this->getSearchParam();
  30. $_page = $this->request->param('page/d', 1);
  31. $_list_rows = $this->request->param('list_rows/d', 10);
  32. $_data = (new AgentCpaLogLogic())->getAdminList($_param, $_page.','.$_list_rows);
  33. $_page_data = \huolib\tool\Page::paginate($_data['count'], $_data['list'], $_page, $_list_rows);
  34. $this->assign('items', $_page_data);
  35. $this->assign('page', $_page_data->render());
  36. return $this->fetch('index');
  37. }
  38. /**
  39. * 导出数据
  40. *
  41. */
  42. public function export() {
  43. $_param = $this->getSearchParam();
  44. $_p = 1;
  45. $_offset = Export::MAX_ROWS;
  46. $_page = $_p.','.$_offset;
  47. $_data = (new AgentCpaLogLogic())->getAdminList($_param, $_page);
  48. $_total_cnt = $_data['count'];
  49. if ($_total_cnt <= 0) {
  50. $_total_cnt = 1;
  51. }
  52. $_for_cnt = ceil($_total_cnt / $_offset);
  53. $_file_name_arr = [];
  54. $_file_name = '渠道CPA明细';
  55. while ($_p <= $_for_cnt) {
  56. $_head = [
  57. '时间',
  58. '记录号',
  59. '玩家账号',
  60. '注册IP',
  61. '游戏',
  62. '二级渠道',
  63. '二级CPA',
  64. '一级渠道',
  65. '一级CPA'
  66. ];
  67. $_export_datas = [];
  68. foreach ($_data['list'] as $_key => $_val) {
  69. $_export_data['create_time'] = date('Y-m-d H:i:s', $_val['create_time']);
  70. $_export_data['order_id'] = $_val['order_id'];
  71. $_export_data['username'] = $_val['username'];
  72. $_export_data['ip'] = $_val['ip'];
  73. $_export_data['game_name'] = $_val['game_name'];
  74. $_export_data['agent_name'] = $_val['agent_name'];
  75. $_export_data['agent_cpa'] = $_val['agent_cpa'];
  76. $_export_data['parent_name'] = $_val['parent_name'];
  77. $_export_data['parent_cpa'] = $_val['parent_cpa'];
  78. $_export_datas[] = $_export_data;
  79. }
  80. if (1 == $_for_cnt) {
  81. Export::exportCsv($_head, $_export_datas, $path = $this->admin_id, $_file_name, '.csv', true);
  82. break;
  83. } else {
  84. $_file_name = $_file_name.$_p;
  85. Export::exportCsv($_head, $_export_datas, $path = $this->admin_id, $_file_name);
  86. $_file_name_arr[] = $_file_name.'.csv';
  87. $_p++;
  88. if ($_p > 1) {
  89. $_data = null;
  90. $_page = $_p.','.$_offset;
  91. $_data = (new AgentCpaLogLogic())->getAdminList($_param, $_page);
  92. }
  93. }
  94. }
  95. Export::exportZip($_file_name_arr, $path = $this->admin_id, $_file_name);
  96. }
  97. /**
  98. * 获取请求参数
  99. */
  100. public function getSearchParam() {
  101. $_param = [];
  102. $agent_id = 0;
  103. if ($this->isAgent()) {
  104. $agent_id = $this->admin_id;
  105. }
  106. $_param['agent_id'] = $this->request->param('agent_id/d', $agent_id);
  107. $this->_agents($_param['agent_id'], false, [AgentConst::ROLE_TYPE_AGENT], true);
  108. $_param['parent_id'] = $this->request->param('parent_id/d', 0);
  109. $this->_agents($_param['parent_id'], false, [AgentConst::ROLE_TYPE_GROUP], true);
  110. $_param['start_time'] = $this->request->param('start_time', date('Y-m-d', strtotime('-1 month')));
  111. $_param['end_time'] = $this->request->param('end_time', date('Y-m-d'));
  112. $this->_time($_param['start_time'], $_param['end_time']);
  113. $_param['order_id'] = $this->request->param('order_id/s', '');
  114. $_order_text = Filter::text('order_id', $_param['order_id'], '请输入订单号');
  115. $this->assign('order_text', $_order_text);
  116. $_param['username'] = $this->request->param('username/s', '');
  117. $_username_text = Filter::text('username', $_param['username'], '请输入玩家账号');
  118. $this->assign('username_text', $_username_text);
  119. return $_param;
  120. }
  121. }