add project_labor_budget
This commit is contained in:
parent
a1727ed68a
commit
696ef7c544
108
app/adminapi/controller/project/ProjectLaborBudgetController.php
Normal file
108
app/adminapi/controller/project/ProjectLaborBudgetController.php
Normal 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\ProjectLaborBudgetLists;
|
||||
use app\adminapi\logic\project\ProjectLaborBudgetLogic;
|
||||
use app\adminapi\validate\project\ProjectLaborBudgetValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算控制器
|
||||
* Class ProjectLaborBudgetController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectLaborBudgetController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectLaborBudgetLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加人工预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetValidate())->post()->goCheck('add');
|
||||
$result = ProjectLaborBudgetLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectLaborBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑人工预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetValidate())->post()->goCheck('edit');
|
||||
$result = ProjectLaborBudgetLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectLaborBudgetLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除人工预算
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetValidate())->post()->goCheck('delete');
|
||||
ProjectLaborBudgetLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetValidate())->goCheck('detail');
|
||||
$result = ProjectLaborBudgetLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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\ProjectLaborBudgetDetailLists;
|
||||
use app\adminapi\logic\project\ProjectLaborBudgetDetailLogic;
|
||||
use app\adminapi\validate\project\ProjectLaborBudgetDetailValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算明细控制器
|
||||
* Class ProjectLaborBudgetDetailController
|
||||
* @package app\adminapi\controller\project
|
||||
*/
|
||||
class ProjectLaborBudgetDetailController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算明细列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new ProjectLaborBudgetDetailLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加人工预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetDetailValidate())->post()->goCheck('add');
|
||||
$result = ProjectLaborBudgetDetailLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectLaborBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑人工预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetDetailValidate())->post()->goCheck('edit');
|
||||
$result = ProjectLaborBudgetDetailLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(ProjectLaborBudgetDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除人工预算明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetDetailValidate())->post()->goCheck('delete');
|
||||
ProjectLaborBudgetDetailLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算明细详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new ProjectLaborBudgetDetailValidate())->goCheck('detail');
|
||||
$result = ProjectLaborBudgetDetailLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
89
app/adminapi/lists/project/ProjectLaborBudgetDetailLists.php
Normal file
89
app/adminapi/lists/project/ProjectLaborBudgetDetailLists.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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\Project;
|
||||
use app\common\model\project\ProjectJobType;
|
||||
use app\common\model\project\ProjectLaborBudget;
|
||||
use app\common\model\project\ProjectLaborBudgetDetail;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算明细列表
|
||||
* Class ProjectLaborBudgetDetailLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectLaborBudgetDetailLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id', 'labor_budget_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算明细列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectLaborBudgetDetail::where($this->searchWhere)
|
||||
->field('id,project_id,labor_budget_id,job_type_id,desc,unit,num,price,amount,remark')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$labor_budget = ProjectLaborBudget::field('labor_budget_code')->where('id',$data['labor_budget_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$job_type = ProjectJobType::field('type_name')->where('id',$data['job_type_id'])->findOrEmpty();
|
||||
$data['labor_budget_code'] = $labor_budget['labor_budget_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['job_type_name'] = $job_type['type_name'];
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算明细数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectLaborBudgetDetail::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
88
app/adminapi/lists/project/ProjectLaborBudgetLists.php
Normal file
88
app/adminapi/lists/project/ProjectLaborBudgetLists.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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\Project;
|
||||
use app\common\model\project\ProjectLaborBudget;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\ProjectLaborBudgetDetail;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算列表
|
||||
* Class ProjectLaborBudgetLists
|
||||
* @package app\adminapi\listsproject
|
||||
*/
|
||||
class ProjectLaborBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id'],
|
||||
'%like%' => ['labor_budget_code'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return ProjectLaborBudget::where($this->searchWhere)
|
||||
->field(['id', 'project_id', 'labor_budget_code', 'remark', 'annex'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
//预算总工作量
|
||||
$data['total_num'] = ProjectLaborBudgetDetail::where('labor_budget_id',$data['id'])->sum('num');
|
||||
//预算总金额
|
||||
$data['total_amount'] = ProjectLaborBudgetDetail::where('labor_budget_id',$data['id'])->sum('amount');
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return ProjectLaborBudget::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
133
app/adminapi/logic/project/ProjectLaborBudgetDetailLogic.php
Normal file
133
app/adminapi/logic/project/ProjectLaborBudgetDetailLogic.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?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\Project;
|
||||
use app\common\model\project\ProjectJobType;
|
||||
use app\common\model\project\ProjectLaborBudget;
|
||||
use app\common\model\project\ProjectLaborBudgetDetail;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算明细逻辑
|
||||
* Class ProjectLaborBudgetDetailLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectLaborBudgetDetailLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加人工预算明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$labor_budget = ProjectLaborBudget::field('project_id')->where('id',$params['labor_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectLaborBudgetDetail::create([
|
||||
'project_id' => $labor_budget['project_id'],
|
||||
'labor_budget_id' => $params['labor_budget_id'],
|
||||
'job_type_id' => $params['job_type_id'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'unit' => $params['unit'] ?? '',
|
||||
'num' => $params['num'],
|
||||
'price' => $params['price'],
|
||||
'amount' => $params['num'] * $params['price'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑人工预算明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$labor_budget = ProjectLaborBudget::field('project_id')->where('id',$params['labor_budget_id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectLaborBudgetDetail::where('id', $params['id'])->update([
|
||||
'project_id' => $labor_budget['project_id'],
|
||||
'labor_budget_id' => $params['labor_budget_id'],
|
||||
'job_type_id' => $params['job_type_id'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'unit' => $params['unit'] ?? '',
|
||||
'num' => $params['num'],
|
||||
'price' => $params['price'],
|
||||
'amount' => $params['num'] * $params['price'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除人工预算明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectLaborBudgetDetail::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算明细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectLaborBudgetDetail::field('id,project_id,labor_budget_id,job_type_id,desc,unit,num,price,amount,remark')->findOrEmpty($params['id']);
|
||||
$labor_budget = ProjectLaborBudget::field('labor_budget_code')->where('id',$data['labor_budget_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$job_type = ProjectJobType::field('type_name')->where('id',$data['job_type_id'])->findOrEmpty();
|
||||
$data['labor_budget_code'] = $labor_budget['labor_budget_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['job_type_name'] = $job_type['type_name'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
167
app/adminapi/logic/project/ProjectLaborBudgetLogic.php
Normal file
167
app/adminapi/logic/project/ProjectLaborBudgetLogic.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?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\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectLaborBudget;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\ProjectLaborBudgetDetail;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算逻辑
|
||||
* Class ProjectLaborBudgetLogic
|
||||
* @package app\adminapi\logic\project
|
||||
*/
|
||||
class ProjectLaborBudgetLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加人工预算
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = ProjectLaborBudget::create([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'labor_budget_code' => data_unique_code('项目人工预算'),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
]);
|
||||
foreach ($params['labor_budget_detail'] as $item)
|
||||
{
|
||||
ProjectLaborBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'labor_budget_id' => $res->id,
|
||||
'job_type_id' => $item['job_type_id'],
|
||||
'desc' => $item['desc'] ?? '',
|
||||
'unit' => $item['unit'] ?? '',
|
||||
'price' => $item['price'],
|
||||
'num' => $item['num'],
|
||||
'amount' => $item['price'] * $item['num'],
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑人工预算
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
ProjectLaborBudget::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||||
'update_time' =>time(),
|
||||
]);
|
||||
foreach ($params['labor_budget_detail'] as $item)
|
||||
{
|
||||
if(isset($item['id']) && $item['id'] != ''){
|
||||
ProjectLaborBudgetDetail::where('id',$item['id'])->update([
|
||||
'project_id' => $params['project_id'],
|
||||
'job_type_id' => $item['job_type_id'],
|
||||
'desc' => $item['desc'] ?? '',
|
||||
'unit' => $item['unit'] ?? '',
|
||||
'price' => $item['price'],
|
||||
'num' => $item['num'],
|
||||
'amount' => $item['price'] * $item['num'],
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}else{
|
||||
ProjectLaborBudgetDetail::create([
|
||||
'project_id' => $params['project_id'],
|
||||
'labor_budget_id' => $params['id'],
|
||||
'job_type_id' => $item['job_type_id'],
|
||||
'desc' => $item['desc'] ?? '',
|
||||
'unit' => $item['unit'] ?? '',
|
||||
'price' => $item['price'],
|
||||
'num' => $item['num'],
|
||||
'amount' => $item['price'] * $item['num'],
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除人工预算
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return ProjectLaborBudget::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取人工预算详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = ProjectLaborBudget::field('id,org_id,dept_id,project_id,labor_budget_code,remark,annex')->findOrEmpty($params['id']);
|
||||
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
|
||||
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$data['org_name'] = $org['name'];
|
||||
$data['dept_name'] = $dept['name'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -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\ProjectJobType;
|
||||
use app\common\model\project\ProjectLaborBudget;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算明细验证器
|
||||
* Class ProjectLaborBudgetDetailValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectLaborBudgetDetailValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'labor_budget_id' => 'require|checkLaborBudget',
|
||||
'job_type_id' => 'require|checkJobType',
|
||||
'num' => 'require|float|gt:0',
|
||||
'price' => 'require|float|egt:0',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'labor_budget_id' => '人工预算id',
|
||||
'job_type_id' => '工种id',
|
||||
'num' => '数量',
|
||||
'price' => '单价',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectLaborBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectLaborBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectLaborBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectLaborBudgetDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkLaborBudget($value): bool|string
|
||||
{
|
||||
$data = ProjectLaborBudget::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '人工预算信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkJobType($value): bool|string
|
||||
{
|
||||
$data = ProjectJobType::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '工种信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
183
app/adminapi/validate/project/ProjectLaborBudgetValidate.php
Normal file
183
app/adminapi/validate/project/ProjectLaborBudgetValidate.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?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\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectJobType;
|
||||
use app\common\model\project\ProjectLaborBudgetDetail;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 人工预算验证器
|
||||
* Class ProjectLaborBudgetValidate
|
||||
* @package app\adminapi\validate\project
|
||||
*/
|
||||
class ProjectLaborBudgetValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'project_id' => 'require|checkProject',
|
||||
'annex' => 'checkAnnex',
|
||||
'labor_budget_detail' => 'require|checkLaborBudgetDetail'
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'project_id.require' => '请选择项目',
|
||||
'labor_budget_detail.require' => '请填写人工预算清单'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return ProjectLaborBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return ProjectLaborBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return ProjectLaborBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return ProjectLaborBudgetValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/16 09:26
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkOrg($value): bool|string
|
||||
{
|
||||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||||
if($org->isEmpty()){
|
||||
return '组织不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkDept($value,$rule,$data): bool|string
|
||||
{
|
||||
$dept = Dept::where('id',$value)->findOrEmpty();
|
||||
if($dept->isEmpty()){
|
||||
return '部门不存在';
|
||||
}
|
||||
if($dept['org_id'] != $data['org_id']){
|
||||
return '部门无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkProject($value): bool|string
|
||||
{
|
||||
$project = Project::where('id',$value)->findOrEmpty();
|
||||
if($project->isEmpty()){
|
||||
return '项目信息不存在';
|
||||
}
|
||||
if($project['is_budget'] != 1){
|
||||
return '该项目没有编制总预算,不能添加材料预算';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
if(!is_array($value)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkLaborBudgetDetail($value): bool|string
|
||||
{
|
||||
if(empty($value) || !is_array($value)){
|
||||
return '人工预算清单数据格式错误';
|
||||
}
|
||||
foreach($value as $v) {
|
||||
if(isset($v['id']) && $v['id'] != ''){
|
||||
$data = ProjectLaborBudgetDetail::where('id',$v['id'])->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '人工预算明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['job_type_id'])){
|
||||
return '请选择工种';
|
||||
}else{
|
||||
$job_type = ProjectJobType::where('id',$v['job_type_id'])->findOrEmpty();
|
||||
if($job_type->isEmpty()){
|
||||
return '工种信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['num'])){
|
||||
return '数量不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['num']) || $v['num'] < 0){
|
||||
return '数量必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
if(empty($v['price'])){
|
||||
return '单价不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['price']) || $v['price'] < 0){
|
||||
return '单价必须是大于0的数字';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
36
app/common/model/project/ProjectLaborBudget.php
Normal file
36
app/common/model/project/ProjectLaborBudget.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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 ProjectLaborBudget
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectLaborBudget extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_labor_budget';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value,true) : '';
|
||||
}
|
||||
}
|
34
app/common/model/project/ProjectLaborBudgetDetail.php
Normal file
34
app/common/model/project/ProjectLaborBudgetDetail.php
Normal 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 ProjectLaborBudgetDetail
|
||||
* @package app\common\model\project
|
||||
*/
|
||||
class ProjectLaborBudgetDetail extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'project_labor_budget_detail';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user