This commit is contained in:
hant 2025-07-12 16:58:44 +08:00
parent c81a282707
commit 4ff7c0c2c5
6 changed files with 103 additions and 8 deletions

View File

@ -215,7 +215,7 @@ class Cars extends Backend
$insert = []; $insert = [];
// dd($data); // dd($data);
foreach ($data as $datum){ foreach ($data as $datum){
if ($params[$datum['field_key']]){ if (isset($params[$datum['field_key']])){
$insert [] = [ $insert [] = [
'car_id' => $car_id, 'car_id' => $car_id,
'attribute_id' => $datum->id, 'attribute_id' => $datum->id,

View File

@ -29,7 +29,21 @@ class Api extends Backend
$tree = $this->buildTree($data); $tree = $this->buildTree($data);
$formattedTree = $this->formatTree($tree); $formattedTree = $this->formatTree($tree);
$service = [
[
'label' => '全部',
'value' => null
]
];
foreach ($formattedTree as $item){
$item['children'] = [
[
'label' => $item['label'],
'value' => 'b_'.$item['value']
],...$item['children']
];
$service [] = $item;
}
$data = Attributes::order('sort_order')->select(); $data = Attributes::order('sort_order')->select();
@ -49,7 +63,7 @@ class Api extends Backend
} }
$out = [ $out = [
'brands' => $formattedTree, 'brands' => $service,
'extend' => $res 'extend' => $res
]; ];
return $this->return_json($out); return $this->return_json($out);
@ -67,7 +81,11 @@ class Api extends Backend
$build->whereIn('id',$ids); $build->whereIn('id',$ids);
} }
if ($brand){ if ($brand){
$build->whereIn('series_id',$brand); if (str_starts_with($brand,'b')){
$build->whereIn('brand_id',str_replace('b_','',$brand));
}else{
$build->whereIn('series_id',$brand);
}
} }
$list = $build->paginate(); $list = $build->paginate();
@ -105,7 +123,6 @@ class Api extends Backend
'options' => $re['options'], 'options' => $re['options'],
'name' => $re['field_key'], 'name' => $re['field_key'],
'sort_order' => $re['sort_order'], 'sort_order' => $re['sort_order'],
]; ];
$attr_field_array [] =$out; $attr_field_array [] =$out;
} }
@ -114,7 +131,7 @@ class Api extends Backend
foreach ($res as &$re){ foreach ($res as &$re){
if (isset($car_attr_map[$re['id']])){ if (isset($car_attr_map[$re['id']])){
$re['attr'] = $car_attr_map[$re['id']]; $re['attr'] = array_splice($car_attr_map[$re['id']],0,3);
} }
} }
@ -128,6 +145,57 @@ class Api extends Backend
} }
public function carInfo()
{
$id = request()->get('id');
$build = Cars::where('is_active',1)->where('id',$id)->with([
'brand','series'
]);
$car = $build->select()[0];
if (!$car){
return $this->return_json([],'未找到信息',code: 0);
}
$car = $car->toArray();
$images = explode(',',$car['cover_image']);
$images = array_map(function($url) {
return cdnurl($url, true); // true 表示生成绝对路径
}, $images);
$car['cover_image'] = $images;
$attr_value = AttributeValue::where('car_id',$car['id'])->select();
$attr_array = [];
foreach ($attr_value as $item){
$attr_array [] = $item->toArray();
}
$attr_field = Attributes::order('sort_order')->select();
$attr_field_array = [];
foreach ($attr_field as $datum){
$datum->options = json_decode($datum->options,true);
$re = $datum->toArray();
$out = [
'id' => $re['id'],
'label' => $re['name'],
'type' => $re['input_type'],
'options' => $re['options'],
'name' => $re['field_key'],
'sort_order' => $re['sort_order'],
];
$attr_field_array [] =$out;
}
$car_attr_map = $this->mapAllCarAttributesSorted($attr_array,$attr_field_array);
$car['attr'] = $car_attr_map[$car['id']];
return $this->return_json($car);
}
function mapAllCarAttributesSorted(array $carAttributes, array $attributeDefs): array function mapAllCarAttributesSorted(array $carAttributes, array $attributeDefs): array
{ {
// 把属性定义按 id 映射为键,并附带 sort_order // 把属性定义按 id 映射为键,并附带 sort_order

View File

@ -61,7 +61,16 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">类型:</label>
<div class="col-xs-12 col-sm-8">
<select name="row[car_type]" class="form-control selectpicker">
<option value="1">新车</option>
<option value="2">二手车</option>
<option value="3">租车</option>
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_active')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Is_active')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">

View File

@ -76,6 +76,17 @@
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">类型:</label>
<div class="col-xs-12 col-sm-8">
<select name="row[car_type]" class="form-control selectpicker">
<option {if 1 == $row.car_type} selected {/if} value="1">新车</option>
<option {if 2 == $row.car_type} selected {/if} value="2">二手车</option>
<option {if 3 == $row.car_type} selected {/if} value="3">租车</option>
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">上牌时间:</label> <label class="control-label col-xs-12 col-sm-2">上牌时间:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">

View File

@ -9,7 +9,7 @@ return [
/** /**
* CDN地址 * CDN地址
*/ */
'cdnurl' => '', 'cdnurl' => 'https://car.cherrybless.com',
/** /**
* 文件保存格式 * 文件保存格式
*/ */

View File

@ -36,6 +36,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
class: 'autocontent', class: 'autocontent',
formatter: Table.api.formatter.content formatter: Table.api.formatter.content
}, },
{field: 'car_type', title: '类型',
searchList: {
"1": '新车',
"2": '二手车',
"3": '租车',
},
formatter: Table.api.formatter.status},
{field: 'brand.name', title: __('Brand_id'), operate: false}, {field: 'brand.name', title: __('Brand_id'), operate: false},
{field: 'series.name', title: __('Series_id'), operate: false}, {field: 'series.name', title: __('Series_id'), operate: false},
{field: 'price', title: __('Price'), operate: 'BETWEEN'}, {field: 'price', title: __('Price'), operate: 'BETWEEN'},