Merge pull request '新增镇街合同列表,发起合同,重发短信接口' (#12) from zhangwei into master

Reviewed-on: #12
This commit is contained in:
weiz 2023-09-06 09:50:08 +08:00
commit 3c80dcad81
2 changed files with 140 additions and 1 deletions

View File

@ -3,6 +3,7 @@
namespace app\adminapi\controller\contract;
use app\adminapi\controller\BaseAdminController;
use app\api\controller\JunziqianController;
use app\common\enum\notice\NoticeEnum;
use app\common\model\contract\VehicleContract;
@ -114,7 +115,7 @@ class VehicleContractController extends BaseAdminController
}
$pageNo = !empty($param['page_no']) ? $param['page_no'] : 1;
$pageSize = !empty($param['page_size']) ? $param['page_size'] : 15;
$data = VehicleContract::where($where)->where('contract_logistic_id')
$data = VehicleContract::where($where)->where('contract_logistic_id','<>',0)
->page($pageNo, $pageSize)
->order('create_time desc')
->select()->each(function($item){
@ -123,6 +124,104 @@ class VehicleContractController extends BaseAdminController
return $this->success('success',['lists'=>$data->toArray(),'page_no'=>$pageNo,'page_size'=>$pageSize,'count'=>$data->count()]);
}
public function initiatingRentCarContract() {
//获取参数
$params = $this->request->post(['id']);
if(empty($params['id'])){
return $this->fail('缺少必要参数');
}
//获取数据
$contract = VehicleContract::where('id',$params['id'])->find();
if(empty($contract)){
return $this->fail('数据不存在');
}
if($contract['status'] != 1){
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']
];
$signRes = app(JunziqianController::class)->VehicleRentSigning($signData, $params['id'],env('project.website_domain').'/api/index/townCarRent');
if ($signRes->success) {
$contract->save([
'id' => $contract['id'],
'contract_no' => $signRes->data,
'status' => 2
]);
$this->sendSms($params['id'],'《租赁合同》');
return $this->success('合同发送成功');
} else {
return $this->fail($signRes->msg);
}
}
public function sendSms($id,$title) {
//获取合同数据
$contract = VehicleContract::where('id',$id)->find();
if ($contract && !$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;
}
}
public function detail() {
$id = $this->request->get('id');
if(empty($id)){

View File

@ -118,6 +118,46 @@ class IndexController extends BaseApiController
return json(['success' => true, 'msg' => '成功']);
}
//镇街车辆租赁回调
public function townCarRent() {
$id = Request()->get('id');
if(empty($id)){
return json(['success' => false, 'msg' => '缺少参数']);
}
//获取合同数据
$contract = VehicleContract::where('id', $id)->find();
if (empty($contract)) {
return json(['success' => false, 'msg' => '获取数据失败']);
}
if($contract['status'] != 2){
return json(['success' => false, 'msg' => '合同状态错误']);
}
if ($contract['signing_timer'] == 0) {
//更新本地合同状态
$updateLocalRes = VehicleContract::where('id',$contract['id'])->update(['signing_timer'=>1]);
//更新远程
$updateSverRes =curl_post(env('project.logistic_domain').'/api/index/notifyContractUpdate',[],[
'id' => $contract['contract_logistic_id'],
'signing_timer' => 1,
]);
if(!$updateLocalRes || $updateSverRes['code']==0){
return json(['success' => false, 'msg' => '更新失败']);
}
}else if($contract['signing_timer'] == 1){
//更新本地合同状态
$updateLocalRes = VehicleContract::where('id',$contract['id'])->update(['signing_timer'=>2,'status' => 3]);
//更新远程
$updateSverRes =curl_post(env('project.logistic_domain').'/api/index/notifyContractUpdate',[],[
'id' => $contract['contract_logistic_id'],
'signing_timer' => 2,
'status' => 3
]);
if(!$updateLocalRes || $updateSverRes['code']==0){
return json(['success' => false, 'msg' => '更新失败']);
}
}
}
//系统车辆租赁回来
public function systemCarRent()
{