<?php

namespace App\Console\Commands;

use App\Facades\WechatService;
use App\Jobs\SendSubscribeMessage;
use App\Models\User;
use App\Models\Wechat;
use Illuminate\Console\Command;

class StepSubmitNotice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'step:submit:notice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '运动步数上传提醒';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $user_ids = User::query()->pluck('id')->toArray();
        if (!$user_ids) {
            return Command::SUCCESS;
        }
        foreach ($user_ids as $user_id) {
            $openid = Wechat::query()->where('user_id', $user_id)->where('type', 'mp')->value('openid');
            if (!$openid) {
                continue;
            }
            $param = [
                'touser' => $openid,
                'template_id' => config('wechat.sub_tpls.step_submit_notice'),
                'page' => 'pages/user/motionRecord',
                'data' => [
                    'thing1' => ['value' => '今天的走路步数记得上传记录哦'],
                    'time2' => ['value' => date('Y-m-d')],
                    'thing3' => ['value' => '您的健康是我们最关心的,请注意安全运动'],
                ]
            ];
            SendSubscribeMessage::dispatch($param)->onQueue('health');
//            WechatService::sendSubscribeMessage($param);
        }

        return Command::SUCCESS;
    }
}
