114 lines
4.5 KiB
PHP
114 lines
4.5 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\model\build\BuildProcessSettings;
|
||
use app\common\model\build\BuildReport;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\build\BuildReportDetail;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectMember;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* 施工汇报逻辑
|
||
* Class BuildReportLogic
|
||
* @package app\adminapi\logic\build
|
||
*/
|
||
class BuildReportLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加施工汇报
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public static function add(array $params,$admin_id): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$detail =$params['person_detail'];// json_decode($params['person_detail'],true);
|
||
$reportRes = BuildReport::create([
|
||
'report_code' => data_unique_code('施工汇报'),
|
||
'plan_id' => $params['plan_id'],
|
||
'scene_file' => !empty($params['scene_file']) ? json_encode($params['scene_file']) : null,
|
||
'report_workload' => $params['report_workload'],
|
||
'report_amount' => $params['report_amount'],
|
||
'remark' => $params['remark'],
|
||
'add_user' => $admin_id,
|
||
]);
|
||
foreach($detail as $v){
|
||
BuildReportDetail::create([
|
||
'report_id' => $reportRes->id,
|
||
'person_id' => $v['person_id'],
|
||
'work_num' => $v['work_num'],
|
||
'remark' => $v['remark']??''
|
||
]);
|
||
}
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @notes 获取施工汇报详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = BuildReport::findOrEmpty($params['id'])->toArray();
|
||
if(empty($data)) return [];
|
||
$plan = BuildPlan::where('id',$data['plan_id'])->findOrEmpty();
|
||
$project = Project::field('name')->where('id',$plan['project_id'])->findOrEmpty();
|
||
$process = BuildProcessSettings::field('division_id,process_step_no,process_step,quality_control_points,annex')->where('id',$plan['process_id'])->findOrEmpty();
|
||
$division = BuildDivision::field('subentry_engineering')->where('id',$process['division_id'])->findOrEmpty();
|
||
$projectMember = ProjectMember::field('admin_id')->where('id',$plan['project_member_id'])->findOrEmpty();
|
||
$admin = Admin::field('name')->where('id','in',[$projectMember['admin_id'],$data['add_user']])->column('name','id');
|
||
$data['zy_code'] = $plan['zy_code'];
|
||
$data['project_name'] = $project['name'];
|
||
$data['subentry_engineering'] = $division['subentry_engineering'];
|
||
$data['process_step'] = $process['process_step'];
|
||
$data['process_step_no'] = $process['process_step_no'];
|
||
$data['quality_control_points'] = $process['quality_control_points'];
|
||
$data['process_file'] = $process['annex'];
|
||
$data['project_member_name'] = $admin[$projectMember['admin_id']];
|
||
$data['work_user'] = $plan['work_user'];
|
||
$data['work_content'] = $plan['work_content'];
|
||
$data['plan_start_date'] = $plan['plan_start_date'];
|
||
$data['plan_end_date'] = $plan['plan_end_date'];
|
||
$data['unit'] = $plan['unit'];
|
||
$data['workload'] = $plan['workload'];
|
||
$data['price'] = $plan['price'];
|
||
$data['add_user_name'] = $admin[$data['add_user']];
|
||
$data['residue_workload'] = ($data['workload'] - $data['report_workload']) <=0 ? 0 : $data['workload'] - $data['report_workload'];
|
||
$data['completion_degree'] = round($data['report_workload'] / $data['workload'],3).'%';
|
||
return $data;
|
||
}
|
||
} |