['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(); } public function setFileName(): string { return '项目合同洽商列表'; } /** * @notes 导出字段 * @return string[] * @author 段誉 * @date 2022/11/24 16:17 */ public function setExcelFields(): array { return [ "id" => "id", "negotiation_no" => "洽商编号", "contract_code" => "合同编号", "custom_name" => "客户名称", "project_name" => "项目名称", "negotiation_amount" => "洽商报价金额", "negotiation_type" => "洽商类别", "contract_date" => "签约日期", "business_director" => "业务负责人", "profit" => "利润", "profit_rate" => "利润率", ]; } }