<?php

namespace App\Console\Commands\ActionTrigger\BatchWechatMaterial;
use App\Http\Controllers\WechatController;
use Illuminate\Console\Command;
use DB;

/**
 * 删除微信素材
 *
 */
class DelWechatMaterial extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ActionTrigger:del_zs_wechat_material  {data}';

    /**
     * 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()
    {
        \Log::info('del_zs_wechat_material start:');
        $data = $this->argument('data');
        try{
            $this->start($data['data']);
        }catch(\Exception $e){
            \Log::error($e->getMessage());
        }

        \Log::info('del_zs_wechat_material end:');
    }

    public function start($data){


        \Log::info('$data');\Log::info($data);
        //检查参数
        if(!($data['appid']&&$data['media_id'])){
            \Log::info('params_empty');
            return;
        }
        //微信删除素材接口
        try{
            $WechatController = new WechatController($data['appid']);
            $res = $WechatController->app->material->delete($data['media_id']);
            \Log::info($res);
        }catch(\Exception $e){
            \Log::error($e->getMessage());
        }

        return;
    }
}