update
This commit is contained in:
parent
917c7e6c06
commit
5874bb8fb8
@ -5,11 +5,12 @@ namespace app\api\controller;
|
||||
use app\common\model\contract\Contract;
|
||||
use app\common\model\platform\Platform;
|
||||
use app\common\model\vehicle\Vehicle;
|
||||
use app\common\model\vehicle\VehicleRent;
|
||||
use think\facade\Db;
|
||||
|
||||
class ContractController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['signContract','updateContract'];
|
||||
public array $notNeedLogin = ['signContract','contractUpdate','checkCarNum','getAvailableVehicles'];
|
||||
public function signContract() {
|
||||
//获取参数
|
||||
$params = $this->request->post(['num','company_id','company_name','company_code','company_user','company_phone','company_email']);
|
||||
@ -22,14 +23,6 @@ class ContractController extends BaseApiController
|
||||
if(!$platform || $platform->isEmpty()){
|
||||
return $this->fail('甲方公司不存在');
|
||||
}
|
||||
//获取车辆数据
|
||||
$cars = Vehicle::field('id,license')->where([
|
||||
['type','=',0],
|
||||
['status','=',0],
|
||||
])->limit($params['num'])->select();
|
||||
if($cars->isEmpty() || $cars->count() < $params['num']){
|
||||
return $this->fail('车辆数量不足');
|
||||
}
|
||||
//设置数据
|
||||
$data = [
|
||||
'contract_no' => time(),
|
||||
@ -45,7 +38,7 @@ class ContractController extends BaseApiController
|
||||
'company_b_phone' => $params['company_phone'],
|
||||
'company_b_email' => $params['company_email'],
|
||||
'num' => $params['num'],
|
||||
'cars_info' => $cars->toJson(),
|
||||
'cars_info' => null,
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
@ -53,8 +46,7 @@ class ContractController extends BaseApiController
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res1 = Contract::create($data);
|
||||
$res2 = Vehicle::where('id','in',array_column($cars->toArray(),'id'))->update(['status'=>1,'update_time'=>time()]);
|
||||
if($res1->id && $res2){
|
||||
if($res1->id){
|
||||
$data['contract_logistic_id'] = $res1->id;
|
||||
$data['type'] = 0;
|
||||
Db::commit();
|
||||
@ -70,16 +62,89 @@ class ContractController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function updateContract() {
|
||||
public function contractUpdate() {
|
||||
//获取参数
|
||||
$params = $this->request->post();
|
||||
if(empty($params['id'])){
|
||||
if(!isset($params['id']) || empty($params['id'])) {
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
//更新数据
|
||||
$model = Contract::where('id',$params['id'])->find();
|
||||
$result = $model->save($params);
|
||||
//返回
|
||||
return $result ? $this->success('更新成功') : $this->fail('更新失败');
|
||||
$contract = Contract::where('id',$params['id'])->find();
|
||||
if(empty($contract)) {
|
||||
return $this->fail('未找到相应数据');
|
||||
}
|
||||
if(isset($params['signing_timer']) && isset($params['status']) && $params['signing_timer'] == 2 && $params['status'] == 3){
|
||||
//获取签约后的合同
|
||||
$signContractFile = app(JunziqianController::class)->download_file($contract['contract_no']);
|
||||
$params['contract_url'] = $signContractFile ?? '';
|
||||
//获取租赁车辆
|
||||
$cars = json_decode($contract['cars_info'], true);
|
||||
$data = [];
|
||||
foreach($cars as $v){
|
||||
$data[] = [
|
||||
'car_id' => $v['id'],
|
||||
'contract_id' => $contract['id'],
|
||||
'company_id' => $contract['company_b_id'],
|
||||
'company_name' => $contract['company_b_name'],
|
||||
'company_user' => $contract['company_b_user'],
|
||||
'company_phone' => $contract['company_b_phone'],
|
||||
'create_time' => time(),
|
||||
'status' => 0,
|
||||
'use_user_id' => 0,
|
||||
'use_user_name' => '',
|
||||
'use_user_phone' => ''
|
||||
];
|
||||
}
|
||||
try{
|
||||
//更新合同状态
|
||||
$update_result = $contract->where('id', $contract['id'])->save($params);
|
||||
//更新本地车辆状态
|
||||
$vehicle_result = Vehicle::where('id','in',array_column($cars,'id'))->update(['status'=>2]);
|
||||
//添加车辆到租赁列表
|
||||
$create_result = (new VehicleRent()) -> saveAll($data);
|
||||
if($update_result && $vehicle_result && $create_result){
|
||||
Db::commit();
|
||||
return $this->success('更新成功1');
|
||||
}else{
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败1');
|
||||
}
|
||||
}catch (\Exception){
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败1.1');
|
||||
}
|
||||
}
|
||||
try{
|
||||
$update_result = $contract->where('id', $contract['id'])->save($params);
|
||||
if($update_result){
|
||||
Db::commit();
|
||||
return $this->success('更新成功2');
|
||||
}else{
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败2');
|
||||
}
|
||||
}catch (\Exception){
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败2.1');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkCarNum() {
|
||||
//获取参数
|
||||
$num = $this->request->post('num');
|
||||
if(empty($num)){
|
||||
return $this->fail('车辆数量不足');
|
||||
}
|
||||
//获取车辆
|
||||
$data = Vehicle::where('status',0)->where('type',0)->limit($num)->select();
|
||||
//判断
|
||||
if($data->count() < $num){
|
||||
return $this->fail('车辆数量不足');
|
||||
}
|
||||
return $this->success('车辆数量充足');
|
||||
}
|
||||
|
||||
public function getAvailableVehicles() {
|
||||
$data = Vehicle::field('id,license')->where('status',0)->where('type',0)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ use think\response\Json;
|
||||
*/
|
||||
class VehicleController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['getCarLocal','getCarHistory','addSelfCar','updateVehicleRent','cancelRent','contractUpdate'];
|
||||
public array $notNeedLogin = ['getCarLocal','getCarHistory','addSelfCar','updateVehicleRent','cancelRent'];
|
||||
|
||||
//获取车辆当前位置
|
||||
public function getCarLocal():Json {
|
||||
@ -145,70 +145,4 @@ class VehicleController extends BaseApiController
|
||||
return $this->fail('失败');
|
||||
}
|
||||
}
|
||||
|
||||
public function contractUpdate() {
|
||||
//获取参数
|
||||
$params = $this->request->post();
|
||||
if(!isset($params['id']) || empty($params['id'])) {
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$contract = Contract::where('id',$params['id'])->find();
|
||||
if(empty($contract)) {
|
||||
return $this->fail('未找到相应数据');
|
||||
}
|
||||
if(isset($params['signing_timer']) && isset($params['status']) && $params['signing_timer'] == 2 && $params['status'] == 3){
|
||||
//获取签约后的合同
|
||||
$signContractFile = app(JunziqianController::class)->download_file($contract['contract_no']);
|
||||
$params['contract_url'] = $signContractFile ?? '';
|
||||
//获取租赁车辆
|
||||
$cars = json_decode($contract['cars_info'], true);
|
||||
$data = [];
|
||||
foreach($cars as $v){
|
||||
$data[] = [
|
||||
'car_id' => $v['id'],
|
||||
'contract_id' => $contract['id'],
|
||||
'company_id' => $contract['company_b_id'],
|
||||
'company_name' => $contract['company_b_name'],
|
||||
'company_user' => $contract['company_b_user'],
|
||||
'company_phone' => $contract['company_b_phone'],
|
||||
'create_time' => time(),
|
||||
'status' => 0,
|
||||
'use_user_id' => 0,
|
||||
'use_user_name' => '',
|
||||
'use_user_phone' => ''
|
||||
];
|
||||
}
|
||||
try{
|
||||
//更新合同状态
|
||||
$update_result = $contract->where('id', $contract['id'])->save($params);
|
||||
//更新本地车辆状态
|
||||
$vehicle_result = Vehicle::where('id','in',array_column($cars,'id'))->update(['status'=>2]);
|
||||
//添加车辆到租赁列表
|
||||
$create_result = (new VehicleRent()) -> saveAll($data);
|
||||
if($update_result && $vehicle_result && $create_result){
|
||||
Db::commit();
|
||||
return $this->success('更新成功1');
|
||||
}else{
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败1');
|
||||
}
|
||||
}catch (\Exception){
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败1.1');
|
||||
}
|
||||
}
|
||||
try{
|
||||
$update_result = $contract->where('id', $contract['id'])->save($params);
|
||||
if($update_result){
|
||||
Db::commit();
|
||||
return $this->success('更新成功2');
|
||||
}else{
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败2');
|
||||
}
|
||||
}catch (\Exception){
|
||||
Db::rollback();
|
||||
return $this->fail('更新失败2.1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,10 +30,11 @@ Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
||||
Route::rule('addSelfCar','Vehicle/addSelfCar','post');
|
||||
Route::rule('updateVehicleRent','Vehicle/updateVehicleRent','post');
|
||||
Route::rule('cancelRent','Vehicle/cancelRent','post');
|
||||
Route::rule('contractUpdate','Vehicle/contractUpdate','post');
|
||||
|
||||
/*-------------------------------------------------------------------------------------------*/
|
||||
Route::rule('signContract','Contract/signContract','post');
|
||||
Route::rule('updateContract','Contract/updateContract','post');
|
||||
Route::rule('contractUpdate','Contract/contractUpdate','post');
|
||||
Route::rule('checkCarNum','Contract/checkCarNum','post');
|
||||
Route::rule('getAvailableVehicles','Contract/getAvailableVehicles','get');
|
||||
|
||||
Route::rule('/Hetong/url','Hetong/url','get');
|
Loading…
x
Reference in New Issue
Block a user