This commit is contained in:
yaooo 2023-12-14 14:37:08 +08:00
commit e63b0934d0
6 changed files with 479 additions and 1 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\ProjectCostTempSetLists;
use app\adminapi\logic\project\ProjectCostTempSetLogic;
use app\adminapi\validate\project\ProjectCostTempSetValidate;
/**
* 项目费用模板控制器
* Class ProjectCostTempSetController
* @package app\adminapi\controller\project
*/
class ProjectCostTempSetController extends BaseAdminController
{
/**
* @notes 获取项目费用模板列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function lists()
{
return $this->dataLists(new ProjectCostTempSetLists());
}
/**
* @notes 添加项目费用模板
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function add()
{
$params = (new ProjectCostTempSetValidate())->post()->goCheck('add');
$result = ProjectCostTempSetLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectCostTempSetLogic::getError());
}
/**
* @notes 编辑项目费用模板
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function edit()
{
$params = (new ProjectCostTempSetValidate())->post()->goCheck('edit');
$result = ProjectCostTempSetLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectCostTempSetLogic::getError());
}
/**
* @notes 删除项目费用模板
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function delete()
{
$params = (new ProjectCostTempSetValidate())->post()->goCheck('delete');
ProjectCostTempSetLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目费用模板详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function detail()
{
$params = (new ProjectCostTempSetValidate())->goCheck('detail');
$result = ProjectCostTempSetLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?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\project\ProjectCostTempSet;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectTypeSet;
/**
* 项目费用模板列表
* Class ProjectCostTempSetLists
* @package app\adminapi\listsproject
*/
class ProjectCostTempSetLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function setSearch(): array
{
return [
'%like%' => ['subject_code', 'first_level_subject', 'second_level_subject', 'third_level_subject', 'unit'],
'=' => ['is_travel'],
];
}
/**
* @notes 获取项目费用模板列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['project_type_name']) && $params['project_type_name'] != ''){
$projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id');
$where[] = ['project_type_id','in',$projectTypeIds];
}
return ProjectCostTempSet::where($this->searchWhere)->where($where)
->field(['id', 'project_type_id', 'subject_code', 'first_level_subject', 'second_level_subject', 'third_level_subject', 'unit', 'is_travel'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$projectType = ProjectTypeSet::field('name')->where('id',$item['project_type_id'])->findOrEmpty();
$item['project_type_name'] = $projectType['name'];
return $item;
})
->toArray();
}
/**
* @notes 获取项目费用模板数量
* @return int
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['project_type_name']) && $params['project_type_name'] != ''){
$projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id');
$where[] = ['project_type_id','in',$projectTypeIds];
}
return ProjectCostTempSet::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -0,0 +1,120 @@
<?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\ProjectCostTempSet;
use app\common\logic\BaseLogic;
use app\common\model\project\ProjectTypeSet;
use think\facade\Db;
/**
* 项目费用模板逻辑
* Class ProjectCostTempSetLogic
* @package app\adminapi\logic\project
*/
class ProjectCostTempSetLogic extends BaseLogic
{
/**
* @notes 添加项目费用模板
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/14 11:54
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ProjectCostTempSet::create([
'project_type_id' => $params['project_type_id'],
'subject_code' => $params['subject_code'],
'first_level_subject' => $params['first_level_subject'],
'second_level_subject' => $params['second_level_subject'],
'third_level_subject' => $params['third_level_subject'],
'unit' => $params['unit'],
'is_travel' => $params['is_travel'],
]);
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/14 11:54
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectCostTempSet::where('id', $params['id'])->update([
'project_type_id' => $params['project_type_id'],
'subject_code' => $params['subject_code'],
'first_level_subject' => $params['first_level_subject'],
'second_level_subject' => $params['second_level_subject'],
'third_level_subject' => $params['third_level_subject'],
'unit' => $params['unit'],
'is_travel' => $params['is_travel'],
]);
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/14 11:54
*/
public static function delete(array $params): bool
{
return ProjectCostTempSet::destroy($params['id']);
}
/**
* @notes 获取项目费用模板详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/14 11:54
*/
public static function detail($params): array
{
$data = ProjectCostTempSet::field('id,project_type_id,subject_code,first_level_subject,second_level_subject,third_level_subject,unit,is_travel')->findOrEmpty($params['id'])->toArray();
$projectType = ProjectTypeSet::field('name')->where('id',$data['project_type_id'])->findOrEmpty();
$data['project_type_name'] = $projectType['name'];
return $data;
}
}

View File

@ -0,0 +1,120 @@
<?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\project\ProjectCostTempSet;
use app\common\model\project\ProjectTypeSet;
use app\common\validate\BaseValidate;
/**
* 项目费用模板验证器
* Class ProjectCostTempSetValidate
* @package app\adminapi\validate\project
*/
class ProjectCostTempSetValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'project_type_id' => 'require|checkProjectType',
'subject_code' => 'require|unique:'.ProjectCostTempSet::class,
'first_level_subject' => 'require',
'is_travel' => 'require|integer|in:1,2',
];
protected $message = [
'id.require' => '缺少你要参数',
'project_type_id.require' => '请选择项目类型',
'subject_code.require' => '请填写科目编码',
'subject_code.unique' => '科目编码不能重复',
'first_level_subject' => '请填写一级科目',
'is_travel.require' => '请选择是否是差旅科目',
'is_travel.integer' => '差旅科目数据格式错误',
'is_travel.in' => '差旅科目数据值错误'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_type_id' => '项目类型id',
'subject_code' => '科目编码',
'first_level_subject' => '一级科目',
'is_travel' => '是否是差旅科目 1-是 2-否',
];
/**
* @notes 添加场景
* @return ProjectCostTempSetValidate
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectCostTempSetValidate
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectCostTempSetValidate
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectCostTempSetValidate
* @author likeadmin
* @date 2023/12/14 11:54
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkProjectType($value): bool|string
{
$data = ProjectTypeSet::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目类型不存在';
}
return true;
}
}

View File

@ -38,7 +38,7 @@ class ProjectLogsValidate extends BaseValidate
'project_id' => 'require|checkProject',
'theme' => 'require',
'date' => 'require|date',
'follow_type' => 'checkFollowType',
'follow_type' => 'require|checkFollowType',
'next_follow_up_date' => 'date|checkNextFollowUpDate',
];
@ -48,6 +48,7 @@ class ProjectLogsValidate extends BaseValidate
'theme.require' => '主题不能为空',
'date.require' => '日期不能为空',
'date.date' => '日期格式不正确',
'follow_type.require' => '请选择类型',
'next_follow_up_date.date' => '下次跟进时间格式不正确',
];

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;
/**
* 项目费用模板模型
* Class ProjectCostTempSet
* @package app\common\model\project
*/
class ProjectCostTempSet extends BaseModel
{
protected $name = 'project_cost_temp_set';
}