From 4ff7c0c2c5f68d7aecee33287d5414fafbe796d2 Mon Sep 17 00:00:00 2001 From: hant Date: Sat, 12 Jul 2025 16:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Cars.php | 2 +- application/admin/controller/wechat/Api.php | 78 +++++++++++++++++++-- application/admin/view/cars/add.html | 11 ++- application/admin/view/cars/edit.html | 11 +++ application/extra/upload.php | 2 +- public/assets/js/backend/cars.js | 7 ++ 6 files changed, 103 insertions(+), 8 deletions(-) diff --git a/application/admin/controller/Cars.php b/application/admin/controller/Cars.php index f1becbb..e87c822 100644 --- a/application/admin/controller/Cars.php +++ b/application/admin/controller/Cars.php @@ -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, diff --git a/application/admin/controller/wechat/Api.php b/application/admin/controller/wechat/Api.php index ae8fb06..33e2f84 100644 --- a/application/admin/controller/wechat/Api.php +++ b/application/admin/controller/wechat/Api.php @@ -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 diff --git a/application/admin/view/cars/add.html b/application/admin/view/cars/add.html index ec21000..d5e332f 100644 --- a/application/admin/view/cars/add.html +++ b/application/admin/view/cars/add.html @@ -61,7 +61,16 @@ - +
+ +
+ +
+
diff --git a/application/admin/view/cars/edit.html b/application/admin/view/cars/edit.html index 725af2b..3dadb14 100644 --- a/application/admin/view/cars/edit.html +++ b/application/admin/view/cars/edit.html @@ -76,6 +76,17 @@
+
+ +
+ +
+
+
diff --git a/application/extra/upload.php b/application/extra/upload.php index 8a79610..d6b7333 100644 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -9,7 +9,7 @@ return [ /** * CDN地址 */ - 'cdnurl' => '', + 'cdnurl' => 'https://car.cherrybless.com', /** * 文件保存格式 */ diff --git a/public/assets/js/backend/cars.js b/public/assets/js/backend/cars.js index 763bf0d..39ff85b 100644 --- a/public/assets/js/backend/cars.js +++ b/public/assets/js/backend/cars.js @@ -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'},