Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/app/admin/controller/ |
<?php namespace app\admin\controller; use app\common\model\Adv as AdvModel; use app\common\model\AdvData; use think\facade\View; class Adv extends Controller { //广告位管理 public function index() { $name = $this->request->param('name'); $type = $this->request->param('type'); $where = []; $where[] = ['type', '=', $type]; $name && $where[] = ['name','like',"%{$name}%"]; $data = \app\admin\model\Adv::getList($where, $this->limit, ['create_time'=>'desc']); return success($data); } public function add() { if($this->request->isPost()) { $data = $this->request->param(); try { AdvModel::add($data); }catch (\Exception $e) { return error($e->getMessage()); } return success(); } } public function edit($id) { $model = AdvModel::detail($id); if($this->request->isPost()) { $data = $this->request->param(); AdvModel::saveData($model, $data); } return success($model); } public function del($id) { /*if(\app\admin\model\AdvData::getAll(['ap_id'=>$id])) { return error('此广告下有广告位,请先删除'); }*/ $data = \app\admin\model\AdvData::getAll(['ap_id'=>$id]); if(!$data->isEmpty()) { return error('此广告下有广告位,请先删除'); } AdvModel::del($id); return success(); } /** * 获取所有广告位 * @return \think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getAdvAll() { $data = AdvModel::getAll(); return success($data); } //广告管理 public function advDataIndex() { $ap_id = $this->request->param('ap_id'); $where = []; $where[] = ['ap_id', '=', $ap_id]; $data = \app\admin\model\AdvData::getList($where, $this->limit, ['sort'=>'asc'], ['adv']); return success($data); } public function AdvDataAdd() { if($this->request->isPost()) { $data = $this->request->param(); try { AdvData::add($data); }catch (\Exception $e) { return error($e->getMessage()); } return success(); } } public function AdvDataEdit($adv_data_id) { $model = AdvData::detail($adv_data_id); if($this->request->isPost()) { $data = $this->request->param(); AdvData::saveData($model, $data); } return success($model); } public function AdvDataDel($adv_data_id) { AdvData::del($adv_data_id); return success(); } /*public function index() { $keyword = $this->request->param('keyword'); $where = []; $where[] = ['type' ,'=', $this->type]; $keyword && $where[] = ['name','like',"%{$keyword}%"]; $data = AdvModel::getList($where, 10, ['id'=>'asc']); View::assign('data', $data); return view(); } public function ap_add() { if($this->request->isPost()) { $data = $this->request->param(); $validata = new \app\admin\validate\Adv(); if(true !== $validata->check($data)) { showDialog($validata->getError()); } $res = AdvModel::add($data); if($res) { showDialog('数据提交成功',$this->_url('ap_index',['type'=>$this->type]),'succ'); }else { showDialog('数据提交失败'); } } View::assign('adv', Config::get('tables.adv')); return view(); } public function ap_edit($id) { if($this->request->isPost()) { $data = $this->request->post(); $validata = new \app\admin\validate\Adv(); if(true !== $validata->check($data)) { showDialog($validata->getError()); } $model = AdvModel::detail($id); if(!$model || !$id) { showDialog('信息不存在'); } $res = AdvModel::saveData($model, $data); if($res!==false) { showDialog('数据提交成功',$this->_url('ap_index',['type'=>$this->type])); }else { showDialog('数据提交失败'); } } $data = AdvModel::detail($id); if(!$id || !$data) { showDialog('信息不存在'); }; View::assign('data', $data); View::assign('adv', Config::get('tables.adv')); return view(); } public function ap_delete($id) { AdvModel::del($id); showDialog('数据提交成功',$this->_url('ap_index',['type'=>$this->type]),'succ'); }*/ //广告管理 public function adv($ap_id) { $where = []; $where[] = ['ap_id','=', $ap_id]; $data = AdvData::getList($where, 10, ['sort'=>'asc']); View::assign('data', $data); return view(); } /** * 添加广告位 * @param unknown $ap_id * @return unknown */ public function adv_add($ap_id) { if($this->request->isPost()) { $data = $this->request->post(); if(empty($data['name'])) { showDialog('广告标题不能为空'); } $upload = \Upload::uploadify('file', 'adv'); if(false !== $upload) { $data['filename'] = $upload['savename']; } $res = AdvData::add($data); if($res) { showDialog('数据提交成功',$this->_url('adv',['ap_id'=>$data['ap_id']]),'succ'); }else { showDialog('数据提交失败'); } } View::assign('ap_adv', AdvModel::getAllColumn()); return view(); } public function adv_edit($id) { if($this->request->isPost()) { $model = AdvData::detail($id); if(!$model || !$id) { showDialog('信息不存在'); } $data = $this->request->param(); $upload = \Upload::uploadify('file','adv'); if(false !== $upload) { $data['filename'] = $upload['savename']; $model->getData('filename') && \Upload::delAttach($model->getData('filename')); } $res = AdvData::saveData($model, $data); if($res) { showDialog('数据提交成功',$this->_url('adv',['ap_id'=>$data['ap_id']]),'succ'); }else { showDialog('数据提交失败'); } } $data = AdvData::detail($id); View::assign('data',$data); View::assign('ap_adv', AdvModel::getAllColumn()); return view(); } public function adv_delete($id) { $ap_id = $this->request->param('ap_id/d'); AdvData::del($id); showDialog('数据提交成功',$this->_url('adv',['ap_id'=>$ap_id])); } /** * 更新排序 */ public function sort() { $ap_id = $this->request->param('ap_id/d'); $type = $this->type; $sort = $this->request->param('sort/a'); $model = new AdvData(); if(!empty($sort)) { $this->_sort($model, $sort); } showDialog('数据提交成功', $this->_url('adv',['ap_id'=>$ap_id])); } }