Compare commits
No commits in common. "1b855a2acd3512ce24a6cd34e325693187b3d07c" and "9d2dfdac95590ac59670815c3a2af97b8ad8920f" have entirely different histories.
1b855a2acd
...
9d2dfdac95
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Peidikeji\Keywords\Models\Keywords;
|
|
||||||
use Peidikeji\Keywords\Http\Resources\KeywordResource;
|
|
||||||
|
|
||||||
class KeywordController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 农作物
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function crops(Request $request){
|
|
||||||
$list = Keywords::filter($request->all())->where('type_key', 'like', 'crops-cate-%')->get();
|
|
||||||
|
|
||||||
return $this->json(KeywordResource::collection($list));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 农作物产业分类
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function cropsCate(Request $request){
|
|
||||||
$cropsId = $request->input('crops_id', 0);
|
|
||||||
$crops = null;
|
|
||||||
if($cropsId){
|
|
||||||
$crops = Keywords::find($cropsId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = Keywords::filter($request->all())->where('type_key', 'crops-category');
|
|
||||||
|
|
||||||
if($crops){
|
|
||||||
$query->where('id', $crops->parent_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$list = $query->get();
|
|
||||||
return $this->json(KeywordResource::collection($list));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\AdminUser;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
|
||||||
|
|
@ -25,47 +25,28 @@ class KeywordsTableSeeder extends Seeder
|
||||||
Admin::extension()->enable($name);
|
Admin::extension()->enable($name);
|
||||||
Keywords::truncate();
|
Keywords::truncate();
|
||||||
$list = [
|
$list = [
|
||||||
['key' => 'crops-category', 'name' => '农作物产业分类', 'value' => '', 'list' => [
|
|
||||||
['key' => 'crops-cate-nongye', 'name' => '农业', 'type_key'=>'crops-category', 'value' => '', 'list' =>[
|
|
||||||
['key' => 'crops-shuidao', 'name' => '水稻', 'type_key'=>'crops-cate-nongye', 'value' => ''],
|
|
||||||
['key' => 'crops-papagan', 'name' => '耙耙柑', 'type_key'=>'crops-cate-nongye', 'value' => ''],
|
|
||||||
['key' => 'crops-aiyuan', 'name' => '爱媛', 'type_key'=>'crops-cate-nongye', 'value' => ''],
|
|
||||||
['key' => 'crops-buzhihuo', 'name' => '不知火', 'type_key'=>'crops-cate-nongye', 'value' => '']
|
|
||||||
]],
|
|
||||||
['key' => 'crops-cate-yuye', 'name' => '渔业', 'type_key'=>'crops-category', 'value' => '', 'list' =>[
|
|
||||||
['key' => 'crops-huocaoyu', 'name' => '活草鱼', 'type_key'=>'crops-cate-yuye', 'value' => ''],
|
|
||||||
['key' => 'crops-daoxia', 'name' => '稻虾', 'type_key'=>'crops-cate-yuye', 'value' => ''],
|
|
||||||
['key' => 'crops-wuyu', 'name' => '乌鱼', 'type_key'=>'crops-cate-yuye', 'value' => ''],
|
|
||||||
['key' => 'crops-luyu', 'name' => '鲈鱼', 'type_key'=>'crops-cate-yuye', 'value' => ''],
|
|
||||||
]],
|
|
||||||
['key' => 'crops-cate-xumuye', 'name' => '畜牧业', 'type_key'=>'crops-category', 'value' => '', 'list' => [
|
|
||||||
['key' => 'crops-shengzhu', 'name' => '生猪', 'type_key'=>'crops-cate-xumuye', 'value' => ''],
|
|
||||||
]],
|
|
||||||
['key' => 'crops-cate-lingye', 'name' => '林业', 'type_key'=>'crops-category', 'value' => ''],
|
|
||||||
]],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if($list){
|
foreach ($list as $item) {
|
||||||
$this->createKeywords($list);
|
$type = Keywords::create(Arr::except($item, 'list'));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createKeywords($keywords, $parentType = null){
|
|
||||||
foreach ($keywords as $item) {
|
|
||||||
if($parentType){
|
|
||||||
$type = Keywords::create([
|
|
||||||
'name' => $item['name'],
|
|
||||||
'key' => $item['key'] ?? $parentType->key.($parentType + 1),
|
|
||||||
'type_key' => $parentType->key,
|
|
||||||
'level' => ($parentType->level ?? 1) + 1,
|
|
||||||
'parent_id' => $parentType->id,
|
|
||||||
]);
|
|
||||||
}else{
|
|
||||||
$type = Keywords::create(Arr::except($item, 'list'));
|
|
||||||
}
|
|
||||||
$list = data_get($item, 'list');
|
$list = data_get($item, 'list');
|
||||||
if($list){
|
if ($list) {
|
||||||
$this->createKeywords($list, $type);
|
$keywords = [];
|
||||||
|
foreach ($list as $index => $name) {
|
||||||
|
$template = [
|
||||||
|
'key' => $type->key.($index + 1),
|
||||||
|
'type_key' => $type->key,
|
||||||
|
'level' => $type->level + 1,
|
||||||
|
];
|
||||||
|
if (is_array($name)) {
|
||||||
|
$template = array_merge($template, $name);
|
||||||
|
} else {
|
||||||
|
$template['name'] = $name;
|
||||||
|
}
|
||||||
|
array_push($keywords, $template);
|
||||||
|
}
|
||||||
|
$type->children()->createMany($keywords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ use Illuminate\Support\Facades\Route;
|
||||||
Route::post('auth/login', [AuthController::class, 'login']);
|
Route::post('auth/login', [AuthController::class, 'login']);
|
||||||
|
|
||||||
Route::group(['middleware' => 'auth:sanctum'], function () {
|
Route::group(['middleware' => 'auth:sanctum'], function () {
|
||||||
Route::get('keywords-crops', [KeywordController::class, 'crops']);
|
|
||||||
Route::get('keywords-crops-cate', [KeywordController::class, 'cropsCate']);
|
|
||||||
|
|
||||||
Route::prefix('users')->group(function () {
|
Route::prefix('users')->group(function () {
|
||||||
Route::put('reset-password', [UserController::class, 'resetPwd']);
|
Route::put('reset-password', [UserController::class, 'resetPwd']);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue