2023-09-15 17:00:52 +08:00
< ? php
namespace app\adminapi\lists\approve ;
use app\adminapi\lists\BaseAdminDataLists ;
use app\common\lists\ListsSearchInterface ;
use app\common\model\Approve ;
2023-09-15 18:49:11 +08:00
use app\common\model\auth\Admin ;
use app\common\model\Company ;
2023-10-20 17:48:05 +08:00
use app\common\model\task\Task ;
2023-09-15 18:49:11 +08:00
use think\facade\Db ;
2023-09-15 17:00:52 +08:00
class ApproveLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @ notes 设置搜索条件
* @ return \string [][]
* @ author likeadmin
* @ date 2023 / 08 / 31 11 : 08
*/
public function setSearch () : array
{
2023-09-25 14:10:39 +08:00
return [
2023-10-26 14:39:38 +08:00
'in' => [ 'type' ],
'=' => [ 'check_status' ]
2023-09-25 14:10:39 +08:00
];
2023-09-15 17:00:52 +08:00
}
public function queryWhere ()
{
$where = [];
// $where[] = ['check_admin_ids', '=', $this->adminId]; // todo 放开过滤条件,只有片区经理才能查看
return $where ;
}
public function lists () : array
{
2023-09-15 18:49:11 +08:00
return Approve :: where ( $this -> searchWhere )
2023-09-15 17:00:52 +08:00
-> where ( $this -> queryWhere ())
-> with ( 'task' )
-> field ( '*' )
2023-09-15 18:49:11 +08:00
-> append ([ 'area_manager' , 'company_name' ], true )
2023-09-15 17:00:52 +08:00
-> limit ( $this -> limitOffset , $this -> limitLength )
-> order ([ 'id' => 'desc' ])
-> select ()
2023-09-15 18:49:11 +08:00
-> withAttr ( 'area_manager' , function ( $value , $data ){
return Admin :: where ([ 'id' => $data [ 'check_admin_ids' ]]) -> value ( 'name' );
})
-> withAttr ( 'company_name' , function ( $value , $data ){
2023-10-20 17:48:05 +08:00
$task = Task :: where ( 'id' , $data [ 'task_id' ]) -> find ();
return Company :: where ([ 'id' => $task [ 'company_id' ]]) -> value ( 'company_name' );
2023-09-15 18:49:11 +08:00
})
2023-09-15 17:00:52 +08:00
-> toArray ();
}
2023-10-26 13:45:27 +08:00
public function lists2 () : array
{
2023-10-26 13:56:50 +08:00
$list = Approve :: where ( $this -> searchWhere )
2023-10-26 13:45:27 +08:00
-> where ( $this -> queryWhere ())
-> with ( 'task' )
-> field ( '*' )
-> append ([ 'area_manager' , 'company_name' ], true )
-> limit ( $this -> limitOffset , $this -> limitLength )
-> order ([ 'id' => 'desc' ])
-> select ()
-> withAttr ( 'area_manager' , function ( $value , $data ){
2023-11-17 13:53:31 +08:00
$company = Company :: where ([ 'admin_id' => $data [ 'check_admin_ids' ]]) -> find ();
return Admin :: where ([ 'id' => $company [ 'area_manager' ]]) -> value ( 'name' );
2023-10-26 13:45:27 +08:00
})
-> withAttr ( 'company_name' , function ( $value , $data ){
2023-11-17 13:51:13 +08:00
$company = Company :: where ([ 'admin_id' => $data [ 'check_admin_ids' ]]) -> find ();
return $company [ 'company_name' ];
2023-10-26 13:45:27 +08:00
})
-> toArray ();
2023-10-26 13:56:50 +08:00
$count = Approve :: where ( $this -> searchWhere )
-> where ( $this -> queryWhere ()) -> count ();
return [
'lists' => $list ,
'count' => $count ,
'page_no' => $this -> pageNo ,
'page_size' => $this -> pageSize ,
];
2023-10-26 13:45:27 +08:00
}
2023-09-15 17:00:52 +08:00
2023-11-16 10:36:32 +08:00
public function lists3 () : array
{
$list = Approve :: where ( $this -> searchWhere )
-> where ( $this -> queryWhere ())
-> with ( 'task' )
-> field ( '*' )
-> append ([ 'area_manager' , 'company_a_name' , 'company_b_name' ], true )
-> limit ( $this -> limitOffset , $this -> limitLength )
-> order ([ 'id' => 'desc' ])
-> select ()
-> withAttr ( 'area_manager' , function ( $value , $data ){
return Admin :: where ([ 'id' => $data [ 'check_admin_ids' ]]) -> value ( 'name' );
})
-> withAttr ( 'company_b_name' , function ( $value , $data ){
$task = Task :: where ( 'id' , $data [ 'task_id' ]) -> find ();
2023-11-17 19:14:10 +08:00
if ( $data [ 'type' ] == Approve :: APPROVE_TYPE_11 ) {
return '下属小组服务公司' ;
}
2023-11-18 09:52:43 +08:00
if ( $data [ 'type' ] == Approve :: APPROVE_TYPE_13 ) {
$townCompanyName = Company :: where ([ 'id' => $task [ 'company_id' ]]) -> value ( 'company_name' );
return $townCompanyName . '(镇农科公司)下属小组服务公司' ;
}
2023-11-17 19:14:10 +08:00
if ( $data [ 'type' ] == Approve :: APPROVE_TYPE_14 ) {
return '下属村管理公司' ;
}
2023-11-16 10:36:32 +08:00
return Company :: where ([ 'id' => $task [ 'company_id' ]]) -> value ( 'company_name' );
})
-> withAttr ( 'company_a_name' , function ( $value , $data ){
$task = Task :: where ( 'id' , $data [ 'task_id' ]) -> find ();
$companyB = Company :: where ([ 'id' => $task [ 'company_id' ]]) -> find ();
2023-11-17 19:14:10 +08:00
if ( $data [ 'type' ] == Approve :: APPROVE_TYPE_12 || $data [ 'type' ] == Approve :: APPROVE_TYPE_14 ) {
return Db :: query ( " select * from la_company where company_type=:company_type and FIND_IN_SET(:street,responsible_area) " , [ 'company_type' => 41 , 'street' => $companyB [ 'street' ]], true )[ 0 ][ 'company_name' ];
}
2023-11-18 09:52:43 +08:00
if ( $data [ 'type' ] == Approve :: APPROVE_TYPE_13 ) {
$townCompanyName = Company :: where ([ 'id' => $task [ 'company_id' ]]) -> value ( 'company_name' );
return $townCompanyName . '(镇农科公司)下属村管理公司' ;
}
2023-11-16 10:36:32 +08:00
return Company :: where ([ 'village' => $companyB [ 'village' ], 'company_type' => 17 ]) -> value ( 'company_name' );
})
-> toArray ();
$count = Approve :: where ( $this -> searchWhere )
-> where ( $this -> queryWhere ()) -> count ();
return [
'lists' => $list ,
'count' => $count ,
'page_no' => $this -> pageNo ,
'page_size' => $this -> pageSize ,
];
}
2023-09-15 17:00:52 +08:00
public function count () : int
{
return Approve :: where ( $this -> searchWhere ) -> count ();
}
}