This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

428
app/admin/controller/Download.php Executable file
View File

@@ -0,0 +1,428 @@
<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
class Download extends BaseController {
public function index() {
$this->redirect('/admin/download/lists');
}
private function init_search(&$search)
{
$search['name'] = '';
$search['tags'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
public function lists($cid = 0) {
$data = $this->request->param();
$cid = isset($data['cid']) ? intval($data['cid']) : 0;
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != '')
{
$arg_where['a.name'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if (isset($data['tags']) && $data['tags'] != '')
{
$arg_where['a.tags'] = ['like', "%$data[tags]%"];
$search['tags'] = $data['tags'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != ''))
{
// 时间有一个不为空就初始化
$arg_where['a.createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = strtotime($data['timebegin']);
array_push($arg_where['a.createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = strtotime($data['timeend']);
array_push($arg_where['a.createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
}
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if ($cid > 0) {
$arg_where['a.cid'] = $cid;
}
$dataObject = model('download')->getCategoryDownloadLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search
];
$this->assign($value);
return $this->fetch();
}
public function add($cid = 0) {
$cid = is_numeric($cid) ? intval($cid) : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value = ['categoryOptions' => $categoryOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$downloadpath = [];
$downloadpath64 = [];
if (isset($data['downloadpath'])) {
foreach ($data['downloadpath'] as $k => $dl) {
if (empty($dl) && empty($data['downloadpath64'][$k]))
break;
$downloadpath[] = $dl;
$downloadpath64[] = empty($data['downloadpath64'][$k]) ? '下载' : $data['downloadpath64'][$k];
}
}
$data['downloadpath'] = trim(implode(',', $downloadpath), ',');
$data['downloadpath64'] = trim(implode(',', $downloadpath64), ',');
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['user_id'] = $this->user_id;
$data['country_code'] = $this->country_code;
$model = model('download')->insertRow($data);
//$model = Loader::model('Download')->insertRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$download = model('download')->getRow($id);
if (empty($download)) {
return $this->error(lang::get('incorrect operation'));
}
$value['download'] = $download;
} else {
return $this->error(lang::get('incorrect operation'));
}
$cid = isset($download['cid']) ? $download['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = [ 'name' => 'require', 'cid' => 'number|between:0,2147483647',];
$validatemsg = [ 'name.require' => '名称不能为空', 'cid.between' => '所属上级值无效',];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$downloadpath = [];
$downloadpath64 = [];
if (isset($data['downloadpath'])) {
foreach ($data['downloadpath'] as $k => $dl) {
if (empty($dl) && empty($data['downloadpath64'][$k]))
break;
$downloadpath[] = $dl;
$downloadpath64[] = empty($data['downloadpath64'][$k]) ? '下载' : $data['downloadpath64'][$k];
}
}
$data['downloadpath'] = trim(implode(',', $downloadpath), ',');
$data['downloadpath64'] = trim(implode(',', $downloadpath64), ',');
$data['sort'] = intval($data['sort']);
$model = model('download')->updateRow($data);
//$model = Loader::model('Download')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id > 0 && $sort < 2147483647) {
$model = model('download')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleheadline() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'headline' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleishot() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'ishot' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglerecommend() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'recommend' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function copy($id = 0) {
$id = intval($id);
if ($id > 0) {
$download = model('download')->getRow($id);
if (empty($download)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['download'] = $download;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$cid = isset($download['cid']) ? $download['cid'] : 0;
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions($cid, $arg_where, $arg_order, $arg_field, 100);
$value['categoryOptions'] = $categoryOptions;
$value['cid'] = $cid;
$this->assign($value);
return $this->fetch();
}
public function movecategory() {
$cid = $this->request->post('cid', 0);
$ids = $this->request->post('ids');
$cid = intval($cid);
if ($this->request->isPost() && $cid && $ids) {
$result = model('download')->updateRows(['cid' => $cid], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recommends() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->updateRows(['recommend' => 1], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('download')->deleteRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->deleteRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recycle() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.stat' => -1, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$arg_order = ['a.sort' => 'asc', 'a.id' => 'desc'];
$arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name|a.tags'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('download')->getRecycleLists($arg_where, $arg_order, $arg_field, 24);
$argc_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$argc_order = array('sort' => 'asc', 'id' => 'asc');
$argc_field = array('id', 'pid', 'haschild', 'name', 'sort');
$categoryOptions = model('download_category')->getCategoryOptions(0, $argc_where, $argc_order, $argc_field, 100);
$value = [
'categoryOptions' => $categoryOptions,
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function recovery($id = 0) {
$id = intval($id);
if ($id > 0) {
$model = model('download')->updateRow(['id' => $id, 'stat' => 0]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function recoverys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->updateRows(['stat' => 0], ['id' => ['in', $ids]]);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroy($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('download')->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function destroys() {
$ids = $this->request->post('ids');
if ($this->request->isPost() && $ids) {
$result = model('download')->destroyRows($ids);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/download/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}