engineering/app/adminapi/controller/build/BuildPlanController.php
2023-12-27 11:52:40 +08:00

186 lines
6.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\build;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\build\BuildPlanLists;
use app\adminapi\logic\build\BuildPlanLogic;
use app\adminapi\validate\build\BuildPlanValidate;
use app\common\model\auth\Admin;
use app\common\model\build\BuildPlan;
use app\common\model\build\BuildReport;
use app\common\model\build\BuildReportDetail;
use app\common\model\project\ProjectPersonnel;
use think\app\command\Build;
/**
* 施工计划控制器
* Class BuildPlanController
* @package app\adminapi\controller\build
*/
class BuildPlanController extends BaseAdminController
{
/**
* @notes 获取施工计划列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 11:04
*/
public function lists()
{
return $this->dataLists(new BuildPlanLists());
}
/**
* @notes 添加施工计划
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 11:04
*/
public function add()
{
$params = (new BuildPlanValidate())->post()->goCheck('add');
$result = BuildPlanLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(BuildPlanLogic::getError());
}
/**
* @notes 编辑施工计划
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 11:04
*/
public function edit()
{
$params = (new BuildPlanValidate())->post()->goCheck('edit');
$result = BuildPlanLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(BuildPlanLogic::getError());
}
/**
* @notes 删除施工计划
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 11:04
*/
public function delete()
{
$params = (new BuildPlanValidate())->post()->goCheck('delete');
BuildPlanLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取施工计划详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 11:04
*/
public function detail()
{
$params = (new BuildPlanValidate())->goCheck('detail');
$result = BuildPlanLogic::detail($params);
return $this->data($result);
}
//某个计划下的施工汇报列表
public function reports(): \think\response\Json
{
$params = $this->request->get(['plan_id','page_no','page_size']);
if(empty($params['plan_id'])){
return $this->fail('缺少必要参数');
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$planInfo = BuildPlan::field('price')->where('id',$params['plan_id'])->findOrEmpty();
if($planInfo->isEmpty()){
return $this->fail('施工计划数据不存在');
}
$data = BuildReport::field('report_code,add_user,create_time,scene_file,report_workload,report_amount,remark')
->where('plan_id',$params['plan_id'])
->page($pageNo,$pageSize)
->order('id desc')
->select()->each(function($item)use($planInfo){
$admin = Admin::field('name')->where('id',$item['add_user'])->findOrEmpty();
$item['price'] = $planInfo['price'];
$item['add_user_name'] = $admin['name'];
return $item;
})
->toArray();
$count = BuildReport::field('id')->where('plan_id',$params['plan_id'])->count();
$result = [
'count' => $count,
'page_no' => $pageNo,
'page_size' => $pageSize,
'lists' => $data
];
return $this->success('请求成功',$result);
}
//某个计划下的人工明细列表
public function persons(): \think\response\Json
{
$params = $this->request->get(['plan_id','page_no','page_size']);
if(empty($params['plan_id'])){
return $this->fail('缺少必要参数');
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$planInfo = BuildPlan::field('price,unit')->where('id',$params['plan_id'])->findOrEmpty();
if($planInfo->isEmpty()){
return $this->fail('施工计划数据不存在');
}
$report_ids = BuildReport::where('plan_id',$params['plan_id'])->column('id');
$data = BuildReportDetail::field('report_id,person_id,work_num')->where('report_id','in',$report_ids)
->page($pageNo,$pageSize)->order('id desc')
->select()->each(function($item)use($planInfo){
$report = BuildReport::field('report_code,create_time')->where('id',$item['report_id'])->findOrEmpty();
$person = ProjectPersonnel::field('name,idcard,work_type')->where('id',$item['person_id'])->findOrEmpty();
$item['report_code'] = $report['report_code'];
$item['report_date'] = $report['create_time'];
$item['person_name'] = $person['name'];
$item['person_idcard'] = $person['idcard'];
$item['person_work_type_text'] = $person->work_type_text;
$item['price'] = $planInfo['price'];
$item['unit'] = $planInfo['unit'];
$item['amount'] = $item['price']*$item['work_num'];
return $item;
})
->toArray();
$count = BuildReportDetail::field('id')->where('report_id','in',$report_ids)->count();
$result = [
'count' => $count,
'page_no' => $pageNo,
'page_size' => $pageSize,
'lists' => $data
];
return $this->success('请求成功',$result);
}
}