This commit is contained in:
unknown 2023-08-26 11:13:14 +08:00
parent c02180a9fa
commit f3b98a3fd6
3 changed files with 50 additions and 5 deletions

View File

@ -11,7 +11,7 @@ use think\response\Json;
*/
class VehicleController extends BaseApiController
{
public array $notNeedLogin = ['checkNum','vehicleRent','getCarLocal','getCarHistory'];
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','getCarLocal','getCarHistory'];
//验证租赁数量
@ -49,6 +49,23 @@ class VehicleController extends BaseApiController
}
}
public function companyCarList():Json {
//获取参数
$params = $this->request->post(['company_id','is_rent','license','company_name','page_no','page_size']);
//验证参数
if(empty($params['company_id']) || empty($params['is_rent'])){
return $this->fail('缺少必要参数');
}
//获取数据
$result = VehicleLogic::companyCarList($params);
//返回数据
if($result['code'] == 1){
return $this->success($result['msg'],$result['data']);
}else{
return $this->fail($result['msg']);
}
}
//获取车辆当前位置
public function getCarLocal():Json {
$params = $this->request->get(['car_id']);

View File

@ -54,7 +54,8 @@ class VehicleLogic extends BaseLogic
$data = [];
foreach($ids as $v){
$car = Vehicle::where('id',$v)->find();
if($car){
$rent = VehicleRent::where('car_id',$v)->find();
if($car && !$rent){
$data[] = [
'car_id' => $v,
'lessee_one_contract_id' => $param['contract_id'],
@ -104,6 +105,34 @@ class VehicleLogic extends BaseLogic
}
}
public static function companyCarList($params):array {
if($params['is_rent'] == 1){
$lessee_two_flag = 0;
}else{
$lessee_two_flag = 1;
}
$pageNo = $params['page_no'] ?? 1;
$pageSize = $params['page_size'] ?? 10;
$license = $params['license'] ?? '';
$companyName = $params['company_name'] ?? '';
$rent = VehicleRent::alias('r')
->leftJoin('vehicle v','r.car_id = v.id')
->field('r.*,v.license')
->where('r.lessee_one_company_id',$params['company_id'])
->where('r.lessee_two_flag',$lessee_two_flag)
->where('v.license','like','%'.$license.'%')
->where('v.lessee_two_company_name','like','%'.$companyName.'%')
->page($pageNo,$pageSize)->order('r.lessee_one_start_time desc,r.car_id desc')->select()->each(function ($item){
$item['mileage'] = 10.0;
return $item;
});
if($rent){
return ['code'=>1,'msg'=>'请求成功','data'=>$rent->toArray()];
}else{
return ['code'=>0,'msg'=>'请求失败'];
}
}
public static function getCarLocal($params):array {
$car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->find();
if(!$car){

View File

@ -25,9 +25,8 @@ Route::rule('hasCourier','Logistics/hasCourier','get');
/*-------------------------------------------------------------------------------------------*/
Route::rule('checkNum','Vehicle/checkNum','get');
Route::rule('vehicleRent','Vehicle/vehicleRent','post');
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
Route::rule('checkNum','Vehicle/checkNum','get');
Route::rule('companyCarList','Vehicle/companyCarList','post');