141 lines
4.8 KiB
PHP
141 lines
4.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\auth\Admin;
|
||
use app\common\model\oa\FlowApprove;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectCostAdjustment;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 成本调整逻辑
|
||
* Class ProjectCostAdjustmentLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectCostAdjustmentLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加成本调整
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/17 13:43
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$res = ProjectCostAdjustment::create([
|
||
'project_id' => $params['project_id'],
|
||
'adjust_date' => strtotime($params['adjust_date']),
|
||
'adjust_amount' => $params['adjust_amount'],
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'add_user' => $admin_id,
|
||
'update_user' => $admin_id,
|
||
]);
|
||
//添加审批信息
|
||
addApprove(
|
||
'成本调整',
|
||
$res->id,
|
||
'app\common\model\project\ProjectCostAdjustment',
|
||
'app\adminapi\logic\project\ProjectCostAdjustmentLogic',
|
||
$params['approve_detail']['path'],
|
||
$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/17 13:43
|
||
*/
|
||
public static function edit(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectCostAdjustment::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'adjust_date' => strtotime($params['adjust_date']),
|
||
'adjust_amount' => $params['adjust_amount'],
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
||
'update_user' => $admin_id,
|
||
'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/17 13:43
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectCostAdjustment::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取成本调整详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/17 13:43
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = ProjectCostAdjustment::field('id,project_id,adjust_date,adjust_amount,remark,annex,add_user,update_user,create_time,update_time')->findOrEmpty($params['id']);
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id');
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['add_user'] = $admin[$data['add_user']];
|
||
$data['update_user'] = $admin[$data['update_user']];
|
||
$approve_info = FlowApprove::field('id')->where('content_id',$params['id'])
|
||
->where('content_model','app\common\model\project\ProjectCostAdjustment')
|
||
->where('content_logic','app\adminapi\logic\project\ProjectCostAdjustmentLogic')->findOrEmpty();
|
||
$data['approve_id'] = $approve_info['id'];
|
||
return $data->toArray();
|
||
}
|
||
} |