80 lines
2.6 KiB
PHP
80 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
|
||
->field('id,context,status,starttime,endtime')
|
||
->order('starttime');
|
||
$data = $model->paginate($this->admin['per_page'], false, ['query' => $request->get()])->each(function ($item){
|
||
$item['starttime'] = date("Y-m-d H:i:s",intval($item['starttime']));
|
||
$item['endtime'] = date("Y-m-d H:i:s",intval($item['endtime']));
|
||
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[] = [
|
||
'context' => $param['context'],
|
||
'status' => 1,
|
||
'starttime' => strtotime($param['starttime']),
|
||
'endtime' => strtotime($param['endtime']),
|
||
];
|
||
$result = $model->saveAll($inset);
|
||
$result ? admin_success(lang('success'), URL_BACK) : admin_error();
|
||
|
||
}
|
||
|
||
return $this->fetch();
|
||
}
|
||
|
||
//删除
|
||
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('id', $id)->delete();
|
||
|
||
return $result ? admin_success(lang('delete_success'), URL_RELOAD) : admin_error(lang('delete_error'));
|
||
}
|
||
|
||
|
||
|
||
} |