<?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\auth\Admin; use app\common\model\bid\BidBuyBiddingDocument; use app\common\model\contract\Contract; use app\common\lists\ListsSearchInterface; use app\common\model\contract\ContractNegotiation; use app\common\model\custom\Custom; use app\common\model\finance\FinanceReturnedRecord; use app\common\model\project\Project; use think\facade\Db; /** * 项目合同列表 * Class ContractLists * @package app\adminapi\listscontract */ class ContractLists extends BaseAdminDataLists implements ListsSearchInterface { /** * @notes 设置搜索条件 * @return \string[][] * @author likeadmin * @date 2023/12/02 17:19 */ public function setSearch(): array { return [ '=' => ['contract_type', 'contract_code'], '%like%' => ['contract_code'] ]; } /** * @notes 获取项目合同列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2023/12/02 17:19 */ public function lists(): array { $params = $this->request->get(['project_name','business_director_name','custom_id']); $where = []; if(isset($params['project_name']) && $params['project_name'] != ''){ $project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$project_ids]; } if(isset($params['business_director_name']) && $params['business_director_name'] != ''){ $business_director_ids = Admin::where('name','like','%'.$params['business_director_name'].'%')->column('id'); $where[] = ['business_director','in',$business_director_ids]; } if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Admin::where('custom_id','=',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } return Contract::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($data){ $project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); $buy_bidding_document = BidBuyBiddingDocument::field('bid_document_no')->where('id',$data['buy_bidding_document_id'])->findOrEmpty(); $business_director = Admin::field('name')->where('id',$data['business_director'])->findOrEmpty(); $data['custom_name'] = $custom['name']; $data['bid_document_no'] = $buy_bidding_document['bid_document_no']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['contract_type_text'] = $data->contract_type_text; $data['contract_pricing_method_text'] = $data->contract_pricing_method_text; $data['contract_status_text'] = $data->contract_status_text; $data['contract_pricing_method_text'] = $data->contract_pricing_method_text; $data['business_director_name'] = $business_director['name']; $data['negotiation_amount'] = ContractNegotiation::where('contract_id',$data['id'])->sum('negotiation_amount'); $data['reality_contract_amount'] = $data['amount'] + $data['negotiation_amount']; $data['returned_amount'] = FinanceReturnedRecord::where('contract_id',$data['id'])->sum('amount'); $data['not_returned_amount'] = $data['reality_contract_amount'] - $data['returned_amount']; return $data; }) ->toArray(); } /** * @notes 获取项目合同数量 * @return int * @author likeadmin * @date 2023/12/02 17:19 */ public function count(): int { $params = $this->request->get(['project_name','business_director_name','custom_id']); $where = []; if(isset($params['project_name']) && $params['project_name'] != ''){ $project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$project_ids]; } if(isset($params['business_director_name']) && $params['business_director_name'] != ''){ $business_director_ids = Admin::where('name','like','%'.$params['business_director_name'].'%')->column('id'); $where[] = ['business_director','in',$business_director_ids]; } if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Admin::where('custom_id','=',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } return Contract::field('id')->where($this->searchWhere)->where($where)->count(); } }