351 lines
14 KiB
PHP
351 lines
14 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\controller\project;
|
||
|
||
|
||
use app\adminapi\controller\BaseAdminController;
|
||
use app\adminapi\lists\project\ProjectPersonnelLists;
|
||
use app\adminapi\logic\project\ProjectPersonnelLogic;
|
||
use app\adminapi\validate\project\ProjectPersonnelValidate;
|
||
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\model\build\BuildReportDetail;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectAttendanceDetail;
|
||
use app\common\model\project\ProjectInsuranceManagement;
|
||
use app\common\model\project\ProjectLaborContract;
|
||
use app\common\model\project\ProjectPersonnel;
|
||
use app\common\model\project\ProjectSalaryDetail;
|
||
use app\common\model\project\ProjectSalaryPayment;
|
||
|
||
|
||
/**
|
||
* 项目人员控制器
|
||
* Class ProjectPersonnelController
|
||
* @package app\adminapi\controller\project
|
||
*/
|
||
class ProjectPersonnelController extends BaseAdminController
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 获取项目人员列表
|
||
* @return \think\response\Json
|
||
* @author likeadmin
|
||
* @date 2023/12/22 14:38
|
||
*/
|
||
public function lists()
|
||
{
|
||
return $this->dataLists(new ProjectPersonnelLists());
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 添加项目人员
|
||
* @return \think\response\Json
|
||
* @author likeadmin
|
||
* @date 2023/12/22 14:38
|
||
*/
|
||
public function add()
|
||
{
|
||
$params = (new ProjectPersonnelValidate())->post()->goCheck('add');
|
||
$result = ProjectPersonnelLogic::add($params,$this->adminId);
|
||
if (true === $result) {
|
||
return $this->success('添加成功', [], 1, 1);
|
||
}
|
||
return $this->fail(ProjectPersonnelLogic::getError());
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑项目人员
|
||
* @return \think\response\Json
|
||
* @author likeadmin
|
||
* @date 2023/12/22 14:38
|
||
*/
|
||
public function edit()
|
||
{
|
||
$params = (new ProjectPersonnelValidate())->post()->goCheck('edit');
|
||
$result = ProjectPersonnelLogic::edit($params,$this->adminId);
|
||
if (true === $result) {
|
||
return $this->success('编辑成功', [], 1, 1);
|
||
}
|
||
return $this->fail(ProjectPersonnelLogic::getError());
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除项目人员
|
||
* @return \think\response\Json
|
||
* @author likeadmin
|
||
* @date 2023/12/22 14:38
|
||
*/
|
||
public function delete()
|
||
{
|
||
$params = (new ProjectPersonnelValidate())->post()->goCheck('delete');
|
||
ProjectPersonnelLogic::delete($params);
|
||
return $this->success('删除成功', [], 1, 1);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取项目人员详情
|
||
* @return \think\response\Json
|
||
* @author likeadmin
|
||
* @date 2023/12/22 14:38
|
||
*/
|
||
public function detail()
|
||
{
|
||
$params = (new ProjectPersonnelValidate())->goCheck('detail');
|
||
$result = ProjectPersonnelLogic::detail($params);
|
||
return $this->data($result);
|
||
}
|
||
|
||
//某个项目下的人员列表
|
||
public function listToProject(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['project_id','page_size','page_no']);
|
||
if(empty($params['project_id'])){
|
||
return $this->fail('参数错误');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$data = ProjectPersonnel::field(['id', 'project_id', 'name', 'idcard', 'mobile', 'work_type', 'unit_price', 'daily_living_expenses', 'idcard_front', 'idcard_backend', 'bank_card', 'bank_no', 'deposit_bank', 'remark', 'opening_income'])
|
||
->where('project_id',$params['project_id'])
|
||
->page($pageNo, $pageSize)
|
||
->order(['id' => 'desc'])
|
||
->select()
|
||
->each(function($item){
|
||
$item['work_type_text'] = $item->work_type_text;
|
||
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
|
||
$item['project_name'] = $project['name'];
|
||
$item['project_code'] = $project['project_code'];
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = ProjectPersonnel::field('id')->where('project_id',$params['project_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
|
||
//某个人员下的劳动合同列表
|
||
public function laborContracts(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['person_id','page_no','page_size']);
|
||
if(empty($params['person_id'])){
|
||
return $this->fail('缺少必要参数');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$person = ProjectPersonnel::field('id,name,idcard')->where('id',$params['person_id'])->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return $this->fail('项目人员信息不存在');
|
||
}
|
||
$data = ProjectLaborContract::field('id,contract_status,contract_type,contract_title,signing_date,start_date,end_date,remark,annex')
|
||
->where('project_person_id',$params['person_id'])
|
||
->page($pageNo,$pageSize)->order('id desc')
|
||
->select()->each(function($item)use($person){
|
||
$item['person_name'] = $person['name'];
|
||
$item['person_idcard'] = $person['idcard'];
|
||
$item['contract_status_text'] = $item->contract_status_text;
|
||
$item['contract_type_text'] = $item->contract_type_text;
|
||
$item['contract_title_text'] = $item->contract_title_text;
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = ProjectLaborContract::field('id')->where('project_person_id',$params['person_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
|
||
//某个人员下的保险列表
|
||
public function insurances(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['person_id','page_no','page_size']);
|
||
if(empty($params['person_id'])){
|
||
return $this->fail('缺少必要参数');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$person = ProjectPersonnel::field('id,name,idcard')->where('id',$params['person_id'])->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return $this->fail('项目人员信息不存在');
|
||
}
|
||
$data = ProjectInsuranceManagement::field('id,insurance_date,due_date,type,insurance_no,insurance,insured_amount,insurance_company')
|
||
->where('project_person_id',$params['person_id'])
|
||
->page($pageNo,$pageSize)->order('id desc')
|
||
->select()->each(function($item)use($person){
|
||
$item['person_name'] = $person['name'];
|
||
$item['person_idcard'] = $person['idcard'];
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = ProjectInsuranceManagement::field('id')->where('project_person_id',$params['person_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
|
||
//某个人员下的考勤明细列表
|
||
public function attendances(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['person_id','page_no','page_size']);
|
||
if(empty($params['person_id'])){
|
||
return $this->fail('缺少必要参数');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$person = ProjectPersonnel::field('id,name,idcard,work_type')->where('id',$params['person_id'])->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return $this->fail('项目人员信息不存在');
|
||
}
|
||
$data = ProjectAttendanceDetail::field('id,attendance_code,attendance_date,work_start_time,work_end_time,work_record_num,daily_salary,daily_living,daily_subsidy,daily_other,daily_income,remark')
|
||
->where('person_id',$params['person_id'])
|
||
->page($pageNo,$pageSize)->order('id desc')
|
||
->select()->each(function($item)use($person){
|
||
$item['person_name'] = $person['name'];
|
||
$item['person_idcard'] = $person['idcard'];
|
||
$item['work_type_text'] = $person->work_type_text;
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = ProjectAttendanceDetail::field('id')->where('person_id',$params['person_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
|
||
//某个员工下的施工记录列表
|
||
public function buildworks(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['person_id','page_no','page_size']);
|
||
if(empty($params['person_id'])){
|
||
return $this->fail('缺少必要参数');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$person = ProjectPersonnel::field('id,name,idcard,work_type')->where('id',$params['person_id'])->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return $this->fail('项目人员信息不存在');
|
||
}
|
||
$data = BuildReportDetail::field('id,report_id,work_num,create_time')
|
||
->where('person_id',$params['person_id'])
|
||
->page($pageNo,$pageSize)->order('id desc')
|
||
->select()->each(function($item)use($person){
|
||
$report = BuildReport::field('report_code,plan_id')->where('id',$item['report_id'])->findOrEmpty();
|
||
$plan = BuildPlan::field('process_id,zy_code,unit,price')->where('id',$report['plan_id'])->findOrEmpty();
|
||
$process = BuildProcessSettings::field('division_id,process_step')->where('id',$plan['process_id'])->findOrEmpty();
|
||
$division = BuildDivision::field('subentry_engineering')->where('id',$process['division_id'])->findOrEmpty();
|
||
$item['report_code'] = $report['report_code'];
|
||
$item['zy_code'] = $plan['zy_code'];
|
||
$item['process_step'] = $process['process_step'];
|
||
$item['subentry_engineering'] = $division['subentry_engineering'];
|
||
$item['report_date'] = date('Y-m-d',strtotime($item['create_time']));
|
||
$item['person_name'] = $person['name'];
|
||
$item['person_idcard'] = $person['idcard'];
|
||
$item['work_type_text'] = $person->work_type_text;
|
||
$item['unit'] = $plan['unit'];
|
||
$item['price'] = $plan['price'];
|
||
$item['amount'] = $plan['price'] * $item['work_num'];
|
||
unset($item['create_time']);
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = BuildReportDetail::field('id')->where('person_id',$params['person_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
|
||
//某个人员下的工资付款列表
|
||
public function payments(): \think\response\Json
|
||
{
|
||
$params = $this->request->get(['person_id','page_no','page_size']);
|
||
if(empty($params['person_id'])){
|
||
return $this->fail('缺少必要参数');
|
||
}
|
||
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
|
||
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
|
||
$person = ProjectPersonnel::field('id,name,idcard,work_type')->where('id',$params['person_id'])->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return $this->fail('项目人员信息不存在');
|
||
}
|
||
$data = ProjectSalaryDetail::field(['id', 'salary_payment_id', 'person_id', 'apply_date', 'apply_amount', 'remark'])
|
||
->where('person_id',$params['person_id'])
|
||
->page($pageNo,$pageSize)->order('id desc')
|
||
->select()->each(function($item)use($person){
|
||
$payment = ProjectSalaryPayment::field('payment_code,project_id')->where('id',$item['salary_payment_id'])->findOrEmpty();
|
||
$project = Project::field('name,project_code')->where('id',$payment['project_id'])->findOrEmpty();
|
||
$person = ProjectPersonnel::field('name,idcard,work_type')->where('id',$item['person_id'])->findOrEmpty();
|
||
$item['payment_code'] = $payment['payment_code'];
|
||
$item['project_name'] = $project['name'];
|
||
$item['project_code'] = $project['project_code'];
|
||
$item['person_name'] = $person['name'];
|
||
$item['person_idcard'] = $person['idcard'];
|
||
$item['person_work_type_text'] = $person->work_type_text;
|
||
//总考勤收入
|
||
$daily_income = ProjectAttendanceDetail::where('person_id',$item['person_id'])->sum('daily_income');
|
||
//总施工收入
|
||
$build_report_details = BuildReportDetail::field('report_id,work_num')->where('person_id',$item['person_id'])->select()->each(function($item2){
|
||
$report = BuildReport::field('plan_id')->where('id',$item2['report_id'])->findOrEmpty();
|
||
$plan = BuildPlan::field('price')->where('id',$report['plan_id'])->findOrEmpty();
|
||
$item2['amount'] = $item2['work_num'] * $plan['price'];
|
||
})->toArray();
|
||
$work_income = 0;
|
||
foreach($build_report_details as $v){
|
||
$work_income += $v['amount'];
|
||
}
|
||
$item['total_income'] = $daily_income + $work_income;
|
||
//总支出
|
||
$item['total_pay_out'] = ProjectSalaryDetail::where('person_id',$item['person_id'])->sum('apply_amount');
|
||
$item['balance'] = $item['total_income'] - $item['total_pay_out'];
|
||
return $item;
|
||
})
|
||
->toArray();
|
||
$count = BuildReportDetail::field('id')->where('person_id',$params['person_id'])->count();
|
||
$result = [
|
||
'count' => $count,
|
||
'page_no' => $pageNo,
|
||
'page_size' => $pageSize,
|
||
'lists' => $data
|
||
];
|
||
return $this->success('请求成功',$result);
|
||
}
|
||
} |