169 lines
6.1 KiB
PHP
169 lines
6.1 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\ProjectTotalBudget;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 项目总预算逻辑
|
||
* Class ProjectTotalBudgetLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectTotalBudgetLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加项目总预算
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = ProjectTotalBudget::create([
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'project_id' => $params['project_id'],
|
||
'total_budget_code' => data_unique_code('项目总预算'),
|
||
'contract_amount' => $params['contract_amount'],
|
||
'cl_cost' => $params['cl_cost'] ?? 0,
|
||
'fb_cost' => $params['fb_cost'] ?? 0,
|
||
'rg_cost' => $params['rg_cost'] ?? 0,
|
||
'fy_cost' => $params['fy_cost'] ?? 0,
|
||
'jj_cost' => $params['jj_cost'] ?? 0,
|
||
'remark' => $params['remark'] ?? '',
|
||
'budget_list' => !empty($params['budget_list']) ? $params['budget_list'] : null,
|
||
'budget_date' => strtotime($params['budget_date']),
|
||
'project_manager' => $params['project_manager'],
|
||
]);
|
||
Project::where('id',$params['project_id'])->update([
|
||
'is_budget' => 1,
|
||
'update_time' => time(),
|
||
]);
|
||
//添加审批信息
|
||
addApprove(
|
||
'项目总预算',
|
||
$res->id,
|
||
'app\common\model\project\ProjectTotalBudget',
|
||
'app\adminapi\logic\project\ProjectTotalBudgetLogic',
|
||
$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/08 14:25
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectTotalBudget::where('id', $params['id'])->update([
|
||
'contract_amount' => $params['contract_amount'],
|
||
'cl_cost' => $params['cl_cost'] ?? 0,
|
||
'fb_cost' => $params['fb_cost'] ?? 0,
|
||
'rg_cost' => $params['rg_cost'] ?? 0,
|
||
'fy_cost' => $params['fy_cost'] ?? 0,
|
||
'jj_cost' => $params['jj_cost'] ?? 0,
|
||
'remark' => $params['remark'] ?? '',
|
||
'budget_list' => !empty($params['budget_list']) ? $params['budget_list'] : null,
|
||
'budget_date' => strtotime($params['budget_date']),
|
||
'project_manager' => $params['project_manager'],
|
||
'update_time' => time(),
|
||
]);
|
||
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/08 14:25
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectTotalBudget::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取项目总预算详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectTotalBudget::field('id,org_id,dept_id,project_id,total_budget_code,contract_amount,cl_cost,fb_cost,rg_cost,fy_cost,jj_cost,remark,budget_list,budget_date,project_manager')
|
||
->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'];
|
||
//总成本
|
||
$data['total_cost'] = $data['cl_cost'] + $data['fb_cost'] + $data['rg_cost'] + $data['fy_cost'] + $data['jj_cost'];
|
||
//项目利润
|
||
$data['profit'] = $data['contract_amount'] - $data['total_cost'];
|
||
//利润率
|
||
$data['profit_rate'] = $data['profit'] / $data['contract_amount'];
|
||
//材料成本占比
|
||
$data['cl_cost_ratio'] = number_format($data['cl_cost'] / $data['total_cost'],2);
|
||
//分包成本占比
|
||
$data['fb_cost_ratio'] = number_format($data['fb_cost'] / $data['total_cost'],2);
|
||
//人工成本占比
|
||
$data['rg_cost_ratio'] = number_format($data['rg_cost'] / $data['total_cost'],2);
|
||
//费用成本占比
|
||
$data['fy_cost_ratio'] = number_format($data['fy_cost'] / $data['total_cost'],2);
|
||
//机具成本占比
|
||
$data['jj_cost_ratio'] = number_format($data['jj_cost'] / $data['total_cost'],2);
|
||
return $data->toArray();
|
||
}
|
||
} |