正在显示
3 个修改的文件
包含
66 行增加
和
0 行删除
| @@ -160,4 +160,57 @@ class ProductController extends BaseController | @@ -160,4 +160,57 @@ class ProductController extends BaseController | ||
| 160 | } | 160 | } |
| 161 | return $category_id; | 161 | return $category_id; |
| 162 | } | 162 | } |
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * @param Request $request | ||
| 166 | + * @author zbj | ||
| 167 | + * @date 2024/1/22 | ||
| 168 | + */ | ||
| 169 | + protected function searchProduct(Request $request) | ||
| 170 | + { | ||
| 171 | + $text = $request->input('text'); | ||
| 172 | + $limit = $request->input('limit'); | ||
| 173 | + $project_id = $request->input('project_id'); | ||
| 174 | + $project = ProjectServer::useProject($project_id); | ||
| 175 | + if (!$project) { | ||
| 176 | + $this->response('项目不存在', Code::SYSTEM_ERROR); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + //匹配产品 | ||
| 180 | + $products = Product::with('category') | ||
| 181 | + ->where("title", 'like', $text . '%') | ||
| 182 | + ->where("status", 1) | ||
| 183 | + ->orderBy("id", "DESC") | ||
| 184 | + ->limit($limit) | ||
| 185 | + ->select('title', 'thumb', 'id', 'route') | ||
| 186 | + ->get() | ||
| 187 | + ->toArray(); | ||
| 188 | + | ||
| 189 | + //对应分类 | ||
| 190 | + $categories = []; | ||
| 191 | + foreach ($products as &$product) { | ||
| 192 | + foreach ($product['category'] as $category) { | ||
| 193 | + $categories[$category['route']] = [ | ||
| 194 | + 'title' => $category['title'], | ||
| 195 | + 'route' => '/' . $category['route'] . '/', | ||
| 196 | + ]; | ||
| 197 | + } | ||
| 198 | + unset($product['id']); | ||
| 199 | + unset($product['category']); | ||
| 200 | + | ||
| 201 | + if(!empty($product['thumb']) && !empty($product['thumb']['url'])){ | ||
| 202 | + $product['thumb'] = getImageUrl($product['thumb']['url'],$project['storage_type'] ?? 0,$project['project_location']); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + $product['route'] = '/' . $product['route'] . '/'; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + $data = [ | ||
| 209 | + 'products' => $products, | ||
| 210 | + 'categories' => array_values($categories), | ||
| 211 | + ]; | ||
| 212 | + | ||
| 213 | + $this->response('success', Code::SUCCESS, $data); | ||
| 214 | + | ||
| 215 | + } | ||
| 163 | } | 216 | } |
| @@ -4,6 +4,7 @@ namespace App\Models\Product; | @@ -4,6 +4,7 @@ namespace App\Models\Product; | ||
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | use App\Models\Base; | 6 | use App\Models\Base; |
| 7 | +use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
| 7 | use Illuminate\Database\Eloquent\SoftDeletes; | 8 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| @@ -209,4 +210,15 @@ class Product extends Base | @@ -209,4 +210,15 @@ class Product extends Base | ||
| 209 | } | 210 | } |
| 210 | return $value; | 211 | return $value; |
| 211 | } | 212 | } |
| 213 | + | ||
| 214 | + /** | ||
| 215 | + * 多对多关联 | ||
| 216 | + * @return BelongsToMany | ||
| 217 | + * @author zbj | ||
| 218 | + * @date 2024/1/22 | ||
| 219 | + */ | ||
| 220 | + public function category(): BelongsToMany | ||
| 221 | + { | ||
| 222 | + return $this->belongsToMany(Category::class, 'gl_product_category_related', 'product_id', 'cate_id'); | ||
| 223 | + } | ||
| 212 | } | 224 | } |
| @@ -23,6 +23,7 @@ Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController | @@ -23,6 +23,7 @@ Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController | ||
| 23 | Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route'); | 23 | Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route'); |
| 24 | Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images'); | 24 | Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images'); |
| 25 | Route::any('saveProduct', [\App\Http\Controllers\Api\ProductController::class, 'saveProduct'])->name('api.saveProduct'); | 25 | Route::any('saveProduct', [\App\Http\Controllers\Api\ProductController::class, 'saveProduct'])->name('api.saveProduct'); |
| 26 | +Route::any('searchProduct', [\App\Http\Controllers\Api\ProductController::class, 'searchProduct'])->name('api.searchProduct'); | ||
| 26 | Route::post('inquiry_submit', [\App\Http\Controllers\Api\InquiryController::class, 'submit'])->name('api.inquiry_submit'); | 27 | Route::post('inquiry_submit', [\App\Http\Controllers\Api\InquiryController::class, 'submit'])->name('api.inquiry_submit'); |
| 27 | Route::any('getOptimizationReport', [\App\Http\Controllers\Api\OptimizationReportController::class, 'getOptimizationReport'])->name('api.getOptimizationReport'); | 28 | Route::any('getOptimizationReport', [\App\Http\Controllers\Api\OptimizationReportController::class, 'getOptimizationReport'])->name('api.getOptimizationReport'); |
| 28 | // 视频任务回调信息 | 29 | // 视频任务回调信息 |
-
请 注册 或 登录 后发表评论