实现效果:

 

 后台:

 

 

 

                     <dl>

                        <label class="item-label">相册:</label>

                        <div style='float:left;width:80%'>

                            <input type="hidden" id="albumpic_id" value="{$info.albumpic_id}" name='albumpic_id' />

                            <button type="button" class="layui-btn" id="albumpic_id_upload"><i
                                    class="layui-icon">&#xe67c;</i>上传图片<span class="percent"></span></button>

                            <div class="upload-img-box">

                                <notempty name="albumList">

                                    <volist name='albumList' id='val'>

                                        <div class="upload-pre-item">

                                            <p><img src="{$val.pic_url}" /></p>

                                            <span>描述:<input type="text" name="edit_album_title[]"
                                                            value="{$val.title}" /></span>

                                            <span>排序:<input type="text" name="edit_album_sort[]"
                                                            value="{$val.sort}" /></span>

                                            <input type="hidden" name="edit_xiangceid[]" value="{$val.id}">

                                            <a href="javascript:void(0);" class="sc"
                                               onclick="delxcimg(this, {$val.id})">删除</a>
                                        </div>

                                    </volist>

                                </notempty>

                            </div>
                        </div>

                    </dl>

add:

     public function add() {

        if (IS_POST) { //提交表单
            setCookieData("ClientsId", $_POST['cate_id']);

            $tid = $this->pro_model->update();

            if (false !== $tid) {

                $banner = array();

                $album_pic_url = $_POST['album_pic_url'];  //得到传输的数据,以数组的形式

                foreach ($album_pic_url as $k => $item) {

                    $banner[$k]['title'] = $_POST['album_title'][$k];

                    $banner[$k]['sort'] = $_POST['album_sort'][$k];

                    $banner[$k]['uid'] = $this->uid;

                    $banner[$k]['pic_url'] = $item;

                    $banner[$k]['create_time'] = time();

                    $banner[$k]['product_id'] = $tid;

                    $banner[$k]['type'] = 'product';
                }

                if ($banner) {

                    $res = M("Xiangce")->addAll($banner);
                }

                $this->success('添加成功!', U('add'));
            } else {

                $error = $this->pro_model->getError();

                $this->error(empty($error) ? '未知错误!' : $error);
            }
        } else {





            $list = $this->db_model->catList(0);

            $this->assign('list', $list);


            $info = $this->db->where("status = 1 and lang='" . $this->lang_en . "'")->order('sort desc')->limit(1)->find();

            $this->assign('sort', $info['sort'] + 1);

            $this->display('edit');
        }
    }

edit:

 public function edit() {

        if (IS_POST) { //提交表单
            setCookieData("ClientsId", '');

            $tid = $this->pro_model->update();

            if (false !== $tid) {

                $xiangce_id = $_POST['edit_xiangceid'];

                if ($xiangce_id) {

                    $data = array();

                    foreach ($xiangce_id as $xc_key => $xc_id) {

                        $data = array(
                            'type' => 'product',
                            'title' => $_POST['edit_album_title'][$xc_key],
                            'sort' => $_POST['edit_album_sort'][$xc_key]
                        );

                        M('Xiangce')->where("id=$xc_id and product_id=$tid")->save($data);
                    }
                }

                $banner = array();

                $album_pic_url = $_POST['album_pic_url'];  //得到传输的数据,以数组的形式

                foreach ($album_pic_url as $k => $item) {

                    $banner[$k]['title'] = $_POST['album_title'][$k];

                    $banner[$k]['sort'] = $_POST['album_sort'][$k];

                    $banner[$k]['uid'] = $this->uid;

                    $banner[$k]['pic_url'] = $item;

                    $banner[$k]['create_time'] = time();

                    $banner[$k]['product_id'] = $tid;

                    $banner[$k]['type'] = 'product';
                }

                if ($banner) {

                    $res = M("Xiangce")->addAll($banner);
                }

                $this->success('编辑成功!', $_POST['httpref']);
            } else {

                $error = $this->pro_model->getError();

                $this->error(empty($error) ? '未知错误!' : $error);
            }
        } else {

            $id = $_REQUEST['id'];

            if (!$id) {

                return;
            }

            $this->assign('albumList', M('Xiangce')->where("product_id=$id")->order("sort asc")->select());
            
            $info = $this->db->where('id=' . $id)->find();

            $this->assign('info', $info);

            $this->assign('banner_list', array_filter(explode(',', $info['banner_id'])));

            $list = $this->db_model->catList(0, $info['cate_id']); //获取产品

            $this->assign('list', $list);

            $extendcate = array();

            $extend = array_unique(array_filter(explode(',', $info['cateid_extend'])));

            if ($extend) {

                foreach ($extend as $val) {

                    $extendcate[] = $this->db_model->catList(0, $val);
                }

                $this->assign('extendcate', $extendcate);
            }



            $this->display();
        }
    }

 

 

前台渲染:

    <volist name="gallery_list" id="item" empty="缺少图片">
        <div class="swiper-slide">
            <img src="{$item.pic_url}" alt="">
        </div>
    </volist>

 

      $info['gallery'] = M('Xiangce')
            ->where([
                'product_id' => $info['id']
            ])
            ->order('sort asc, id desc')
            ->select();
        $this->assign('gallery_list', $info['gallery']);