企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ <?php namespace app\admin\controller; use app\common\controller\AdminBase; use think\Db; use think\Session; class Imgfiletag extends AdminBase { protected function _initialize() { parent::_initialize(); } public function index() { return $this->fetch(); } //添加1-1 public function add() { return $this->fetch(); } //添加1-2 public function save() { if ($this->request->isPost()) { $status=0; $message="添加失败"; $data=$this->request->param(); $map = ['title'=> $data['title']]; $admin = model('ImgfileTag')::get($map); if($admin){ $message='添加失败,分组名已存在'; }else { $data['create_time']=time(); if (model('ImgfileTag')->allowField(true)->save($data)) { $status = 1; $message = '添加成功'; } } } return ['status'=>$status,'message'=>$message]; } //编辑1-1 public function edit($id) { $apage=Db::table('yp_imgfile_tag')->where('id',$id)->find(); $this->assign('apage',$apage); return $this->fetch(); } //编辑1-2 public function update($id) { $status=0; $message="更新失败"; $data=$this->request->param(); $map = ['title'=> $data['title']]; $admin = model('ImgfileTag')::get($map); if($admin){ $message='更新失败,分组名已存在'; }else { $data['create_time']=time(); if (model('ImgfileTag')->allowField(true)->save($data,['id'=>$data['id']])){ $status = 1; $message = '更新成功'; } } return ['status'=>$status,'message'=>$message]; } //删除 public function delete($id) { $message="删除失败"; if($id==1){ $message="默认分组不允许删除"; }else{ $ta=Db::name('imgfile')->where('tag_id',$id)->field('id')->select(); if (empty($ta)) { model('ImgfileTag')->destroy($id); $message="已删除"; }else{ //halt($ta); $tag[]=''; foreach ($ta as $key => $val) { if(is_array($val)){ foreach ($val as $k => $v) { $tag[$key]=$v; } } } if(Db::name('imgfile')->where('id','in',$tag)->setField('tag_id',1)){ model('ImgfileTag')->destroy($id); $message="已删除"; } } } return $message; } } ~~~