<?php // +---------------------------------------------------------------------- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] // +---------------------------------------------------------------------- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: 小夏 < 449134904@qq.com> // +---------------------------------------------------------------------- namespace app\portal\controller; use cmf\controller\AdminBaseController; use app\portal\model\ImageModel; use think\Db; //封面图片管理 class AdminImageController extends AdminBaseController { //首页 public function index(){ $type = $this->request->param('type'); $imageModel = new ImageModel(); if(!empty($type) && isset($type)){ $image = $imageModel->where('type',$type)->order('weigh desc')->select(); }else{ $image = $imageModel->order('weigh desc')->select(); } $this->assign('image', $image); //封面图分类 $list = $this->getImgCategory(); $this->assign('list',$list); $this->assign('type',$type); return $this->fetch(); } //添加页面 public function add(){ //封面图分类 $list = $this->getImgCategory(); $this->assign('list',$list); return $this->fetch(); } //自定义封面图分类 private function getImgCategory(){ $imgCategory = [ ['id'=>1,'name'=>'首页'], ['id'=>2,'name'=>'星球画廊'], ['id'=>3,'name'=>'星享体验'], ['id'=>4,'name'=>'星探推荐'], ['id'=>5,'name'=>'星际活动'] ]; return $imgCategory; } //提交保存 public function addPost(){ $data = $this->request->param(); $imageModel = new ImageModel(); $result = $this->validate($data, 'AdminImage'); if ($result !== true) { $this->error($result); } $imageModel->allowField(true)->save($data); $this->success("添加成功!", url("AdminImage/index")); } //编辑页面 public function edit(){ $id = $this->request->param('id', 0, 'intval'); $imageModel = new ImageModel(); $image = $imageModel->get($id); //封面图分类 $list = $this->getImgCategory(); $this->assign('list',$list); $this->assign('image', $image); return $this->fetch(); } //编辑保存页面 public function editPost() { $data = $this->request->param(); $imageModel = new ImageModel(); $result = $this->validate($data, 'AdminImage'); if ($result !== true) { $this->error($result); } $imageModel->allowField(true)->isUpdate(true)->save($data); $this->success("保存成功!", url("AdminImage/index")); } //删除 public function delete(){ $id = $this->request->param('id', 0, 'intval'); $imageModel = new ImageModel(); $imageModel->where('id',$id)->delete(); $this->success("删除成功!", url("AdminImage/index")); } }