123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <?php
- /**
- * RankDataLogic.php UTF-8
- *
- *
- * @date : 5/22/2018 5:25 PM
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\data;
- use huo\logic\agent\AgentLogic;
- use huo\model\common\CommonModel;
- use huo\model\data\DayAgentModel;
- use huo\model\data\DayGameAgentModel;
- use huo\model\data\DayGameModel;
- use huo\model\data\DayModel;
- use huo\model\game\GameModel;
- class RankDataLogic extends CommonModel {
- private $sum_field
- = [
- 'sum(user_cnt)' => 'user_cnt',
- 'sum(reg_device_cnt)' => 'reg_device_cnt',
- 'sum(reg_cnt)' => 'reg_cnt',
- 'sum(pay_user_cnt)' => 'pay_user_cnt',
- 'sum(reg_order_cnt)' => 'reg_order_cnt',
- 'sum(reg_pay_cnt)' => 'reg_pay_cnt',
- 'sum(sum_money)' => 'sum_money',
- 'sum(reg_sum_money)' => 'reg_sum_money',
- ];
- /**
- * @param array $param
- *
- * @return array
- */
- protected function getWhere($param = []) {
- $_map = [];
- 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['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- if (!empty($param['agent_id'])) {
- if ($param['agent_id'] == -1) {
- $_map['agent_id'] = 0;
- } else {
- $_map['agent_id'] = $param['agent_id'];
- }
- }
- return $_map;
- }
- public function getDataModel($where) {
- if (isset($where['agent_id']) && isset($where['app_id'])) {
- return new DayGameAgentModel();
- } elseif (isset($where['agent_id'])) {
- return new DayGameAgentModel();
- } elseif (isset($where['app_id'])) {
- return new DayGameAgentModel();
- } else {
- return new DayGameModel();
- }
- }
- /**
- * 获取组条件
- *
- * @param array $where
- *
- * @return string
- */
- public function getGroup($where) {
- if (isset($where['agent_id']) && isset($where['app_id'])) {
- $_group = 'app_id,agent_id';
- } elseif (isset($where['agent_id'])) {
- $_group = 'app_id,agent_id';
- } elseif (isset($where['app_id'])) {
- $_group = 'app_id,agent_id';
- } else {
- $_group = 'app_id';
- }
- return $_group;
- }
- /**
- * 获取关联
- *
- * @param $where
- *
- * @return string
- */
- public function getWith($where) {
- if (isset($where['app_id']) && isset($where['agent_id'])) {
- $_with = 'agent,game';
- } elseif (isset($where['app_id'])) {
- $_with = 'agent,game';
- } elseif (isset($where['agent_id'])) {
- $_with = 'agent,game';
- } else {
- $_with = 'game';
- }
- return $_with;
- }
- /**
- * 获取关联
- *
- * @param $where
- *
- * @return array
- */
- public function getField($where) {
- $_field = $this->sum_field;
- if (isset($where['app_id']) && !isset($where['agent_id'])) {
- $_field['app_id'] = 'app_id';
- $_field['agent_id'] = 'agent_id';
- } elseif (isset($where['app_id'])) {
- $_field['agent_id'] = 'agent_id';
- $_field['app_id'] = 'app_id';
- } elseif (isset($where['agent_id'])) {
- $_field['agent_id'] = 'agent_id';
- $_field['app_id'] = 'app_id';
- } else {
- $_field['app_id'] = 'app_id';
- }
- return $_field;
- }
- public function getAgentDataModel($where) {
- if (isset($where['agent_id']) && isset($where['app_id'])) {
- return new DayGameAgentModel();
- } elseif (isset($where['agent_id'])) {
- return new DayGameAgentModel();
- } elseif (isset($where['app_id'])) {
- return new DayGameAgentModel();
- } else {
- return new DayAgentModel();
- }
- }
- /**
- * 获取关联
- *
- * @param $where
- *
- * @return string
- */
- public function getAgentWith($where) {
- if (isset($where['app_id']) && isset($where['agent_id'])) {
- $_with = 'agent,agent.parent,game';
- } elseif (isset($where['app_id'])) {
- $_with = 'agent,agent.parent,game';
- } elseif (isset($where['agent_id'])) {
- $_with = 'agent,agent.parent,game';
- } else {
- $_with = 'agent';
- }
- return $_with;
- }
- /**
- * 获取关联
- *
- * @param $where
- *
- * @return array
- */
- public function getAgentField($where) {
- $_field = $this->sum_field;
- if (isset($where['app_id']) && !isset($where['agent_id'])) {
- $_field['app_id'] = 'app_id';
- $_field['agent_id'] = 'agent_id';
- } elseif (isset($where['app_id'])) {
- $_field['agent_id'] = 'agent_id';
- $_field['app_id'] = 'app_id';
- } elseif (isset($where['agent_id'])) {
- $_field['agent_id'] = 'agent_id';
- $_field['app_id'] = 'app_id';
- } else {
- $_field['agent_id'] = 'agent_id';
- }
- return $_field;
- }
- /**
- * 获取组条件
- *
- * @param array $where
- *
- * @return string
- */
- public function getAgentGroup($where) {
- if (isset($where['agent_id']) && isset($where['app_id'])) {
- $_group = 'app_id,agent_id';
- } elseif (isset($where['agent_id'])) {
- $_group = 'app_id,agent_id';
- } elseif (isset($where['app_id'])) {
- $_group = 'app_id,agent_id';
- } else {
- $_group = 'agent_id';
- }
- return $_group;
- }
- /**
- * 游戏排行
- *
- * @param $param
- * @param int $_list_rows
- * @param string $order
- *
- * @return \think\Paginator
- * @throws \think\exception\DbException
- */
- public function game($param, $_list_rows = 10, $order = '-sum_money') {
- if (!empty($param['game_name'])) {
- $_where['name'] = ['like', "{$param['game_name']}%"];
- $_app_id = (new GameModel())->getIdsByWhere($_where);
- $param['app_id'] = ['in', $_app_id];
- }
- if (!empty($param['classify'])) {
- $_where['classify'] = ['=', "{$param['classify']}"];
- $_app_id = (new GameModel())->getIdsByWhere($_where);
- $param['app_id'] = ['in', $_app_id];
- }
- if (!empty($param['rank_by'])) {
- $order = '-'.$param['rank_by'];
- }
- if (!empty($param['agent_id'])) {
- if (isset($param['agent_summary'])) {
- $_agent_id_names = (new AgentLogic())->getIdNames($param['agent_id'], true);
- $_agent_ids = array_keys($_agent_id_names);
- $param['agent_id'] = ['in', $_agent_ids];
- }
- }
- $_map = $this->getWhere($param);
- // $_filed = $this->sum_field;
- // $_filed['app_id'] = 'app_id';
- // $_model = new DayGameModel();
- $_model = $this->getDataModel($_map);
- $_group = $this->getGroup($_map);
- $_with = $this->getWith($_map);
- $_filed = $this->getField($_map);
- $_order = $this->orderFilter($order);
- $_items = $_model->with($_with)
- ->field($_filed)
- ->where($_map)
- ->order($_order)
- ->group($_group)
- ->paginate($_list_rows);
- return $_items;
- }
- public function agent($param, $_list_rows = 10, $order = '-sum_money') {
- if (!empty($param['game_name'])) {
- $_where['name'] = ['like', "{$param['game_name']}%"];
- $_app_id = (new GameModel())->getIdsByWhere($_where);
- $param['app_id'] = ['in', $_app_id];
- }
- if (!empty($param['classify'])) {
- $_where['classify'] = ['=', "{$param['classify']}"];
- $_app_id = (new GameModel())->getIdsByWhere($_where);
- $param['app_id'] = ['in', $_app_id];
- }
- if (!empty($param['rank_by'])) {
- $order = '-'.$param['rank_by'];
- }
- if (!empty($param['agent_id'])) {
- if (isset($param['agent_summary'])) {
- $_agent_id_names = (new AgentLogic())->getIdNames($param['agent_id'], true);
- $_agent_ids = array_keys($_agent_id_names);
- $param['agent_id'] = ['in', $_agent_ids];
- }
- }
- $_map = $this->getWhere($param);
- // $_filed = $this->sum_field;
- // $_filed['agent_id'] = 'agent_id';
- // $_model = new DayAgentModel();
- $_model = $this->getAgentDataModel($_map);
- $_group = $this->getAgentGroup($_map);
- $_with = $this->getAgentWith($_map);
- $_filed = $this->getAgentField($_map);
- $_order = $this->orderFilter($order);
- $_items = $_model->with($_with)
- ->field($_filed)
- ->where($_map)
- ->order($_order)
- ->group($_group)
- ->paginate($_list_rows);;
- return $_items;
- }
- }
|