180 lines
6.0 KiB
PHP
180 lines
6.0 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\ProjectEquipmentBudget;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\project\ProjectEquipmentBudgetDetail;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 机具预算逻辑
|
||
* Class ProjectEquipmentBudgetLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectEquipmentBudgetLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加机具预算
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/16 11:40
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = ProjectEquipmentBudget::create([
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'project_id' => $params['project_id'],
|
||
'equipment_budget_code' => data_unique_code('项目机具预算'),
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
]);
|
||
foreach ($params['equipment_budget_detail'] as $item)
|
||
{
|
||
ProjectEquipmentBudgetDetail::create([
|
||
'project_id' => $params['project_id'],
|
||
'equipment_budget_id' => $res->id,
|
||
'type' => $item['type'],
|
||
'name' => $item['name'],
|
||
'spec' => $item['spec'] ?? '',
|
||
'unit' => $item['unit'],
|
||
'price' => $item['price'],
|
||
'num' => $item['num'],
|
||
'amount' => $item['price'] * $item['num'],
|
||
'remark' => $item['remark'] ?? '',
|
||
]);
|
||
}
|
||
//添加审批信息
|
||
addApprove(
|
||
'项目机具预算',
|
||
$res->id,
|
||
'app\common\model\project\ProjectEquipmentBudget',
|
||
'app\adminapi\logic\project\ProjectEquipmentBudgetLogic',
|
||
$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 11:40
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectEquipmentBudget::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 ($params['equipment_budget_detail'] as $item)
|
||
{
|
||
if(isset($item['id']) && $item['id'] != ''){
|
||
ProjectEquipmentBudgetDetail::where('id',$item['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'equipment_budget_id' => $params['id'],
|
||
'type' => $item['type'],
|
||
'name' => $item['name'],
|
||
'spec' => $item['spec'] ?? '',
|
||
'unit' => $item['unit'],
|
||
'price' => $item['price'],
|
||
'num' => $item['num'],
|
||
'amount' => $item['price'] * $item['num'],
|
||
'remark' => $item['remark'] ?? '',
|
||
]);
|
||
}else{
|
||
ProjectEquipmentBudgetDetail::create([
|
||
'project_id' => $params['project_id'],
|
||
'equipment_budget_id' => $params['id'],
|
||
'type' => $item['type'],
|
||
'name' => $item['name'],
|
||
'spec' => $item['spec'] ?? '',
|
||
'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 11:40
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectEquipmentBudget::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取机具预算详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/16 11:40
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectEquipmentBudget::field('id,org_id,dept_id,project_id,equipment_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();
|
||
}
|
||
} |