瀏覽代碼

add:推送pvuv统计;

Wang Chen 4 年之前
父節點
當前提交
7bc8c0aa0e

+ 2 - 2
app/Cache/Push/PushCache.php

@@ -84,7 +84,7 @@ class PushCache
      */
      */
     public static function getPushyPv($pushId, $date): int
     public static function getPushyPv($pushId, $date): int
     {
     {
-        $cacheKey = Utils::getCacheKey('push.statPv', [$pushId, $date]);
+        $cacheKey = Utils::getCacheKey('push.statsPv', [$pushId, $date]);
         $exist    = Redis::exists($cacheKey);
         $exist    = Redis::exists($cacheKey);
         if (!$exist) {
         if (!$exist) {
             return 0;
             return 0;
@@ -101,7 +101,7 @@ class PushCache
      */
      */
     public static function getPushUv($pushId, $date): int
     public static function getPushUv($pushId, $date): int
     {
     {
-        $cacheKey = Utils::getCacheKey('push.statUv', [$pushId, $date]);
+        $cacheKey = Utils::getCacheKey('push.statsUv', [$pushId, $date]);
         $exist    = Redis::exists($cacheKey);
         $exist    = Redis::exists($cacheKey);
         if (!$exist) {
         if (!$exist) {
             return 0;
             return 0;

+ 0 - 72
app/Console/Commands/Push/HwPushTest.php

@@ -1,72 +0,0 @@
-<?php
-
-
-namespace App\Console\Commands\Push;
-
-
-use App\Consts\PushConst;
-use App\Libs\Push\HuaWei\Admin\Constants;
-use App\Libs\Push\HuaWei\HwPushCommon;
-use App\Libs\Push\HuaWei\PushMsgCommon;
-use Illuminate\Console\Command;
-
-class HwPushTest extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'push:hw:test';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'test push';
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $appId     = '102612543';
-        $appSecret = '07c896089f432163421923bdcab83a8da9d386274be43e61d510c27f56c23269';
-        $pushToken = 'AN0R08PKJjTJvCTRCL8hATh5ZxIVHQQOhpQ1JkpyRBjG25pRKbBckpUntQYBLpXNb2SFj8_bGb18uMeCT7KY5ehosiWZlopKUIphPYqeWKJeQcHGrn2fPKUsFEM-72X5Zg';
-
-        $fastAppPushCommon = new HwPushCommon($appId, $appSecret);
-        $fastAppPushCommon->setToken([$pushToken]);
-//        $fastAppPushCommon->subscribeTopic(PushConst::TOPIC_ALL, [$pushToken]);
-//        $fastAppPushCommon->unSubscribeTopic(PushConst::TOPIC_ALL, [$pushToken]);
-//        $result = $fastAppPushCommon->subscribeList($pushToken);
-//        $result            = $fastAppPushCommon->queryPushToken($pushToken);
-        $result = $fastAppPushCommon->sendPushMessage('我是标题', '我是内容', '/');
-        dd($result);
-
-//        $testPushMsgSample = new PushMsgCommon();
-//        $testPushMsgSample->sendPushMsgMessageByMsgType(Constants::PUSHMSG_FASTAPP_MSG_TYPE);
-
-//        $message = '{
-//	"data": "{\"pushtype\":1,\"pushbody\":{\"messageId\":\"111110001\",\"data\":\"test pass-through msg\"}}",
-//	"ssss":"{k1:v1}",
-//	"android": {
-//		"collapse_key": -1,
-//		"urgency": "HIGH",
-//		"ttl": "1448s",
-//		"bi_tag": "Trump",
-//		"fast_app_target": 1
-//	},
-//	"token": [
-//		*push_token*
-//		]
-//}';
-//
-//
-//        $message = str_ireplace("*push_token*", '"' . $testPushMsgSample->fast_push_token . '"', $message);
-//        $testPushMsgSample->sendPushMsgRealMessage(json_decode($message), Constants::PUSHMSG_FASTAPP_MSG_TYPE);
-    }
-
-}

+ 0 - 100
app/Console/Commands/Push/MiPushTest.php

@@ -1,100 +0,0 @@
-<?php
-
-namespace App\Console\Commands\Push;
-
-use App\Libs\Push\XMPush\Builder;
-use App\Libs\Push\XMPush\Constants;
-use App\Libs\Push\XMPush\Message;
-use App\Libs\Push\XMPush\Sender;
-use App\Libs\Push\XMPush\Stats;
-use App\Libs\Push\XMPush\TargetedMessage;
-use App\Libs\Push\XMPush\Tracer;
-use Illuminate\Console\Command;
-
-class MiPushTest extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'push:mi:test';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $secret  = 'W0OBbzwRFYE2qfqqzdxV7A==';
-        $package = 'com.beidao.kuaiying.zsy';
-
-        // 常量设置必须在new Sender()方法之前调用
-        Constants::setPackage($package);
-        Constants::setSecret($secret);
-
-        $aliasList = array('alias1', 'alias2');
-        $title     = '测试标题22';
-        $desc      = '这是一条mipush推送消息22';
-        $payload   = '{"test":1,"ok":"It\'s a string"}';
-
-        $sender = new Sender();
-
-        // message1 演示自定义的点击行为
-        $message1 = new Builder();
-        $message1->title($title);  // 通知栏的title
-        $message1->description($desc); // 通知栏的descption
-        $message1->passThrough(0);  // 这是一条通知栏消息,如果需要透传,把这个参数设置成1,同时去掉title和descption两个参数
-        $message1->payload($payload); // 携带的数据,点击后将会通过客户端的receiver中的onReceiveMessage方法传入。
-        $message1->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0
-        $message1->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存
-        $message1->build();
-        $targetMessage = new TargetedMessage();
-        $targetMessage->setTarget('alias1', TargetedMessage::TARGET_TYPE_ALIAS); // 设置发送目标。可通过regID,alias和topic三种方式发送
-        $targetMessage->setMessage($message1);
-
-        // message2 演示预定义点击行为中的点击直接打开app行为
-        $message2 = new Builder();
-        $message2->title($title);
-        $message2->description($desc);
-        $message2->passThrough(0);
-        $message2->payload($payload); // 对于预定义点击行为,payload会通过点击进入的界面的intent中的extra字段获取,而不会调用到onReceiveMessage方法。
-        $message2->extra(Builder::notifyEffect, 1); // 此处设置预定义点击行为,1为打开app
-        $message2->extra(Builder::notifyForeground, 1);
-        $message2->notifyId(0);
-        $message2->build();
-        $targetMessage2 = new TargetedMessage();
-        $targetMessage2->setTarget('alias2', TargetedMessage::TARGET_TYPE_ALIAS);
-        $targetMessage2->setMessage($message2);
-
-        $targetMessageList = array($targetMessage, $targetMessage2);
-        print_r($sender->send($message1, 'yeCXNzRSIiqLPfeoejM4gaLlpz3Tm8zyOctN+wFx0v6U73mTud4cYEJhEDyCEQrC')->getRaw());
-        //print_r($sender->multiSend($targetMessageList, TargetedMessage::TARGET_TYPE_ALIAS)->getRaw());
-
-        // print_r($sender->sendToAliases($message1, $aliasList)->getRaw());
-        $stats     = new Stats();
-        $startDate = '20200727';
-        $endDate   = '20200728';
-        // print_r($stats->getStats($startDate, $endDate)->getRaw());
-        //$tracer = new Tracer();
-        //print_r($tracer->getMessageStatusById('sdm58749595907489079Yl')->getRaw());
-    }
-}

+ 0 - 67
app/Console/Commands/Push/OppoPushTest.php

@@ -1,67 +0,0 @@
-<?php
-
-
-namespace App\Console\Commands\Push;
-
-
-use App\Consts\PushConst;
-use App\Libs\Push\OPPOPush\OPPOPushCommon;
-use Illuminate\Console\Command;
-use GuzzleHttp\Exception\GuzzleException;
-
-class OppoPushTest extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'push:oppo:test';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * @throws GuzzleException
-     */
-    public function handle()
-    {
-        // 配置
-        $regId = 'CN_83427bab875a0a40e4da3eeb2055f331';
-        [$appKey, $masterSecret] = ['354f2fba4c834e94a206fca247f132a0', 'ba2d9968c45b489da75e6bde7147b32a'];
-
-        // 初始化
-        $instance = new OPPOPushCommon($appKey, $masterSecret);
-
-        // 查询APP当天发送量的状态
-        $res = $instance->fetchPushPermit();
-        dd($res);
-
-        // 标签相关
-        $tag  = PushConst::TOPIC_ALL;
-        $res1 = $instance->addTags($tag, '全部用户');
-        $res2 = $instance->subscribeTags($regId, $tag);
-        $res3 = $instance->getAllTags($regId);
-        dd($res1, $res2, $res3);
-
-        // 发送消息
-        $messageId = $instance->getMessageId('我是标题11', '我是内容11', '/');
-        $res4      = $instance->broadCastRegIds($messageId, [$regId]);
-        dd($messageId, $res4);
-
-    }
-}

+ 57 - 0
app/Console/Commands/Push/PushStats.php

@@ -0,0 +1,57 @@
+<?php
+
+
+namespace App\Console\Commands\Push;
+
+
+use App\Cache\Push\PushCache;
+use App\Modules\Push\Models\QappPushTask;
+use Illuminate\Console\Command;
+
+class PushStats extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'push:stats';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '推送PVUV统计';
+
+    public function handle()
+    {
+        $date = date('Ymd', strtotime('-1 day'));
+
+        // 获取所有有效的推送任务
+        $tasks = QappPushTask::getAllValidTasks();
+        if (empty($tasks)) {
+            return false;
+        }
+
+        foreach ($tasks as $task) {
+            $pushId = getProp($task, 'id');
+            $pv     = getProp($task, 'pv');
+            $uv     = getProp($task, 'uv');
+
+            // 获取缓存数据
+            $cachePv = PushCache::getPushyPv($pushId, $date);
+            $cacheUv = PushCache::getPushUv($pushId, $date);
+
+            myLog('pushStats')->info('', compact('date', 'pushId', 'pv', 'uv', 'cachePv', 'cacheUv'));
+
+            // 更新pv uv
+            QappPushTask::updatePushTask($pushId, [
+                'pv' => $pv + $cachePv,
+                'uv' => $uv + $cacheUv,
+            ]);
+        }
+
+        return true;
+    }
+}

+ 5 - 3
app/Console/Kernel.php

@@ -5,6 +5,7 @@ namespace App\Console;
 use App\Console\Commands\Push\HwPushTest;
 use App\Console\Commands\Push\HwPushTest;
 use App\Console\Commands\Push\MiPushTest;
 use App\Console\Commands\Push\MiPushTest;
 use App\Console\Commands\Push\OppoPushTest;
 use App\Console\Commands\Push\OppoPushTest;
+use App\Console\Commands\Push\PushStats;
 use App\Console\Commands\Push\PushTask;
 use App\Console\Commands\Push\PushTask;
 use App\Console\Commands\Push\PushTest;
 use App\Console\Commands\Push\PushTest;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Console\Scheduling\Schedule;
@@ -18,9 +19,7 @@ class Kernel extends ConsoleKernel
      * @var array
      * @var array
      */
      */
     protected $commands = [
     protected $commands = [
-        MiPushTest::class,
-        HwPushTest::class,
-        OppoPushTest::class,
+        PushStats::class,
         PushTest::class,
         PushTest::class,
         PushTask::class,
         PushTask::class,
         Commands\Activity\ActivityStats::class,
         Commands\Activity\ActivityStats::class,
@@ -53,5 +52,8 @@ class Kernel extends ConsoleKernel
 
 
         // 每天的活动统计
         // 每天的活动统计
         $schedule->command('activity:stats')->dailyAt('01:00');
         $schedule->command('activity:stats')->dailyAt('01:00');
+
+        // 每天的推送统计
+        $schedule->command('push:stats')->dailyAt('00:30');
     }
     }
 }
 }

