WokerTask/app/adminapi/lists/contract/ContractLists.php

121 lines
4.4 KiB
PHP
Raw Permalink 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\contract;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\Contract;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\Company;
use think\facade\Db;
/**
* Contract列表
* Class ContractLists
* @package app\adminapi\listscontract
*/
class ContractLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function setSearch(): array
{
return [
'=' => ['contract_type', 'contract_no', 'status'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function lists(): array
{
$params=$this->request->param();
$where=[];
if ($this->adminInfo['root'] != 1) {
// if($this->adminInfo['role_id'][0]==10){
// if(isset($params['type']) && $params['type']==1){
// $where[] = ['check_status', '=',1];
// }else{
// $where[] = ['status', '=',0];
// $where[] = ['check_status', 'in',[2,3]];
// }
// }
}
if(isset($params['company_id']) && $params['company_id']!=''){
$arr= Company::where('company_name','like','%'.$params['company_id'].'%')->column('id');
if($arr){
$where[]=['party_a|party_b','in',$arr];
}
}
if(isset($params['area_manager']) && $params['area_manager']!=''){
$arr= Admin::where('name','like','%'.$params['area_manager'].'%')->column('id');
if($arr){
$where[]=['area_manager','in',$arr];
}
}
return Contract::where($this->searchWhere)->where($where)->with(['companyName','party_a_info','contractType'])
// ->field(['id', 'company_id', 'contract_type', 'contract_no', 'status', 'party_a', 'party_b', 'area_manager'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item, $key) {
if($item->type==1){
$item->party_b_name=Db::name('company')->where('id',$item->party_b)->value('company_name');
}else{
$item->party_b_name=Db::name('user')->where('id',$item->party_b)->value('nickname');
}
if(!empty($item->party_a_info)){
$area_manager_name=Db::name('admin')->where('id',$item->party_a_info->area_manager)->value('name');
if($area_manager_name){
$item->area_manager_name=$area_manager_name;
}else{
$item->area_manager_name='暂无片区经理';
}
}else{
$item->area_manager_name='暂无片区经理';
}
$item->contract_type_name=Db::name('dict_data')->where('id',$item->contract_type)->value('name');
$item->status_name=$item->status==1?'已签约':'未签约';
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function count(): int
{
return Contract::where($this->searchWhere)->count();
}
}