175 lines
5.8 KiB
PHP
175 lines
5.8 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\ProjectMaterialBudget;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 材料预算逻辑
|
||
* Class ProjectMaterialBudgetLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectMaterialBudgetLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加材料预算
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/08 16:30
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
$detail = $params['material_budget_detail'];//json_decode($params['material_budget_detail'],true);
|
||
Db::startTrans();
|
||
try {
|
||
$project_material_budget = ProjectMaterialBudget::create([
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'project_id' => $params['project_id'],
|
||
'material_budget_code' => data_unique_code('项目材料预算'),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
foreach ($detail as $item)
|
||
{
|
||
ProjectMaterialBudgetDetail::create([
|
||
'project_id' => $params['project_id'],
|
||
'material_budget_id' => $project_material_budget->id,
|
||
'material_id' => $item['material_id'],
|
||
'budget_type' => 0,
|
||
'price' => $item['price'],
|
||
'num' => $item['num'],
|
||
'amount' => $item['price'] * $item['num'],
|
||
'remark' => $item['remark'] ?? '',
|
||
]);
|
||
}
|
||
//添加审批信息
|
||
addApprove(
|
||
'项目材料结算',
|
||
$project_material_budget->id,
|
||
'app\common\model\project\ProjectMaterialBudget',
|
||
'app\adminapi\logic\project\ProjectMaterialBudgetLogic',
|
||
$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 16:30
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
$detail = $params['material_budget_detail'];//json_decode($params['material_budget_detail'],true);
|
||
Db::startTrans();
|
||
try {
|
||
ProjectMaterialBudget::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,
|
||
]);
|
||
foreach ($detail as $item)
|
||
{
|
||
if(isset($item['id']) && $item['id'] != ''){
|
||
ProjectMaterialBudgetDetail::where('id',$item['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'material_budget_id' => $params['id'],
|
||
'material_id' => $item['material_id'],
|
||
'price' => $item['price'],
|
||
'num' => $item['num'],
|
||
'amount' => $item['price'] * $item['num'],
|
||
'remark' => $item['remark'] ?? '',
|
||
]);
|
||
}else{
|
||
ProjectMaterialBudgetDetail::create([
|
||
'project_id' => $params['project_id'],
|
||
'material_budget_id' => $params['id'],
|
||
'material_id' => $item['material_id'],
|
||
'budget_type' => 0,
|
||
'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/08 16:30
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectMaterialBudget::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取材料预算详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/08 16:30
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectMaterialBudget::field('id,org_id,dept_id,project_id,material_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();
|
||
}
|
||
} |