审查视图

simplewind/vendor/overtrue/wechat/src/MiniProgram/Stats/Stats.php 4.8 KB
景龙 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
<?php

/*
 * This file is part of the overtrue/wechat.
 *
 * (c) overtrue <i@overtrue.me>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

/**
 * Stats.php.
 *
 * Part of Overtrue\WeChat.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author    mingyoung <mingyoungcheung@gmail.com>
 * @copyright 2017
 *
 * @see      https://github.com/overtrue
 * @see      http://overtrue.me
 */

namespace EasyWeChat\MiniProgram\Stats;

use EasyWeChat\MiniProgram\Core\AbstractMiniProgram;

class Stats extends AbstractMiniProgram
{
    const SUMMARY_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend';
    const DAILY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend';
    const WEEKLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend';
    const MONTHLY_VISIT_TREND = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend';
    const VISIT_DISTRIBUTION = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution';
    const DAILY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo';
    const WEEKLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo';
    const MONTHLY_RETAIN_INFO = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo';
    const VISIT_PAGE = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage';
    const USER_PORTRAIT = 'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait';

    /**
     * Get summary trend.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function summaryTrend($from, $to)
    {
        return $this->query(self::SUMMARY_TREND, $from, $to);
    }

    /**
     * Get daily visit trend.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function dailyVisitTrend($from, $to)
    {
        return $this->query(self::DAILY_VISIT_TREND, $from, $to);
    }

    /**
     * Get weekly visit trend.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function weeklyVisitTrend($from, $to)
    {
        return $this->query(self::WEEKLY_VISIT_TREND, $from, $to);
    }

    /**
     * Get monthly visit trend.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function monthlyVisitTrend($from, $to)
    {
        return $this->query(self::MONTHLY_VISIT_TREND, $from, $to);
    }

    /**
     * Get visit distribution.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function visitDistribution($from, $to)
    {
        return $this->query(self::VISIT_DISTRIBUTION, $from, $to);
    }

    /**
     * Get daily retain info.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function dailyRetainInfo($from, $to)
    {
        return $this->query(self::DAILY_RETAIN_INFO, $from, $to);
    }

    /**
     * Get weekly retain info.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function weeklyRetainInfo($from, $to)
    {
        return $this->query(self::WEEKLY_RETAIN_INFO, $from, $to);
    }

    /**
     * Get monthly retain info.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function montylyRetainInfo($from, $to)
    {
        return $this->query(self::MONTHLY_RETAIN_INFO, $from, $to);
    }

    /**
     * Get visit page.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function visitPage($from, $to)
    {
        return $this->query(self::VISIT_PAGE, $from, $to);
    }

    /**
     * Get user portrait.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    public function userPortrait($from, $to)
    {
        return $this->query(self::USER_PORTRAIT, $from, $to);
    }

    /**
     * Unify query.
     *
     * @param string $from
     * @param string $to
     *
     * @return \EasyWeChat\Support\Collection
     */
    protected function query($api, $from, $to)
    {
        $params = [
            'begin_date' => $from,
            'end_date' => $to,
        ];

        return $this->parseJSON('json', [$api, $params]);
    }
}