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

210
app/admin/controller/Country.php Executable file
View File

@@ -0,0 +1,210 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-12-10
* Time: 13:48
*/
namespace app\admin\controller;
use think\Session;
use think\Lang;
class Country extends BaseController
{
public function index(){
// session_start();
$ct= session('cit',$_GET['cit']);
$ct = session('cit');
if($ct){
$this->success('修改成功');
}else{
$this->error('修改国家失败');
}
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = null;
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['country_name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = model('country')->getLists($arg_where, ['sort' => 'asc'], null, 20);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
'search' => $search,
];
$this->assign($value);
return $this->fetch();
}
public function add() {
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 = [
'country_name' => 'require',
'code' => 'require',
'url' => 'require',
'icon' => 'require',
'stat' => 'require',
'sort' => 'require|min:0|max:10000',
];
//验证提示信息
$validatemsg = [
'country_name.require' => '国家名不能为空',
'code.require' => '国家标记码不能为空',
'url.require' => '链接不能为空',
'icon.require' => '图标不能为空',
'sort.require' => '排序不能为空',
'stat.require' => '状态不能为空',
'sort.min' => '排序有效值为0-10000',
'sort.max' => '排序有效值为0-10000',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$insert_data = [
'country_name' => $data['country_name'],
'code' => $data['code'],
'url' => $data['url'],
'icon' => $data['icon'],
'sort' => $data['sort'],
'stat' => $data['stat'],
'create_time' => time(),
];
$model = model('country')->insertRow($insert_data);
if ($model && $model->getData('id')) {
$this->cacheDelete('country_list');
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function edit($id = 0) {
$id = intval($id);
if ($id > 0) {
$country = model('country')->where('id', $id)->find();
if (empty($country)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['country'] = $country;
$this->assign($value);
return $this->fetch();
} else {
return $this->fetch('add');
}
}
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 = [
'id' => 'require',
'country_name' => 'require',
'url' => 'require',
'code' => 'require',
'icon' => 'require',
'stat' => 'require',
'sort' => 'require|min:0|max:10000',
];
//验证提示信息
$validatemsg = [
'id.require' => 'id不能为空',
'country_name.require' => '国家名不能为空',
'code.require' => '国家标记码不能为空',
'url.require' => '链接不能为空',
'icon.require' => '图标不能为空',
'stat.require' => '状态不能为空',
'sort.require' => '排序不能为空',
'sort.min' => '排序有效值为0-10000',
'sort.max' => '排序有效值为0-10000',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$update_data = [
'id' => $data['id'],
'country_name' => $data['country_name'],
'code' => $data['code'],
'url' => $data['url'],
'icon' => $data['icon'],
'sort' => $data['sort'],
'stat' => $data['stat'],
'create_time' => time(),
];
$model = model('country')->updateRow($update_data);
if ($model && $model->getData('id')) {
if ($this->cacheHas('country_list')) {
$this->cacheDelete('country_list');
}
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$result = model('country')->where('id', $id)->update(['stat' => 1]);
if ($result) {
if ($this->cacheHas('country_list')) {
$this->cacheDelete('country_list');
}
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function deletes() {
if ($this->request->isPost()) {
$data = $this->request->post();
$result = model('country')->deleteRows($data['ids']);
if ($result) {
return $this->success(Lang::get('operation successed'), url('/admin/country/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}