Compare commits
3 Commits
9d2dfdac95
...
1b855a2acd
| Author | SHA1 | Date |
|---|---|---|
|
|
1b855a2acd | |
|
|
1910bd568e | |
|
|
02f37d22c1 |
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?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,7 +2,6 @@
|
||||||
|
|
||||||
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,28 +25,47 @@ 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' => ''],
|
||||||
|
]],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($list as $item) {
|
if($list){
|
||||||
|
$this->createKeywords($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'));
|
$type = Keywords::create(Arr::except($item, 'list'));
|
||||||
|
}
|
||||||
$list = data_get($item, 'list');
|
$list = data_get($item, 'list');
|
||||||
if ($list) {
|
if($list){
|
||||||
$keywords = [];
|
$this->createKeywords($list, $type);
|
||||||
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,6 +19,8 @@ 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