| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 | <?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\model\common\CommonModel;use huo\model\data\DayAgentGameCountryModel;use huo\model\data\DayAgentGameCountryVipModel;use huo\model\game\GameModel;use huo\logic\user\UserLogic;class CpDataLogic extends CommonModel {    protected $_id;    protected $_agent_id;    protected $_app_id;    protected $_cp_id;    public function __construct($data = []) {        parent::__construct($data);        List($this->_id, $this->_cp_id, $this->_agent_id, $this->_app_id)            = (new UserLogic())->getRoleLevelID(session('ADMIN_ID'));    }    /**     * cp对账单     * @param null $date     * @param null $cp_id     *     * @return array     * @throws \think\exception\DbException     */    public function getBalanceIndex($yearMonth = null, $cp_id = null){        $_model = new DayAgentGameCountryVipModel();        $_fields = <<<EOF          id, app_id, date, sum(vip_day_cnt) vip_day_cnt, sum(vip_day_money) vip_day_money,           sum(vip_down_cnt) vip_down_cnt, sum(vip_reg_cnt) vip_reg_cnt, sum(vip_sum_money) vip_sum_money,          sum(vip_user_cnt) vip_user_cnt, sum(vip_free_cnt) vip_free_cntEOF;        $_model = $_model->field($_fields);        if($yearMonth){            $_model = $_model->where('left(date, 7) = "'.$yearMonth.'"' );        }        if($cp_id){            $_game_model = new GameModel();            $_app_id = $_game_model->where('cp_id', $cp_id)->column('id');            $_model = $_model->whereIn('app_id', $_app_id);        }        $_model = $_model->whereIn('app_id', $this->_app_id)                         ->whereIn('agent_id', $this->_agent_id)                         ->with('game')                         ->group('app_id')                         ->paginate(10);        $_page = $_model->render();        $_data = $_model->toArray()['data'];        $this->getBalanceScope($_data);        $this->handleBalanceData($_data);        return [$_data, $_page];    }    /**     * 封装     * @param $data     */    private function handleBalanceData(&$data){        if(count($data)){            foreach ($data as &$val){                /*游戏名*/                $val['game_name'] = null;                /*下载占比*/                $val['vip_down_cnt_percent'] =                    number_format($val['vip_down_cnt'] / $val['vip_day_cnt'], 2) * 100 .'%';                /*vip订阅数*/                $val['vip_sub_cnt'] = $val['vip_user_cnt'] + $val['vip_free_cnt'];                if(!empty($val['game'])){                    $val['game_name'] = $val['game']['name'];                    unset($val['game']);                }            }        }    }    /**     * cp附加数据     * @param $data     *     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    private function getBalanceScope(&$data){        if(!empty($data)){            $_model = new DayAgentGameCountryModel();            $_fields = <<<EOF          id, app_id, date, sum(user_cnt) user_cntEOF;            $_model = $_model->field($_fields);            $_model = $_model->where('left(date, 7) = "'.substr($data[0]['date'], 0, 7).'"')                             ->whereIn('app_id', array_column($data, 'app_id'))                             ->group('app_id')                             ->select()                             ->toArray();            foreach ($data as &$val){                /*活跃玩家数*/                $val['scope_user_cnt'] = 0;                if(count($_model)){                    foreach ($_model as $vale){                        if($vale['date'] == $val['date'] && $vale['app_id'] == $val['app_id']){                            $val['scope_user_cnt'] = $vale['user_cnt'];                            break;                        }                    }                }            }        }    }}
 |