fixed categories
This commit is contained in:
parent
1031b2e89f
commit
d064095e92
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
|
||||
use Beike\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
use Beike\Repositories\CategoryRepo;
|
||||
use Beike\Admin\Services\CategoryService;
|
||||
use Beike\Admin\Http\Requests\CategoryRequest;
|
||||
use Beike\Admin\Http\Resources\CategoryResource;
|
||||
use Beike\Repositories\CategoryRepo;
|
||||
use Beike\Models\Category;
|
||||
use Beike\Admin\Services\CategoryService;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
|
@ -63,12 +64,11 @@ class CategoryController extends Controller
|
|||
$data = [
|
||||
'category' => $category ?? new Category(),
|
||||
'descriptions' => $descriptions ?? null,
|
||||
'categories' => \Beike\Admin\Repositories\CategoryRepo\CategoryRepo::flatten(locale()),
|
||||
'categories' => CategoryRepo::flatten(locale()),
|
||||
'_redirect' => $this->getRedirect(),
|
||||
];
|
||||
|
||||
return view('admin::pages.categories.form', $data);
|
||||
return view('admin::pages.categories.form-vue', $data);
|
||||
}
|
||||
|
||||
protected function save(Request $request, ?Category $category = null)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Admin\Http\Resources\ProductResource;
|
||||
use Beike\Admin\Repositories\CategoryRepo;
|
||||
use Beike\Models\Product;
|
||||
use Beike\Admin\Services\ProductService;
|
||||
use Beike\Repositories\LanguageRepo;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Illuminate\Http\Request;
|
||||
use Beike\Repositories\ProductRepo;
|
||||
use Beike\Repositories\CategoryRepo;
|
||||
use Beike\Repositories\LanguageRepo;
|
||||
use Beike\Admin\Services\ProductService;
|
||||
use Beike\Admin\Http\Resources\ProductResource;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Beike\Admin\Repositories;
|
||||
|
||||
use Beike\Models\Category;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CategoryRepo
|
||||
{
|
||||
public static function flatten(string $locale, $separator = ' > '): array
|
||||
{
|
||||
$sql = "SELECT cp.category_id AS id, TRIM(LOWER(GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR '{$separator}'))) AS name, c1.parent_id, c1.position";
|
||||
$sql .= " FROM category_paths cp";
|
||||
$sql .= " LEFT JOIN categories c1 ON (cp.category_id = c1.id)";
|
||||
$sql .= " LEFT JOIN categories c2 ON (cp.path_id = c2.id)";
|
||||
$sql .= " LEFT JOIN category_descriptions cd1 ON (cp.path_id = cd1.category_id)";
|
||||
$sql .= " WHERE cd1.locale = '" . $locale . "' GROUP BY cp.category_id ORDER BY name ASC";
|
||||
$results = DB::select($sql);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $categoryData
|
||||
*/
|
||||
public static function create($categoryData)
|
||||
{
|
||||
// Category::query()->create($categoryData);
|
||||
$category = new Category();
|
||||
$category->parent_id = 12;
|
||||
}
|
||||
|
||||
public static function update(Category $category)
|
||||
{
|
||||
$category->update([
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,12 +12,26 @@
|
|||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Category;
|
||||
use Beike\Shop\Http\Resources\CategoryList;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Beike\Shop\Http\Resources\CategoryList;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class CategoryRepo
|
||||
{
|
||||
public static function flatten(string $locale, $separator = ' > '): array
|
||||
{
|
||||
$sql = "SELECT cp.category_id AS id, TRIM(LOWER(GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR '{$separator}'))) AS name, c1.parent_id, c1.position";
|
||||
$sql .= " FROM category_paths cp";
|
||||
$sql .= " LEFT JOIN categories c1 ON (cp.category_id = c1.id)";
|
||||
$sql .= " LEFT JOIN categories c2 ON (cp.path_id = c2.id)";
|
||||
$sql .= " LEFT JOIN category_descriptions cd1 ON (cp.path_id = cd1.category_id)";
|
||||
$sql .= " WHERE cd1.locale = '" . $locale . "' GROUP BY cp.category_id ORDER BY name ASC";
|
||||
$results = DB::select($sql);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顶级及其子分类
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue