<?php

namespace App\Console\Commands\BatchWechatMaterial;

use App\Http\Controllers\Wechat\Statistic\NewsStatisticsController;
use App\Http\Controllers\WechatController;
use App\Modules\User\Services\UserService;
use Illuminate\Console\Command;
use App\Modules\WechatMaterial\Services\WechatMaterialSendMsgService;
use Illuminate\Support\Facades\DB;
use Redis;

/**
 * 同步微信素材统计信息
 *
 */
class SyncWechatMaterialStatistics extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sync_wechat_material_statistics';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步微信素材统计信息';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->start();
    }

    public function start()
    {
        myLog('SyncWechatMaterialStatistics')->notice('-------  查询群发消息送达数开始');


        #region 短网址测试
//        $url = $WechatController->app->url;
//        $shortUrl = $url->shorten('https://m.ycsd.cn/');
//        var_dump($shortUrl);
        #endregion

        #region 基本框架 为确保公众号数据已完成统计和处理，请于每天上午8点后查询公众号前一天的数据。
//        $queryDay = date("Y-m-d",strtotime('-1 day', time()));
//        WechatMaterialSendMsgService::updateFirstDayMaterialUV($queryDay);
        #endregion

        $WechatController = new WechatController('wxdbc486f1b4f6a8c3');
        $stats            = $WechatController->app->stats;
        $r                = $stats->articleSummary('2020-07-14', '2020-07-14');


        var_dump($r);
        var_dump(json_decode($r, true)['list']);
        $list = json_decode($r, true)['list'];
        foreach ($list as $item) {
            if ($item['msgid'] != '') {
                var_dump($item['msgid']);
            }
        }


        myLog('SyncWechatMaterialStatistics')->notice('-------  查询群发消息送达数结束');
    }


}
