增加自有车辆接口
This commit is contained in:
parent
f3b98a3fd6
commit
3427e6cae2
@ -11,7 +11,7 @@ use think\response\Json;
|
|||||||
*/
|
*/
|
||||||
class VehicleController extends BaseApiController
|
class VehicleController extends BaseApiController
|
||||||
{
|
{
|
||||||
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','getCarLocal','getCarHistory'];
|
public array $notNeedLogin = ['checkNum','vehicleRent','companyCarList','addVehicle','getCarLocal','getCarHistory'];
|
||||||
|
|
||||||
|
|
||||||
//验证租赁数量
|
//验证租赁数量
|
||||||
@ -66,6 +66,21 @@ class VehicleController extends BaseApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addVehicle():Json {
|
||||||
|
//获取参数
|
||||||
|
$params = $this->request->post(['company_id','license']);
|
||||||
|
if(empty($params['company_id']) || empty($params['license'])){
|
||||||
|
return $this->fail('缺少必要参数');
|
||||||
|
}
|
||||||
|
$result = VehicleLogic::addVehicle($params);
|
||||||
|
//返回数据
|
||||||
|
if($result['code'] == 1){
|
||||||
|
return $this->success($result['msg']);
|
||||||
|
}else{
|
||||||
|
return $this->fail($result['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//获取车辆当前位置
|
//获取车辆当前位置
|
||||||
public function getCarLocal():Json {
|
public function getCarLocal():Json {
|
||||||
$params = $this->request->get(['car_id']);
|
$params = $this->request->get(['car_id']);
|
||||||
|
@ -32,7 +32,7 @@ class VehicleLogic extends BaseLogic
|
|||||||
public static function checkNum($num):array {
|
public static function checkNum($num):array {
|
||||||
try {
|
try {
|
||||||
//获取数据
|
//获取数据
|
||||||
$cars = Vehicle::field('id,company_id')->where('status',0)->where('type',0)->limit($num)->select();
|
$cars = Vehicle::field('id,company_id')->where('status',0)->where('type',0)->where('type',0)->limit($num)->select();
|
||||||
//验证数据
|
//验证数据
|
||||||
if($cars->count() < $num){
|
if($cars->count() < $num){
|
||||||
return ['code'=>0,'msg'=>'车辆数量不足'];
|
return ['code'=>0,'msg'=>'车辆数量不足'];
|
||||||
@ -133,6 +133,32 @@ class VehicleLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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' => 1,
|
||||||
|
'status' => 0,
|
||||||
|
'is_check' => 0,
|
||||||
|
'is_del' => 0,
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time(),
|
||||||
|
]);
|
||||||
|
if($result){
|
||||||
|
return ['code'=>1,'msg'=>'添加成功,等待审核'];
|
||||||
|
}else{
|
||||||
|
return ['code'=>1,'msg'=>'添加失败'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function getCarLocal($params):array {
|
public static function getCarLocal($params):array {
|
||||||
$car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->find();
|
$car = Vehicle::field('gps_carid')->where('id',$params['car_id'])->find();
|
||||||
if(!$car){
|
if(!$car){
|
||||||
|
@ -30,3 +30,4 @@ Route::rule('vehicleRent','Vehicle/vehicleRent','post');
|
|||||||
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
Route::rule('getCarLocal','Vehicle/getCarLocal','get');
|
||||||
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
Route::rule('getCarHistory','Vehicle/getCarHistory','get');
|
||||||
Route::rule('companyCarList','Vehicle/companyCarList','post');
|
Route::rule('companyCarList','Vehicle/companyCarList','post');
|
||||||
|
Route::rule('addVehicle','Vehicle/addVehicle','post');
|
Loading…
x
Reference in New Issue
Block a user