87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
||
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
||
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
||
// +----------------------------------------------------------------------
|
||
// | 创建时间: 2022/1/5 22:51
|
||
// +----------------------------------------------------------------------
|
||
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\model\Broad;
|
||
use think\Request;
|
||
use think\Db;
|
||
|
||
class BroadController extends Controller
|
||
{
|
||
public function index(Request $request, Broad $model)
|
||
{
|
||
$param = $request->param();
|
||
$model = $model
|
||
->order('server_id');
|
||
$data = $model->paginate($this->admin['per_page'], false, ['query' => $request->get()])->each(function ($item){
|
||
return $item;
|
||
});
|
||
// dump($data);
|
||
$this->assign($request->get());
|
||
$this->assign([
|
||
'data' => $data->toArray()['data'],
|
||
'page' => $data->render(),
|
||
'total' => $data->total(),
|
||
]);
|
||
return $this->fetch();
|
||
}
|
||
|
||
|
||
public function add(Request $request, Broad $model)
|
||
{
|
||
if ($request->isPost()) {
|
||
$param = $request->param();
|
||
|
||
$inset = [
|
||
'server_id' => $param['server_id'],
|
||
'text' => $param['context'],
|
||
'title' => $param['title']
|
||
];
|
||
$result = $model->insertGetId($inset);
|
||
admin_success(lang('success'), URL_BACK);
|
||
|
||
}
|
||
|
||
return $this->fetch();
|
||
}
|
||
|
||
public function edit($id, Request $request, Broad $model)
|
||
{
|
||
$data = $model::get($id);
|
||
if ($request->isPost()) {
|
||
$param = $request->param();
|
||
$data->save($param) ? admin_success() : admin_error();
|
||
}
|
||
$this->assign('data', $data);
|
||
return $this->fetch('add');
|
||
}
|
||
|
||
//删除
|
||
public function del($id, Broad $model)
|
||
{
|
||
if (count($model->noDeletionId) > 0) {
|
||
if (is_array($id)) {
|
||
if (array_intersect($model->noDeletionId, $id)) {
|
||
return admin_error('ID为' . implode(',', $model->noDeletionId) . '的数据无法删除');
|
||
}
|
||
} else if (in_array($id, $model->noDeletionId)) {
|
||
return admin_error('ID为' . $id . '的数据无法删除');
|
||
}
|
||
}
|
||
|
||
$result = $model->whereIn('server_id', $id)->delete();
|
||
|
||
return $result ? admin_success(lang('delete_success'), URL_RELOAD) : admin_error(lang('delete_error'));
|
||
}
|
||
|
||
|
||
|
||
} |