64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\common\logic\vehicle;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\Company;
|
|
use app\common\model\contract\Contract;
|
|
use Exception;
|
|
use think\facade\Db;
|
|
|
|
class VehicleLogic extends BaseLogic
|
|
{
|
|
public static function initiate_contract($data):array {
|
|
$party_b = Company::field('company_type')->where('id',$data['party_b'])->find();
|
|
if($data['rent_type'] == 1){
|
|
//镇街公司
|
|
if($party_b['company_type'] != 16){
|
|
return ['code'=>0,'msg'=>'非镇街公司不能签约'];
|
|
}
|
|
}elseif($data['rent_type'] == 2){
|
|
//小组服务公司
|
|
if($party_b['company_type'] != 18){
|
|
return ['code'=>0,'msg'=>'非小组服务公司不能签约'];
|
|
}
|
|
}else{
|
|
return ['code'=>0,'msg'=>'参数错误'];
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
$contract = Contract::create([
|
|
'contract_type' => 29,
|
|
'contract_no' => time(),
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
'check_status' => 1,
|
|
'party_a' => $data['party_a'],
|
|
'party_b' => $data['party_b'],
|
|
'area_manager' => 0,
|
|
'type' => 1,
|
|
]);
|
|
$vehicleRent = Db::name('vehicle_rent')->insert([
|
|
'car_ids' => $data['car_ids'],
|
|
'contract_id' => $contract->id,
|
|
'party_a' => $data['party_a'],
|
|
'party_b' => $data['party_b'],
|
|
'num' => $data['num'],
|
|
'rent_type' => $data['rent_type'],
|
|
'status' => 1,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
]);
|
|
if($contract->id && $vehicleRent) {
|
|
Db::commit();
|
|
return ['code'=>1,'msg'=>'发起成功,等待平台风控部上传合同','data'=>['id'=>$contract->id]];
|
|
}else{
|
|
Db::rollback();
|
|
return ['code'=>0,'msg'=>'发起失败,请稍后重试'];
|
|
}
|
|
}catch (Exception $e) {
|
|
Db::rollback();
|
|
return ['code'=>0,'msg'=>$e->getMessage()];
|
|
}
|
|
}
|
|
} |