123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * TeamIncomeLogic.php UTF-8
- * 团队收益排行
- *
- * @date : 2018/8/18 14:48
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HuoMP 1.0
- */
- namespace huomp\logic\member;
- use huo\controller\agent\AgentCache;
- use huo\controller\finance\AoRequest;
- use huo\controller\member\MemCache;
- use huo\model\agent\AgentOrderModel;
- use huo\model\common\CommonModel;
- use huo\model\member\MemberModel;
- use huo\model\user\UserModel;
- use huolib\tool\StrUtils;
- class TeamIncomeLogic extends CommonModel {
- protected function getWhere($param = []) {
- $_map = [];
- if (!empty($param['parent_id'])) {
- $_map['parent_id'] = $param['parent_id'];
- }
- return $_map;
- }
- public function getIncomeRankList($agent_id, $param = [], $page = '1,10') {
- $_where = $this->getWhere($param);
- $_where['share_total'] = ['gt', 0];
- $_field = [];
- $_data_list = $this->getList($agent_id, $_field, $_where, $page);
- $_agent_info = (new AgentCache())->getInfoByAgentId($agent_id);
- $_today_cnt = (new MemberModel())->todayCount(['parent_mem_id' => $_agent_info['mem_id']]);
- $_today_cnt_arr = ['today_cnt' => $_today_cnt];
- return array_merge($_data_list, $_today_cnt_arr);
- }
- public function getList($agent_id, $field = [], $where = [], $page = '1,10') {
- $_model = new UserModel();
- $_count = $_model->with('ext')->where($where)->count();
- $_count += 1;
- $_order = 'share_total desc';
- $_data_list = $_model->with('ext')
- ->field($field)
- ->where($where)
- ->whereOr('id', '=', $agent_id)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_data_list)) {
- $_data_list = $_data_list->toArray();
- }
- $_data = [];
- $_mem_cache = new MemCache();
- foreach ($_data_list as $key => $value) {
- $_mem_info = $_mem_cache->getInfoById($value['mem_id']);
- $_me_data = $_mem_cache->getMeInfoById($value['mem_id']);
- $_share_total = !empty($value['ext']) ? $value['ext']['share_total'] : 0;
- $_data[] = [
- 'id' => $value['mem_id'],
- 'avatar' => !empty($_mem_info) ? $_mem_info['avatar'] : '',
- 'nickname' => !empty($_mem_info) ? $_mem_info['nickname'] : '',
- 'amount' => StrUtils::formatNumber($_share_total),
- 'integral_total' => !empty($_me_data) ? intval($_me_data['integral_total']) : 0,
- ];
- }
- return [
- 'count' => $_count,
- 'list' => $_data,
- ];
- }
- /**
- * 成员自己获得的收益记录
- *
- * @param $agent_id
- * @param string $page
- *
- * @return array
- */
- public function getIncomeList($agent_id, $page = '1,10') {
- $_flag = [AoRequest::FLAG_REGISTER, AoRequest::FLAG_OPEN_GAME];
- $_model = new AgentOrderModel();
- $_count = $_model->where('agent_id', '=', $agent_id)
- ->where('flag', 'in', $_flag)
- ->count();
- if (empty($_count)) {
- return [
- 'count' => $_count,
- 'list' => [],
- ];
- }
- $_order = 'create_time desc';
- $_data_list = $_model->where('agent_id', '=', $agent_id)
- ->where('flag', 'in', $_flag)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_data_list)) {
- $_data_list = $_data_list->toArray();
- }
- if (empty($_data_list)) {
- return [
- 'count' => $_count,
- 'list' => [],
- ];
- }
- $_data = [];
- $_agent_cache = new AgentCache();
- $_memcache = new MemCache();
- $_agent_info = $_agent_cache->getInfoByAgentId($agent_id);
- $_mem_info = $_memcache->getInfoById($_agent_info['mem_id']);
- foreach ($_data_list as $_ao_data) {
- $_data[] = [
- 'id' => $_ao_data['id'],
- 'title' => !empty($_mem_info) ? $_mem_info['nickname'] : '',
- 'icon' => !empty($_mem_info) ? $_mem_info['avatar'] : '',
- 'desc' => $_ao_data['remark'],
- 'amount' => StrUtils::formatNumber($_ao_data['agent_gain']),
- 'create_time' => $_ao_data['create_time'],
- ];
- }
- return [
- 'count' => $_count,
- 'list' => $_data,
- ];
- }
- }
|