where('super_type_id', 0)->where('type_id', '>', 10)->select(); for ($i = 0; $i < count($FirstLeveType); $i++) { $SecondLeveType = db('contract_type')->where('super_type_id', $FirstLeveType[$i]['type_id'])->select(); for ($m = 0; $m < count($SecondLeveType); $m++) { $count = db('contract_info')->where('contract_type', $SecondLeveType[$m]['type_id'])->where('del_time',null)->count(); if ($count>0) { $SecondLeveType[$m]['type_name'] .= '【'.$count.'】'; } } for ($j = 0; $j < count($SecondLeveType); $j++) { $ThridLeveType = db('contract_type')->where('super_type_id', $SecondLeveType[$j]['type_id'])->select(); for ($k = 0; $k < count($ThridLeveType); $k++) { $count = db('contract_info')->where('contract_type', $ThridLeveType[$k]['type_id'])->where('del_time',null)->count(); if ($count>0) { $ThridLeveType[$k]['type_name'] .= '【'.$count.'】'; } } $SecondLeveType[$j]['sub_type'] = $ThridLeveType; } $FirstLeveType[$i]['sub_type'] = $SecondLeveType; } return $this->sendSuccess($FirstLeveType); } //根据合同类型获取合同列表 public function GetOperationContractList() { $param = request()->post(); $ContractInfoList = db('contract_info')->where('contract_type', $param['contract_type']) ->where('del_time',null) ->select(); return $this->sendSuccess($ContractInfoList); } public function GetCustomerProjectList() { $param = request()->post(); $FirstLeveType = db('partner_company')->where('company_type & 0x01', 1)->field('company_id as id, company_name as name')->select(); for ($i = 0; $i < count($FirstLeveType); $i++) { //dump($FirstLeveType[$i]['type_id']); $SecondLeveType = db('project_info')->where('customer_id', $FirstLeveType[$i]['id'])->field('project_id as id, project_name as name')->select(); //dump($SecondLeveType); for ($j = 0; $j < count($SecondLeveType); $j++) { $count = db('contract_info')->where('project_id', $SecondLeveType[$j]['id'])->where('contract_category','in', [1, 3])->count(); $SecondLeveType[$j]['name'] .= '【'.$count.'】'; } $FirstLeveType[$i]['customer_projects'] = $SecondLeveType; } return $this->sendSuccess($FirstLeveType); } public function GetDevelopProjectList() { $param = request()->post(); $FirstLeveType = db('project_info')->where('project_type', 3)->field('project_id as id, project_name as name')->select(); for ($j = 0; $j < count($FirstLeveType); $j++) { $count = db('contract_info')->where('project_id', $FirstLeveType[$j]['id'])->where('contract_type', 2)->where('del_time',null)->count(); $FirstLeveType[$j]['name'] .= '【'.$count.'】'; } return $this->sendSuccess($FirstLeveType); } public function GetProjectContractList() { $param = request()->post(); $ContractInfoList = []; if (isset($param['contract_category'])) { //销售合同/技术协议 if (1 == $param['contract_category']){ $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', 'in', [1, 2]) ->where('contract_category', 'in', [1, 3]) ->where('del_time',null) ->select(); }elseif (2 == $param['contract_category']){ $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', 'in', [1, 2]) ->where('contract_category', 'in', [2, 4]) ->where('del_time',null) ->select(); } if (5 == $param['contract_category']){ $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', 'in', [1, 2]) ->where('contract_category', $param['contract_category']) ->where('del_time',null) ->select(); } } else { $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', $param['contract_type']) ->where('contract_category', 'in', [1, 3]) ->where('del_time',null) ->select(); } if(isset($param['contract_type'])){ //采购合同/技术协议 if (1 == $param['contract_type'] || 2 == $param['contract_type']) { if(isset($param['partner_id'])){ $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', $param['contract_type']) ->where('partner_id', $param['partner_id']) ->whereIn('contract_category', $param['contract_category']) ->where('del_time',null) ->select(); }else{ $ContractInfoList = db('contract_info')->where('project_id', $param['project_id']) ->where('contract_type', $param['contract_type']) ->where('contract_category', 'in', [1, 3]) ->where('del_time',null) ->select(); } } } return $this->sendSuccess($ContractInfoList); } //添加合同类型 public function AddContractType() { $param = request()->post(); $ret = []; if ($param['type_id']>0) { //添加子类型 $ret = db('contract_type')->where('type_id', $param['type_id'])->field('type_id,super_type_id')->find(); } else { //添加基类型 $ret['type_id'] = 0; } if ($ret != null) { $insert = []; $insert['type_name'] = $param['type_name']; $insert['super_type_id'] = $ret['type_id']; $insert['create_time'] = date('Y-m-d H:i:s'); db('contract_type')->insert($insert); } } public function AddContractInfo() { $param = request()->post(); $insert_info = []; $insert_info['contract_number'] = $param['contract_number']; $insert_info['contract_name'] = $param['contract_name']; $insert_info['create_time'] = $param['create_time']; if(isset($param['contract_des'])){ $insert_info['contract_des'] = $param['contract_des']; } if(isset($param['contract_price'])) { $insert_info['contract_price'] = $param['contract_price']; } if(isset($param['partner_id'])){ $insert_info['partner_id'] = $param['partner_id']; } if (isset($param['project_id'])) { $insert_info['project_id'] = $param['project_id']; //合同所属项目ID $insert_info['contract_category'] = $param['contract_category']; //合同类型 1 商务合同,2 技术协议 } if (isset($param['contract_type'])) { $insert_info['contract_type'] = $param['contract_type']; //合同所属项目ID } if (isset($param['contract_category'])) { $insert_info['contract_category']= $param['contract_category']; } if($param['contract_url'] == ''){ $insert_info['contract_url'] = ''; }else{ $insert_info['contract_url'] = $param['contract_url']; $insert_info['contract_file_name'] = $param['contract_file_name']; } db('contract_info')->insert($insert_info); return $this->sendSuccess('添加成功'); } public function AddProjectContract() { $param = request()->post(); $insert_info = []; $insert_info['contract_number'] = $param['contract_number']; $insert_info['contract_name'] = $param['contract_name']; $insert_info['create_time'] = $param['create_time']; $insert_info['contract_price'] = $param['contract_price']; if(isset($param['partner_id'])){ $insert_info['partner_id'] = $param['partner_id']; } if (isset($param['project_id'])) { $insert_info['project_id'] = $param['project_id']; //合同所属项目ID $insert_info['contract_type'] = $param['contract_type']; //合同类型 1 商务合同,2 技术协议 } $insert_info['contract_type'] = 1; //客户项目合同类 if (isset($param['contract_category'])) { $insert_info['contract_category']= $param['contract_category']; } if($param['contract_url'] == ''){ $insert_info['contract_url'] = ''; }else{ $insert_info['contract_url'] = $param['contract_url']; } db('contract_info')->insert($insert_info); return $this->sendSuccess('添加成功'); } public function updateContractInfo() { $param = request()->post(); if($param != null){ $update = []; $update['contract_name'] = $param['contract_name']; $update['contract_category'] = $param['contract_category']; $update['contract_number'] = $param['contract_number']; $update['contract_des'] = $param['contract_des']; if($param['contract_url'] != '') { $update['contract_url'] = $param['contract_url']; } $update['contract_price'] = $param['contract_price']; $update['create_time'] = $param['create_time']; $update['contract_file_name'] = $param['contract_file_name']; $ret = db('contract_info')->where('contract_id',$param['contract_id'])->update($update); if($ret){ return $this->sendSuccess('修改成功'); }else{ return $this->sendError('修改失败'); } } } public function delContractInfo() { $param = request()->post(); // dump($param); $update = []; $update['del_time'] = date('Y-m-d H:i:s'); $ret = db('contract_info')->where('contract_id',$param['contract_id'])->update($update); if($ret){ return $this->sendSuccess('删除成功'); }else{ return $this->sendError('删除失败'); } } }