<?php

namespace App\Jobs;

use App\Facades\CommonService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class MakeNutrient implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $user;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user)
    {
        $this->user = $user;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $user = $this->user;
        $method = "GET";
        $url1 = "http://192.168.1.201:8585/dma/nutrient/".$user->id;
        CommonService::http($method, $url1);
        $param = [
            'touser'=>$user->officialWechat->openid,
            'template_id'=>config('wechat.tpls.make_nutrient_notice'),
            'url'=>'',
            'miniprogram'=>[
                'appid'=>config('wechat.mini_program.app_id'),
                'pagepath'=>'pages/tabBar/serve',
            ],
            'data'=>[
                'first'=>['value'=>'您的营养素生成成功！'],
                'keyword1'=>['value'=>$user->name],
                "keyword2"=>['value'=>date('Y-m-d H:i:s')],
                'remark'=>['value'=>"点击进入查看详情"]
            ]
        ];
        SendTemplateNotice::dispatch($param)->onQueue('health')->delay(now()->addSeconds(5));
//        $url2 = "http://192.168.1.201:8585/dma/guide/".$user->id;
//        CommonService::http($method, $url2);
    }
}
