diff --git a/app/adminapi/controller/contract/VehicleContractController.php b/app/adminapi/controller/contract/VehicleContractController.php index 3c3fcc495..af7c02c41 100644 --- a/app/adminapi/controller/contract/VehicleContractController.php +++ b/app/adminapi/controller/contract/VehicleContractController.php @@ -40,6 +40,7 @@ class VehicleContractController extends BaseAdminController 'id' => $vehicle_contract['contract_logistic_id'], 'file' => $params['file'], 'status' => 1, + 'update_time' => time() ]; //判断合同类型 if($vehicle_contract['type'] == 0 && $vehicle_contract['contract_logistic_id'] != 0){ @@ -186,7 +187,8 @@ class VehicleContractController extends BaseAdminController 'id' => $contract['contract_logistic_id'], 'contract_no' => $signRes->data, 'status' => 2, - 'signing_timer' => 0 + 'signing_timer' => 0, + 'update_time' => time() ]); } $this->sendSms($params['id'],$smsTitle); diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 1814d6891..ecd7ea1c5 100755 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -178,6 +178,7 @@ class IndexController extends BaseApiController $updateSverRes =curl_post(env('project.logistic_domain').'/api/contractUpdate',[],[ 'id' => $contract['contract_logistic_id'], 'signing_timer' => 1, + 'update_time' => time() ]); if(!$updateLocalRes || $updateSverRes['code']==0){ return json(['success' => false, 'msg' => '更新失败']); @@ -224,7 +225,8 @@ class IndexController extends BaseApiController 'signing_timer' => 2, 'status' => 3, 'contract_url'=>$signContractFile, - 'contract_evidence'=>$contractEvidence + 'contract_evidence'=>$contractEvidence, + 'update_time' => time() ]); if(!$updateLocalRes || $updateSverRes['code']==0){ return json(['success' => false, 'msg' => '更新失败']); @@ -429,6 +431,7 @@ class IndexController extends BaseApiController 'status' => 3, 'contract_url'=>$signContractFile, 'contract_evidence'=>$contractEvidence, + 'update_time' => time() ]); } //判断合同是否存在购买记录表中 @@ -644,6 +647,7 @@ class IndexController extends BaseApiController 'use_user_id' =>$compay['user_id'], 'use_user_name' =>$compay['master_name'], 'use_user_phone' =>$compay['master_phone'], + 'update_time' => time() ]); if(!$updateLocalRes || $updateSverRes['code']==0){ return json(['success' => false, 'msg' => '更新失败']); @@ -700,7 +704,6 @@ class IndexController extends BaseApiController public function notifyProperty() { $parmas = Request()->post(); - Log::info(['资产回调', $parmas]); if ($parmas) { if (!isset($parmas['company_id']) || $parmas['company_id'] < 0) { return json(['success' => false, 'msg' => '公司id不能为空']); diff --git a/app/middleapi/controller/ContractController.php b/app/middleapi/controller/ContractController.php new file mode 100644 index 000000000..d8615f4b4 --- /dev/null +++ b/app/middleapi/controller/ContractController.php @@ -0,0 +1,181 @@ +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'])){ + $where[] = ['contract_no','like','%'.$params['contract_no'].'%']; + } + if(isset($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); + } + } \ No newline at end of file diff --git a/app/middleapi/controller/VehicleController.php b/app/middleapi/controller/VehicleController.php new file mode 100644 index 000000000..757c653aa --- /dev/null +++ b/app/middleapi/controller/VehicleController.php @@ -0,0 +1,314 @@ +request->isPost()){ + return $this->fail('请求方式错误'); + } + $param = $this->request->post(['page_no','page_size','company_name','contract_no','status']); + $where = []; + if(isset($param['company_name'])){ + $where[] = ['company_b_name','like','%'.$param['company_name'].'%']; + } + if(isset($param['contract_no'])){ + $where[] = ['contract_no','like','%'.$param['contract_no'].'%']; + } + if(isset($param['status']) && in_array($param['status'],[0,1])){ + if($param['status'] == 1){ + $where[] = ['status','in', '1,2,3']; + }else{ + $where[] = ['status','=', $param['status']]; + } + }else{ + $where[] = ['status','in', '0,1,2,3']; + } + $pageNo = !empty($param['page_no']) ? $param['page_no'] : 1; + $pageSize = !empty($param['page_size']) ? $param['page_size'] : 20; + $data = VehicleContract::where($where) + ->page($pageNo, $pageSize) + ->order('create_time desc') + ->select()->each(function($item){ + $item['cars_info'] = json_decode($item['cars_info'],true); + }); + return $this->success('success',['lists'=>$data->toArray(),'page_no'=>$pageNo,'page_size'=>$pageSize,'count'=>$data->count()]); + } + + //三轮车合同详情 + public function detail(): Json + { + if(!$this->request->isPost()){ + return $this->fail('请求方式错误'); + } + $id = $this->request->post('id'); + if(empty($id)){ + $this->fail('参数错误'); + } + $data = VehicleContract::where('id',$id)->findOrEmpty(); + if($data->isEmpty()){ + return $this->fail('未查找到数据'); + } + $cars = json_decode($data['cars_info'],true); + //判断合同类型 + if(!empty($data['contract_logistic_id']) && $data['type'] == 0){ + $carList = curl_get(env('project.logistic_domain').'/api/getAvailableVehicles'); + $data['car_list'] = $carList&&$carList['code']==1 ? $carList['data'] : []; + } + if(!empty($cars)){ + foreach ($cars as $k=>$v) { + if($data['type'] == 0){ + $cars[$k]['type'] = 0; + } + if($data['type'] == 1){ + if(empty($v['id'])){ + $cars[$k]['type'] = 1; + }else{ + $rentInfo = VehicleRent::where('car_id',$v['id'])->findOrEmpty(); + if($rentInfo->isEmpty()){ + $cars[$k]['type'] = 0; + }else{ + $cars[$k]['type'] = $rentInfo['type']; + } + } + } + if($data['type'] == 2){ + $rentInfo = VehicleRent::where('car_id',$v['id'])->findOrEmpty(); + if($rentInfo->isEmpty()){ + $cars[$k]['type'] = 0; + }else{ + $cars[$k]['type'] = $rentInfo['type']; + } + } + if($data['type'] == 3){ + $rentInfo = VehicleRent::where('car_id',$v['id'])->findOrEmpty(); + if($rentInfo->isEmpty()){ + $cars[$k]['type'] = 2; + }else{ + $cars[$k]['type'] = $rentInfo['type']; + } + } + $cars[$k]['rent_time'] = $data['update_time']; + } + } + $data['cars_info'] = $cars; + return $this->success('success',$data->toArray()); + } + + //上传三轮车合同 + public function uploadContract(): Json + { + //获取参数 + $params = $this->request->post(['id','file','cars']); + if(empty($params['id']) || empty($params['file'])){ + return $this->fail('缺少必要参数'); + } + //获取合同信息 + $vehicle_contract = VehicleContract::where('id',$params['id'])->findOrEmpty(); + if($vehicle_contract->isEmpty()){ + return $this->fail('合同信息错误'); + } + if($vehicle_contract['type']==0 && $vehicle_contract['contract_logistic_id'] != 0){ + if(empty($params['cars'])){ + return $this->fail('缺少必要参数cars'); + } + $cars = json_decode($params['cars'],true); + if(empty($cars)){ + return $this->fail('参数cars无效'); + } + } + if($vehicle_contract['status'] != 0){ + return $this->fail('合同状态错误'); + } + //更新本地 + try { + $data = [ + 'id' => $vehicle_contract['contract_logistic_id'], + 'file' => $params['file'], + 'status' => 1, + 'update_time' => time() + ]; + //判断合同类型 + if($vehicle_contract['type'] == 0 && $vehicle_contract['contract_logistic_id'] != 0){ + $data['cars_info'] = $params['cars']; + } + if(!empty($vehicle_contract['contract_logistic_id'])){ + //更新物流系统 + curl_post(env('project.logistic_domain').'/api/contractUpdate',[],$data); + } + unset($data['id']); + VehicleContract::where('id', $params['id'])->update($data); + + }catch (\Exception $e){ + return $this->fail($e->getMessage()); + } + return $this->success('上传成功', [], 1, 1); + } + + //发起三轮车合同 + public function initiatingContract(): Json + { + //获取参数 + $params = $this->request->post(['id']); + if(empty($params['id'])){ + return $this->fail('缺少必要参数'); + } + //获取数据 + $contract = VehicleContract::where('id',$params['id'])->findOrEmpty(); + if($contract->isEmpty()){ + return $this->fail('数据不存在'); + } + if(!($contract['status'] == 1 || ($contract['status'] == 2 && $contract['signing_timer'] != 2))){ + return $this->fail('合同状态错误'); + } + $signData = [ + 'name' => $contract['company_a_name'] . '的合同', + 'signatories' => [ + ['fullName' => $contract['company_a_name'], 'identityType' => 12, 'identityCard' => $contract['company_a_code'], 'email' => $contract['company_a_email'], 'noNeedVerify' => 1, 'signLevel' => 1], + ['fullName' => $contract['company_b_name'], 'identityType' => 12, 'identityCard' => $contract['company_b_code'], 'email' => $contract['company_b_email'], 'noNeedVerify' => 1, 'signLevel' => 1] + ], + 'url' => $contract['file'] + ]; + $notify_url = ''; + $smsTitle = ''; + if($contract['type'] == 0){ + $smsTitle = '《租赁合同》'; + if(empty($contract['contract_logistic_id'])){ + $notify_url = env('project.website_domain').'/api/index/systemCarRent'; + }else{ + $notify_url = env('project.website_domain').'/api/index/townCarRent'; + } + }elseif($contract['type'] == 1){ + $smsTitle = '《自有车辆上传合同》'; + $notify_url = env('project.website_domain').'/api/index/selfCarRent'; + }elseif($contract['type'] == 2){ + $smsTitle = '《解约合同》'; + $notify_url = env('project.website_domain').'/api/index/cancelRent'; + }elseif($contract['type'] == 3){ + $smsTitle = '《购买合同》'; + $notify_url = env('project.website_domain').'/api/index/buyCar'; + } + $signRes = app(JunziqianController::class)->VehicleRentSigning($signData, $params['id'],$notify_url); + if ($signRes->success) { + $contract->save([ + 'id' => $contract['id'], + 'contract_no' => $signRes->data, + 'status' => 2, + 'signing_timer' => 0 + ]); + if(!empty($contract['contract_logistic_id'])){ + curl_post(env('project.logistic_domain').'/api/contractUpdate',[],[ + 'id' => $contract['contract_logistic_id'], + 'contract_no' => $signRes->data, + 'status' => 2, + 'signing_timer' => 0, + 'update_time' => time() + ]); + } + $this->sendSms($params['id'],$smsTitle); + return $this->success('合同发送成功'); + } else { + return $this->fail($signRes->msg); + } + } + + //重新发送三轮车合同短信 + public function sendSmsAgain(): Json + { + //获取参数 + $id = $this->request->post('id'); + if(empty($id)){ + return $this->fail('参数错误'); + } + //获取数据 + $contract = VehicleContract::where('id',$id)->find(); + if(empty($contract)){ + return $this->fail('数据错误'); + } + $smsTitle = ''; + if($contract['type'] == 0){ + $smsTitle = '《租赁合同》'; + }elseif($contract['type'] == 1){ + $smsTitle = '《自有车辆上传合同》'; + }elseif($contract['type'] == 2){ + $smsTitle = '《解约合同》'; + }elseif($contract['type'] == 3){ + $smsTitle = '《购买合同》'; + } + $this->sendSms($id,$smsTitle); + return $this->success('发送成功'); + } + + protected function sendSms($id,$title): bool + { + //获取合同数据 + $contract = VehicleContract::where('id',$id)->findOrEmpty(); + if (!$contract->isEmpty() && $contract['file'] != '') { + //发送短信 + $data = [ + //甲方 + [ + "applyNo" => $contract['contract_no'], + "fullName" => $contract['company_a_name'], + "identityCard" => $contract['company_a_code'], + "identityType" => 12, + "master_phone" => $contract['company_a_phone'], + "type"=>"party_a" + ], + //乙方 + [ + "applyNo" => $contract['contract_no'], + "fullName" => $contract['company_b_name'], + "identityCard" => $contract['company_b_code'], + "identityType" => 12, + "master_phone" => $contract['company_b_phone'], + "type"=>"party_b" + + ], + ]; + + $url = []; + foreach ($data as $v) { + $res = app(JunziqianController::class)->SigningLink($v); + if (!$res->success) { + return false; + } + if ($v['type'] == 'party_a') { + $url['party_a'] =$res->data; + } else { + $url['party_b'] =$res->data; + } + //发送短信 + $sms = [ + 'mobile' => $v['master_phone'], + 'name' => $v['fullName'], + 'type' => $title, + 'code' => 'api/Hetong/info?id='.$id.'&type='.$v['type'], + 'scene' => 'WQ' + ]; + $scene = NoticeEnum::getSceneByTag($sms['scene']); + if (empty($scene)) { + throw new \Exception('场景值异常'); + } + event('Notice', [ + 'scene_id' => $scene, + 'params' => $sms + ]); + } + VehicleContract::where('id', $id)->update(['url' => json_encode($url)]); + return true; + }else{ + return false; + } + } + } \ No newline at end of file