+ 15 - 1
app/Modules/Push/Models/QappPushTask.php

@@ -11,7 +11,8 @@ class QappPushTask extends Model
 {
 {
     protected $table = 'qapp_push_task';
     protected $table = 'qapp_push_task';
     protected $fillable = ['uid', 'package_id', 'type', 'title', 'content', 'url', 'num',
     protected $fillable = ['uid', 'package_id', 'type', 'title', 'content', 'url', 'num',
-        'status', 'providers', 'push_time', 'push_filter', 'push_result', 'select_user_status'];
+        'status', 'providers', 'push_time', 'push_filter', 'push_result', 'select_user_status',
+        'qapp_account', 'pv', 'uv'];
 
 
     /**
     /**
      * @param $id
      * @param $id
@@ -69,4 +70,17 @@ class QappPushTask extends Model
             ->orderBy('push_time', 'ASC')
             ->orderBy('push_time', 'ASC')
             ->first();
             ->first();
     }
     }
+
+    /**
+     * @return mixed
+     */
+    public static function getAllValidTasks()
+    {
+        $result = self::where('status', PushConst::STATUS_TODO)
+            ->where('select_user_status', PushConst::SELECT_USER_OK)
+            ->where('push_time', '<=', date('Y-m-d H:i:s'))
+            ->orderBy('push_time', 'ASC')
+            ->get();
+        return $result ? $result->toArray() : [];
+    }
 }
 }