['contract_id', 'project_id', 'negotiation_type'], '%like%' => ['negotiation_name','negotiation_no'] ]; } /** * @notes 获取合同洽商列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2023/12/04 21:26 */ public function lists(): array { $params = $this->request->get(['custom_id','project_name']); $where = []; if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Project::where('custom_id',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } 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]; } return ContractNegotiation::field('id,project_id,contract_id,negotiation_name,negotiation_no,negotiation_amount,negotiation_type,profit,profit_rate') ->where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($data){ $contract = Contract::field('contract_name,contract_code,contract_date,business_director')->where('id',$data['contract_id'])->findOrEmpty(); $project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); $business_director = Admin::field('name')->where('id',$contract['business_director'])->findOrEmpty(); $data['contract_name'] = $contract['contract_name']; $data['contract_code'] = $contract['contract_code']; $data['contract_date'] = $contract['contract_date']; $data['business_director'] = $business_director['name']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['custom_name'] = $custom['name']; $data['negotiation_type'] = $data->negotiation_type_text; $data['profit_rate'] = ($data['profit_rate'] * 100).'%'; return $data; }) ->toArray(); } /** * @notes 获取合同洽商数量 * @return int * @author likeadmin * @date 2023/12/04 21:26 */ public function count(): int { $params = $this->request->get(['custom_id','project_name']); $where = []; if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Project::where('custom_id',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } 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]; } return ContractNegotiation::field('id')->where($this->searchWhere)->where($where)->count(); } }