小程序首页配置
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Http\Requests\Client\BannerFormRequest;
|
||||
use App\Models\HomeBannerModel;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Modules\AnnoRoute\Attribute\DeleteRoute;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\Common\Http\Controllers\BaseController;
|
||||
use Modules\SystemTool\Services\SysFileService;
|
||||
|
||||
/**
|
||||
* 首页轮播图配置(小程序首页)
|
||||
*/
|
||||
#[RequestAttribute('/client/banner', 'client.banner')]
|
||||
class BannerController extends BaseController
|
||||
{
|
||||
protected array $searchField = [
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
protected array $quickSearchField = ['title'];
|
||||
|
||||
/** 轮播图列表(默认按排序升序) */
|
||||
#[GetRoute(authorize: 'query')]
|
||||
public function query(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->all();
|
||||
$pageSize = $params['pageSize'] ?? 10;
|
||||
$data = $this->buildSearch($params, HomeBannerModel::query())
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->paginate($pageSize)
|
||||
->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/** 上传轮播图片(文件分组:客户端配置) */
|
||||
#[PostRoute('/upload', 'create')]
|
||||
public function uploadImage(Request $request, SysFileService $service): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['file' => 'required|file']);
|
||||
$result = $service->upload(
|
||||
$data['file'],
|
||||
12,
|
||||
20,
|
||||
Auth::id()
|
||||
);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/** 新增轮播图 */
|
||||
#[PostRoute(authorize: 'create')]
|
||||
public function create(BannerFormRequest $request): JsonResponse
|
||||
{
|
||||
HomeBannerModel::create($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 编辑轮播图 */
|
||||
#[PutRoute(route: '/{id}', authorize: 'update', where: ['id' => '[0-9]+'])]
|
||||
public function update(int $id, BannerFormRequest $request): JsonResponse
|
||||
{
|
||||
$model = HomeBannerModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('轮播图不存在');
|
||||
}
|
||||
$model->update($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 删除轮播图 */
|
||||
#[DeleteRoute(route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'])]
|
||||
public function delete(int $id): JsonResponse
|
||||
{
|
||||
$model = HomeBannerModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('轮播图不存在');
|
||||
}
|
||||
$model->delete();
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Http\Requests\Client\NavFormRequest;
|
||||
use App\Models\HomeNavModel;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Modules\AnnoRoute\Attribute\DeleteRoute;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\Common\Http\Controllers\BaseController;
|
||||
use Modules\SystemTool\Services\SysFileService;
|
||||
|
||||
/**
|
||||
* 宫格导航配置(小程序首页)
|
||||
*/
|
||||
#[RequestAttribute('/client/nav', 'client.nav')]
|
||||
class NavController extends BaseController
|
||||
{
|
||||
protected array $searchField = [
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
protected array $quickSearchField = ['name'];
|
||||
|
||||
/** 导航列表(默认按排序升序) */
|
||||
#[GetRoute(authorize: 'query')]
|
||||
public function query(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->all();
|
||||
$pageSize = $params['pageSize'] ?? 10;
|
||||
$data = $this->buildSearch($params, HomeNavModel::query())
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->paginate($pageSize)
|
||||
->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/** 上传导航图标(文件分组:客户端配置) */
|
||||
#[PostRoute('/upload', 'create')]
|
||||
public function uploadImage(Request $request, SysFileService $service): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['file' => 'required|file']);
|
||||
$result = $service->upload(
|
||||
$data['file'],
|
||||
12,
|
||||
20,
|
||||
Auth::id()
|
||||
);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/** 新增导航 */
|
||||
#[PostRoute(authorize: 'create')]
|
||||
public function create(NavFormRequest $request): JsonResponse
|
||||
{
|
||||
HomeNavModel::create($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 编辑导航 */
|
||||
#[PutRoute(route: '/{id}', authorize: 'update', where: ['id' => '[0-9]+'])]
|
||||
public function update(int $id, NavFormRequest $request): JsonResponse
|
||||
{
|
||||
$model = HomeNavModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('导航不存在');
|
||||
}
|
||||
$model->update($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 删除导航 */
|
||||
#[DeleteRoute(route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'])]
|
||||
public function delete(int $id): JsonResponse
|
||||
{
|
||||
$model = HomeNavModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('导航不存在');
|
||||
}
|
||||
$model->delete();
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Http\Requests\Client\PromoFormRequest;
|
||||
use App\Models\HomePromoModel;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Modules\AnnoRoute\Attribute\DeleteRoute;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\PostRoute;
|
||||
use Modules\AnnoRoute\Attribute\PutRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\Common\Http\Controllers\BaseController;
|
||||
use Modules\SystemTool\Services\SysFileService;
|
||||
|
||||
/**
|
||||
* 促销推荐卡片配置(小程序首页)
|
||||
*/
|
||||
#[RequestAttribute('/client/promo', 'client.promo')]
|
||||
class PromoController extends BaseController
|
||||
{
|
||||
protected array $searchField = [
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
protected array $quickSearchField = ['title', 'sub_title'];
|
||||
|
||||
/** 促销卡片列表(默认按排序升序) */
|
||||
#[GetRoute(authorize: 'query')]
|
||||
public function query(Request $request): JsonResponse
|
||||
{
|
||||
$params = $request->all();
|
||||
$pageSize = $params['pageSize'] ?? 10;
|
||||
$data = $this->buildSearch($params, HomePromoModel::query())
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->paginate($pageSize)
|
||||
->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/** 上传卡片图片(文件分组:客户端配置) */
|
||||
#[PostRoute('/upload', 'create')]
|
||||
public function uploadImage(Request $request, SysFileService $service): JsonResponse
|
||||
{
|
||||
$data = $request->validate(['file' => 'required|file']);
|
||||
$result = $service->upload(
|
||||
$data['file'],
|
||||
12,
|
||||
20,
|
||||
Auth::id()
|
||||
);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/** 新增促销卡片 */
|
||||
#[PostRoute(authorize: 'create')]
|
||||
public function create(PromoFormRequest $request): JsonResponse
|
||||
{
|
||||
HomePromoModel::create($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 编辑促销卡片 */
|
||||
#[PutRoute(route: '/{id}', authorize: 'update', where: ['id' => '[0-9]+'])]
|
||||
public function update(int $id, PromoFormRequest $request): JsonResponse
|
||||
{
|
||||
$model = HomePromoModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('促销卡片不存在');
|
||||
}
|
||||
$model->update($request->validated());
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/** 删除促销卡片 */
|
||||
#[DeleteRoute(route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'])]
|
||||
public function delete(int $id): JsonResponse
|
||||
{
|
||||
$model = HomePromoModel::find($id);
|
||||
if (empty($model)) {
|
||||
throw new RepositoryException('促销卡片不存在');
|
||||
}
|
||||
$model->delete();
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mini;
|
||||
|
||||
use App\Models\HomeBannerModel;
|
||||
use App\Models\HomeNavModel;
|
||||
use App\Models\HomePromoModel;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\AnnoRoute\Attribute\GetRoute;
|
||||
use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
|
||||
/**
|
||||
* 小程序首页配置(轮播图 + 宫格导航 + 促销推荐卡片,仅返回启用项)
|
||||
*/
|
||||
#[RequestAttribute('/mini', 'mini', authGuard: 'users')]
|
||||
class HomeController extends BaseMiniController
|
||||
{
|
||||
/** 首页配置聚合:banners / navs / promos,按 sort 升序 */
|
||||
#[GetRoute('/home', authorize: false)]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$banners = HomeBannerModel::query()
|
||||
->where('status', HomeBannerModel::STATUS_NORMAL)
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->get(['id', 'title', 'image_id', 'link', 'sort']);
|
||||
|
||||
$navs = HomeNavModel::query()
|
||||
->where('status', HomeNavModel::STATUS_NORMAL)
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->get(['id', 'name', 'image_id', 'link', 'sort']);
|
||||
|
||||
$promos = HomePromoModel::query()
|
||||
->where('status', HomePromoModel::STATUS_NORMAL)
|
||||
->orderBy('sort')
|
||||
->orderBy('id')
|
||||
->get(['id', 'title', 'sub_title', 'image_id', 'link', 'sort']);
|
||||
|
||||
return $this->success([
|
||||
'banners' => $banners,
|
||||
'navs' => $navs,
|
||||
'promos' => $promos,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,8 @@ class ProductController extends BaseMiniController
|
||||
|
||||
/**
|
||||
* 商品列表:价格取当前门店客户等级价;
|
||||
* 未绑定门店/门店未设客户等级 → 仍可浏览,price 为 null(不可见价格,加购/下单另由前置校验拦截);
|
||||
* ?category_id=&keyword=&page=&pageSize=
|
||||
*/
|
||||
#[GetRoute('/product/list', authorize: true)]
|
||||
#[GetRoute('/product/list', authorize: false)]
|
||||
public function products(Request $request): JsonResponse
|
||||
{
|
||||
$user = $this->currentUser($request);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Client;
|
||||
|
||||
use Modules\Common\Http\Requests\BaseFormRequest;
|
||||
|
||||
/**
|
||||
* 首页轮播图 创建/编辑 验证
|
||||
*/
|
||||
class BannerFormRequest extends BaseFormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = true;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:50',
|
||||
'image_id' => 'required|integer|min:1',
|
||||
'link' => 'nullable|string|max:255',
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'status' => 'required|integer|in:0,1',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => '轮播图标题不能为空',
|
||||
'title.max' => '轮播图标题最长 50 个字符',
|
||||
'image_id.required' => '请上传轮播图片',
|
||||
'link.max' => '跳转链接最长 255 个字符',
|
||||
'status.in' => '状态只能是 0 或 1',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Client;
|
||||
|
||||
use Modules\Common\Http\Requests\BaseFormRequest;
|
||||
|
||||
/**
|
||||
* 宫格导航 创建/编辑 验证
|
||||
*/
|
||||
class NavFormRequest extends BaseFormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = true;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:50',
|
||||
'image_id' => 'required|integer|min:1',
|
||||
'link' => 'nullable|string|max:255',
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'status' => 'required|integer|in:0,1',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => '导航名称不能为空',
|
||||
'name.max' => '导航名称最长 50 个字符',
|
||||
'image_id.required' => '请上传导航图标',
|
||||
'link.max' => '跳转链接最长 255 个字符',
|
||||
'status.in' => '状态只能是 0 或 1',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Client;
|
||||
|
||||
use Modules\Common\Http\Requests\BaseFormRequest;
|
||||
|
||||
/**
|
||||
* 促销推荐卡片 创建/编辑 验证
|
||||
*/
|
||||
class PromoFormRequest extends BaseFormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = true;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'nullable|string|max:50',
|
||||
'sub_title' => 'nullable|string|max:100',
|
||||
'image_id' => 'required|integer|min:1',
|
||||
'link' => 'nullable|string|max:255',
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'status' => 'required|integer|in:0,1',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => '卡片标题不能为空',
|
||||
'title.max' => '卡片标题最长 50 个字符',
|
||||
'sub_title.max' => '副标题最长 100 个字符',
|
||||
'image_id.required' => '请上传卡片图片',
|
||||
'link.max' => '跳转链接最长 255 个字符',
|
||||
'status.in' => '状态只能是 0 或 1',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
|
||||
/**
|
||||
* 小程序首页轮播图
|
||||
*/
|
||||
class HomeBannerModel extends Model
|
||||
{
|
||||
/** 状态:停用 */
|
||||
public const int STATUS_DISABLED = 0;
|
||||
/** 状态:正常 */
|
||||
public const int STATUS_NORMAL = 1;
|
||||
|
||||
protected $table = 'mini_home_banner';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'image_id',
|
||||
'link',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'image_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
protected $appends = ['image_url'];
|
||||
|
||||
protected $with = ['image'];
|
||||
|
||||
/**
|
||||
* 关联图片
|
||||
*/
|
||||
public function image(): HasOne
|
||||
{
|
||||
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
public function getImageUrlAttribute(): ?string
|
||||
{
|
||||
return $this->image?->preview_url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
|
||||
/**
|
||||
* 小程序首页宫格导航
|
||||
*/
|
||||
class HomeNavModel extends Model
|
||||
{
|
||||
/** 状态:停用 */
|
||||
public const int STATUS_DISABLED = 0;
|
||||
/** 状态:正常 */
|
||||
public const int STATUS_NORMAL = 1;
|
||||
|
||||
protected $table = 'mini_home_nav';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'image_id',
|
||||
'link',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'image_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
protected $appends = ['image_url'];
|
||||
|
||||
protected $with = ['image'];
|
||||
|
||||
/**
|
||||
* 关联图标
|
||||
*/
|
||||
public function image(): HasOne
|
||||
{
|
||||
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 图标链接
|
||||
*/
|
||||
public function getImageUrlAttribute(): ?string
|
||||
{
|
||||
return $this->image?->preview_url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
|
||||
/**
|
||||
* 小程序首页促销推荐卡片
|
||||
*/
|
||||
class HomePromoModel extends Model
|
||||
{
|
||||
/** 状态:停用 */
|
||||
public const int STATUS_DISABLED = 0;
|
||||
/** 状态:正常 */
|
||||
public const int STATUS_NORMAL = 1;
|
||||
|
||||
protected $table = 'mini_home_promo';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'sub_title',
|
||||
'image_id',
|
||||
'link',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'image_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
|
||||
protected $appends = ['image_url'];
|
||||
|
||||
protected $with = ['image'];
|
||||
|
||||
/**
|
||||
* 关联图片
|
||||
*/
|
||||
public function image(): HasOne
|
||||
{
|
||||
return $this->hasOne(SysFileModel::class, 'id', 'image_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片链接
|
||||
*/
|
||||
public function getImageUrlAttribute(): ?string
|
||||
{
|
||||
return $this->image?->preview_url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user