TP框架使用命令行

TP框架使用命令行

 

<?php

namespace app\command;


use think\Db;
use app\shopee\Item;
use think\console\Input;
use think\console\Output;
use think\console\Command;
use think\console\input\Argument;


class ShoppeCategoryUpdate extends Command
{

    protected function configure()
    {
        $this->setName('shoppe_category_update')->setDescription('shoppe_category_update');//命令别名    例如 执行命令:php think shoppe_category_update  VN
        $this->addArgument('site_name', Argument::REQUIRED, "site_name");//接收参数的变量 
    }

    protected function execute(Input $input, Output $output)
    {
        $site = $input->getArgument('site_name');
        if(empty($site)){
            echo '请输入站点';exit;
        }
        $siteArr = [
            'TW',//*
            'SG',//新加坡
            'MY',//马来
            'PH',//菲律宾
            'VN',//越南
            'ID',//印尼
            'TH',//泰国
        ];
        if(!in_array($site,$siteArr)){
            echo '目前支持站点:';
            dump($siteArr);exit;
        }
        $model = new Item();
        switch($site){
            case 'TW'://*
                $delete = Db::name('ShoppeCategory')->where(['area'=>'TW'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('1533044','en');//*1 TW   本土
                $res2 = $model->GetCategrories('458766274','en');//*2 TW   跨境
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'TW',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                     $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'TW',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'SG'://新加坡
                $delete = Db::name('ShoppeCategory')->where(['area'=>'SG'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('275569197','en');//新加坡店 SG
                $res2 = $model->GetCategrories('275569197','en');//新加坡店 SG
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'SG',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'SG',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'MY'://马来
                $delete = Db::name('ShoppeCategory')->where(['area'=>'MY'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('455538205','en');//马来店1  MY
                $res2 = $model->GetCategrories('417299243','en');//马来店2  MY
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'MY',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'MY',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'PH'://菲律宾
                $delete = Db::name('ShoppeCategory')->where(['area'=>'PH'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('428277955','en');//菲律宾1 TW   本土
                $res2 = $model->GetCategrories('408955886','en');//菲律宾2 TW   跨境
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'PH',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'PH',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'VN'://越南
                $delete = Db::name('ShoppeCategory')->where(['area'=>'VN'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('275567669','en');//越南1 VN 跨境
                $res2 = $model->GetCategrories('275567669','en');//越南2 VN 跨境
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'VN',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'VN',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'ID'://印尼
                $delete = Db::name('ShoppeCategory')->where(['area'=>'ID'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('275564952','en');//印尼1 ID   跨境
                $res2 = $model->GetCategrories('275564952','en');//印尼2 ID   跨境
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'ID',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'ID',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            case 'TH'://泰国
                $delete = Db::name('ShoppeCategory')->where(['area'=>'TH'])->delete();
                dump('旧分类删除数量:'.$delete);
                $res1 = $model->GetCategrories('397682289','en');//泰国1 TH   本土
                $res2 = $model->GetCategrories('464886765','en');//泰国2 TH   跨境
                $data1 = json_decode($res1,true);
                $data2 = json_decode($res2,true);
                $arr1 = [];
                $arr2 = [];
                foreach ($data1['categories'] as $v){
                    $arr1[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>0,
                        'area'=>'TH',
                        'add_time'=>time(),
                    ];
                }
                foreach($data2['categories'] as $v){
                    $arr2[] = [
                        'cid'=>$v['category_id'],
                        'pid'=>$v['parent_id'],
                        'name'=>$v['category_name'],
                        'is_cb'=>1,
                        'area'=>'TH',
                        'add_time'=>time(),
                    ];
                }
                $arr = array_merge($arr1,$arr2);
                $in = Db::name('ShoppeCategory')->insertAll($arr);
                dd('插入新分类数量:'.$in . '  本土:'.count($arr1) . '  跨境:'.count($arr2));
                break;
            default:
                dd('站点不支持');
                break;
        }


    }

}

 

上一篇:Linux Deepin镜像服务覆盖范围新增十一个国家


下一篇:C#去除HTML标签