engineering/app/adminapi/lists/project/ProjectExpenseReimbursementDetailLists.php
2024-01-30 18:01:46 +08:00

149 lines
6.5 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\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsExcelInterface;
use app\common\model\project\Project;
use app\common\model\project\ProjectCostTempSet;
use app\common\model\project\ProjectExpenseReimbursement;
use app\common\model\project\ProjectExpenseReimbursementDetail;
use app\common\lists\ListsSearchInterface;
/**
* 报销明细列表
* Class ProjectExpenseReimbursementDetailLists
* @package app\adminapi\listsproject
*/
class ProjectExpenseReimbursementDetailLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function setSearch(): array
{
return [
'=' => ['expense_reimbursement_id'],
];
}
/**
* @notes 获取报销明细列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function lists(): array
{
$params = $this->request->get(['expense_reimbursement_code','project_code','apply_user']);
$where = [];
if(isset($params['expense_reimbursement_code']) && $params['expense_reimbursement_code'] != ''){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('expense_reimbursement_code','like','%'.$params['expense_reimbursement_code'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['project_code']) && $params['project_code'] != ''){
$project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('project_id','in',$project_ids)->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['apply_user']) && $params['apply_user'] != ''){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('apply_user','like','%'.$params['apply_user'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
return ProjectExpenseReimbursementDetail::where($this->searchWhere)->where($where)
->field(['id', 'expense_reimbursement_id', 'project_cost_temp_id', 'amount', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$expense_reimbursement = ProjectExpenseReimbursement::field('expense_reimbursement_code,project_id,apply_user,apply_date')->where('id',$data['expense_reimbursement_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$expense_reimbursement['project_id'])->findOrEmpty();
$project_cost_temp = ProjectCostTempSet::field('first_level_subject,second_level_subject,third_level_subject')->where('id',$data['project_cost_temp_id'])->findOrEmpty();
$data['expense_reimbursement_code'] = $expense_reimbursement['expense_reimbursement_code'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['apply_user'] = $expense_reimbursement['apply_user'];
$data['apply_date'] = $expense_reimbursement['apply_date'];
$data['first_level_subject'] = $project_cost_temp['first_level_subject'];
$data['second_level_subject'] = $project_cost_temp['second_level_subject'];
$data['third_level_subject'] = $project_cost_temp['third_level_subject'];
return $data;
})
->toArray();
}
/**
* @notes 获取报销明细数量
* @return int
* @author likeadmin
* @date 2024/01/19 13:44
*/
public function count(): int
{
$params = $this->request->get(['expense_reimbursement_code','project_code','apply_user']);
$where = [];
if(isset($params['expense_reimbursement_code']) && $params['expense_reimbursement_code'] != ''){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('expense_reimbursement_code','like','%'.$params['expense_reimbursement_code'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['project_code']) && $params['project_code'] != ''){
$project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id');
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('project_id','in',$project_ids)->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
if(isset($params['apply_user']) && $params['apply_user'] != ''){
$expense_reimbursement_ids = ProjectExpenseReimbursement::where('apply_user','like','%'.$params['apply_user'].'%')->column('id');
$where[] = ['expense_reimbursement_id','in',$expense_reimbursement_ids];
}
return ProjectExpenseReimbursementDetail::where($this->searchWhere)->where($where)->count();
}
public function setFileName(): string
{
return '费用报销明细列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 段誉
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
return [
"id" => "id",
"expense_reimbursement_code" => "费用报销单号",
"project_name" => "项目名称",
"first_level_subject" => "一级科目",
"second_level_subject" => "二级科目",
"third_level_subject" => "三级科目",
"amount" => "金额",
"remark" => "备注",
];
}
}