|
|
|
<?php
|
|
|
|
/**
|
|
|
|
+-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
* 管理端控制层: Category 控制类
|
|
|
|
+-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* PHP version 7
|
|
|
|
*
|
|
|
|
* @category App\Admin\Controllers
|
|
|
|
* @package App\Admin\Controllers
|
|
|
|
* @author Richer <yangzi1028@163.com>
|
|
|
|
* @date 2023年4月20日14:26:14
|
|
|
|
* @copyright 2020-2022 Richer (http://www.Richer.com/)
|
|
|
|
* @license http://www.Richer.com/ License
|
|
|
|
* @link http://www.Richer.com/
|
|
|
|
*/
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
|
|
|
|
use App\Admin\Forms\FirstCategoryForm;
|
|
|
|
use App\Admin\Grids\FirstCategoryGrid;
|
|
|
|
use App\Jobs\Category\CategoryLabelCreatedJob;
|
|
|
|
use App\Models\Category\Category;
|
|
|
|
use App\Models\Category\CategoryExample;
|
|
|
|
use App\Models\Category\CategoryLabel;
|
|
|
|
use App\Models\Category\CategoryLabelItem;
|
|
|
|
use App\Models\Label;
|
|
|
|
use App\Models\LabelItem;
|
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class FirstCategoriesController.
|
|
|
|
*
|
|
|
|
* @package App\Admin\Controllers
|
|
|
|
*/
|
|
|
|
class FirstCategoriesController extends BaseController
|
|
|
|
{
|
|
|
|
use FirstCategoryGrid, FirstCategoryForm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FirstCategoriesController constructor.
|
|
|
|
*
|
|
|
|
* @param Category $model 注入model
|
|
|
|
*/
|
|
|
|
public function __construct(Category $model)
|
|
|
|
{
|
|
|
|
// 资源显示的中名称
|
|
|
|
$this->title = $model::OBJ_NAME_ZH;
|
|
|
|
// 是否可查看
|
|
|
|
$this->can_view = false;
|
|
|
|
// 是否可新增
|
|
|
|
$this->can_create = true;
|
|
|
|
// 是否可编辑
|
|
|
|
$this->can_edit = true;
|
|
|
|
// 是否可删除
|
|
|
|
$this->can_delete = true;
|
|
|
|
// 是否开启下拉菜单
|
|
|
|
$this->dropdownActions = false;
|
|
|
|
|
|
|
|
// 执行父类构造方法
|
|
|
|
parent::__construct($model);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取 实例
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
*/
|
|
|
|
public function examples($id)
|
|
|
|
{
|
|
|
|
$list = null;
|
|
|
|
try {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
|
|
|
|
$list = $model->examples()->get();
|
|
|
|
return view('admin::category.examples', compact('id', 'list')) ;
|
|
|
|
|
|
|
|
} catch (ModelNotFoundException $e) {
|
|
|
|
return view('admin::category.examples', compact('id', 'list')) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加实例界面
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function examplePage($id)
|
|
|
|
{
|
|
|
|
$example_id = request('example_id', 0);
|
|
|
|
$example = null;
|
|
|
|
if ($example_id) {
|
|
|
|
$example = CategoryExample::find($example_id);
|
|
|
|
}
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
return view('admin::category.example', compact('id', 'example_id','example')) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加站点
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function addExample($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
|
|
|
|
$example_id = request('example_id', 0);
|
|
|
|
if ($example_id > 0) {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = CategoryExample::findOrFail($example_id);
|
|
|
|
$model->question = request('question');
|
|
|
|
$model->answer = request('answer');
|
|
|
|
$model->save();
|
|
|
|
} else {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
$model->examples()->create([
|
|
|
|
'question' => request('question'),
|
|
|
|
'answer' => request('answer'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' => __('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 线路更新站点的顺序
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function deleteExample($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
|
|
|
|
$result = $model->examples()->where('id', request('id'))->delete();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('操作失败。'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取 实例
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
*/
|
|
|
|
public function labels($id)
|
|
|
|
{
|
|
|
|
$list = null;
|
|
|
|
try {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
|
|
|
|
$list = $model->labels()->get();
|
|
|
|
return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
|
|
|
|
} catch (ModelNotFoundException $e) {
|
|
|
|
return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签 界面
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function labelPage($id)
|
|
|
|
{
|
|
|
|
$label_id = request('label_id', 0);
|
|
|
|
$label = null;
|
|
|
|
if ($label_id) {
|
|
|
|
$label = CategoryLabel::find($label_id);
|
|
|
|
}
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
return view('admin::category.label', compact('id', 'label_id','label')) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function addLabel($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$label_id = request('label_id', 0);
|
|
|
|
if ($label_id > 0) {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = CategoryLabel::findOrFail($label_id);
|
|
|
|
$model->name = request('name');
|
|
|
|
$model->can_multiple = request('can_multiple', 0);
|
|
|
|
$model->semantics = request('semantics');
|
|
|
|
$model->description = request('description');
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
$result = $model->labels()->create([
|
|
|
|
'name' => request('name'),
|
|
|
|
'semantics' => request('semantics'),
|
|
|
|
'description' => request('description'),
|
|
|
|
'can_multiple' => request('can_multiple', 0),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// 同步到远程服务器
|
|
|
|
// CategoryLabelCreatedJob::dispatch($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' => __('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除 标签
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function deleteLabel($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
|
|
|
|
$result = $model->labels()->where('id', request('id'))->delete();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('操作失败。'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签明细 界面
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function labelItemPage($id)
|
|
|
|
{
|
|
|
|
$label_item_id = request('label_item_id', 0);
|
|
|
|
$label_item = null;
|
|
|
|
if ($label_item_id) {
|
|
|
|
$label_item = CategoryExample::find($label_item_id);
|
|
|
|
}
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
return view('admin::category.label-item', compact('id', 'label_item_id','label_item')) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签明细
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function addLabelItem($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$label_id = request('label_item_id', 0);
|
|
|
|
if ($label_id > 0) {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = CategoryLabelItem::findOrFail($label_id);
|
|
|
|
$model->name = request('name');
|
|
|
|
$model->description = request('description');
|
|
|
|
$model->save();
|
|
|
|
} else {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = CategoryLabel::findOrFail($id);
|
|
|
|
$model->items()->create([
|
|
|
|
'name' => request('name'),
|
|
|
|
'description' => request('description'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' => __('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除 标签明细
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function deleteLabelItem($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$result = CategoryLabelItem::where('id', request('id'))->delete();
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 1,
|
|
|
|
'message' =>__('操作失败。'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * 获取 实例
|
|
|
|
// *
|
|
|
|
// * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|JsonResponse
|
|
|
|
// */
|
|
|
|
// public function labels($id)
|
|
|
|
// {
|
|
|
|
// $list = null;
|
|
|
|
// try {
|
|
|
|
// // 获取数据,如果没有获取到抛出异常
|
|
|
|
// $model = $this->model->findOrFail($id);
|
|
|
|
//
|
|
|
|
// $list = $model->labels()->get();
|
|
|
|
// return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
//
|
|
|
|
// } catch (ModelNotFoundException $e) {
|
|
|
|
// return view('admin::category.labels', compact('id', 'list')) ;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签 界面
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function childPage($id)
|
|
|
|
{
|
|
|
|
$label_id = request('id', 0);
|
|
|
|
$label = null;
|
|
|
|
if ($label_id) {
|
|
|
|
$label = CategoryLabel::find($label_id);
|
|
|
|
}
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
return view('admin::category.child', compact('id', 'label_id','label')) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加 标签
|
|
|
|
*
|
|
|
|
* @param integer $id 主键id
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function addChild($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$label_id = request('label_id', 0);
|
|
|
|
if ($label_id > 0) {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = CategoryLabel::findOrFail($label_id);
|
|
|
|
$model->name = request('name');
|
|
|
|
$model->can_multiple = request('can_multiple', 0);
|
|
|
|
$model->semantics = request('semantics');
|
|
|
|
$model->description = request('description');
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// 获取数据,如果没有获取到抛出异常
|
|
|
|
$model = $this->model->findOrFail($id);
|
|
|
|
$result = $model->labels()->create([
|
|
|
|
'name' => request('name'),
|
|
|
|
'semantics' => request('semantics'),
|
|
|
|
'description' => request('description'),
|
|
|
|
'can_multiple' => request('can_multiple', 0),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// 同步到远程服务器
|
|
|
|
// CategoryLabelCreatedJob::dispatch($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 0,
|
|
|
|
'status' => 1,
|
|
|
|
'message' => __('operate_succeeded'),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return response()->json(
|
|
|
|
[
|
|
|
|
'code' => 1,
|
|
|
|
'status' => 0,
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|