car interface
This commit is contained in:
parent
528580cfd1
commit
1a36052dae
@ -37,7 +37,8 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
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
|
||||
{
|
||||
return Vehicle::where($this->searchWhere)
|
||||
return Vehicle::where($this->searchWhere)->where('is_del',0)
|
||||
->field(['id', 'license', 'gps_imei', 'gps_carid', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function($item){
|
||||
$item['status_name'] = $item->status_name;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
@ -41,12 +41,16 @@ class VehicleLogic extends BaseLogic
|
||||
try {
|
||||
//获取gps_car_id
|
||||
$car = (new GpsLogic()) -> info($params['gps_imei']);
|
||||
if($car['code'] == 0) self::setError('添加失败');
|
||||
if($car['code'] == 0){
|
||||
self::setError('添加失败');
|
||||
return false;
|
||||
}
|
||||
Vehicle::create([
|
||||
'license' => $params['license'],
|
||||
'gps_imei' => $params['gps_imei'],
|
||||
'gps_carid' => $car['data']['carId'],
|
||||
'status' => $params['status']
|
||||
'status' => $params['status'],
|
||||
'is_del' => 0
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
@ -70,13 +74,23 @@ class VehicleLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
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([
|
||||
'license' => $params['license'],
|
||||
'gps_imei' => $params['gps_imei'],
|
||||
'gps_carid' => $params['gps_carid'],
|
||||
'gps_carid' => $data['gps_carid'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -96,7 +110,17 @@ class VehicleLogic extends BaseLogic
|
||||
*/
|
||||
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
|
||||
{
|
||||
return Vehicle::findOrEmpty($params['id'])->toArray();
|
||||
$data = Vehicle::findOrEmpty($params['id']);
|
||||
$data['status_name'] = $data->status_name;
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -12,4 +12,10 @@ class Vehicle extends BaseModel
|
||||
{
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
|
||||
public function getStatusNameAttr($value,$data): string
|
||||
{
|
||||
$status = [0=>'未出租',1=>'一级出租',2=>'二级出租'];
|
||||
return $status[$data['status']];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user