123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- <?php
- /**
- * AgentGameRateLogic.php UTF-8
- * 渠道游戏折扣逻辑
- *
- * @date : 2019/4/20 16:43
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.5
- */
- namespace huoRate\logic;
- use huo\controller\agent\AgentGame;
- use huo\controller\common\CommonFunc;
- use huo\logic\game\GameLogic;
- use huo\model\agent\AgentGameModel;
- use huo\model\common\CommonModel;
- use huo\model\game\GameModel;
- use huo\model\game\GameversionModel;
- use huo\model\user\RoleModel;
- use huo\model\user\UserModel;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huomp\controller\agent\AgentState;
- use huomp\model\game\GameMiniModel;
- use huoRate\model\AgentGameRateModel;
- class AgentGameRateLogic extends CommonModel {
- protected $base_field = [];
- /**
- * 转换查询条件
- *
- * @param array $param
- *
- * @return array
- */
- public function getWhere($param = []) {
- $_map = [];
- /* 时间搜索 */
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['create_time']
- = [
- 'between',
- [
- strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
- ]
- ];
- } elseif (!empty($param['start_time'])) {
- $_map['create_time'] = ['egt', strtotime($param['start_time'])];
- } elseif (!empty($param['end_time'])) {
- $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- /* ID搜索 */
- if (!empty($param['id'])) {
- $_map['id'] = $param['id'];
- }
- /* 优惠类型搜索 */
- if (!empty($param['benefit_type'])) {
- $_map['benefit_type'] = $param['benefit_type'];
- }
- /* 推广模式搜索 */
- if (!empty($param['agent_benefit_type'])) {
- $_map['agent_benefit_type'] = $param['agent_benefit_type'];
- }
- /* 推广状态搜索 */
- if (!empty($param['promote_switch'])) {
- $_map['promote_switch'] = $param['promote_switch'];
- }
- /* 渠道类型搜索 */
- if (!empty($param['role_type'])) {
- $_role_ids = (new RoleModel())->getIdsByRoleType($param['role_type']);
- if (!empty($_role_ids)) {
- if (!empty($param['role_id'])) {
- /* 取交集 */
- $param['role_id'] = array_intersect($_role_ids, [$param['role_id']]);
- } else {
- $param['role_id'] = $_role_ids;
- }
- }
- }
- /* 渠道ID搜索 */
- if (!empty($param['role_id'])) {
- $_agent_ids = (new UserModel())->getIdsByRoleId($param['role_id']);
- $_map['agent_id'] = ['in', $_agent_ids];
- }
- /* 渠道ID搜索 */
- if (!empty($param['agent_id'])) {
- if (CommonConst::CONST_ADMIN_SEARCH_ZERO == $param['agent_id']) {
- $param['agent_id'] = 0;
- }
- $_map['agent_id'] = $param['agent_id'];
- }
- /* 应用ID搜索 */
- if (!empty($param['app_id'])) {
- if (CommonConst::CONST_ADMIN_SEARCH_ZERO == $param['app_id']) {
- $param['app_id'] = 0;
- }
- $_map['app_id'] = $param['app_id'];
- }
- if (empty($_map['app_id'])) {
- $_game_map = [
- 'delete_time' => ['eq', 0],
- ];
- if (!empty($param['game_name'])) {
- $_game_map['name'] = ['like', '%'.$param['game_name'].'%'];
- }
- if (!empty($param['classify'])) {
- $_game_map['classify'] = $param['classify'];
- }
- if (!empty($param['game_status'])) {
- $_game_map['status'] = $param['game_status'];
- }
- $_game_ids = (new GameModel())->getIdsByWhere($_game_map);
- $_exclude_app_ids = CommonFunc::getAppAppId();
- if (!empty($param['exclude_app_ids'])) {
- $_exclude_app_ids = array_merge($_exclude_app_ids, $param['exclude_app_ids']);
- }
- $_map['app_id'] = [
- ['notin', $_exclude_app_ids],
- ['in', $_game_ids],
- 'and'
- ];
- }
- return $_map;
- }
- /**
- * 获取列表底层函数
- *
- * @param array $where 搜索条件
- * @param string $page 列表个数
- * @param string $order 排序
- * @param array $field 附加字段
- * @param array $with 关联
- *
- * @return array ['count'=>0,'list'=>[]]
- */
- public function getList($where = [], $page = '1,10', $order = '', $field = [], $with = '') {
- $_map = $where;
- $_field = $field;
- $_model = new AgentGameRateModel();
- $_count = $_model->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_order = $this->orderFilter($order);
- if (!empty($with)) {
- $_datas = $_model->with($with)->field($_field)->where($_map)->order($_order)->page($page)->select();
- } else {
- $_datas = $_model->field($_field)->where($_map)->order($_order)->page($page)->select();
- }
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- return [
- 'count' => $_count,
- 'list' => $_datas
- ];
- }
- /**
- * 获取后台列表
- *
- * @param array $where 搜索条件
- * @param string $page 列表个数
- * @param string $order 排序
- * @param array $field 附加字段
- *
- * @return array ['count'=>0,'list'=>[]]
- */
- public function getAdminList($where = [], $page = '1,10', $order = '-id', $field = []) {
- $_map = $this->getWhere($where);
- $_field = $this->base_field;
- if (!empty($field)) {
- $_field = array_merge($_field, $field);/* 获取后台字段 */
- }
- if (!empty($where['app_id']) && is_numeric($where['app_id'])) {
- /* 无对应游戏优惠则添加 */
- $_agr_model = new AgentGameRateModel();
- $_agent_id = 0;
- $_ag_id = $_agr_model->getIdByGameAgent($where['app_id'], $_agent_id);
- if (empty($_ag_id)) {
- $_add_data = [
- 'app_id' => $where['app_id'],
- 'agent_id' => $_agent_id
- ];
- $_agr_model->addData($_add_data);
- }
- if (!empty($where['agent_id']) && is_numeric($where['agent_id'])) {
- $_agent_id = $where['agent_id'];
- $_agr_id = $_agr_model->getIdByGameAgent($where['app_id'], $_agent_id);
- $_ag_id = (new AgentGameModel())->getIdByAgentApp($_agent_id, $where['app_id']);
- if (!empty($_ag_id) && empty($_agr_id)) {
- (new AgentGame())->addAgentGameRate($where['app_id'], $_agent_id);
- }
- }
- }
- $_rdata = $this->getList($_map, $page, $order, $_field, 'game,user');
- $_datas = $_rdata['list'];
- $_game_mini_model = new GameMiniModel();
- $_agent_game_model = new AgentGameModel();
- $_agent_state = new AgentState();
- $_gv_model = new GameversionModel();
- foreach ($_datas as $_k => $_v) {
- if (!empty($_v['game'])) {
- $_datas[$_k]['game_name'] = get_val($_v['game'], 'name', '');
- $_datas[$_k]['game_icon'] = get_val($_v['game'], 'icon', '');
- $_classify = get_val($_v['game'], 'classify', 0);
- $_datas[$_k]['classify'] = $_classify;
- $_datas[$_k]['agent_name'] = get_val($_v['user'], 'user_login', '');
- $_datas[$_k]['agent_nickname'] = get_val($_v['user'], 'user_nicename', '');
- $_datas[$_k]['role_id'] = get_val($_v['user'], 'role_id', 0);
- $_datas[$_k]['benefit_type_label'] = GameConst::getRateMsg($_v['benefit_type']);
- $_datas[$_k]['agent_benefit_type_label'] = GameConst::getAgentBenefitTypeMsg($_v['agent_benefit_type']);
- /* 获取小游戏id */
- $_datas[$_k]['mini_app_id'] = $_game_mini_model->getMpIdByAppId($_v['app_id']);
- /* 获取渠道游戏id */
- $_datas[$_k]['ag_id'] = $_agent_game_model->getIdByAgentApp($_v['agent_id'], $_v['app_id']);
- /* 获取游戏是否切量 */
- $_datas[$_k]['is_switch'] = $_agent_game_model->getIsSwitchByAgentApp($_v['agent_id'], $_v['app_id']);
- /* 获取渠道推广码 */
- $_share_code = $_agent_state->genAgentCode($_datas[$_k]['ag_id']);
- $_datas[$_k]['share_code'] = $_share_code;
- /* 获取渠道推广路径 */
- $_datas[$_k]['path'] = '';
- if (GameConst::GAME_MP == $_classify || GameConst::GAME_H5MP == $_classify) {
- $_gv_data = $_gv_model->getDefaultInfoByAppId($_v['app_id']);
- $_datas[$_k]['path'] = empty($_gv_data['package_url']) ? ''
- : $_gv_data['package_url'].'?state='.$_share_code;
- } elseif (GameConst::GAME_H5 == $_classify) {
- $_datas[$_k]['path'] = H5SITE.'/sdk.php/game?game_id='.$_v['app_id'].'&agent_id='.$_v['agent_id'];
- }
- unset($_datas[$_k]['game']);
- unset($_datas[$_k]['user']);
- }
- }
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- /***
- * 获取渠道可申请游戏列表
- *
- * @param int $agent_id 渠道id
- * @param array $where 搜索条件
- * @param string $page 分页数据
- * @param string $order 排序
- *
- * @return array ['count'=>0,'list'=>[]]
- */
- public function getNoApplyList($agent_id, $where = [], $page = '1,10', $order = '-id') {
- /* 排除已申请的游戏 */
- $_game_ids = (new AgentGameModel())->getGameIdsByAgentId($agent_id);
- $where['exclude_app_ids'] = $_game_ids;
- $where['agent_id'] = CommonConst::CONST_ADMIN_SEARCH_ZERO;
- $where['game_status'] = GameConst::GAME_STATUS_ON;
- $where['promote_switch'] = ['neq', GameConst::GAME_PROMOTE_SWITCH_NO];
- $_map = $this->getWhere($where);
- $_field = [
- 'app_id' => 'app_id',
- 'agent_rate' => 'agent_rate',
- 'sub_agent_rate' => 'sub_agent_rate',
- 'agent_rebate' => 'agent_rebate',
- 'sub_agent_rebate' => 'sub_agent_rebate',
- 'benefit_type' => 'benefit_type',
- 'agent_benefit_type' => 'agent_benefit_type',
- 'agent_reward' => 'agent_reward',
- 'sub_agent_reward' => 'sub_agent_reward',
- 'promote_switch' => 'promote_switch'
- ];
- $_rdata = $this->getList($_map, $page, $order, $_field);
- $_datas = $_rdata['list'];
- $_game_logic = new GameLogic();
- $_game_field = [
- 'app_id',
- 'game_name',
- 'icon',
- 'size',
- 'down_url',
- 'classify'
- ];
- foreach ($_datas as $_k => $_v) {
- $_game_data = $_game_logic->getFieldDataByAppId($_v['app_id'], $agent_id, 0, $_game_field);
- $_datas[$_k] = array_merge($_game_data, $_v);
- }
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- /**
- * 获取渠道游戏列表
- *
- * @param int $agent_id 渠道id
- * @param array $where 搜索条件
- * @param string $page 列表个数
- * @param string $order 排序
- *
- * @return array ['count'=>0,'list'=>[]]
- */
- public function getAgentList($agent_id, $where = [], $page = '1,10', $order = '-id') {
- $where['agent_id'] = $agent_id;
- $where['status'] = GameConst::GAME_STATUS_ON;
- $where['is_delete'] = CommonConst::CONST_NOT_DELETE;
- $_map = $this->getWhere($where);
- $_field = [
- 'app_id' => 'app_id',
- 'agent_rate' => 'agent_rate',
- 'sub_agent_rate' => 'sub_agent_rate',
- 'agent_rebate' => 'agent_rebate',
- 'sub_agent_rebate' => 'sub_agent_rebate',
- 'benefit_type' => 'benefit_type',
- 'promote_switch' => 'promote_switch'
- ];
- $_rdata = $this->getList($_map, $page, $order, $_field);
- $_datas = $_rdata['list'];
- $_ag_model = new AgentGameModel();
- $_game_logic = new GameLogic();
- $_game_field = [
- 'app_id',
- 'game_name',
- 'icon',
- 'size',
- 'down_url',
- 'classify',
- 'share_url',
- ];
- foreach ($_datas as $_k => $_v) {
- $_game_data = $_game_logic->getFieldDataByAppId($_v['app_id'], $agent_id, 0, $_game_field);
- $_datas[$_k] = array_merge($_game_data, $_v);
- $_ag_data = $_ag_model->getInfoByAgentApp($agent_id, $_v['app_id']);
- $_datas[$_k]['ag_id'] = get_val($_ag_data, 'id', CommonConst::CONST_ZERO);
- $_datas[$_k]['pack_status'] = get_val($_ag_data, 'status', CommonConst::CONST_ZERO);
- $_datas[$_k]['down_url'] = huo_get_down_url(get_val($_ag_data, 'package_url', CommonConst::CONST_ZERO));
- }
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- }
|