diff --git a/app/AdminAgent/Controllers/SpecialController.php b/app/AdminAgent/Controllers/SpecialController.php
new file mode 100644
index 0000000..d011fc6
--- /dev/null
+++ b/app/AdminAgent/Controllers/SpecialController.php
@@ -0,0 +1,133 @@
+disableFilterButton();
+
+ $grid->model()->where('agent_id', Admin::user()->id);
+
+ $grid->column('id')->sortable();
+ $grid->column('picture_ad')->image('', 60, 60);
+ $grid->column('agent_product_id', '专题产品')
+ ->display('查看')
+ ->modal(function ($modal) use ($grid) {
+ $data = AgentProduct::with('product:id,title,pictures')
+ ->whereIn('id', $this->agent_product_id)
+ ->get(['id', 'product_id', 'sale', 'stock']);
+ $result = [];
+ $prefix = Storage::disk('public')->url('');
+ foreach ($data as $k => $v) {
+ $result[] = [
+ $v->id,
+ $v->product->title,
+ '
',
+ $v->sale,
+ $v->stock,
+ ];
+ }
+ return Table::make(['产品ID', '标题', '图片', '销量', '库存'], $result);
+ });
+ $grid->column('sort');
+ $grid->column('created_at');
+ $grid->column('updated_at')->sortable();
+
+ $grid->filter(function (Grid\Filter $filter) {
+ $filter->panel();
+
+ $filter->equal('id');
+ });
+ });
+ }
+
+ /**
+ * Make a show builder.
+ *
+ * @param mixed $id
+ *
+ * @return Show
+ */
+ protected function detail($id)
+ {
+ return Show::make($id, new Special(), function (Show $show) {
+ $show->field('id');
+ $show->field('picture_ad')->image('', 80, 80);
+ $show->field('picture')->image('', 80, 80);
+ $show->field('agent_product_id', '产品')
+ ->unescape()
+ ->as(function ($v) {
+ $data = AgentProduct::with('product:id,title')
+ ->whereIn('id', $v)
+ ->orderBy('id')->get(['id', 'product_id']);
+ return join("
", $data->map(fn($v) => $v->product->title)->toArray());
+ });
+ $show->field('sort');
+ $show->field('created_at');
+ $show->field('updated_at');
+ });
+ }
+
+ /**
+ * Make a form builder.
+ *
+ * @return Form
+ */
+ protected function form()
+ {
+ return Form::make(new Special(), function (Form $form) {
+ $form->display('id');
+ $form->image('picture_ad')
+ ->required()->removable(false)->uniqueName()
+ ->help('图片大小:750*230');
+ $form->multipleImage('picture')
+ ->required()->removable(false)->uniqueName()
+ ->help('图片大小:750*490');
+ $form->multipleSelectTable('agent_product_id')
+ ->title('选择在售产品')->required()
+ ->dialogWidth('80%;min-width:825px;')
+ ->from(SelectAgentProduct::make())
+ ->options(function ($v) {
+ if (!$v) return [];
+ $agent_product = AgentProduct::with('product:id,title')
+ ->select(['id', 'product_id'])
+ ->whereIn('id', $v)
+ ->orderBy('id')->get();
+ $result = [];
+ foreach ($agent_product as $v) {
+ $result[$v->id] = $v->product->title ?? '';
+ }
+ return $result;
+ })
+ ->pluck('product.title')
+ ->value(join(',', $form->model()->agent_product_id ?? []));
+ $form->text('sort')->default(255);
+ })->saving(function (Form $form) {
+ //处理特殊字段
+ $form->hidden(['agent_id', 'created_at', 'updated_at']);
+ $form->agent_id = Admin::user()->id;
+
+ //不允许编辑的字段
+ $form->ignore(['id', 'agent_id', 'created_at', 'updated_at']);
+ });
+ }
+}
diff --git a/app/AdminAgent/Renderable/SelectAgentProduct.php b/app/AdminAgent/Renderable/SelectAgentProduct.php
index 0adca98..b4d480d 100644
--- a/app/AdminAgent/Renderable/SelectAgentProduct.php
+++ b/app/AdminAgent/Renderable/SelectAgentProduct.php
@@ -24,7 +24,8 @@ class SelectAgentProduct extends LazyRenderable
$grid->disableBatchDelete();
$grid->disableBatchActions();
- $grid->model()->where(['agent_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
+ $grid->model()->where('stock', '>', 0)
+ ->where(['agent_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
$grid->quickSearch(['product.title', 'product.supplier.name'])->placeholder('搜索产品名称、供应商');
$grid->column('id');
diff --git a/app/AdminAgent/Repositories/Special.php b/app/AdminAgent/Repositories/Special.php
new file mode 100644
index 0000000..7f60576
--- /dev/null
+++ b/app/AdminAgent/Repositories/Special.php
@@ -0,0 +1,16 @@
+resource('user/list', 'UserController');
$router->resource('order/list', 'OrderController');
$router->resource('slide/list', 'SlideController');
+ $router->resource('special/list', 'SpecialController');
});
diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php
index 19727d6..ec47bb7 100644
--- a/app/Http/Controllers/Api/IndexController.php
+++ b/app/Http/Controllers/Api/IndexController.php
@@ -8,6 +8,7 @@ use App\Models\AgentProduct;
use App\Models\Slide;
use App\Models\Special;
use App\Models\UserChannel;
+use Illuminate\Support\Facades\Storage;
/**
* 小程序首页
@@ -61,9 +62,14 @@ class IndexController extends Controller
# 专题列表
$special = Special::query()
->where('agent_id', $this->agent_id)
- ->orderBy('sort')
- ->orderBy('id')
- ->get(['id', 'picture_ad']);
+ ->orderBy('sort')->orderBy('id')
+ ->limit(6)->get(['id', 'picture_ad']);
+ if (!$special->isEmpty()) {
+ $prefix = Storage::disk('public')->url('');
+ foreach ($special as $k=>&$v) {
+ $v->picture_ad = $prefix . $v->picture_ad;
+ }
+ }
# 人气爆款
$hots = AgentProduct::query()
diff --git a/app/Http/Controllers/Api/SpecialController.php b/app/Http/Controllers/Api/SpecialController.php
index e890266..681f4b2 100644
--- a/app/Http/Controllers/Api/SpecialController.php
+++ b/app/Http/Controllers/Api/SpecialController.php
@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\AgentProduct;
use App\Models\Special;
-use Illuminate\Http\Request;
class SpecialController extends Controller
{
@@ -16,10 +15,9 @@ class SpecialController extends Controller
->select(['id', 'picture', 'picture_ad', 'updated_at', 'agent_product_id'])
->find($id);
- $detail->product = AgentProduct::query()
+ $detail->product = AgentProduct::list()
+ ->where('agent_id', $this->agent_id)
->whereIn('id', $detail->agent_product_id)
- ->select('id', 'sale', 'product_id', 'price', 'original_price')
- ->with('product:id,title,pictures')
->limit(6)->get();
unset($detail->agent_product_id);
diff --git a/app/Models/Special.php b/app/Models/Special.php
index 24060f0..c9be5d1 100644
--- a/app/Models/Special.php
+++ b/app/Models/Special.php
@@ -8,32 +8,26 @@ class Special extends BaseModel
{
use HasFactory;
+ protected $casts = ['picture' => 'array'];
+
//轮播图片
public function getPictureAttribute($value): array
{
$value = json_decode($value, true);
- if (is_array($value)) {
- foreach ($value as &$v) {
- $v = $v ? $this->host . $v : '';
- }
- }
return $value;
}
- //首页广告图
- public function getPictureAdAttribute($value): string
- {
- return $value ? $this->host . $value : '';
- }
-
//代理商产品ID
public function getAgentProductIdAttribute($value)
{
return explode(',', $value);
}
- public function agentProduct()
+ //代理商产品ID
+ public function setAgentProductIdAttribute($value)
{
- return $this->belongsTo(AgentProduct::class);
+ if (is_array($value)) {
+ $this->attributes['agent_product_id'] = join(',', $value);
+ }
}
}
diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php
index e15c178..9bdf614 100644
--- a/dcat_admin_ide_helper.php
+++ b/dcat_admin_ide_helper.php
@@ -11,20 +11,16 @@ namespace Dcat\Admin {
use Illuminate\Support\Collection;
/**
- * @property Grid\Column|Collection id
- * @property Grid\Column|Collection agent_id
- * @property Grid\Column|Collection picture
- * @property Grid\Column|Collection name
- * @property Grid\Column|Collection tag
- * @property Grid\Column|Collection desc
- * @property Grid\Column|Collection created_at
- * @property Grid\Column|Collection updated_at
* @property Grid\Column|Collection product_id
* @property Grid\Column|Collection know
* @property Grid\Column|Collection content
+ * @property Grid\Column|Collection id
+ * @property Grid\Column|Collection name
* @property Grid\Column|Collection type
* @property Grid\Column|Collection version
* @property Grid\Column|Collection detail
+ * @property Grid\Column|Collection created_at
+ * @property Grid\Column|Collection updated_at
* @property Grid\Column|Collection is_enabled
* @property Grid\Column|Collection parent_id
* @property Grid\Column|Collection order
@@ -43,6 +39,10 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection password
* @property Grid\Column|Collection avatar
* @property Grid\Column|Collection remember_token
+ * @property Grid\Column|Collection agent_id
+ * @property Grid\Column|Collection picture
+ * @property Grid\Column|Collection tag
+ * @property Grid\Column|Collection desc
* @property Grid\Column|Collection about
* @property Grid\Column|Collection reg_protocol
* @property Grid\Column|Collection buy_protocol
@@ -93,6 +93,7 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection paid_money
* @property Grid\Column|Collection paid_at
* @property Grid\Column|Collection refund_info
+ * @property Grid\Column|Collection verify_code
* @property Grid\Column|Collection email
* @property Grid\Column|Collection token
* @property Grid\Column|Collection pictures
@@ -106,20 +107,16 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection openid
* @property Grid\Column|Collection unionid
*
- * @method Grid\Column|Collection id(string $label = null)
- * @method Grid\Column|Collection agent_id(string $label = null)
- * @method Grid\Column|Collection picture(string $label = null)
- * @method Grid\Column|Collection name(string $label = null)
- * @method Grid\Column|Collection tag(string $label = null)
- * @method Grid\Column|Collection desc(string $label = null)
- * @method Grid\Column|Collection created_at(string $label = null)
- * @method Grid\Column|Collection updated_at(string $label = null)
* @method Grid\Column|Collection product_id(string $label = null)
* @method Grid\Column|Collection know(string $label = null)
* @method Grid\Column|Collection content(string $label = null)
+ * @method Grid\Column|Collection id(string $label = null)
+ * @method Grid\Column|Collection name(string $label = null)
* @method Grid\Column|Collection type(string $label = null)
* @method Grid\Column|Collection version(string $label = null)
* @method Grid\Column|Collection detail(string $label = null)
+ * @method Grid\Column|Collection created_at(string $label = null)
+ * @method Grid\Column|Collection updated_at(string $label = null)
* @method Grid\Column|Collection is_enabled(string $label = null)
* @method Grid\Column|Collection parent_id(string $label = null)
* @method Grid\Column|Collection order(string $label = null)
@@ -138,6 +135,10 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection password(string $label = null)
* @method Grid\Column|Collection avatar(string $label = null)
* @method Grid\Column|Collection remember_token(string $label = null)
+ * @method Grid\Column|Collection agent_id(string $label = null)
+ * @method Grid\Column|Collection picture(string $label = null)
+ * @method Grid\Column|Collection tag(string $label = null)
+ * @method Grid\Column|Collection desc(string $label = null)
* @method Grid\Column|Collection about(string $label = null)
* @method Grid\Column|Collection reg_protocol(string $label = null)
* @method Grid\Column|Collection buy_protocol(string $label = null)
@@ -188,6 +189,7 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection paid_money(string $label = null)
* @method Grid\Column|Collection paid_at(string $label = null)
* @method Grid\Column|Collection refund_info(string $label = null)
+ * @method Grid\Column|Collection verify_code(string $label = null)
* @method Grid\Column|Collection email(string $label = null)
* @method Grid\Column|Collection token(string $label = null)
* @method Grid\Column|Collection pictures(string $label = null)
@@ -206,20 +208,16 @@ namespace Dcat\Admin {
class MiniGrid extends Grid {}
/**
- * @property Show\Field|Collection id
- * @property Show\Field|Collection agent_id
- * @property Show\Field|Collection picture
- * @property Show\Field|Collection name
- * @property Show\Field|Collection tag
- * @property Show\Field|Collection desc
- * @property Show\Field|Collection created_at
- * @property Show\Field|Collection updated_at
* @property Show\Field|Collection product_id
* @property Show\Field|Collection know
* @property Show\Field|Collection content
+ * @property Show\Field|Collection id
+ * @property Show\Field|Collection name
* @property Show\Field|Collection type
* @property Show\Field|Collection version
* @property Show\Field|Collection detail
+ * @property Show\Field|Collection created_at
+ * @property Show\Field|Collection updated_at
* @property Show\Field|Collection is_enabled
* @property Show\Field|Collection parent_id
* @property Show\Field|Collection order
@@ -238,6 +236,10 @@ namespace Dcat\Admin {
* @property Show\Field|Collection password
* @property Show\Field|Collection avatar
* @property Show\Field|Collection remember_token
+ * @property Show\Field|Collection agent_id
+ * @property Show\Field|Collection picture
+ * @property Show\Field|Collection tag
+ * @property Show\Field|Collection desc
* @property Show\Field|Collection about
* @property Show\Field|Collection reg_protocol
* @property Show\Field|Collection buy_protocol
@@ -288,6 +290,7 @@ namespace Dcat\Admin {
* @property Show\Field|Collection paid_money
* @property Show\Field|Collection paid_at
* @property Show\Field|Collection refund_info
+ * @property Show\Field|Collection verify_code
* @property Show\Field|Collection email
* @property Show\Field|Collection token
* @property Show\Field|Collection pictures
@@ -301,20 +304,16 @@ namespace Dcat\Admin {
* @property Show\Field|Collection openid
* @property Show\Field|Collection unionid
*
- * @method Show\Field|Collection id(string $label = null)
- * @method Show\Field|Collection agent_id(string $label = null)
- * @method Show\Field|Collection picture(string $label = null)
- * @method Show\Field|Collection name(string $label = null)
- * @method Show\Field|Collection tag(string $label = null)
- * @method Show\Field|Collection desc(string $label = null)
- * @method Show\Field|Collection created_at(string $label = null)
- * @method Show\Field|Collection updated_at(string $label = null)
* @method Show\Field|Collection product_id(string $label = null)
* @method Show\Field|Collection know(string $label = null)
* @method Show\Field|Collection content(string $label = null)
+ * @method Show\Field|Collection id(string $label = null)
+ * @method Show\Field|Collection name(string $label = null)
* @method Show\Field|Collection type(string $label = null)
* @method Show\Field|Collection version(string $label = null)
* @method Show\Field|Collection detail(string $label = null)
+ * @method Show\Field|Collection created_at(string $label = null)
+ * @method Show\Field|Collection updated_at(string $label = null)
* @method Show\Field|Collection is_enabled(string $label = null)
* @method Show\Field|Collection parent_id(string $label = null)
* @method Show\Field|Collection order(string $label = null)
@@ -333,6 +332,10 @@ namespace Dcat\Admin {
* @method Show\Field|Collection password(string $label = null)
* @method Show\Field|Collection avatar(string $label = null)
* @method Show\Field|Collection remember_token(string $label = null)
+ * @method Show\Field|Collection agent_id(string $label = null)
+ * @method Show\Field|Collection picture(string $label = null)
+ * @method Show\Field|Collection tag(string $label = null)
+ * @method Show\Field|Collection desc(string $label = null)
* @method Show\Field|Collection about(string $label = null)
* @method Show\Field|Collection reg_protocol(string $label = null)
* @method Show\Field|Collection buy_protocol(string $label = null)
@@ -383,6 +386,7 @@ namespace Dcat\Admin {
* @method Show\Field|Collection paid_money(string $label = null)
* @method Show\Field|Collection paid_at(string $label = null)
* @method Show\Field|Collection refund_info(string $label = null)
+ * @method Show\Field|Collection verify_code(string $label = null)
* @method Show\Field|Collection email(string $label = null)
* @method Show\Field|Collection token(string $label = null)
* @method Show\Field|Collection pictures(string $label = null)
diff --git a/resources/lang/zh_CN/special.php b/resources/lang/zh_CN/special.php
new file mode 100644
index 0000000..85c0053
--- /dev/null
+++ b/resources/lang/zh_CN/special.php
@@ -0,0 +1,16 @@
+ [
+ 'Special' => '专题',
+ 'special' => '专题',
+ ],
+ 'fields' => [
+ 'agent_id' => '代理商ID',
+ 'picture' => '专题页轮播图',
+ 'picture_ad' => '首页广告图',
+ 'agent_product_id' => '产品ID',
+ 'sort' => '排序',
+ ],
+ 'options' => [
+ ],
+];