97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\controller\Backend;
|
||
use think\facade\Db;
|
||
|
||
class UrlAddress extends Backend
|
||
{
|
||
protected array $noNeedLogin = ['*'];
|
||
|
||
public function selectUrlAddress()
|
||
{
|
||
$info = Db::name('url_address')->order('num', 'asc')->limit(1)->find();
|
||
if ($info) {
|
||
$info['num'] = $info['num'] ? $info['num'] + 1 : 1;
|
||
Db::name('url_address')->where([
|
||
'url_id' => $info['url_id']
|
||
])->update([
|
||
'num' => $info['num']
|
||
]);
|
||
}
|
||
|
||
$this->successWithData(convertToCamelCase($info));
|
||
|
||
}
|
||
|
||
public function selectUrlAddressList()
|
||
{
|
||
$get = $this->request->get();
|
||
$page = $get['page']; // 页码,默认1
|
||
$limit = $get['limit']; // 每页条数,默认10
|
||
$urlAddress = $get['urlAddress']; // URL地址关键词
|
||
$status = $get['status']; // 状态值
|
||
$db = Db::connect(get_master_connect_name());
|
||
// 构建查询
|
||
$query = $db->name('url_address');
|
||
if(!empty($urlAddress)) {
|
||
$query->where('url_address', 'like', "%{$urlAddress}%");
|
||
}
|
||
if(!empty($status)) {
|
||
$query->where('status', $status);
|
||
}
|
||
$count = $query->count();
|
||
$info = $query->limit(page($page, $limit), $limit)->select()->toArray();
|
||
$this->n_success(['data' => [
|
||
'totalCount' => $count,
|
||
'pageSize' => $get['limit'],
|
||
'totalPage' => ceil($count / $get['limit']),
|
||
'currPage' => $get['page'],
|
||
'list' => $info,
|
||
'records' => null
|
||
]]);
|
||
}
|
||
|
||
|
||
public function updateUrlAddress()
|
||
{
|
||
$post = $this->request->post();
|
||
|
||
$url_id = $post['urlId'] ?? null;
|
||
$data['num'] = $post['num'] ?? null;
|
||
$data['url_address'] = $post['urlAddress'] ?? null;
|
||
$data['status'] = $post['status'] ?? null;
|
||
Db::name('url_address')->where(['url_id' => $url_id])->update($data);
|
||
$this->success();
|
||
}
|
||
|
||
|
||
// 创建域名
|
||
public function insertUrlAddress()
|
||
{
|
||
$post = $this->request->post();
|
||
$data['num'] = $post['num'] ?? null;
|
||
$data['url_address'] = $post['urlAddress'] ?? null;
|
||
$data['status'] = $post['status'] ?? null;
|
||
$data['create_time'] = date('Y-m-d H:i:s');
|
||
Db::name('url_address')->insert($data);
|
||
$this->success();
|
||
}
|
||
|
||
public function deleteUrlAddress()
|
||
{
|
||
$param = $this->request->get();
|
||
if(empty($param['addressId'])) {
|
||
$this->error('参数错误');
|
||
}
|
||
Db::name('url_address')->where(['url_id' => $param['addressId']])->delete();
|
||
$this->success();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |