2020年9月

//    导入图片  参数 暂存目录  保存目录   分类
    public function importpro()
    {
        $save_path = DOC_PATH;

        exit();
        set_time_limit(0);
        // 定义主存储路径


        //windows下目录有中文需要转码
        $source = iconv("UTF-8",'gb2312','E:\web\centuryceramic\新网站--2014年以前图片');
        $dest = ROOT_PATH . '';
        $class = '6';


        foreach (file_list($source) as $file)
        {
            //是否为图片文件
            if(is_image($source . '\\'.$file))
            {
                $ico =   STATIC_DIR . '/upload' .'/image/product/' . time() . mt_rand(100000, 999999) . '.jpg';
                $file_path = $save_path . $ico;
                //缩放并复制图片
                resize_img($source . '\\'.$file,$file_path,500,500);
                //插入产品记录
                unset($info);
                $info = [
                    'title' => 'ceramic mug ' . $this->i,
                    'ico' => $ico,
                    'class' => $class,
                ];
                $this->save_pro($info);
            }


        }


    }


    //保存产品

    private function save_pro($info){
        //产品信息结构
        $data = json_decode('{"acode":"cn","scode":"16","subscode":"","title":"\u6807\u9898","titlecolor":"#333333","subtitle":"","filename":"","author":"admin","source":"\u672c\u7ad9","outlink":"","date":"2018-12-30 10:45:46","ico":"\/static\/upload\/image\/20181230\/1546137994102175.png","pics":"\/static\/upload\/image\/20181230\/1546138005227320.png,\/static\/upload\/image\/20181230\/1546138006814526.png","content":"<p>\u5185\u5bb9<\/p>","enclosure":"","keywords":"","description":"\u5185\u5bb9","sorting":255,"status":"1","istop":0,"isrecommend":0,"isheadline":0,"visits":0,"likes":0,"oppose":0,"create_user":"admin","update_user":"admin"}',true);
        //var_dump($info);die();

        $data['scode'] = $info['class'];
        $data['pics'] = "";
        $data['ico'] = $info['ico'];

        //重置这些内容 以免下一个

        $data['title'] =  $info['title'];
        $data['content'] = $info['title'];
        $data['description'] = "";
        $data['date'] = date('Y-m-d H:i:s');
        //var_dump($data);
        //exit();
        if (! ! $id = $this->model->addContent($data)) {
            //添加扩展内容 addContentExt

            unset($ext);
            $ext = [
                'contentid' => $id,
                'ext_ext_country' => 'china',
                'ext_color' => $this->i,//编号
                'ext_type' => 'CenturyCeramic',
            ];

            if (! $this->model->addContentExt($ext)) {
                $this->model->delContent($id);
                echo "导入失败" . $info['title']  .   '<br />';
            }
            else{
                echo "成功导入数据" . $info['title']  .   '<br />';
                $this->i += 1;//编号累加
            }


        }

    }