diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index b1125e92..543dd0f4 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -2,6 +2,7 @@ namespace app\api\controller; use app\api\logic\VehicleLogic; +use app\common\model\contract\Contract; use app\common\model\vehicle\Vehicle; use app\common\model\vehicle\VehicleRent; use think\facade\Db; @@ -146,6 +147,68 @@ class VehicleController extends BaseApiController } 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'); + } } } diff --git a/app/api/logic/LogisticsLogic.php b/app/api/logic/LogisticsLogic.php index 6765d68d..cffb2a57 100644 --- a/app/api/logic/LogisticsLogic.php +++ b/app/api/logic/LogisticsLogic.php @@ -225,7 +225,6 @@ class LogisticsLogic extends BaseLogic 'create_time' => time(), ]); Logistics::commit(); - return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['master_name'],'phone'=>$courier['master_phone']]]; } catch (\Exception $e) { Logistics::rollback(); return ['code'=>0, 'msg'=>$e->getMessage()]; @@ -238,6 +237,7 @@ class LogisticsLogic extends BaseLogic Log::write('["极光推送:"]'.$push_result['msg'],'error'); } } + return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['master_name'],'phone'=>$courier['master_phone']]]; } /* @@ -279,15 +279,15 @@ class LogisticsLogic extends BaseLogic 'content' => '已提取商品', 'create_time' => time(), ]); - //调用接口通知商超平台 - $url = env('project.shop_notify_domain').'/api/goods/take/'.$params['order_id']; - curl_post($url,[],['order_sn'=>$params['order_sn']]); Logistics::commit(); - return ['code'=>1, 'msg'=>'操作成功']; } catch (\Exception $e) { Logistics::rollback(); return ['code'=>0, 'msg'=>$e->getMessage()]; } + //调用接口通知商超平台 + $url = env('project.shop_notify_domain').'/api/goods/take/'.$params['order_id']; + curl_post($url,[],['order_sn'=>$params['order_sn']]); + return ['code'=>1, 'msg'=>'操作成功']; } /* @@ -326,15 +326,15 @@ class LogisticsLogic extends BaseLogic 'content' => '已完成配送', 'create_time' => time(), ]); - //调用接口通知商超平台 - $url = env('project.shop_notify_domain').'/api/goods/take/'.$logistics['order_id']; - curl_post($url,[],['order_sn'=>$logistics['order_sn'],'logistics_code'=>$params['take_code']]); Logistics::commit(); - return ['code'=>1, 'msg'=>'操作成功']; } catch (\Exception $e) { Logistics::rollback(); return ['code'=>0, 'msg'=>$e->getMessage()]; } + //调用接口通知商超平台 + $url = env('project.shop_notify_domain').'/api/goods/take/'.$logistics['order_id']; + curl_post($url,[],['order_sn'=>$logistics['order_sn'],'logistics_code'=>$params['take_code']]); + return ['code'=>1, 'msg'=>'操作成功']; } /* diff --git a/app/api/route/app.php b/app/api/route/app.php index dd3433e3..9c20e690 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -30,7 +30,7 @@ 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');