123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- /**
- * DayAgentLogic.php UTF-8
- *
- *
- * @date : 2018/8/17 11:15
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HuoMP 1.0
- */
- namespace huomp\logic\data;
- use huo\controller\agent\AgentCache;
- use huo\controller\member\MemCache;
- use huo\model\common\CommonModel;
- use huo\model\data\DayAgentModel;
- use huolib\tool\StrUtils;
- class DayAgentLogic extends CommonModel {
- public function getWhere($param = []) {
- $_map = [];
- if (!empty($param['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- }
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['date'] = ['between', [$param['start_time'], $param['end_time']]];
- } elseif (!empty($param['start_time'])) {
- $_map['date'] = ['egt', $param['start_time']];
- } elseif (!empty($param['end_time'])) {
- $_map['date'] = ['elt', $param['end_time']];
- }
- if (!empty($param['role_id'])) {
- $_map['mpagent.role_id'] = $param['role_id'];
- }
- return $_map;
- }
- public function getRankList($agent_id, $where, $page = '1,10') {
- $_map = $this->getWhere($where);
- $_field = [
- 'sum(reg_cnt)' => 'sum_reg_cnt',
- 'sum(share_money)' => 'sum_share_money',
- ];
- $_data = $this->getList($_field, $_map, $page);
- $_ranking = $this->getRanking($agent_id, $_field, $_map);
- return array_merge($_data, ['ranking' => $_ranking]);
- }
- public function getList($field, $where, $page = '1,10') {
- $_model = new DayAgentModel();
- $_count = $_model->with('mpagent')->where($where)->group('day_agent_model.agent_id')->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => [],
- ];
- }
- $_order = 'sum_share_money desc';
- $_data_list = $_model->with('mpagent')
- ->field($field)
- ->where($where)
- ->order($_order)
- ->page($page)
- ->group('day_agent_model.agent_id')
- ->select();
- if (is_object($_data_list)) {
- $_data_list = $_data_list->toArray();
- }
- if (empty($_data_list)) {
- return [
- 'count' => 0,
- 'list' => [],
- ];
- }
- $_data = [];
- $_mem_cache = new MemCache();
- $_agent_cache = new AgentCache();
- foreach ($_data_list as $_item) {
- $_agent_info = $_agent_cache->getInfoByAgentId($_item['agent_id']);
- $_mem_info = $_mem_cache->getInfoById($_agent_info['mem_id']);
- $_data[] = [
- 'avatar' => !empty($_mem_info) ? $_mem_info['avatar'] : '',
- 'nickname' => !empty($_mem_info) ? $_mem_info['nickname'] : '',
- 'mem_id' => $_agent_info['mem_id'],
- 'agent_id' => $_item['agent_id'],
- 'reg_cnt' => StrUtils::formatNumber($_item['sum_reg_cnt']),
- 'share_total' => StrUtils::formatNumber($_item['sum_share_money']),
- ];
- }
- return [
- 'count' => $_count,
- 'list' => $_data,
- ];
- }
- /**
- * 获取排名
- * @param $agent_id
- * @param $field
- * @param $where
- *
- * @return int|string
- */
- public function getRanking($agent_id, $field, $where) {
- $_model = new DayAgentModel();
- $_order = 'sum_share_money desc';
- $_day_agent_info = $_model->with('mpagent')
- ->field($field)
- ->where($where)
- ->where('day_agent_model.agent_id', '=', $agent_id)
- ->order($_order)
- ->group('day_agent_model.agent_id')
- ->find();
- if (is_object($_day_agent_info)) {
- $_day_agent_info = $_day_agent_info->toArray();
- }
- $_agent_share_total = !empty($_day_agent_info) ? $_day_agent_info['sum_share_money'] : 0;
- $_ranking = $_model->with('mpagent')
- ->field($field)
- ->where($where)
- ->group('day_agent_model.agent_id')
- ->having('sum_share_money>'.$_agent_share_total)
- ->order($_order)
- ->count();
- $_ranking += 1;
- return $_ranking;
- }
- }
|