123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- /**
- * RemainDataLogic.php UTF-8
- * 切量留存逻辑处理
- *
- * @date : 2018/5/21 18:55
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huoAgentSwitch\logic;
- 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 huoAgentSwitch\model\DayAgentSwitchModel;
- use huoAgentSwitch\model\DayGameSwitchModel;
- use huoAgentSwitch\model\DaySwitchModel;
- use huoAgentSwitch\model\DgaSwitchModel;
- class SwitchRemainDataLogic extends CommonModel {
- private $base_field
- = [
- 'date',
- 'reg_cnt',
- 'day2',
- 'day3',
- 'day4',
- 'day5',
- 'day6',
- 'day7',
- 'day15',
- 'day30'
- ];
- private $sum_field
- = [
- 'date' => 'date',
- 'sum(reg_cnt)' => 'reg_cnt',
- 'sum(day2)' => 'day2',
- 'sum(day3)' => 'day3',
- 'sum(day4)' => 'day4',
- 'sum(day5)' => 'day5',
- 'sum(day6)' => 'day6',
- 'sum(day7)' => 'day7',
- 'sum(day15)' => 'day15',
- 'sum(day30)' => 'day30',
- ];
- /**
- * @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['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- }
- if (!empty($param['app_id'])) {
- $_map['app_id'] = $param['app_id'];
- }
- return $_map;
- }
- public function main($param, $order = '-date') {
- $_map = $this->getWhere($param);
- $_filed = $this->sum_field;
- $_model = new DayModel();
- $_order = $this->orderFilter($order);
- $_items = $_model->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_items->count();
- if (!empty($_count)) {
- $_switch_items = (new DaySwitchModel())->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_switch_items->count();
- if (!empty($_count)) {
- foreach ($_items as $_k => $_v) {
- foreach ($_switch_items as $_sk => $_sv) {
- if ($_v->date == $_sv->date) {
- $_items[$_k]->reg_cnt -= $_sv->reg_cnt;
- $_items[$_k]->day2 -= $_sv->day2;
- $_items[$_k]->day3 -= $_sv->day3;
- $_items[$_k]->day4 -= $_sv->day4;
- $_items[$_k]->day5 -= $_sv->day5;
- $_items[$_k]->day6 -= $_sv->day6;
- $_items[$_k]->day7 -= $_sv->day7;
- $_items[$_k]->day15 -= $_sv->day15;
- $_items[$_k]->day30 -= $_sv->day30;
- }
- }
- }
- }
- }
- return $_items;
- }
- public function game($param, $order = '-date') {
- $_map = $this->getWhere($param);
- $_filed = $this->sum_field;
- $_filed['app_id'] = 'app_id';
- $_model = new DayGameModel();
- $_order = $this->orderFilter($order);
- $_items = $_model->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_items->count();
- if (!empty($_count)) {
- $_switch_items = (new DayGameSwitchModel())->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_switch_items->count();
- if (!empty($_count)) {
- foreach ($_items as $_k => $_v) {
- foreach ($_switch_items as $_sk => $_sv) {
- if ($_v->date == $_sv->date) {
- $_items[$_k]->reg_cnt -= $_sv->reg_cnt;
- $_items[$_k]->day2 -= $_sv->day2;
- $_items[$_k]->day3 -= $_sv->day3;
- $_items[$_k]->day4 -= $_sv->day4;
- $_items[$_k]->day5 -= $_sv->day5;
- $_items[$_k]->day6 -= $_sv->day6;
- $_items[$_k]->day7 -= $_sv->day7;
- $_items[$_k]->day15 -= $_sv->day15;
- $_items[$_k]->day30 -= $_sv->day30;
- }
- }
- }
- }
- }
- return $_items;
- }
- public function agent($param, $order = '-date') {
- $_map = $this->getWhere($param);
- $_filed = $this->sum_field;
- $_filed['agent_id'] = 'agent_id';
- $_model = new DayAgentModel();
- $_order = $this->orderFilter($order);
- if (isset($_map['agent_id']) && -1 == $_map['agent_id']) {
- $_map['agent_id'] = 0;
- }
- $_items = $_model->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_items->count();
- if (!empty($_count)) {
- $_switch_items = (new DayAgentSwitchModel())->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_switch_items->count();
- if (!empty($_count)) {
- foreach ($_items as $_k => $_v) {
- foreach ($_switch_items as $_sk => $_sv) {
- if ($_v->date == $_sv->date) {
- $_items[$_k]->reg_cnt -= $_sv->reg_cnt;
- $_items[$_k]->day2 -= $_sv->day2;
- $_items[$_k]->day3 -= $_sv->day3;
- $_items[$_k]->day4 -= $_sv->day4;
- $_items[$_k]->day5 -= $_sv->day5;
- $_items[$_k]->day6 -= $_sv->day6;
- $_items[$_k]->day7 -= $_sv->day7;
- $_items[$_k]->day15 -= $_sv->day15;
- $_items[$_k]->day30 -= $_sv->day30;
- }
- }
- }
- }
- }
- return $_items;
- }
- public function gameAgent($param, $order = '-date') {
- $_map = $this->getWhere($param);
- $_filed = $this->sum_field;
- $_filed['agent_id'] = 'agent_id';
- $_filed['app_id'] = 'app_id';
- if (isset($_map['agent_id']) && -1 == $_map['agent_id']) {
- $_map['agent_id'] = 0;
- }
- $_model = new DayGameAgentModel();
- $_order = $this->orderFilter($order);
- $_items = $_model->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_items->count();
- if (!empty($_count)) {
- $_switch_items = (new DgaSwitchModel())->field($_filed)->where($_map)->group('date')->order($_order)->paginate();
- $_count = $_switch_items->count();
- if (!empty($_count)) {
- foreach ($_items as $_k => $_v) {
- foreach ($_switch_items as $_sk => $_sv) {
- if ($_v->date == $_sv->date) {
- $_items[$_k]->reg_cnt -= $_sv->reg_cnt;
- $_items[$_k]->day2 -= $_sv->day2;
- $_items[$_k]->day3 -= $_sv->day3;
- $_items[$_k]->day4 -= $_sv->day4;
- $_items[$_k]->day5 -= $_sv->day5;
- $_items[$_k]->day6 -= $_sv->day6;
- $_items[$_k]->day7 -= $_sv->day7;
- $_items[$_k]->day15 -= $_sv->day15;
- $_items[$_k]->day30 -= $_sv->day30;
- }
- }
- }
- }
- }
- return $_items;
- }
- }
|