This commit is contained in:
unknown 2023-09-01 15:00:38 +08:00
parent 5d85f2ae7f
commit 205ba5e352
2 changed files with 0 additions and 212 deletions

View File

@ -52,7 +52,6 @@ class VehicleController extends BaseApiController
}
}
//添加自有车辆
public function addSelfCar() {
//获取参数

View File

@ -29,217 +29,6 @@ use Exception;
*/
class VehicleLogic extends BaseLogic
{
public static function checkNum($num):array {
try {
//获取数据
$cars = Vehicle::field('id,company_id')->where('status',1)->where('type',1)->limit($num)->select();
//验证数据
if($cars->count() < $num){
return ['code'=>0,'msg'=>'车辆数量不足'];
}
$ids = implode(',',array_column($cars->toArray(),'id'));
$company_id = array_column($cars->toArray(),'company_id')[0];
return ['code'=>1,'msg'=>'车辆数量充足','data'=>['car_ids'=>$ids,'company_id'=>$company_id]];
}catch (Exception $e) {
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
public static function setRent($param):array {
VehicleRent::startTrans();
try {
if($param['rent_type'] == 1){
//设置数据
$ids = explode(',',$param['car_id']);
$data = [];
foreach($ids as $v){
$car = Vehicle::where('id',$v)->find();
$rent = VehicleRent::where('car_id',$v)->find();
if($car && !$rent){
$data[] = [
'car_id' => $v,
'lessee_one_contract_id' => $param['contract_id'],
'lessee_one_company_id' => $param['company_id'],
'lessee_one_company' => $param['company_name'],
'lessee_one_user_id' => $param['company_user_id'],
'lessee_one_user' => $param['company_user_name'],
'lessee_one_phone' => $param['company_user_phone'],
'lessee_one_start_time' => time(),
'lessee_one_flag' => 1,
];
}
}
$res = (new VehicleRent()) -> saveAll($data);
//更新车辆列表中的车辆状态
Vehicle::where('id','in',$ids)->update(['status'=>2]);
}elseif($param['rent_type'] == 2){
//获取数据
$rent = VehicleRent::where('car_id',$param['car_id'])->find();
//设置数据
$data = [
'id' => $rent['id'],
'lessee_two_contract_id' => $param['contract_id'],
'lessee_two_company_id' => $param['company_id'],
'lessee_two_company_name' => $param['company_name'],
'lessee_two_user_id' => $param['company_user_id'],
'lessee_two_user' => $param['company_user_name'],
'lessee_two_phone' => $param['company_user_phone'],
'lessee_two_start_time' => time(),
'lessee_two_flag' => 1,
];
//写入数据
$res = VehicleRent::update($data);
}else{
return ['code'=>0,'msg'=>'操作失败'];
}
if($res){
VehicleRent::commit();
return ['code'=>1,'msg'=>'操作成功'];
}else{
VehicleRent::rollback();
return ['code'=>0,'msg'=>'操作失败'];
}
}catch(Exception $e) {
VehicleRent::rollback();
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
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,v.type')
->where('r.lessee_one_company_id',$params['company_id'])
->where('r.lessee_two_flag',$lessee_two_flag)
->where('v.license','like','%'.$license.'%')
->where('r.lessee_two_company_name','like','%'.$companyName.'%')
->page($pageNo,$pageSize)->order('r.lessee_one_start_time desc,r.car_id desc')->select()->each(function ($item){
//todo
$item['mileage'] = 10.0;
return $item;
});
if($rent){
return ['code'=>1,'msg'=>'请求成功','data'=>$rent->toArray()];
}else{
return ['code'=>0,'msg'=>'请求失败'];
}
}
public static function companyCar($company_id):array {
//查询是否有自有车辆
$selfCar = Vehicle::field('id,company_id,license,type,gps_carid')->where('company_id',$company_id)->where('type',2)->find();
if($selfCar){
$data['id'] = $selfCar['id'];
$data['company_id'] = $selfCar['company_id'];
$data['license'] = $selfCar['license'];
$data['type'] = $selfCar['type'];
//todo 获取里程
$data['mileage'] = 10;
return ['code'=>1,'msg'=>'请求成功','data'=>$data];
}else{
//租赁车辆
$rent = VehicleRent::field('lessee_one_company,lessee_one_user,lessee_one_phone,lessee_one_start_time,lessee_two_company_id,lessee_two_user,lessee_two_phone,lessee_two_start_time,lessee_two_flag')->where('lessee_two_company_id',$company_id)->find();
$info = Vehicle::field('id,license,type,gps_carid')->where('id',$rent['car_id'])->find();
if($rent && $info){
$data['lessee_one_company'] = $rent['lessee_one_company'];
$data['lessee_one_user'] = $rent['lessee_one_user'];
$data['lessee_one_phone'] = $rent['lessee_one_phone'];
$data['lessee_one_start_time'] = $rent['lessee_one_start_time'];
$data['lessee_two_company_id'] = $rent['lessee_two_company_id'];
$data['lessee_two_company_name'] = $rent['lessee_two_company_name'];
$data['lessee_two_user'] = $rent['lessee_two_user'];
$data['lessee_two_phone'] = $rent['lessee_two_phone'];
$data['lessee_two_start_time'] = $rent['lessee_two_start_time'];
$data['lessee_two_flag'] = $rent['lessee_two_flag'];
$data['id'] = $info['id'];
$data['license'] = $info['license'];
$data['type'] = $info['type'];
//todo 获取里程
$data['mileage'] = 10;
return ['code'=>1,'msg'=>'请求成功','data'=>$data];
}else{
return ['code'=>0,'msg'=>'请求失败'];
}
}
}
public static function addVehicle($params):array {
//获取车辆
$vehicle = Vehicle::where('company_id',$params['company_id'])->where('license',$params['license'])->find();
if($vehicle){
return ['code'=>0,'msg'=>'该公司已添加车辆'];
}
//创建
$result = Vehicle::create([
'company_id' => $params['company_id'],
'license' => $params['license'],
'gps_imei' => '',
'gps_carid' => 0,
'type' => 2,
'status' => 1,
'is_check' => 1,
'is_del' => 1,
'create_time' => time(),
'update_time' => time(),
]);
if($result){
return ['code'=>1,'msg'=>'添加成功,等待审核'];
}else{
return ['code'=>1,'msg'=>'添加失败'];
}
}
public static function carInfo($params):array {
//判断车辆类型
if($params['car_type'] == 1){
//租赁车辆
$rent = VehicleRent::field('lessee_one_company,lessee_one_user,lessee_one_phone,lessee_one_start_time,lessee_two_company_id,lessee_two_user,lessee_two_phone,lessee_two_start_time,lessee_two_flag')->where('car_id',$params['car_id'])->find();
$info = Vehicle::field('id,license,type,gps_carid')->where('id',$params['car_id'])->find();
if($rent && $info){
$data['lessee_one_company'] = $rent['lessee_one_company'];
$data['lessee_one_user'] = $rent['lessee_one_user'];
$data['lessee_one_phone'] = $rent['lessee_one_phone'];
$data['lessee_one_start_time'] = $rent['lessee_one_start_time'];
$data['lessee_two_company_id'] = $rent['lessee_two_company_id'];
$data['lessee_two_company_name'] = $rent['lessee_two_company_name'];
$data['lessee_two_user'] = $rent['lessee_two_user'];
$data['lessee_two_phone'] = $rent['lessee_two_phone'];
$data['lessee_two_start_time'] = $rent['lessee_two_start_time'];
$data['lessee_two_flag'] = $rent['lessee_two_flag'];
$data['id'] = $info['id'];
$data['license'] = $info['license'];
$data['type'] = $info['type'];
//todo 获取里程
$data['mileage'] = 10;
return ['code'=>1,'msg'=>'请求成功','data'=>$data];
}else{
return ['code'=>0,'msg'=>'请求失败'];
}
}elseif($params['car_type'] == 2){
//自有车辆
$data = Vehicle::field('id,company_id,license,type')->where('id',$params['car_id'])->where('type',2)->find();
//获取车辆当前位置
if($data){
//todo 获取里程
$data['mileage'] = 10;
return ['code'=>1,'msg'=>'请求成功','data'=>$data->toArray()];
}else{
return ['code'=>0,'msg'=>'请求失败'];
}
}else{
return ['code'=>0,'msg'=>'参数错误'];
}
}
public static function getCarLocal($params):array {
$car = Vehicle::field('gps_imei')->where('id',$params['car_id'])->find();
if(!$car){