feat(shopro): 完善首页商品列表装修逻辑,支持hidden商品展示 - 在Goods控制器中添加normalizeHomeGoodsListParams方法调用, 用于处理首页商品列表参数规范化 - 重构Decorate模型,移除未使用的DecorateContent引用 - 新增resolveHomeGoodsListContext方法,解析首页商品列表上下文 - 实现normalizeHomeGoodsListParams方法,确保关键词搜索为空时 使用装修配置的商品ID - 添加enrichHomeGoodsBlocks方法,丰富首页商品区块数据 - 优化extractHomeGoodsContextFromBlocks方法,从装修区块中提取 商品上下文信息 - 修改Goods模型,在指定goods_ids时允许查询status为hidden的商品, 确保装修中设置的隐藏商品能够正常展示 ```
199 行
6.6 KiB
PHP
199 行
6.6 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\controller;
|
|
|
|
use addons\shopro\exception\Exception;
|
|
use addons\shopro\model\Cart as CartModel;
|
|
|
|
class Goods extends Base
|
|
{
|
|
|
|
protected $noNeedLogin = ['index', 'detail', 'lists', 'activity', 'seckillList', 'promoteList', 'grouponList', 'store'];
|
|
protected $noNeedRight = ['*'];
|
|
|
|
public function index()
|
|
{
|
|
// 测试腾讯云短信
|
|
$user = \addons\shopro\model\User::get(10011);
|
|
$walletLog = \addons\shopro\model\UserWalletLog::get(61);
|
|
|
|
$user && $user->notify(
|
|
new \addons\shopro\notifications\Wallet([
|
|
'walletLog' => $walletLog,
|
|
'event' => 'wallet_change'
|
|
])
|
|
);
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
$id = $this->request->get('id');
|
|
$source = $this->request->header('platform');
|
|
$detail = \addons\shopro\model\Goods::getGoodsDetail($id, $source);
|
|
|
|
// 记录足记
|
|
\addons\shopro\model\UserView::addView($detail);
|
|
|
|
$sku_price = $detail['sku_price']; // 处理过的规格
|
|
// tp bug json_encode 或者 toArray 的时候 sku_price 会重新查询数据库,导致被处理过的规格又还原回去了
|
|
$detail = json_decode(json_encode($detail), true);
|
|
$detail['sku_price'] = $sku_price;
|
|
$detail = getUserVipPrice($this->auth->getUser(), $detail, true);
|
|
$detail['cartNum'] = 0;
|
|
|
|
if ($this->auth->id) {
|
|
$cartList = CartModel::info();
|
|
$detail['cartNum'] = count($cartList);
|
|
}
|
|
|
|
// 复购立减提示信息
|
|
$detail['repurchase_info'] = [
|
|
'is_enable' => false,
|
|
'is_user_repurchase' => false,
|
|
'tip' => ''
|
|
];
|
|
try {
|
|
$isEnable = \addons\shopro\library\commission\RepurchaseService::isGoodsRepurchaseEnable($id);
|
|
if ($isEnable) {
|
|
$config = \addons\shopro\library\commission\RepurchaseService::getConfig();
|
|
if (!empty($config['enable']) && !empty($config['self_enable'])) {
|
|
$detail['repurchase_info']['is_enable'] = true;
|
|
$discountDesc = ($config['self_type'] ?? 'fixed') === 'rate'
|
|
? ($config['self_rate'] . '%')
|
|
: ('¥' . $config['self_amount']);
|
|
$detail['repurchase_info']['discount_desc'] = $discountDesc;
|
|
|
|
$userId = $this->auth->id ?? 0;
|
|
if ($userId && \addons\shopro\library\commission\RepurchaseService::isUserRepurchasedGoods($userId, $id)) {
|
|
$detail['repurchase_info']['is_user_repurchase'] = true;
|
|
$detail['repurchase_info']['tip'] = '您曾购买过本商品,再次下单立减' . $discountDesc;
|
|
} else {
|
|
$detail['repurchase_info']['tip'] = '老客复购享立减' . $discountDesc;
|
|
}
|
|
}
|
|
}
|
|
} catch (\Throwable $e) {
|
|
}
|
|
|
|
$this->success('商品详情', $detail);
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$params = $this->request->get();
|
|
$params['platform'] = $this->request->header('platform');
|
|
$params = \addons\shopro\model\Decorate::normalizeHomeGoodsListParams(
|
|
$params,
|
|
$params['platform'] ?? ''
|
|
);
|
|
$data = \addons\shopro\model\Goods::getGoodsList($params)->toArray();
|
|
|
|
// 获取vip价格
|
|
foreach ($data['data'] as &$v) {
|
|
$v = getUserVipPrice($this->auth->getUser(), $v, true);
|
|
}
|
|
|
|
$this->success('商品列表', $data);
|
|
}
|
|
|
|
/**
|
|
* 获取商品支持的 自提点
|
|
*/
|
|
public function store()
|
|
{
|
|
$params = $this->request->get();
|
|
$data = \addons\shopro\model\Goods::getGoodsStore($params);
|
|
|
|
$this->success('自提列表', $data);
|
|
}
|
|
|
|
// 预约抢购列表
|
|
public function robbuyList()
|
|
{
|
|
$params = $this->request->get();
|
|
|
|
$this->success('预约抢购列表', \addons\shopro\model\Goods::getRobBuyGoodsList($params));
|
|
}
|
|
|
|
// 秒杀列表
|
|
public function seckillList()
|
|
{
|
|
$params = $this->request->get();
|
|
|
|
$this->success('秒杀商品列表', \addons\shopro\model\Goods::getSeckillGoodsList($params));
|
|
}
|
|
|
|
// 限时促销列表
|
|
public function promoteList()
|
|
{
|
|
$params = $this->request->get();
|
|
$params['platform'] = $this->request->header('platform');
|
|
$data = \addons\shopro\model\Goods::getPromoteGoodsList($params)->toArray();
|
|
|
|
// 获取vip价格
|
|
foreach ($data['data'] as &$v) {
|
|
$v = getUserVipPrice($this->auth->getUser(), $v, true);
|
|
}
|
|
|
|
$this->success('限时促销列表', $data);
|
|
}
|
|
|
|
// 限时秒杀列表
|
|
public function timerList()
|
|
{
|
|
$params = $this->request->get();
|
|
|
|
$this->success('限时秒杀商品列表', \addons\shopro\model\Goods::getTimerGoodsList($params));
|
|
}
|
|
|
|
// 拼团列表
|
|
public function grouponList()
|
|
{
|
|
$this->error('拼团功能已关闭');
|
|
$params = $this->request->get();
|
|
$params['platform'] = $this->request->header('platform');
|
|
|
|
$this->success('拼团商品列表', \addons\shopro\model\Goods::getGrouponGoodsList($params));
|
|
}
|
|
|
|
public function activity()
|
|
{
|
|
$activity_id = $this->request->get('activity_id');
|
|
$activity = \addons\shopro\model\Activity::get($activity_id);
|
|
if (!$activity) {
|
|
$this->error('活动不存在', null, -1);
|
|
}
|
|
|
|
$goods = \addons\shopro\model\Goods::getGoodsList(['goods_ids' => $activity->goods_ids]);
|
|
$activity->goods = $goods;
|
|
|
|
$this->success('活动列表', $activity);
|
|
}
|
|
|
|
public function favorite()
|
|
{
|
|
$params = $this->request->post();
|
|
$result = \addons\shopro\model\UserFavorite::edit($params);
|
|
$this->success($result ? '收藏成功' : '取消收藏', $result);
|
|
}
|
|
|
|
public function favoriteList()
|
|
{
|
|
$data = \addons\shopro\model\UserFavorite::getGoodsList();
|
|
$this->success('商品收藏列表', $data);
|
|
}
|
|
|
|
public function viewDelete()
|
|
{
|
|
$params = $this->request->post();
|
|
$result = \addons\shopro\model\UserView::del($params);
|
|
$this->success('删除成功', $result);
|
|
}
|
|
|
|
public function viewList()
|
|
{
|
|
$data = \addons\shopro\model\UserView::getGoodsList();
|
|
$this->success('商品浏览列表', $data);
|
|
}
|
|
}
|