| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 | <?php/** * DayPayLogic.php UTF-8 * * * @date    : 2017/12/18 11:42 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : liguanglong <lgl@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\logic\data;use huo\logic\user\UserLogic;use huo\model\common\CommonModel;use huo\model\data\DayAgentModel;use huo\model\data\DayGameModel;use huo\model\game\GameAgentModel;use huo\model\game\GameModel;use huo\model\member\MemberModel;use huo\model\user\UserModel;class IndexDataLogic extends CommonModel {    public function getRechargeData($agentIDs = array(), $gameIDs = array()){        $_collect = $this->scopesRecharge($agentIDs, $gameIDs);        $_previous = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d', strtotime('-1 day')).'"');        $_now = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d').'"');        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }    public function getPlatformData($agentIDs = array(), $gameIDs = array()){        $_collect = $this->scopesPlatform($agentIDs);        $_time = $this->getLastDate();        $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];        $_previous = $this->scopesPlatform($agentIDs, $gameIDs, $_where);        $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];        $_now = $this->scopesPlatform($agentIDs, $gameIDs, $_where);        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }    public function getExpenseUserData($agentIDs = array(), $gameIDs = array()){        $_collect = $this->scopesExpense($agentIDs);        $_previous = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d', strtotime('-1 day')).'"');        $_now = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d').'"');        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }        public function getGameAgentData($agentIDs = array()){        $_collect = $_previous = $_now = null;        $_model = new GameAgentModel();        $_app_ids = $_model->whereIn('agent_id', $agentIDs)->column('app_id');        if(!empty($_app_ids)){            $_time = $this->getLastDate();            $_collect = $this->scopesGameAgentData($_app_ids);            $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1];            $_previous = $this->scopesGameAgentData($_app_ids, $_where);            $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1];            $_now = $this->scopesGameAgentData($_app_ids, $_where);            $this->handle($_collect, $_previous, $_now);        }        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }    public function getGameCpData($adminID = array()){        $_collect = $_previous = $_now = null;        $_model = new UserModel();        $_model = $_model->whereIn('id', $adminID)->find();        if(!empty($_model)){            $_time = $this->getLastDate();            $_collect = $this->scopesGameCp($_model['cp_id']);            $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1];            $_previous = $this->scopesGameCp($_model['cp_id'], $_where);            $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1];            $_now = $this->scopesGameCp($_model['cp_id'], $_where);        }        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }        public function getChannelAgentData($agentIDs = array()){        $_time = $this->getLastDate();        $_collect = $this->scopesChannelAgent($agentIDs);        $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];        $_previous = $this->scopesChannelAgent($agentIDs, $_where);        $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];        $_now = $this->scopesChannelAgent($agentIDs, $_where);        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }        public function getChannelGameData($adminID = 0){        $_collect = $_previous = $_now = null;        $_model = new UserModel();        $_model = $_model->where('id', $adminID)->find();        if(!empty($_model)){            $_time = $this->getLastDate();            $_collect = $this->scopesChannelGame($_model['cp_id']);            $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];            $_previous = $this->scopesChannelGame($_model['cp_id'], $_where);            $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];            $_now = $this->scopesChannelGame($_model['cp_id'], $_where);        }        $this->handle($_collect, $_previous, $_now);        return [$_collect, $_previous, $_now];    }    private function scopesChannelGame($cpID = 0, $where = null){        $_model = new GameModel();        $_app_ids = $_model->where('cp_id', $cpID)->column('id');        if(!empty($_app_ids)){            $_model = new MemberModel();            $_model = $_model->field('count(distinct(app_id)) count')->whereIn('app_id', $_app_ids);            if(!empty($where)){                $_model = $_model->where($where);            }            return $_model->find();        }        return null;    }    private function scopesChannelAgent($agentIDs = array(), $where = null){        $_model = new GameAgentModel();        $_model = $_model->field('count(distinct(agent_id)) count')                         ->whereIn('agent_id', $agentIDs);        if(!empty($where)){            $_model = $_model->where($where);        }        $_model = $_model->find();        return $_model;    }    private function scopesGameAgentData($appIDs = array(), $where = null){        $_model = new GameModel();        $_model = $_model->field('count(distinct(id)) count')                         ->where('run_time', '>', 0)                         ->whereIn('id', $appIDs);        if(!empty($where)){            $_model = $_model->where($where);        }        return $_model->find();    }    private function scopesGameCp($cpID = 0, $where = null){        $_model = new GameModel();        $_model = $_model->field('count(distinct(id)) count')                         ->where('run_time', '>', 0)                         ->where('cp_id', $cpID);        if(!empty($where)){            $_model = $_model->where($where);        }        return $_model->find();    }    private function scopesExpense($agentIDs = array(), $gameIDs = array(), $where = null){        if(empty($agentIDs) && empty($agentIDs)){            return [];        }        if(!empty($agentIDs)){            $_model = new DayAgentModel();            $_model = $_model->field('id, sum(pay_user_cnt) pay_user_cnt')->whereIn('agent_id', $agentIDs);        }        if(!empty($gameIDs)){            $_model = new DayGameModel();            $_model = $_model->field('id, date, sum(pay_user_cnt) pay_user_cnt')->whereIn('app_id', $gameIDs);        }        if(!empty($where)){            $_model = $_model->where($where);        }        return $_model->find();    }    private function scopesPlatform($agentIDs = array(), $gameIDs = array(), $where = null){        $_model = new MemberModel();        $_model = $_model->field('sum(id) count');        if(!empty($agentIDs)){            $_model = $_model->whereIn('agent_id', $agentIDs);        }        if(!empty($gameIDs)){            $_model = $_model->whereIn('app_id', $gameIDs);        }        if(!empty($where)){            $_model = $_model->where($where);        }        $_model = $_model->find();        return $_model;    }    private function scopesRecharge($agentIDs = array(), $gameIDs = array(), $where = null){        if(empty($agentIDs) && empty($gameIDs)) return [];        if(!empty($agentIDs)) $_model = new DayAgentModel();        if(!empty($gameIDs)) $_model = new DayGameModel();        $_model = $_model->field("id, date, sum(sum_money) sum_money");        if(!empty($agentIDs)){            $_model = $_model->whereIn('agent_id', $agentIDs);        }        if(!empty($gameIDs)){            $_model = $_model->whereIn('app_id', $gameIDs);        }        if(!empty($where)){            $_model = $_model->where($where);        }        $_model = $_model->find();        return $_model;    }    private function getLastDate(){        return [            [                strtotime(date('Y-m-d').' 00:00:00'),                strtotime(date('Y-m-d').' 23:59:59')            ],            [                strtotime(date('Y-m-d', strtotime('-1 day')).' 00:00:00'),                strtotime(date('Y-m-d', strtotime('-1 day')).' 23:59:59')            ]        ];    }    private function handle(&$collect, &$previous, &$now){        if(empty($collect['sum_money'])){            $collect['sum_money'] = 0;        }        if(empty($collect['count'])){            $collect['count'] = 0;        }        if(empty($collect['pay_user_cnt'])){            $collect['pay_user_cnt'] = 0;        }        if(empty($previous['count'])){            $previous['count'] = 0;        }        if(empty($previous['pay_user_cnt'])){            $previous['pay_user_cnt'] = 0;        }        if(empty($previous['sum_money'])){            $previous['sum_money'] = 0;        }        if(empty($now['sum_money'])){            $now['sum_money'] = 0;        }        if(empty($now['pay_user_cnt'])){            $now['pay_user_cnt'] = 0;        }        if(empty($now['count'])){            $now['count'] = 0;        }    }    // TODO: liguanglong 2017/12/28    public function getSwiftList(){        $_list = [            [                'title' => lang('player list'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc2f59d134.png',                'uri' => url('admin/member.member/index')],            [                'title' => lang('order list'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc3c0bdf3c.png',                'uri' => ''            ],            [                'title' => lang('platform currency'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc315a481d.png',                'uri' => ''            ],            [                'title' => lang('game currency'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30952f4e.png',                'uri' => ''            ],            [                'title' => lang('game list'),                'img' => 'http://demo.vlcms.com/Public/Admin/images/icon146.png',                'uri' => url('admin/game.game/index')            ],            [                'title' => lang('channel list'),                'img' => 'http://demo.vlcms.com/Public/Admin/images/icon185.png',                'uri' => ''            ],            [                'title' => lang('open service management'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc44c40905.png',                'uri' => ''            ],            [                'title' => lang('news list'),                'img' => 'http://demo.vlcms.com/Public/Admin/images/icon2.png',                'uri' => url('admin/news.news/index')            ],            [                'title' => lang('advertising effect'),                'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30177ed3.png',                'uri' => ''            ],        ];        return $_list;    }    // TODO: liguanglong 2017/12/28    public function getWaitingList(){        $_list = [            [                'title' => lang('subcontracting audit'),                'content' => '...',                'uri' => ''            ],            [                'title' => lang('channel management'),                'content' => '...',                'uri' => ''            ],            [                'title' => lang('finance review'),                'content' => '...',                'uri' => ''            ],            [                'title' => lang('game recharge'),                'content' => '...',                'uri' => ''            ],        ];        return $_list;    }    // TODO: liguanglong 2017/12/28    public function getTipList(){        $_list = [            [                'title' => lang('promotion games'),                'content' => '...',                'uri' => ''            ],            [                'title' => lang('rebate setting'),                'content' => '...',                'uri' => ''            ],            [                'title' => lang('gift list'),                'content' => '...',                'uri' => 'http://www.huos.com/admin/gift.gift/index.html'            ],            [                'title' => lang('channel list'),                'content' => '...',                'uri' => ''            ],        ];        return $_list;    }}
 |