From f26f62dff2969fea13930061282c020cdea7282c Mon Sep 17 00:00:00 2001 From: liapples Date: Fri, 27 Aug 2021 16:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=A2=9E=E5=8A=A0=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MySQL_change.sql | 10 +++++++++- app/AdminAgent/Controllers/ArticleController.php | 6 ++++++ app/Http/Controllers/Api/ArticleController.php | 14 ++++++++++++++ app/Models/Article.php | 2 ++ resources/lang/zh_CN/article.php | 1 + 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/MySQL_change.sql b/MySQL_change.sql index 8b839fb..32611e9 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -117,7 +117,6 @@ COMMENT='瀑布流内嵌广告' COLLATE='utf8_general_ci' ENGINE=InnoDB; -################################################################# # 12:39 2021/8/24 ALTER TABLE `notices` ADD COLUMN `sort` SMALLINT NOT NULL DEFAULT '255' COMMENT '排序,越小越靠前' AFTER `content`; @@ -202,3 +201,12 @@ CREATE TABLE `agent_settings` ( COMMENT='代理商设置配置' COLLATE='utf8_general_ci' ENGINE=InnoDB; + +################################################################# +# 15:19 2021/8/27 +ALTER TABLE `messages` + ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `content`; +ALTER TABLE `notices` + ADD COLUMN `author` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '作者' COLLATE 'utf8_general_ci' AFTER `sort`; +ALTER TABLE `articles` + ADD COLUMN `agent_product_ids` TEXT NULL DEFAULT NULL COMMENT '绑定产品' AFTER `sort`; diff --git a/app/AdminAgent/Controllers/ArticleController.php b/app/AdminAgent/Controllers/ArticleController.php index 14e7631..2e9478d 100644 --- a/app/AdminAgent/Controllers/ArticleController.php +++ b/app/AdminAgent/Controllers/ArticleController.php @@ -2,7 +2,9 @@ namespace App\AdminAgent\Controllers; +use App\AdminAgent\Renderable\SelectAgentProduct; use App\AdminAgent\Repositories\Article; +use App\Models\AgentProduct; use Dcat\Admin\Admin; use Dcat\Admin\Form; use Dcat\Admin\Grid; @@ -87,6 +89,10 @@ class ArticleController extends AdminController $form->editor('content')->required(); $form->text('sort')->default(255); $form->select('type')->options(['普通列表', '大图显示'])->default(0)->required(); + $form->multipleSelectTable('agent_product_ids') + ->dialogWidth('80%;min-width:825px;') + ->from(new SelectAgentProduct) + ->model(AgentProduct::class); })->saving(function (Form $form) { //不允许修改非自己的数据 if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index 0b171de..d9ca220 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; +use App\Models\AgentProduct; use App\Models\Article; use Illuminate\Support\Facades\Storage; @@ -53,6 +54,19 @@ class ArticleController extends Controller return $this->error('文章不存在或已被删除'); } $article->image = Storage::disk('public')->url('') . $article->image; + + if ($article->agent_product_ids) { + $product = AgentProduct::list($this->agent_id) + ->whereIn('id', $article->agent_product_ids) + ->get(); + if (!$product->isEmpty()) { + $prefix = Storage::disk('public')->url(''); + foreach ($product as &$v) { + $v->pictures = array_map(fn($item) => $prefix . $item, $v->pictures); + } + } + } + $article->product = $product; return $this->success($article); } } diff --git a/app/Models/Article.php b/app/Models/Article.php index b078fd3..2795661 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; class Article extends BaseModel { use HasFactory, SoftDeletes; + + protected $casts = ['agent_product_ids' => 'json']; } diff --git a/resources/lang/zh_CN/article.php b/resources/lang/zh_CN/article.php index af5235b..cd19035 100644 --- a/resources/lang/zh_CN/article.php +++ b/resources/lang/zh_CN/article.php @@ -12,6 +12,7 @@ return [ 'content' => '文章内容', 'sort' => '排序', 'type' => '显示方式', + 'agent_product_ids' => '绑定产品', ], 'options' => [ 'type' => [