diff --git a/MySQL_change.sql b/MySQL_change.sql index 34a9eb6..df1c207 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -124,3 +124,8 @@ ALTER TABLE `notices` ALTER TABLE `users` CHANGE COLUMN `verifier` `is_verify` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '是否是核销人员,1:是;0:否' AFTER `status`; + +# 15:51 2021/8/24 +ALTER TABLE `articles` + ADD COLUMN `type` TINYINT NOT NULL DEFAULT 0 COMMENT '0:普通列表显示;1:大图显示;' AFTER `content`, + ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT 255 COMMENT '排序,越小越靠前' AFTER `type`; diff --git a/app/AdminAgent/Controllers/ArticleController.php b/app/AdminAgent/Controllers/ArticleController.php new file mode 100644 index 0000000..4fdc45f --- /dev/null +++ b/app/AdminAgent/Controllers/ArticleController.php @@ -0,0 +1,111 @@ +model()->where('agent_id', Admin::user()->id) + ->orderBy('sort')->orderBy('id', 'desc'); + + $grid->column('id')->sortable(); + $grid->column('author'); + $grid->column('title'); + $grid->column('image')->image('', 60, 60); + $grid->column('sort')->editable()->width(120)->help('数字超小越靠前'); + $grid->column('type')->using(['普通列表', '大图显示']); + $grid->column('created_at'); + $grid->column('updated_at')->sortable(); + + $grid->filter(function (Grid\Filter $filter) { + $filter->panel(); + + $filter->equal('id')->width(2); + $filter->like('title')->width(3); + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new Article(), function (Show $show) { + //不允许查看非自己的数据 + if ($show->model()->agent_id != Admin::user()->id) { + Admin::exit('数据不存在'); + } + + $show->field('id'); + $show->field('author'); + $show->field('title'); + $show->field('image')->image('', 80, 80); + $show->field('content')->unescape(); + $show->field('sort'); + $show->field('type')->using(['普通列表', '大图显示']); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new Article(), function (Form $form) { + //不允许查看非自己的数据 + if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { + return $form->response()->error('数据不存在'); + } + + $form->display('id'); + $form->text('author')->default(Admin::user()->name); + $form->text('title')->required(); + $form->image('image')->required(); + $form->editor('content')->required(); + $form->text('sort')->default(255); + $form->select('type')->options(['普通列表', '大图显示'])->default(0)->required(); + })->saving(function (Form $form) { + //不允许修改非自己的数据 + if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { + return $form->response()->error('数据不存在'); + } + + //特殊字段处理 + $form->hidden(['agent_id']); + $form->agent_id = Admin::user()->id; + $form->sort = $form->sort ?? 255; + $form->type = $form->type ? 1 : 0; + + //不允许编辑的字段 + $form->ignore(['id', 'created_at', 'updated_at']); + })->deleting(function (Form $form) { + //不允许删除非自己的数据 + if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) { + return $form->response()->error('数据不存在'); + } + }); + } +} diff --git a/app/AdminAgent/Repositories/Article.php b/app/AdminAgent/Repositories/Article.php new file mode 100644 index 0000000..c46b1d6 --- /dev/null +++ b/app/AdminAgent/Repositories/Article.php @@ -0,0 +1,16 @@ +resource('notice/list', 'NoticeController'); $router->resource('agent_info', 'AgentInfoController'); $router->resource('supplier/list', 'SupplierController'); + $router->resource('article/list', 'ArticleController'); }); diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index 2843243..0b171de 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -16,25 +16,27 @@ class ArticleController extends Controller //文章列表 public function index() { - //TODO 此处仅为演示数据,调用数据需要再修改 - $list = Article::query() - ->where('agent_id', $this->agent_id) - ->select('id', 'image', 'title', 'updated_at') - ->orderBy('id', 'DESC') + $list = Article::where('agent_id', $this->agent_id) + ->select('id', 'image', 'title', 'type', 'updated_at') + ->orderBy('sort')->orderBy('id', 'DESC') ->simplePaginate()->toArray(); $new_data = []; $prefix = Storage::disk('public')->url(''); foreach ($list['data'] as $k => &$item) { $item['image'] = $prefix . $item['image']; - $new_key = floor($k / 4); - if ($k % 4 == 0) { - $new_data[$new_key] = [ - 'big' => $item, - 'children' => [] - ]; + + //type=1是大图 + if ($item['type'] == 1) { + $new_data[] = ['big' => $item]; + continue; + } + //普通列表 + $count = count($new_data); + if ($count) { + $new_data[$count - 1]['children'][] = $item; } else { - $new_data[$new_key]['children'][] = $item; + $new_data[] = ['children' => [$item]]; } } $list['data'] = $new_data; diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index 473a1fa..102c0a1 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -72,8 +72,8 @@ namespace Dcat\Admin { * @property Grid\Column|Collection rate * @property Grid\Column|Collection author * @property Grid\Column|Collection image - * @property Grid\Column|Collection pid * @property Grid\Column|Collection sort + * @property Grid\Column|Collection pid * @property Grid\Column|Collection template * @property Grid\Column|Collection end_at * @property Grid\Column|Collection start_at @@ -169,8 +169,8 @@ namespace Dcat\Admin { * @method Grid\Column|Collection rate(string $label = null) * @method Grid\Column|Collection author(string $label = null) * @method Grid\Column|Collection image(string $label = null) - * @method Grid\Column|Collection pid(string $label = null) * @method Grid\Column|Collection sort(string $label = null) + * @method Grid\Column|Collection pid(string $label = null) * @method Grid\Column|Collection template(string $label = null) * @method Grid\Column|Collection end_at(string $label = null) * @method Grid\Column|Collection start_at(string $label = null) @@ -271,8 +271,8 @@ namespace Dcat\Admin { * @property Show\Field|Collection rate * @property Show\Field|Collection author * @property Show\Field|Collection image - * @property Show\Field|Collection pid * @property Show\Field|Collection sort + * @property Show\Field|Collection pid * @property Show\Field|Collection template * @property Show\Field|Collection end_at * @property Show\Field|Collection start_at @@ -368,8 +368,8 @@ namespace Dcat\Admin { * @method Show\Field|Collection rate(string $label = null) * @method Show\Field|Collection author(string $label = null) * @method Show\Field|Collection image(string $label = null) - * @method Show\Field|Collection pid(string $label = null) * @method Show\Field|Collection sort(string $label = null) + * @method Show\Field|Collection pid(string $label = null) * @method Show\Field|Collection template(string $label = null) * @method Show\Field|Collection end_at(string $label = null) * @method Show\Field|Collection start_at(string $label = null) diff --git a/resources/lang/zh_CN/article.php b/resources/lang/zh_CN/article.php new file mode 100644 index 0000000..af5235b --- /dev/null +++ b/resources/lang/zh_CN/article.php @@ -0,0 +1,22 @@ + [ + 'Article' => '文章', + 'article' => '文章', + ], + 'fields' => [ + 'agent_id' => '代理商ID', + 'author' => '作者', + 'title' => '文章标题', + 'image' => '文章缩略图', + 'content' => '文章内容', + 'sort' => '排序', + 'type' => '显示方式', + ], + 'options' => [ + 'type' => [ + 0 => '普通列表', + 1 => '大图显示', + ], + ], +]; diff --git a/resources/lang/zh_CN/product.php b/resources/lang/zh_CN/product.php index 151e444..8d706cd 100644 --- a/resources/lang/zh_CN/product.php +++ b/resources/lang/zh_CN/product.php @@ -7,7 +7,7 @@ return [ 'fields' => [ 'category_id' => '产品分类ID', 'content' => '产品详情', - 'know' => '旅客须知', + 'know' => '旅游须知', 'original_price' => '原价', 'pictures' => '产品图片', 'picture' => '产品图片',