151 lines
5.7 KiB
PHP
151 lines
5.7 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\build;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\build\BuildDivision;
|
||
use app\common\model\build\BuildPlan;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\build\BuildProcessSettings;
|
||
use app\common\model\build\BuildReport;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectMember;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 施工计划逻辑
|
||
* Class BuildPlanLogic
|
||
* @package app\adminapi\logic\build
|
||
*/
|
||
class BuildPlanLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加施工计划
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/22 11:04
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
BuildPlan::create([
|
||
'project_id' => $params['project_id'],
|
||
'process_id' => $params['process_id'],
|
||
'project_member_id' => $params['project_member_id'],
|
||
'zy_code' => data_unique_code('ZY'),
|
||
'plan_start_date' => strtotime($params['plan_start_date']),
|
||
'plan_end_date' => strtotime($params['plan_end_date']),
|
||
'work_user' => $params['work_user'],
|
||
'work_content' => $params['work_content'],
|
||
'workload' => $params['workload'],
|
||
'unit' => $params['unit'],
|
||
'price' => $params['price'],
|
||
'amount' => $params['amount'],
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑施工计划
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/22 11:04
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
BuildPlan::where('id', $params['id'])->update([
|
||
'project_id' => $params['project_id'],
|
||
'process_id' => $params['process_id'],
|
||
'project_member_id' => $params['project_member_id'],
|
||
'plan_start_date' => strtotime($params['plan_start_date']),
|
||
'plan_end_date' => strtotime($params['plan_end_date']),
|
||
'work_user' => $params['work_user'],
|
||
'work_content' => $params['work_content'],
|
||
'workload' => $params['workload'],
|
||
'unit' => $params['unit'],
|
||
'price' => $params['price'],
|
||
'amount' => $params['amount'],
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除施工计划
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/22 11:04
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return BuildPlan::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取施工计划详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/22 11:04
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$field = 'id,zy_code,project_id,process_id,project_member_id,plan_start_date,plan_end_date,work_user,work_content,workload,unit,price,amount';
|
||
$data = BuildPlan::field($field)->findOrEmpty($params['id']);
|
||
if(empty($data)) return [];
|
||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||
$process = BuildProcessSettings::field('division_id,process_step_no,process_step,quality_control_points,annex')->where('id',$data['process_id'])->findOrEmpty();
|
||
$division = BuildDivision::field('subentry_engineering,subentry_engineering_code')->where('id',$process['division_id'])->findOrEmpty();
|
||
$projectMember = ProjectMember::field('admin_id')->where('id',$data['project_member_id'])->findOrEmpty();
|
||
$admin = Admin::field('name')->where('id',$projectMember['admin_id'])->findOrEmpty();
|
||
$data['project_name'] = $project['name'];
|
||
$data['project_code'] = $project['project_code'];
|
||
$data['subentry_engineering'] = $division['subentry_engineering'];
|
||
$data['subentry_engineering_code'] = $division['subentry_engineering_code'];
|
||
$data['process_step_no'] = $process['process_step_no'];
|
||
$data['process_step'] = $process['process_step'];
|
||
$data['quality_control_points'] = $process['quality_control_points'];
|
||
$data['file'] = $process['annex'];
|
||
$data['project_member_name'] = $admin['name'];
|
||
$data['done_workload'] = BuildReport::where('plan_id',$data['id'])->sum('report_workload');
|
||
$data['residue_workload'] = ($data['workload'] - $data['done_workload']) <=0 ? 0 : $data['workload'] - $data['done_workload'];
|
||
$data['completion_degree'] = round($data['done_workload'] / $data['workload'],3).'%';
|
||
return $data->toArray();
|
||
}
|
||
} |