This commit is contained in:
yaooo 2023-12-13 14:17:24 +08:00
commit 9cdd866799
5 changed files with 485 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectTypeSetLists;
use app\adminapi\logic\project\ProjectTypeSetLogic;
use app\adminapi\validate\project\ProjectTypeSetValidate;
/**
* 项目类型设置控制器
* Class ProjectTypeSetController
* @package app\adminapi\controller\project
*/
class ProjectTypeSetController extends BaseAdminController
{
/**
* @notes 获取项目类型设置列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function lists()
{
return $this->dataLists(new ProjectTypeSetLists());
}
/**
* @notes 添加项目类型设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function add()
{
$params = (new ProjectTypeSetValidate())->post()->goCheck('add');
$result = ProjectTypeSetLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectTypeSetLogic::getError());
}
/**
* @notes 编辑项目类型设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function edit()
{
$params = (new ProjectTypeSetValidate())->post()->goCheck('edit');
$result = ProjectTypeSetLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectTypeSetLogic::getError());
}
/**
* @notes 删除项目类型设置
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function delete()
{
$params = (new ProjectTypeSetValidate())->post()->goCheck('delete');
ProjectTypeSetLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目类型设置详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function detail()
{
$params = (new ProjectTypeSetValidate())->goCheck('detail');
$result = ProjectTypeSetLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,83 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\dict\DictData;
use app\common\model\project\ProjectTypeSet;
use app\common\lists\ListsSearchInterface;
/**
* 项目类型设置列表
* Class ProjectTypeSetLists
* @package app\adminapi\listsproject
*/
class ProjectTypeSetLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function setSearch(): array
{
return [
'%like%' => ['name'],
];
}
/**
* @notes 获取项目类型设置列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function lists(): array
{
return ProjectTypeSet::where($this->searchWhere)
->field(['id', 'name', 'web_tags', 'app_tags', 'budget_tags'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$item['web_tags_text'] = DictData::where('type_value','project_web_tags')->where('value','in',$item['web_tags'])->order('sort desc')->column('name');
$item['app_tags_text'] = DictData::where('type_value','project_app_tags')->where('value','in',$item['app_tags'])->order('sort desc')->column('name');
$item['budget_tags_text'] = DictData::where('type_value','project_budget_tags')->where('value','in',$item['budget_tags'])->order('sort desc')->column('name');
return $item;
})
->toArray();
}
/**
* @notes 获取项目类型设置数量
* @return int
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function count(): int
{
return ProjectTypeSet::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,111 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\project;
use app\common\model\project\ProjectTypeSet;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目类型设置逻辑
* Class ProjectTypeSetLogic
* @package app\adminapi\logic\project
*/
class ProjectTypeSetLogic extends BaseLogic
{
/**
* @notes 添加项目类型设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 11:15
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectTypeSet::create([
'name' => $params['name'],
'web_tags' => $params['web_tags'],
'app_tags' => $params['app_tags'],
'budget_tags' => $params['budget_tags']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目类型设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 11:15
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectTypeSet::where('id', $params['id'])->update([
'name' => $params['name'],
'web_tags' => $params['web_tags'],
'app_tags' => $params['app_tags'],
'budget_tags' => $params['budget_tags']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目类型设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 11:15
*/
public static function delete(array $params): bool
{
return ProjectTypeSet::destroy($params['id']);
}
/**
* @notes 获取项目类型设置详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/13 11:15
*/
public static function detail($params): array
{
return ProjectTypeSet::field('id,name,web_tags,app_tags,budget_tags')->findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,149 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\project;
use app\common\model\dict\DictData;
use app\common\model\project\ProjectTypeSet;
use app\common\validate\BaseValidate;
/**
* 项目类型设置验证器
* Class ProjectTypeSetValidate
* @package app\adminapi\validate\project
*/
class ProjectTypeSetValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require|unique:'.ProjectTypeSet::class,
'web_tags' => 'checkWebTags',
'app_tags' => 'checkAppTags',
'budget_tags' => 'checkBudgetTags',
];
protected $message = [
'id.require' => '缺少必要参数',
'name.require' => '请填写类型名称',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '项目类型名称',
];
/**
* @notes 添加场景
* @return ProjectTypeSetValidate
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectTypeSetValidate
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectTypeSetValidate
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectTypeSetValidate
* @author likeadmin
* @date 2023/12/13 11:15
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkWebTags($value): bool|string
{
$tags = explode(',',$value);
if(empty($tags)){
return '请选择web标签';
}
$dictDate = DictData::where('type_value','project_web_tags')->column('value');
foreach($tags as $v) {
if(!in_array($v,$dictDate)){
return 'web标签不存在';
}
}
return true;
}
public function checkAppTags($value): bool|string
{
$tags = explode(',',$value);
if(empty($tags)){
return '请选择app标签';
}
$dictDate = DictData::where('type_value','project_app_tags')->column('value');
foreach($tags as $v) {
if(!in_array($v,$dictDate)){
return 'app标签不存在';
}
}
return true;
}
public function checkBudgetTags($value): bool|string
{
$tags = explode(',', $value);
if (empty($tags)) {
return '请选择预算标签';
}
$dictDate = DictData::where('type_value','project_budget_tags')->column('value');
foreach($tags as $v) {
if(!in_array($v,$dictDate)){
return '预算标签不存在';
}
}
return true;
}
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 项目类型设置模型
* Class ProjectTypeSet
* @package app\common\model\project
*/
class ProjectTypeSet extends BaseModel
{
use SoftDelete;
protected $name = 'project_type_set';
protected $deleteTime = 'delete_time';
}