123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * ReportLogLogic.php UTF-8
- *
- *
- * @date : 2021-04-06 14:08
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 9.0
- */
- namespace huomp\logic\data;
- use huo\model\member\MemberModel;
- use huo\model\user\UserModel;
- use huolib\constant\AgentConst;
- use huolib\constant\CommonConst;
- use huomp\model\common\CommonModel;
- use huomp\model\weixin\MpAdReportLogModel;
- class ReportLogLogic 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'])];
- }
- if (!empty($param['agent_level_1_id'])) {
- $_agent_map = [
- 'role_id' => ['in', [AgentConst::AGENT_ROLE_MP_AGENT, AgentConst::AGENT_ROLE_MP_AD]]
- ];
- $_agent_model = new UserModel();
- $_ids = $_agent_model->getIdsByParentId($param['agent_level_1_id'], $_agent_map);
- $_ids[] = $param['agent_level_1_id'];
- $_map['agent_id'] = ['in', $_ids];
- }
- if (!empty($param['agent_level_2_id'])) {
- $_map['agent_id'] = $param['agent_level_2_id'];
- }
- if (!empty($param['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- }
- if (!empty($param['action_type'])) {
- $_map['action_type'] = $param['action_type'];
- }
- if (!empty($param['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- if (!empty($param['advertiser_app_id'])) {
- $_map['advertiser_app_id'] = $param['advertiser_app_id'];
- }
- if (!empty($param['username'])) {
- $_map['mem_id'] = (new MemberModel())->getIdByUsername($param['username']);
- }
- return $_map;
- }
- /**
- * 获取列表底层函数
- *
- * @param array $where 搜索条件
- * @param string $page 列表个数
- * @param string $order 排序
- * @param array $field 附加字段
- * @param string $group 归类
- * @param string $with
- *
- * @return array ['count'=>0,'list'=>[]]
- */
- public function getList($where = [], $page = '1,10', $order = '-id', $field = [], $group = '', $with = '') {
- $_map = $where;
- $_field = $field;
- $_model = new MpAdReportLogModel();
- $_count = $_model->with($with)->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_order = $this->orderFilter($order);
- $_datas = $_model->with($with)->field($_field)->where($_map)->order($_order)->group($group)->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 = [], $group = '', $with = 'agent,mem,game') {
- $_map = $this->getWhere($where);
- $_field = $this->base_field;
- if (!empty($field)) {
- $_field = array_merge($_field, $field);/* 获取后台字段 */
- }
- $_data = $this->getList($_map, $page, $order, $_field, $group, $with);
- foreach ($_data['list'] as $_key => $_value) {
- $_value['action_param_value'] = (int)$_value['action_param_value'];
- $_data['list'][$_key] = $_value;
- }
- $_data['sum'] = $this->getSummary($where);
- return $_data;
- }
- public function getSummary($where) {
- $_map = $this->getWhere($where);
- $_sum_field = [
- 'sum(action_param_value)' => 'action_param_value',
- ];
- $_model = new MpAdReportLogModel();
- $_sum_data = $_model
- ->field($_sum_field)
- ->where($_map)
- ->find();
- if (is_object($_sum_data)) {
- $_sum_data = $_sum_data->toArray();
- }
- return $_sum_data;
- }
- }
|