批量更新租户规则

This commit is contained in:
2026-03-09 23:00:20 +08:00
parent e09b4c639c
commit e27cc8f457
45 changed files with 579 additions and 314 deletions
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace app\admin\controller\Cms\Demand;
use app\index\BaseController;
use app\admin\BaseController;
use Symfony\Component\VarDumper\VarDumper;
use think\exception\ValidateException;
use think\facade\Request;
@@ -26,6 +26,7 @@ class DemandController extends BaseController
{
// 查询分类
$demandList = Demand::where('delete_time', null)
->where('tid', $this->getTenantId())
->order('id', 'desc')
->select();
@@ -52,7 +53,7 @@ class DemandController extends BaseController
{
try {
$data = Request::only(['title', 'desc', 'applicant', 'status']);
// 验证数据
if (empty($data['title']) || empty($data['desc'])) {
return json([
@@ -60,15 +61,16 @@ class DemandController extends BaseController
'msg' => '标题和描述不能为空',
]);
}
// 创建需求
$demand = Demand::create([
'title' => $data['title'],
'desc' => $data['desc'],
'applicant' => $data['applicant'] ?? '',
'status' => $data['status'] ?? 'pending',
'tid' => $this->getTenantId(),
]);
return json([
'code' => 200,
'msg' => '添加成功',
@@ -91,7 +93,7 @@ class DemandController extends BaseController
try {
$id = Request::param('id');
$data = Request::only(['title', 'desc', 'applicant', 'status']);
// 验证数据
if (empty($id)) {
return json([
@@ -99,23 +101,25 @@ class DemandController extends BaseController
'msg' => '需求ID不能为空',
]);
}
if (empty($data['title']) || empty($data['desc'])) {
return json([
'code' => 400,
'msg' => '标题和描述不能为空',
]);
}
// 查找需求
$demand = Demand::find($id);
// 查找需求(验证tid
$demand = Demand::where('id', $id)
->where('tid', $this->getTenantId())
->find();
if (!$demand) {
return json([
'code' => 404,
'msg' => '需求不存在',
]);
}
// 更新需求
$demand->save([
'title' => $data['title'],
@@ -123,7 +127,7 @@ class DemandController extends BaseController
'applicant' => $data['applicant'] ?? '',
'status' => $data['status'] ?? 'pending',
]);
return json([
'code' => 200,
'msg' => '编辑成功',
@@ -145,7 +149,7 @@ class DemandController extends BaseController
{
try {
$id = Request::param('id');
// 验证数据
if (empty($id)) {
return json([
@@ -153,19 +157,21 @@ class DemandController extends BaseController
'msg' => '需求ID不能为空',
]);
}
// 查找需求
$demand = Demand::find($id);
// 查找需求(验证tid
$demand = Demand::where('id', $id)
->where('tid', $this->getTenantId())
->find();
if (!$demand) {
return json([
'code' => 404,
'msg' => '需求不存在',
]);
}
// 软删除
$demand->delete();
return json([
'code' => 200,
'msg' => '删除成功',