TeamIncomeLogic.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * TeamIncomeLogic.php UTF-8
  4. * 团队收益排行
  5. *
  6. * @date : 2018/8/18 14:48
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HuoMP 1.0
  11. */
  12. namespace huomp\logic\member;
  13. use huo\controller\agent\AgentCache;
  14. use huo\controller\finance\AoRequest;
  15. use huo\controller\member\MemCache;
  16. use huo\model\agent\AgentOrderModel;
  17. use huo\model\common\CommonModel;
  18. use huo\model\member\MemberModel;
  19. use huo\model\user\UserModel;
  20. use huolib\tool\StrUtils;
  21. class TeamIncomeLogic extends CommonModel {
  22. protected function getWhere($param = []) {
  23. $_map = [];
  24. if (!empty($param['parent_id'])) {
  25. $_map['parent_id'] = $param['parent_id'];
  26. }
  27. return $_map;
  28. }
  29. public function getIncomeRankList($agent_id, $param = [], $page = '1,10') {
  30. $_where = $this->getWhere($param);
  31. $_where['share_total'] = ['gt', 0];
  32. $_field = [];
  33. $_data_list = $this->getList($agent_id, $_field, $_where, $page);
  34. $_agent_info = (new AgentCache())->getInfoByAgentId($agent_id);
  35. $_today_cnt = (new MemberModel())->todayCount(['parent_mem_id' => $_agent_info['mem_id']]);
  36. $_today_cnt_arr = ['today_cnt' => $_today_cnt];
  37. return array_merge($_data_list, $_today_cnt_arr);
  38. }
  39. public function getList($agent_id, $field = [], $where = [], $page = '1,10') {
  40. $_model = new UserModel();
  41. $_count = $_model->with('ext')->where($where)->count();
  42. $_count += 1;
  43. $_order = 'share_total desc';
  44. $_data_list = $_model->with('ext')
  45. ->field($field)
  46. ->where($where)
  47. ->whereOr('id', '=', $agent_id)
  48. ->order($_order)
  49. ->page($page)
  50. ->select();
  51. if (is_object($_data_list)) {
  52. $_data_list = $_data_list->toArray();
  53. }
  54. $_data = [];
  55. $_mem_cache = new MemCache();
  56. foreach ($_data_list as $key => $value) {
  57. $_mem_info = $_mem_cache->getInfoById($value['mem_id']);
  58. $_me_data = $_mem_cache->getMeInfoById($value['mem_id']);
  59. $_share_total = !empty($value['ext']) ? $value['ext']['share_total'] : 0;
  60. $_data[] = [
  61. 'id' => $value['mem_id'],
  62. 'avatar' => !empty($_mem_info) ? $_mem_info['avatar'] : '',
  63. 'nickname' => !empty($_mem_info) ? $_mem_info['nickname'] : '',
  64. 'amount' => StrUtils::formatNumber($_share_total),
  65. 'integral_total' => !empty($_me_data) ? intval($_me_data['integral_total']) : 0,
  66. ];
  67. }
  68. return [
  69. 'count' => $_count,
  70. 'list' => $_data,
  71. ];
  72. }
  73. /**
  74. * 成员自己获得的收益记录
  75. *
  76. * @param $agent_id
  77. * @param string $page
  78. *
  79. * @return array
  80. */
  81. public function getIncomeList($agent_id, $page = '1,10') {
  82. $_flag = [AoRequest::FLAG_REGISTER, AoRequest::FLAG_OPEN_GAME];
  83. $_model = new AgentOrderModel();
  84. $_count = $_model->where('agent_id', '=', $agent_id)
  85. ->where('flag', 'in', $_flag)
  86. ->count();
  87. if (empty($_count)) {
  88. return [
  89. 'count' => $_count,
  90. 'list' => [],
  91. ];
  92. }
  93. $_order = 'create_time desc';
  94. $_data_list = $_model->where('agent_id', '=', $agent_id)
  95. ->where('flag', 'in', $_flag)
  96. ->order($_order)
  97. ->page($page)
  98. ->select();
  99. if (is_object($_data_list)) {
  100. $_data_list = $_data_list->toArray();
  101. }
  102. if (empty($_data_list)) {
  103. return [
  104. 'count' => $_count,
  105. 'list' => [],
  106. ];
  107. }
  108. $_data = [];
  109. $_agent_cache = new AgentCache();
  110. $_memcache = new MemCache();
  111. $_agent_info = $_agent_cache->getInfoByAgentId($agent_id);
  112. $_mem_info = $_memcache->getInfoById($_agent_info['mem_id']);
  113. foreach ($_data_list as $_ao_data) {
  114. $_data[] = [
  115. 'id' => $_ao_data['id'],
  116. 'title' => !empty($_mem_info) ? $_mem_info['nickname'] : '',
  117. 'icon' => !empty($_mem_info) ? $_mem_info['avatar'] : '',
  118. 'desc' => $_ao_data['remark'],
  119. 'amount' => StrUtils::formatNumber($_ao_data['agent_gain']),
  120. 'create_time' => $_ao_data['create_time'],
  121. ];
  122. }
  123. return [
  124. 'count' => $_count,
  125. 'list' => $_data,
  126. ];
  127. }
  128. }