云储存
This commit is contained in:
parent
a98d2c3371
commit
39715e1591
|
|
@ -9,7 +9,7 @@ use app\common\controller\Backend;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @icon fa fa-circle-o
|
* @icon fa fa-circle-o
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,6 +17,7 @@ class Api extends Backend
|
||||||
{
|
{
|
||||||
protected $noNeedRight = ['*'];
|
protected $noNeedRight = ['*'];
|
||||||
protected $noNeedLogin = ['*'];
|
protected $noNeedLogin = ['*'];
|
||||||
|
|
||||||
public function select()
|
public function select()
|
||||||
{
|
{
|
||||||
$series = Db::query("SELECT a.id,brand_id as pid, a.name FROM series a LEFT JOIN brands b ON a.brand_id = b.id;");
|
$series = Db::query("SELECT a.id,brand_id as pid, a.name FROM series a LEFT JOIN brands b ON a.brand_id = b.id;");
|
||||||
|
|
@ -25,7 +26,7 @@ class Api extends Backend
|
||||||
$this->series = $series;
|
$this->series = $series;
|
||||||
$this->brands = $brands;
|
$this->brands = $brands;
|
||||||
|
|
||||||
$data = array_merge($brands,$series);
|
$data = array_merge($brands, $series);
|
||||||
$tree = $this->buildTree($data);
|
$tree = $this->buildTree($data);
|
||||||
|
|
||||||
$formattedTree = $this->formatTree($tree);
|
$formattedTree = $this->formatTree($tree);
|
||||||
|
|
@ -35,12 +36,12 @@ class Api extends Backend
|
||||||
'value' => null
|
'value' => null
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
foreach ($formattedTree as $item){
|
foreach ($formattedTree as $item) {
|
||||||
$item['children'] = [
|
$item['children'] = [
|
||||||
[
|
[
|
||||||
'label' => $item['label'],
|
'label' => $item['label'],
|
||||||
'value' => 'b_'.$item['value']
|
'value' => 'b_' . $item['value']
|
||||||
],...$item['children']
|
], ...$item['children']
|
||||||
];
|
];
|
||||||
$service [] = $item;
|
$service [] = $item;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +49,7 @@ class Api extends Backend
|
||||||
$data = Attributes::order('sort_order')->select();
|
$data = Attributes::order('sort_order')->select();
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach ($data as $datum){
|
foreach ($data as $datum) {
|
||||||
$datum->options = json_decode($datum->options);
|
$datum->options = json_decode($datum->options);
|
||||||
$re = $datum->toArray();
|
$re = $datum->toArray();
|
||||||
$out = [
|
$out = [
|
||||||
|
|
@ -59,7 +60,7 @@ class Api extends Backend
|
||||||
'name' => $re['field_key'],
|
'name' => $re['field_key'],
|
||||||
'value' => $value_map[$re['id']] ?? null,
|
'value' => $value_map[$re['id']] ?? null,
|
||||||
];
|
];
|
||||||
$res [] =$out;
|
$res [] = $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = [
|
$out = [
|
||||||
|
|
@ -73,56 +74,56 @@ class Api extends Backend
|
||||||
public function car()
|
public function car()
|
||||||
{
|
{
|
||||||
$data = request()->post();
|
$data = request()->post();
|
||||||
$build = Cars::where('is_active',1);
|
$build = Cars::where('is_active', 1);
|
||||||
$attr = $data['attr'] ?? null;
|
$attr = $data['attr'] ?? null;
|
||||||
$brand = $data['brand'] ?? null;
|
$brand = $data['brand'] ?? null;
|
||||||
$type = $data['type'] ?? 1;
|
$type = $data['type'] ?? 1;
|
||||||
$price = $data['price'] ?? null;
|
$price = $data['price'] ?? null;
|
||||||
$sort = $data['sort'] ?? 1;
|
$sort = $data['sort'] ?? 1;
|
||||||
if ($attr){
|
if ($attr) {
|
||||||
$ids = $this->getAttrIds($attr);
|
$ids = $this->getAttrIds($attr);
|
||||||
$build->whereIn('id',$ids);
|
$build->whereIn('id', $ids);
|
||||||
}
|
}
|
||||||
if ($brand){
|
if ($brand) {
|
||||||
if (str_starts_with($brand,'b')){
|
if (str_starts_with($brand, 'b')) {
|
||||||
$build->whereIn('brand_id',str_replace('b_','',$brand));
|
$build->whereIn('brand_id', str_replace('b_', '', $brand));
|
||||||
}else{
|
} else {
|
||||||
$build->whereIn('series_id',$brand);
|
$build->whereIn('series_id', $brand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($price)){
|
if (!empty($price)) {
|
||||||
$prices = explode('-',$price);
|
$prices = explode('-', $price);
|
||||||
$build->whereBetween('price',$prices);
|
$build->whereBetween('price', $prices);
|
||||||
}
|
}
|
||||||
if (!empty($sort)){
|
if (!empty($sort)) {
|
||||||
$sort = explode('-',$sort);
|
$sort = explode('-', $sort);
|
||||||
$build->order($sort[0],$sort[1]);
|
$build->order($sort[0], $sort[1]);
|
||||||
}else{
|
} else {
|
||||||
$build->order('id','desc');
|
$build->order('id', 'desc');
|
||||||
}
|
}
|
||||||
$build->where('car_type',$type);
|
$build->where('car_type', $type);
|
||||||
|
|
||||||
$list = $build->paginate();
|
$list = $build->paginate();
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
$car_ids = [];
|
$car_ids = [];
|
||||||
|
|
||||||
foreach ($list->items() as $item){
|
foreach ($list->items() as $item) {
|
||||||
$out = $item->toArray();
|
$out = $item->toArray();
|
||||||
$car_ids [] = $item['id'];
|
$car_ids [] = $item['id'];
|
||||||
if ($out['cover_image']){
|
if ($out['cover_image']) {
|
||||||
$images = explode(',',$out['cover_image']);
|
$images = explode(',', $out['cover_image']);
|
||||||
$images = array_map(function($url) {
|
$images = array_map(function ($url) {
|
||||||
return cdnurl($url, true); // true 表示生成绝对路径
|
return cdnurl($url, true) . '?imageMogr2/format/webp'; // true 表示生成绝对路径
|
||||||
}, $images);
|
}, $images);
|
||||||
$out['cover_image'] = $images;
|
$out['cover_image'] = $images;
|
||||||
}
|
}
|
||||||
$res [] = $out;
|
$res [] = $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attr_value = AttributeValue::whereIn('car_id',$car_ids)->select();
|
$attr_value = AttributeValue::whereIn('car_id', $car_ids)->select();
|
||||||
$attr_array = [];
|
$attr_array = [];
|
||||||
foreach ($attr_value as $item){
|
foreach ($attr_value as $item) {
|
||||||
$attr_array [] = $item->toArray();
|
$attr_array [] = $item->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,8 +131,8 @@ class Api extends Backend
|
||||||
$attr_field = Attributes::order('sort_order')->select();
|
$attr_field = Attributes::order('sort_order')->select();
|
||||||
|
|
||||||
$attr_field_array = [];
|
$attr_field_array = [];
|
||||||
foreach ($attr_field as $datum){
|
foreach ($attr_field as $datum) {
|
||||||
$datum->options = json_decode($datum->options,true);
|
$datum->options = json_decode($datum->options, true);
|
||||||
$re = $datum->toArray();
|
$re = $datum->toArray();
|
||||||
$out = [
|
$out = [
|
||||||
'id' => $re['id'],
|
'id' => $re['id'],
|
||||||
|
|
@ -141,14 +142,14 @@ class Api extends Backend
|
||||||
'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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$car_attr_map = $this->mapAllCarAttributesSorted($attr_array,$attr_field_array);
|
$car_attr_map = $this->mapAllCarAttributesSorted($attr_array, $attr_field_array);
|
||||||
|
|
||||||
foreach ($res as &$re){
|
foreach ($res as &$re) {
|
||||||
if (isset($car_attr_map[$re['id']])){
|
if (isset($car_attr_map[$re['id']])) {
|
||||||
$re['attr'] = array_splice($car_attr_map[$re['id']],0,3);
|
$re['attr'] = array_splice($car_attr_map[$re['id']], 0, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,49 +167,64 @@ class Api extends Backend
|
||||||
{
|
{
|
||||||
$banner = config('site.banner_images'); // 获取轮播图数组
|
$banner = config('site.banner_images'); // 获取轮播图数组
|
||||||
$out = [];
|
$out = [];
|
||||||
foreach ($banner as $item){
|
foreach ($banner as $item) {
|
||||||
$out [] = cdnurl($item);
|
$out [] = cdnurl($item) . '?imageMogr2/format/webp';
|
||||||
}
|
}
|
||||||
return $this->return_json($out);
|
if (!empty(config('site.location'))){
|
||||||
|
$location = explode(',', config('site.location') ?? '');
|
||||||
|
}else{
|
||||||
|
$location = [];
|
||||||
|
}
|
||||||
|
$company = [
|
||||||
|
'name' => config('site.name'),
|
||||||
|
'address' => config('site.address') ?? '',
|
||||||
|
'latitude' => $location[0] ?? 31.854870, // 地图坐标
|
||||||
|
'longitude' => $location [1] ?? 106.746141,
|
||||||
|
'phone' => config('site.tel') ??''
|
||||||
|
];
|
||||||
|
$res = [
|
||||||
|
'banner' => $out,
|
||||||
|
'company' => $company
|
||||||
|
];
|
||||||
|
return $this->return_json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function carInfo()
|
public function carInfo()
|
||||||
{
|
{
|
||||||
$id = request()->get('id');
|
$id = request()->get('id');
|
||||||
$build = Cars::where('is_active',1)->where('id',$id)->with([
|
$build = Cars::where('is_active', 1)->where('id', $id)->with([
|
||||||
'brand','series','contact'=>function($q) {
|
'brand', 'series', 'contact' => function ($q) {
|
||||||
$q->field('id,username,mobile');
|
$q->field('id,username,mobile');
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$car = $build->select()[0];
|
$car = $build->select()[0];
|
||||||
if (!$car){
|
if (!$car) {
|
||||||
return $this->return_json([],'未找到信息',code: 0);
|
return $this->return_json([], '未找到信息', code: 0);
|
||||||
}
|
}
|
||||||
$car = $car->toArray();
|
$car = $car->toArray();
|
||||||
|
|
||||||
if($car['cover_image']){
|
if ($car['cover_image']) {
|
||||||
$images = explode(',',$car['cover_image']);
|
$images = explode(',', $car['cover_image']);
|
||||||
$images = array_map(function($url) {
|
$images = array_map(function ($url) {
|
||||||
return cdnurl($url, true); // true 表示生成绝对路径
|
return cdnurl($url, true) . '?imageMogr2/format/webp'; // true 表示生成绝对路径
|
||||||
}, $images);
|
}, $images);
|
||||||
$car['cover_image'] = $images;
|
$car['cover_image'] = $images;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$attr_value = AttributeValue::where('car_id', $car['id'])->select();
|
||||||
$attr_value = AttributeValue::where('car_id',$car['id'])->select();
|
|
||||||
$attr_array = [];
|
$attr_array = [];
|
||||||
foreach ($attr_value as $item){
|
foreach ($attr_value as $item) {
|
||||||
$attr_array [] = $item->toArray();
|
$attr_array [] = $item->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
$attr_field = Attributes::order('sort_order')->select();
|
$attr_field = Attributes::order('sort_order')->select();
|
||||||
|
|
||||||
$attr_field_array = [];
|
$attr_field_array = [];
|
||||||
foreach ($attr_field as $datum){
|
foreach ($attr_field as $datum) {
|
||||||
$datum->options = json_decode($datum->options,true);
|
$datum->options = json_decode($datum->options, true);
|
||||||
$re = $datum->toArray();
|
$re = $datum->toArray();
|
||||||
$out = [
|
$out = [
|
||||||
'id' => $re['id'],
|
'id' => $re['id'],
|
||||||
|
|
@ -218,10 +234,10 @@ class Api extends Backend
|
||||||
'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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$car_attr_map = $this->mapAllCarAttributesSorted($attr_array,$attr_field_array);
|
$car_attr_map = $this->mapAllCarAttributesSorted($attr_array, $attr_field_array);
|
||||||
// dd($car_attr_map);
|
// dd($car_attr_map);
|
||||||
$car['attr'] = $car_attr_map[$car['id']] ?? [];
|
$car['attr'] = $car_attr_map[$car['id']] ?? [];
|
||||||
return $this->return_json($car);
|
return $this->return_json($car);
|
||||||
|
|
@ -275,7 +291,7 @@ class Api extends Backend
|
||||||
// 对每个 car_id 下的属性按 sort_order 排序,并转成 label => key 格式
|
// 对每个 car_id 下的属性按 sort_order 排序,并转成 label => key 格式
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($cars as $carId => $items) {
|
foreach ($cars as $carId => $items) {
|
||||||
usort($items, function($a, $b) {
|
usort($items, function ($a, $b) {
|
||||||
return $a['sort_order'] <=> $b['sort_order'];
|
return $a['sort_order'] <=> $b['sort_order'];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -288,37 +304,36 @@ class Api extends Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function getAttrIds($attrs)
|
private function getAttrIds($attrs)
|
||||||
{
|
{
|
||||||
$attrDB = Attributes::field('id,field_key,input_type')->select();
|
$attrDB = Attributes::field('id,field_key,input_type')->select();
|
||||||
$attr_array = [];
|
$attr_array = [];
|
||||||
foreach ($attrDB as $item){
|
foreach ($attrDB as $item) {
|
||||||
$attr_array[] = $item->toArray();
|
$attr_array[] = $item->toArray();
|
||||||
}
|
}
|
||||||
$attr_map = array_column($attr_array,null,'field_key');
|
$attr_map = array_column($attr_array, null, 'field_key');
|
||||||
$car_id = [];
|
$car_id = [];
|
||||||
foreach ($attrs as $key=>$item) {
|
foreach ($attrs as $key => $item) {
|
||||||
|
|
||||||
if (isset($attr_map[$key])){
|
if (isset($attr_map[$key])) {
|
||||||
$field = $attr_map[$key];
|
$field = $attr_map[$key];
|
||||||
if ($field['input_type'] == 'checkbox'){
|
if ($field['input_type'] == 'checkbox') {
|
||||||
$ids = AttributeValue::where('attribute_id',$field['id'])
|
$ids = AttributeValue::where('attribute_id', $field['id'])
|
||||||
->whereIn('value',$item)->column('DISTINCT car_id');
|
->whereIn('value', $item)->column('DISTINCT car_id');
|
||||||
if ($car_id){
|
if ($car_id) {
|
||||||
$car_id = array_intersect($car_id,$ids);
|
$car_id = array_intersect($car_id, $ids);
|
||||||
}else{
|
} else {
|
||||||
$car_id = $ids;
|
$car_id = $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
}elseif ($field['input_type'] == 'range'){
|
} elseif ($field['input_type'] == 'range') {
|
||||||
$ids = AttributeValue::where('attribute_id',$field['id'])
|
$ids = AttributeValue::where('attribute_id', $field['id'])
|
||||||
->where('value','>=',$item['start'])
|
->where('value', '>=', $item['start'])
|
||||||
->where('value','<=',$item['end'])
|
->where('value', '<=', $item['end'])
|
||||||
->column('DISTINCT car_id');
|
->column('DISTINCT car_id');
|
||||||
if ($car_id){
|
if ($car_id) {
|
||||||
$car_id = array_intersect($car_id,$ids);
|
$car_id = array_intersect($car_id, $ids);
|
||||||
}else{
|
} else {
|
||||||
$car_id = $ids;
|
$car_id = $ids;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -330,5 +345,4 @@ class Api extends Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user