176 lines
5.9 KiB
PHP
176 lines
5.9 KiB
PHP
<?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,$admin_id): 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'] ?? '',
|
||
]);
|
||
}
|
||
//添加审批信息
|
||
addApprove(
|
||
'项目人工预算',
|
||
$res->id,
|
||
'app\common\model\project\ProjectLaborBudget',
|
||
'app\adminapi\logic\project\ProjectLaborBudgetLogic',
|
||
$params['approve_detail']['flow_type'],
|
||
$params['approve_detail']['flow_path'],
|
||
$admin_id
|
||
);
|
||
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();
|
||
}
|
||
} |