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

114 lines
3.8 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\BuildReportLists;
use app\adminapi\logic\build\BuildReportLogic;
use app\adminapi\validate\build\BuildReportValidate;
use app\common\model\build\BuildPlan;
use app\common\model\build\BuildReport;
use app\common\model\build\BuildReportDetail;
use app\common\model\project\ProjectPersonnel;
/**
* 施工汇报控制器
* Class BuildReportController
* @package app\adminapi\controller\build
*/
class BuildReportController extends BaseAdminController
{
/**
* @notes 获取施工汇报列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 16:08
*/
public function lists()
{
return $this->dataLists(new BuildReportLists());
}
/**
* @notes 添加施工汇报
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 16:08
*/
public function add()
{
$params = (new BuildReportValidate())->post()->goCheck('add');
$result = BuildReportLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(BuildReportLogic::getError());
}
/**
* @notes 获取施工汇报详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/22 16:08
*/
public function detail()
{
$params = (new BuildReportValidate())->goCheck('detail');
$result = BuildReportLogic::detail($params);
return $this->data($result);
}
public function personDetails(): \think\response\Json
{
$params = $this->request->get(['report_id','page_no','page_size']);
if(empty($params['report_id'])){
return $this->fail('缺少必要参数');
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$reportInfo = BuildReport::field('plan_id')->where('id',$params['report_id'])->findOrEmpty();
if($reportInfo->isEmpty()){
return $this->fail('施工汇报数据不存在');
}
$planInfo = BuildPlan::field('price,unit')->where('id',$reportInfo['plan_id'])->findOrEmpty();
$data = BuildReportDetail::field('person_id,work_num')->where('report_id',$params['report_id'])
->page($pageNo,$pageSize)->order('id desc')
->select()->each(function($item)use($planInfo){
$person = ProjectPersonnel::field('name,idcard,work_type')->where('id',$item['person_id'])->findOrEmpty();
$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',$params['report_id'])->count();
$result = [
'count' => $count,
'page_no' => $pageNo,
'page_size' => $pageSize,
'lists' => $data
];
return $this->success('请求成功',$result);
}
}