car interface

This commit is contained in:
unknown 2023-08-17 14:08:50 +08:00
parent 528580cfd1
commit 1a36052dae
3 changed files with 44 additions and 8 deletions

View File

@ -37,7 +37,8 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['license', 'gps_imei', 'gps_carid', 'status'], '%like%' => ['gps_imei'],
'=' => ['license','status'],
]; ];
} }
@ -53,11 +54,14 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
return Vehicle::where($this->searchWhere) return Vehicle::where($this->searchWhere)->where('is_del',0)
->field(['id', 'license', 'gps_imei', 'gps_carid', 'status']) ->field(['id', 'license', 'gps_imei', 'gps_carid', 'status'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->each(function($item){
$item['status_name'] = $item->status_name;
})
->toArray(); ->toArray();
} }

View File

@ -41,12 +41,16 @@ class VehicleLogic extends BaseLogic
try { try {
//获取gps_car_id //获取gps_car_id
$car = (new GpsLogic()) -> info($params['gps_imei']); $car = (new GpsLogic()) -> info($params['gps_imei']);
if($car['code'] == 0) self::setError('添加失败'); if($car['code'] == 0){
self::setError('添加失败');
return false;
}
Vehicle::create([ Vehicle::create([
'license' => $params['license'], 'license' => $params['license'],
'gps_imei' => $params['gps_imei'], 'gps_imei' => $params['gps_imei'],
'gps_carid' => $car['data']['carId'], 'gps_carid' => $car['data']['carId'],
'status' => $params['status'] 'status' => $params['status'],
'is_del' => 0
]); ]);
Db::commit(); Db::commit();
@ -70,13 +74,23 @@ class VehicleLogic extends BaseLogic
{ {
Db::startTrans(); Db::startTrans();
try { try {
//获取数据
$data = Vehicle::where('id',$params['id'])->find();
if($data['gps_imei'] != $params['gps_imei']){
//获取gps_car_id
$car = (new GpsLogic()) -> info($params['gps_imei']);
if($car['code'] == 0){
self::setError('添加失败');
return false;
}
$data['gps_carid'] = $car['data']['carId'];
}
Vehicle::where('id', $params['id'])->update([ Vehicle::where('id', $params['id'])->update([
'license' => $params['license'], 'license' => $params['license'],
'gps_imei' => $params['gps_imei'], 'gps_imei' => $params['gps_imei'],
'gps_carid' => $params['gps_carid'], 'gps_carid' => $data['gps_carid'],
'status' => $params['status'] 'status' => $params['status']
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -96,7 +110,17 @@ class VehicleLogic extends BaseLogic
*/ */
public static function delete(array $params): bool public static function delete(array $params): bool
{ {
return Vehicle::destroy($params['id']); try {
$data = Vehicle::where('id', $params['id'])->find();
if($data['is_del'] !== 0){
return false;
}
Vehicle::where('id', $params['id'])->update(['is_del' => 1]);
return true;
}catch (\Exception $e){
self::setError($e->getMessage());
return false;
}
} }
@ -109,6 +133,8 @@ class VehicleLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
return Vehicle::findOrEmpty($params['id'])->toArray(); $data = Vehicle::findOrEmpty($params['id']);
$data['status_name'] = $data->status_name;
return $data->toArray();
} }
} }

View File

@ -12,4 +12,10 @@ class Vehicle extends BaseModel
{ {
return date('Y-m-d H:i:s',$value); return date('Y-m-d H:i:s',$value);
} }
public function getStatusNameAttr($value,$data): string
{
$status = [0=>'未出租',1=>'一级出租',2=>'二级出租'];
return $status[$data['status']];
}
} }