ReportLogLogic.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * ReportLogLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2021-04-06 14:08
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 9.0
  11. */
  12. namespace huomp\logic\data;
  13. use huo\model\member\MemberModel;
  14. use huo\model\user\UserModel;
  15. use huolib\constant\AgentConst;
  16. use huolib\constant\CommonConst;
  17. use huomp\model\common\CommonModel;
  18. use huomp\model\weixin\MpAdReportLogModel;
  19. class ReportLogLogic extends CommonModel {
  20. protected $base_field = [];
  21. /**
  22. * 转换查询条件
  23. *
  24. * @param array $param
  25. *
  26. * @return array
  27. */
  28. public function getWhere($param = []) {
  29. $_map = [];
  30. /* 时间搜索 */
  31. if (!empty($param['start_time']) && !empty($param['end_time'])) {
  32. $_map['create_time']
  33. = [
  34. 'between',
  35. [
  36. strtotime($param['start_time']),
  37. CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
  38. ]
  39. ];
  40. } elseif (!empty($param['start_time'])) {
  41. $_map['create_time'] = ['egt', strtotime($param['start_time'])];
  42. } elseif (!empty($param['end_time'])) {
  43. $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
  44. }
  45. if (!empty($param['agent_level_1_id'])) {
  46. $_agent_map = [
  47. 'role_id' => ['in', [AgentConst::AGENT_ROLE_MP_AGENT, AgentConst::AGENT_ROLE_MP_AD]]
  48. ];
  49. $_agent_model = new UserModel();
  50. $_ids = $_agent_model->getIdsByParentId($param['agent_level_1_id'], $_agent_map);
  51. $_ids[] = $param['agent_level_1_id'];
  52. $_map['agent_id'] = ['in', $_ids];
  53. }
  54. if (!empty($param['agent_level_2_id'])) {
  55. $_map['agent_id'] = $param['agent_level_2_id'];
  56. }
  57. if (!empty($param['agent_id'])) {
  58. $_map['agent_id'] = $param['agent_id'];
  59. }
  60. if (!empty($param['action_type'])) {
  61. $_map['action_type'] = $param['action_type'];
  62. }
  63. if (!empty($param['app_id'])) {
  64. $_map['app_id'] = $param['app_id'];
  65. }
  66. if (!empty($param['advertiser_app_id'])) {
  67. $_map['advertiser_app_id'] = $param['advertiser_app_id'];
  68. }
  69. if (!empty($param['username'])) {
  70. $_map['mem_id'] = (new MemberModel())->getIdByUsername($param['username']);
  71. }
  72. return $_map;
  73. }
  74. /**
  75. * 获取列表底层函数
  76. *
  77. * @param array $where 搜索条件
  78. * @param string $page 列表个数
  79. * @param string $order 排序
  80. * @param array $field 附加字段
  81. * @param string $group 归类
  82. * @param string $with
  83. *
  84. * @return array ['count'=>0,'list'=>[]]
  85. */
  86. public function getList($where = [], $page = '1,10', $order = '-id', $field = [], $group = '', $with = '') {
  87. $_map = $where;
  88. $_field = $field;
  89. $_model = new MpAdReportLogModel();
  90. $_count = $_model->with($with)->where($_map)->count();
  91. if (empty($_count)) {
  92. return [
  93. 'count' => 0,
  94. 'list' => []
  95. ];
  96. }
  97. $_order = $this->orderFilter($order);
  98. $_datas = $_model->with($with)->field($_field)->where($_map)->order($_order)->group($group)->page($page)->select();
  99. if (is_object($_datas)) {
  100. $_datas = $_datas->toArray();
  101. }
  102. if (empty($_datas)) {
  103. return [
  104. 'count' => 0,
  105. 'list' => []
  106. ];
  107. }
  108. return [
  109. 'count' => $_count,
  110. 'list' => $_datas
  111. ];
  112. }
  113. /**
  114. * 获取后台列表
  115. *
  116. * @param array $where 搜索条件
  117. * @param string $page 列表个数
  118. * @param string $order 排序
  119. * @param array $field 附加字段
  120. *
  121. * @return array ['count'=>0,'list'=>[]]
  122. */
  123. public function getAdminList($where = [], $page = '1,10', $order = '-id', $field = [], $group = '', $with = 'agent,mem,game') {
  124. $_map = $this->getWhere($where);
  125. $_field = $this->base_field;
  126. if (!empty($field)) {
  127. $_field = array_merge($_field, $field);/* 获取后台字段 */
  128. }
  129. $_data = $this->getList($_map, $page, $order, $_field, $group, $with);
  130. foreach ($_data['list'] as $_key => $_value) {
  131. $_value['action_param_value'] = (int)$_value['action_param_value'];
  132. $_data['list'][$_key] = $_value;
  133. }
  134. $_data['sum'] = $this->getSummary($where);
  135. return $_data;
  136. }
  137. public function getSummary($where) {
  138. $_map = $this->getWhere($where);
  139. $_sum_field = [
  140. 'sum(action_param_value)' => 'action_param_value',
  141. ];
  142. $_model = new MpAdReportLogModel();
  143. $_sum_data = $_model
  144. ->field($_sum_field)
  145. ->where($_map)
  146. ->find();
  147. if (is_object($_sum_data)) {
  148. $_sum_data = $_sum_data->toArray();
  149. }
  150. return $_sum_data;
  151. }
  152. }