WokerTask/app/adminapi/lists/approve/ApproveLists.php

142 lines
5.4 KiB
PHP

<?php
namespace app\adminapi\lists\approve;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\Approve;
use app\common\model\auth\Admin;
use app\common\model\Company;
use app\common\model\task\Task;
use think\facade\Db;
class ApproveLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function setSearch(): array
{
return [
'in' => ['type'],
'='=>['check_status']
];
}
public function queryWhere()
{
$where = [];
// $where[] = ['check_admin_ids', '=', $this->adminId]; // todo 放开过滤条件,只有片区经理才能查看
return $where;
}
public function lists(): array
{
return Approve::where($this->searchWhere)
->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){
return Admin::where(['id' => $data['check_admin_ids']])->value('name');
})
->withAttr('company_name',function($value,$data){
$task = Task::where('id', $data['task_id'])->find();
return Company::where(['id' => $task['company_id']])->value('company_name');
})
->toArray();
}
public function lists2(): array
{
$list = Approve::where($this->searchWhere)
->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){
$company = Company::where(['admin_id'=>$data['check_admin_ids']])->find();
return Admin::where(['id' => $company['area_manager']])->value('name');
})
->withAttr('company_name',function($value,$data){
$company = Company::where(['admin_id'=>$data['check_admin_ids']])->find();
return $company['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,
];
}
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();
if ($data['type'] == Approve::APPROVE_TYPE_11) {
return '下属小组服务公司';
}
if ($data['type'] == Approve::APPROVE_TYPE_13) {
$townCompanyName = Company::where(['id' => $task['company_id']])->value('company_name');
return $townCompanyName.'(镇农科公司)下属小组服务公司';
}
if ($data['type'] == Approve::APPROVE_TYPE_14) {
return '下属村管理公司';
}
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();
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'];
}
if ($data['type'] == Approve::APPROVE_TYPE_13) {
$townCompanyName = Company::where(['id' => $task['company_id']])->value('company_name');
return $townCompanyName.'(镇农科公司)下属村管理公司';
}
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,
];
}
public function count(): int
{
return Approve::where($this->searchWhere)->count();
}
}