详情
This commit is contained in:
parent
c81a282707
commit
4ff7c0c2c5
|
|
@ -215,7 +215,7 @@ class Cars extends Backend
|
|||
$insert = [];
|
||||
// dd($data);
|
||||
foreach ($data as $datum){
|
||||
if ($params[$datum['field_key']]){
|
||||
if (isset($params[$datum['field_key']])){
|
||||
$insert [] = [
|
||||
'car_id' => $car_id,
|
||||
'attribute_id' => $datum->id,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,21 @@ class Api extends Backend
|
|||
$tree = $this->buildTree($data);
|
||||
|
||||
$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();
|
||||
|
||||
|
|
@ -49,7 +63,7 @@ class Api extends Backend
|
|||
}
|
||||
|
||||
$out = [
|
||||
'brands' => $formattedTree,
|
||||
'brands' => $service,
|
||||
'extend' => $res
|
||||
];
|
||||
return $this->return_json($out);
|
||||
|
|
@ -67,7 +81,11 @@ class Api extends Backend
|
|||
$build->whereIn('id',$ids);
|
||||
}
|
||||
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();
|
||||
|
|
@ -105,7 +123,6 @@ class Api extends Backend
|
|||
'options' => $re['options'],
|
||||
'name' => $re['field_key'],
|
||||
'sort_order' => $re['sort_order'],
|
||||
|
||||
];
|
||||
$attr_field_array [] =$out;
|
||||
}
|
||||
|
|
@ -114,7 +131,7 @@ class Api extends Backend
|
|||
|
||||
foreach ($res as &$re){
|
||||
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
|
||||
{
|
||||
// 把属性定义按 id 映射为键,并附带 sort_order
|
||||
|
|
|
|||
|
|
@ -61,7 +61,16 @@
|
|||
</select>
|
||||
</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">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Is_active')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
|
|||
|
|
@ -76,6 +76,17 @@
|
|||
</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">
|
||||
<label class="control-label col-xs-12 col-sm-2">上牌时间:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ return [
|
|||
/**
|
||||
* CDN地址
|
||||
*/
|
||||
'cdnurl' => '',
|
||||
'cdnurl' => 'https://car.cherrybless.com',
|
||||
/**
|
||||
* 文件保存格式
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -36,6 +36,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
|
|||
class: 'autocontent',
|
||||
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: 'series.name', title: __('Series_id'), operate: false},
|
||||
{field: 'price', title: __('Price'), operate: 'BETWEEN'},
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user