添加数据变更记录
This commit is contained in:
parent
80364d4b1a
commit
788a8cb211
95
app/admin/controller/ChangeLogController.php
Normal file
95
app/admin/controller/ChangeLogController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\ChangeLogLists;
|
||||
use app\admin\logic\ChangeLogLogic;
|
||||
use app\admin\validate\ChangeLogValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog控制器
|
||||
* Class ChangeLogController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class ChangeLogController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ChangeLogLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('add');
|
||||
$result = ChangeLogLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ChangeLogLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('edit');
|
||||
$result = ChangeLogLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ChangeLogLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->post()->goCheck('delete');
|
||||
ChangeLogLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ChangeLogValidate())->goCheck('detail');
|
||||
$result = ChangeLogLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
66
app/admin/lists/ChangeLogLists.php
Normal file
66
app/admin/lists/ChangeLogLists.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\ChangeLog;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog列表
|
||||
* Class ChangeLogLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ChangeLogLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['model', 'link_id', 'nums', 'pm', 'url'],
|
||||
'%like%' => ['mark'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ChangeLog::where($this->searchWhere)
|
||||
->field(['id', 'model', 'link_id', 'nums', 'pm', 'url', 'mark'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ChangeLog::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
103
app/admin/logic/ChangeLogLogic.php
Normal file
103
app/admin/logic/ChangeLogLogic.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use app\common\model\ChangeLog;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog逻辑
|
||||
* Class ChangeLogLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class ChangeLogLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ChangeLog::create([
|
||||
'model' => $params['model'],
|
||||
'link_id' => $params['link_id'],
|
||||
'nums' => $params['nums'],
|
||||
'pm' => $params['pm'],
|
||||
'url' => $params['url'],
|
||||
'mark' => $params['mark'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ChangeLog::where('id', $params['id'])->update([
|
||||
'model' => $params['model'],
|
||||
'link_id' => $params['link_id'],
|
||||
'nums' => $params['nums'],
|
||||
'pm' => $params['pm'],
|
||||
'url' => $params['url'],
|
||||
'mark' => $params['mark'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ChangeLog::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return ChangeLog::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
82
app/admin/validate/ChangeLogValidate.php
Normal file
82
app/admin/validate/ChangeLogValidate.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog验证器
|
||||
* Class ChangeLogValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class ChangeLogValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ChangeLogValidate
|
||||
* @author admin
|
||||
* @date 2025/01/06 10:03
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
22
app/common/model/ChangeLog.php
Normal file
22
app/common/model/ChangeLog.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ChangeLog模型
|
||||
* Class ChangeLog
|
||||
* @package app\common\model
|
||||
*/
|
||||
class ChangeLog extends BaseModel
|
||||
{
|
||||
|
||||
protected $name = 'change_log';
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user