This commit is contained in:
unknown 2023-08-30 22:36:10 +08:00
parent b608079600
commit 636fb51c03
5 changed files with 15 additions and 96 deletions

View File

@ -1,18 +1,4 @@
<?php <?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\vehicle; namespace app\adminapi\controller\vehicle;
@ -75,20 +61,6 @@ class VehicleController extends BaseAdminController
} }
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function delete()
{
$params = (new VehicleValidate())->post()->goCheck('delete');
VehicleLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/** /**
* @notes 获取详情 * @notes 获取详情
* @return \think\response\Json * @return \think\response\Json

View File

@ -28,7 +28,7 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
{ {
return [ return [
'%like%' => ['gps_imei'], '%like%' => ['gps_imei'],
'=' => ['license','status','type','is_check'], '=' => ['license','status','type'],
]; ];
} }
@ -44,16 +44,14 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
return Vehicle::where($this->searchWhere)->where('is_del',1) return Vehicle::where($this->searchWhere)
->field(['id','company_id','license', 'gps_imei', 'status','type','is_check']) ->field(['id','license', 'gps_imei', 'status','type'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->each(function($item){ ->each(function($item){
$item['status_name'] = $item->status_name; $item['status_name'] = $item->status_name;
$item['type_name'] = $item->type_name; $item['type_name'] = $item->type_name;
$item['is_check_name'] = $item->is_check_name;
$item['company_name'] = Platform::where('id',$item['company_id'])->column('company_name')[0];
return $item; return $item;
}) })
->toArray(); ->toArray();
@ -68,7 +66,7 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function count(): int public function count(): int
{ {
return Vehicle::where($this->searchWhere)->where('is_del',1)->count(); return Vehicle::where($this->searchWhere)->count();
} }
} }

View File

@ -26,13 +26,10 @@ class VehicleLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
Vehicle::create([ Vehicle::create([
'company_id' => $params['company_id'],
'license' => $params['license'], 'license' => $params['license'],
'gps_imei' => $params['gps_imei'], 'gps_imei' => $params['gps_imei'],
'type' => 1, 'type' => 0,
'status' => 1, 'status' => 0,
'is_del' => 1,
'is_check' => 2,
]); ]);
Db::commit(); Db::commit();
return true; return true;
@ -56,12 +53,10 @@ class VehicleLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
Vehicle::where('id', $params['id'])->update([ Vehicle::where('id', $params['id'])->update([
'company_id' => $params['company_id'],
'license' => $params['license'], 'license' => $params['license'],
'gps_imei' => $params['gps_imei'], 'gps_imei' => $params['gps_imei'],
'type' => $params['type'], 'type' => $params['type'],
'status' => $params['status'], 'status' => $params['status'],
'is_check' => $params['is_check']
]); ]);
Db::commit(); Db::commit();
return true; return true;
@ -72,30 +67,6 @@ class VehicleLogic extends BaseLogic
} }
} }
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/17 09:23
*/
public static function delete(array $params): bool
{
try {
$data = Vehicle::where('id', $params['id'])->find();
if($data['is_del'] !== 1){
return false;
}
Vehicle::where('id', $params['id'])->update(['is_del' => 2]);
return true;
}catch (\Exception $e){
self::setError($e->getMessage());
return false;
}
}
/** /**
* @notes 获取详情 * @notes 获取详情
* @param $params * @param $params
@ -105,7 +76,7 @@ class VehicleLogic extends BaseLogic
*/ */
public static function detail($params): array public static function detail($params): array
{ {
$data = Vehicle::where('is_del',1)->findOrEmpty($params['id']); $data = Vehicle::findOrEmpty($params['id']);
return $data->toArray(); return $data->toArray();
} }
} }

View File

@ -31,12 +31,10 @@ class VehicleValidate extends BaseValidate
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
'company_id' => 'require|integer',
'license' => 'require|unique:vehicle', 'license' => 'require|unique:vehicle',
'gps_imei' => 'require|number|unique:vehicle', 'gps_imei' => 'require|number|unique:vehicle',
'type' => 'require|in:1,2', 'type' => 'require|in:0,1',
'status' => 'require|in:1,2', 'status' => 'require|in:0,1,2',
'is_check' => 'require|in:1,2',
]; ];
@ -46,12 +44,10 @@ class VehicleValidate extends BaseValidate
*/ */
protected $field = [ protected $field = [
'id' => 'id', 'id' => 'id',
'company_id' => '所属公司',
'license' => '车辆牌照', 'license' => '车辆牌照',
'gps_imei' => 'gps定位器设备标志', 'gps_imei' => 'gps定位器设备标志',
'type' => '车辆类型1平台自营 2社会车辆', 'type' => '车辆类型0平台自营 1社会车辆',
'status' => '车辆状态1未出租 2已出租', 'status' => '车辆状态0未出租 1签约中 2已出租',
'is_check' => '是否审核1未审核 2已审核',
]; ];
@ -63,7 +59,7 @@ class VehicleValidate extends BaseValidate
*/ */
public function sceneAdd() public function sceneAdd()
{ {
return $this->only(['company_id','license','gps_imei']); return $this->only(['license','gps_imei','type','status']);
} }
@ -75,19 +71,7 @@ class VehicleValidate extends BaseValidate
*/ */
public function sceneEdit() public function sceneEdit()
{ {
return $this->only(['id','company_id','license','gps_imei','status','type','is_check'])->remove('license', 'unique')->remove('gps_imei', 'unique'); return $this->only(['id','license','gps_imei','status','type'])->remove('license', 'unique')->remove('gps_imei', 'unique');
}
/**
* @notes 删除场景
* @return VehicleValidate
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function sceneDelete()
{
return $this->only(['id']);
} }

View File

@ -15,19 +15,13 @@ class Vehicle extends BaseModel
public function getStatusNameAttr($value,$data): string public function getStatusNameAttr($value,$data): string
{ {
$status = [1=>'未出租',2=>'已出租']; $status = [0=>'未出租',1=>'签约中',2=>'已出租'];
return $status[$data['status']]; return $status[$data['status']];
} }
public function getTypeNameAttr($value,$data): string public function getTypeNameAttr($value,$data): string
{ {
$type = [1=>'平台车辆',2=>'社会车辆']; $type = [0=>'平台车辆',1=>'社会车辆'];
return $type[$data['type']]; return $type[$data['type']];
} }
public function getIsCheckNameAttr($value,$data): string
{
$is_check = [1=>'未审核',2=>'已审核'];
return $is_check[$data['is_check']];
}
} }