商品多图保存在一条数据里面

<?php
namespace appadmincontroller;

use thinkController;
use 	hinkDb;


/*商品详情列表*/
class ProductList extends Controller
{
    public function index()
    {

        $admin_product_list = db('product_list')->select(); //详情
        //dump($admin_product_list);die;
        foreach ($admin_product_list as $k => $v){
            $admin_product_list[$k]['carousel_images'] = json_decode($v['carousel_images']);
            $admin_product_list[$k]['details_images'] = json_decode($v['details_images']);
        }
        //dump($admin_product_list);

        //所属分类
        $fenlei_column_info = db('fenlei_column')->select();

        $this->assign(array(
            'admin_product_list'=>$admin_product_list,
            'fenlei_column_info'=>$fenlei_column_info,
        ));

        return $this->fetch('index');
    }


    //添加商品详情
    public function add()
    {
        if(request()->isPost())
        {

            $data = [
                'name'=>$this->request->param('name'),
                'price'=>$this->request->param('price'),
                'sold_num'=>$this->request->param('sold_num'),
                'fenlei_column_id'=>$this->request->param('fenlei_column_id'),
                'original_price'=>$this->request->param('original_price'),
                'goods_stock_num'=>$this->request->param('goods_stock_num'),
                'certified_products'=>$this->request->param('certified_products'),
                'speed_goods'=>$this->request->param('speed_goods'),
                'days_return_goods'=>$this->request->param('days_return_goods'),
                'create_time'=>date("Y-m-d H:i:s",time()),
            ];

            // dump($data);die;
            // 获取表单上传文件 例如上传了001.jpg
            //----thumb商品分类图片
            $file = request()->file('thumb');
            // dump($file);die;
            // 移动到框架应用根目录/public/uploads/category/ 目录下
            if($file){
                $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads/spfl/thumb');
                //dump($info);die;

                if($info){
                    // 成功上传后 获取上传信息
                    // 输出 jpg
                    $imgs =str_replace("\","/",$info->getSaveName());
                    $data['thumb'] = '/uploads/spfl/thumb/'.$imgs;
                    // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                }else{
                    // 上传失败获取错误信息
                    echo $file->getError();
                }
            }


            //商品详细轮播图
            $file_carousel_images = request()->file('carousel_images');
            $data_carousel_images = array();
            if($file_carousel_images) {
                foreach ($file_carousel_images as $files_carousel_images) {
                    $info = $files_carousel_images->move(ROOT_PATH . 'public' . DS . 'uploads/splb/carousel_images');
                    //dump($info);die;
                    if ($info) {
                        $imgs  = str_replace("\", "/", $info->getSaveName());
                        $data_carousel_images[] = '/uploads/splb/carousel_images/' . $imgs;
                        // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                    } else {
                        // 上传失败获取错误信息
                        echo $files_carousel_images->getError();
                    }
                }
            }

            //商品详情图
            $file_details_images = request()->file('details_images');
            $data_details_images = array();
            if($file_details_images) {
                foreach ($file_details_images as $files_details_images) {
                    $info = $files_details_images->move(ROOT_PATH . 'public' . DS . 'uploads/spxq/details_images');
                    //dump($info);die;
                    if ($info) {
                        $imgs  = str_replace("\", "/", $info->getSaveName());
                        $data_details_images[] = '/uploads/spxq/details_images/' . $imgs;
                        // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
                    } else {
                        // 上传失败获取错误信息
                        echo $files_details_images->getError();
                    }
                }
            }

            $data['carousel_images'] =json_encode($data_carousel_images); //商品轮播图
            $data['details_images'] = json_encode($data_details_images); //商品详情图
            $res = db('product_list')->insert($data);
            if($res){
                $this->success('添加商品详情内容成功!','index');
            }else{
                $this->error('添加商品详情内容失败!');
            }
        }
        $columnInfo = db('fenlei_column')->select();
        $this->assign('columnInfo',$columnInfo);
        return $this->fetch();
    }

    //编辑分类
    public function edit($id)
    {
        if(request()->isPost()){
            $data = [
                'cate_name'=>input('cate_name')
            ];
            $res = db('fenlei_category')->where('id',$id)->update($data);
            if($res){
                $this->success('编辑分类成功','index');
            }else{
                $this->error('编辑分类失败');
            }
        }
        $categorys = db('fenlei_category')->where('id',$id)->find();
        $this->assign('categorys',$categorys);
        return $this->fetch();
    }










}

原文地址:https://www.cnblogs.com/yehuisir/p/11089021.html