request->isPost()){ return $this->fail('请求方式错误'); } $params = $this->request->post(['page_no','page_size','contract_no','contract_type','contract_status','company_name','area_manager']); $where = []; if(isset($params['contract_no']) && $params['contract_no']!=''){ $where[] = ['contract_no','like','%'.$params['contract_no'].'%']; } if(isset($params['contract_type']) && $params['contract_type']!=''){ $where[] = ['contract_type','=',$params['contract_type']]; } if(isset($params['contract_status']) && in_array($params['contract_status'],[0,1])){ $where[] = ['status','=', $params['contract_status']]; } if(isset($params['company_name']) && $params['company_name']!=''){ $arr= Company::where('company_name','like','%'.$params['company_name'].'%')->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]; } } $pageNo = !empty($param['page_no']) ? $param['page_no'] : 1; $pageSize = !empty($param['page_size']) ? $param['page_size'] : 20; $data = Contract::where($where)->with(['companyName','party_a_info','contractType']) ->page($pageNo, $pageSize) ->order(['id' => 'desc']) ->select()->each(function ($item) { 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(); $count = Contract::where($where)->count(); $result = [ 'lists' => $data, 'count' => $count, 'page_no' => $pageNo, 'page_size' => $pageSize ]; return $this->success('请求成功',$result); } //合同详情 public function detail(): Json { $params = (new ContractValidate())->post()->goCheck('detail'); $result = ContractLogic::detail($params); return $this->data($result); } //上传合同 public function uploadContract(): Json { if(!$this->request->isPost()){ return $this->fail('请求方式错误'); } $params = $this->request->post(['id','file']); if(empty($params['id']) || empty($params['file'])){ return $this->fail('参数错误'); } $res = Contract::where('id', $params['id'])->update(['file' => $params['file'], 'check_status' => 2]); if ($res) { $find = Contract::where('id', $params['id'])->with(['party_a_info'])->field('type,party_b,party_a')->find()->toArray(); if ($find['type'] == 1) { $find['party_b_info'] = Company::where('id', $find['party_b'])->field('company_name name,master_phone phone')->find()->toArray(); } else { $find['party_b_info'] = User::where('id', $find['party_b'])->field('nickname name,mobile phone')->find()->toArray(); } $a = [ 'mobile' => $find['party_a_info']['master_phone'], 'name' => $find['party_a_info']['company_name'], 'scene' => 'WQTZ' ]; SmsLogic::contractUrl($a); $b = [ 'mobile' => $find['party_b_info']['phone'], 'name' => $find['party_b_info']['name'], 'scene' => 'WQTZ' ]; SmsLogic::contractUrl($b); return $this->success('上传成功', [], 1, 1); } else { if ($res == 0) { return $this->success('没有更新', [], 1, 1); } return $this->fail('上传失败'); } } //发起合同 public function DraftingContract(): Json { $params = $this->request->post(['id','part_b','type']); if(empty($params['id']) || empty($params['part_b']) || empty($params['type'])){ return $this->fail('参数错误'); } $data = [ 'id' => $params['part_b'], 'contract_id' => $params['id'] ]; $result = ContractLogic::Draftingcontracts($data,$params['type']); if ($result) { return $this->success('发送合同成功', [], 1, 1); } return $this->fail(ContractLogic::getError()); } //发送短信 public function sendSms(): Json { $params = $this->request->post(['id']); if(empty($params['id'])){ return $this->fail('参数错误'); } $res = ContractLogic::postsms($params); if ($res) { return $this->success('发送成功', [], 1, 1); } else { return $this->fail(ContractLogic::getError()); } } //下载证据包 public function evidence() { $params = $this->request->post(['id']); if(empty($params['id'])){ $this->fail('参数错误'); } $detail=Contract::where('id',$params['id'])->find(); if(!empty($detail['evidence_url'])){ return $this->success('获取成功', ['url' => env('url.url_prefix').$detail['evidence_url']]); } $company=Company::where('id',$detail['party_a'])->find(); $request = array( "applyNo" => $detail['contract_no'], "fullName" => $company['company_name'], "identityCard" => $company['organization_code'], "identityType" => 12, ); return app(JunziqianController::class)->EvidenceDownload($request); } }