Initial commit: queue workspace
Made-with: Cursor
This commit is contained in:
576
pro_v3.5.1/app/controller/api/v1/product/StoreProduct.php
Normal file
576
pro_v3.5.1/app/controller/api/v1/product/StoreProduct.php
Normal file
@@ -0,0 +1,576 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v1\product;
|
||||
|
||||
use app\Request;
|
||||
use app\services\activity\coupon\StoreCouponIssueServices;
|
||||
use app\services\activity\discounts\StoreDiscountsServices;
|
||||
use app\services\activity\promotions\StorePromotionsServices;
|
||||
use app\services\diy\DiyServices;
|
||||
use app\services\other\QrcodeServices;
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\system\SystemRecommendServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* 商品类
|
||||
* Class StoreProduct
|
||||
* @package app\api\controller\store
|
||||
*/
|
||||
class StoreProduct
|
||||
{
|
||||
/**
|
||||
* 商品services
|
||||
* @var StoreProductServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductServices $services;
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function lst(Request $request, StoreProductCategoryServices $services)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['sid', 'd'], 0],
|
||||
[['cid', 'd'], 0],
|
||||
[['tid', 'd'], 0],
|
||||
['keyword', '', '', 'store_name'],
|
||||
['priceOrder', ''],
|
||||
['salesOrder', ''],
|
||||
['defaultOrder', ''],
|
||||
[['news', 'd'], 0, '', 'is_new'],
|
||||
[['type', ''], '', '', 'status'],
|
||||
['ids', ''],
|
||||
[['selectId', 'd'], ''],
|
||||
['cate_id', ''],
|
||||
['productId', ''],
|
||||
['brand_id', ''],
|
||||
['promotions_id', 0],
|
||||
['promotions_type', 0],
|
||||
['store_label_id', 0],
|
||||
['store_label_id', 0],
|
||||
['is_channel', '', '', 'is_channel_product'],//是否采购商品
|
||||
['is_general_product', 1],
|
||||
['is_big', 0],//是否大图模式
|
||||
]);
|
||||
if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
|
||||
$level = $services->value(['id' => (int)$where['selectId']], 'level') ?? 0;
|
||||
$levelArr = $services->cateField;
|
||||
$where[$levelArr[$level] ?? 'cid'] = $where['selectId'];
|
||||
}
|
||||
$where['ids'] = stringToIntArray($where['ids']);
|
||||
if (!$where['ids']) {
|
||||
unset($where['ids']);
|
||||
}
|
||||
$where['brand_id'] = stringToIntArray($where['brand_id']);
|
||||
$where['store_label_id'] = stringToIntArray($where['store_label_id']);
|
||||
|
||||
$cateId = $where['cate_id'];
|
||||
if ($cateId) {
|
||||
$cateId = is_string($cateId) ? stringToIntArray($where['cate_id']) : $cateId;
|
||||
$cateId = array_merge($cateId, $services->getColumn(['pid' => $cateId], 'id'));
|
||||
$cateId = array_unique(array_diff($cateId, [0]));
|
||||
}
|
||||
$where['cate_id'] = $cateId;
|
||||
|
||||
$type = $where['is_big'] ? 'big' : 'mid';
|
||||
unset($where['is_big']);
|
||||
$field = ['image', 'recommend_image'];
|
||||
if ($where['store_name']) {//搜索
|
||||
$field = ['image'];
|
||||
$where['pid'] = 0;
|
||||
}
|
||||
if ($where['is_channel_product'] == 1) {
|
||||
unset($where['is_general_product']);
|
||||
}
|
||||
$list = $this->services->getGoodsList($where, (int)$request->uid(), (int)$where['promotions_type']);
|
||||
return app('json')->successful(get_thumb_water($list, $type, $field));
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索获取商品品牌列表
|
||||
* @param Request $request
|
||||
* @param StoreProductCategoryServices $services
|
||||
* @return mixed
|
||||
*/
|
||||
public function brand(Request $request, StoreProductCategoryServices $services)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['sid', 'd'], 0],
|
||||
[['cid', 'd'], 0],
|
||||
['keyword', '', '', 'store_name'],
|
||||
['priceOrder', ''],
|
||||
['salesOrder', ''],
|
||||
[['news', 'd'], 0, '', 'is_new'],
|
||||
[['type', ''], '', '', 'status'],
|
||||
['ids', ''],
|
||||
['selectId', ''],
|
||||
['productId', '']
|
||||
]);
|
||||
if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
|
||||
if ($services->value(['id' => $where['selectId']], 'pid')) {
|
||||
$where['sid'] = $where['selectId'];
|
||||
} else {
|
||||
$where['cid'] = $where['selectId'];
|
||||
}
|
||||
}
|
||||
if ($where['ids'] && is_string($where['ids'])) {
|
||||
$where['ids'] = explode(',', $where['ids']);
|
||||
}
|
||||
if (!$where['ids']) {
|
||||
unset($where['ids']);
|
||||
}
|
||||
$where['type'] = [0, 2];
|
||||
return app('json')->successful($this->services->getBrandList($where, (int)$request->uid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品搜索页面参数:活动、品牌、标签
|
||||
* @param Request $request
|
||||
* @param StoreProductCategoryServices $services
|
||||
* @return \think\Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function searchFilter(Request $request, StoreProductCategoryServices $services)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['sid', 'd'], 0],
|
||||
[['cid', 'd'], 0],
|
||||
['keyword', '', '', 'store_name'],
|
||||
[['news', 'd'], 0, '', 'is_new'],
|
||||
[['type', ''], '', '', 'status'],
|
||||
['ids', ''],
|
||||
['selectId', ''],
|
||||
['productId', ''],
|
||||
['promotions_id', 0],
|
||||
['promotions_type', 0],
|
||||
]);
|
||||
if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
|
||||
$level = $services->value(['id' => (int)$where['selectId']], 'level') ?? 0;
|
||||
$levelArr = $services->cateField;
|
||||
$where[$levelArr[$level] ?? 'cid'] = $where['selectId'];
|
||||
}
|
||||
if ($where['ids'] && is_string($where['ids'])) {
|
||||
$where['ids'] = stringToIntArray($where['ids']);
|
||||
}
|
||||
if (!$where['ids']) {
|
||||
unset($where['ids']);
|
||||
}
|
||||
return app('json')->successful($this->services->searchFilter((int)$request->uid(), $where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短链
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/11/23 下午3:11
|
||||
*/
|
||||
public function shortLink(Request $request, $id)
|
||||
{
|
||||
$id = (int)$id;
|
||||
if (!$id || !$this->services->isValidProduct($id)) {
|
||||
return app('json')->fail('商品不存在或已下架');
|
||||
}
|
||||
$uid = $request->uid() ?? '';
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
return app('json')->successful(['code' => $qrcodeService->getRoutineShortLink($id, (int)$uid)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品分享二维码 推广员
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function code(Request $request, $id)
|
||||
{
|
||||
$id = (int)$id;
|
||||
if (!$id || !$this->services->isValidProduct($id)) {
|
||||
return app('json')->fail('商品不存在或已下架');
|
||||
}
|
||||
$userType = $request->get('user_type', 'wechat');
|
||||
$user = $request->user() ?? [];
|
||||
$uid = $user['uid'] ?? 0;
|
||||
$is_promoter = $user['is_promoter'] ?? 0;
|
||||
try {
|
||||
switch ($userType) {
|
||||
case 'wechat':
|
||||
//公众号
|
||||
$name = $id . '_product_detail_' . $uid . '_is_promoter_' . $is_promoter . '_wap.jpg';
|
||||
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
if (sys_config('share_qrcode', 0) && request()->isWechat()) {
|
||||
$url = $qrcodeService->getTemporaryQrcode('product-' . $id . '-' . $uid, $uid)->url;
|
||||
} else {
|
||||
$url = $qrcodeService->getWechatQrcodePath($name, '/pages/goods_details/index?id=' . $id . '&spread=' . $uid . 'spid=' . $uid);
|
||||
}
|
||||
|
||||
if ($url === false)
|
||||
return app('json')->fail('二维码生成失败');
|
||||
else {
|
||||
// $codeTmp = $code = $url ? image_to_base64($url) : false;
|
||||
// if (!$codeTmp) {
|
||||
// $putCodeUrl = put_image($url);
|
||||
// $code = $putCodeUrl ? image_to_base64(app()->request->domain(true) . '/' . $putCodeUrl) : false;
|
||||
// $code ?? unlink(public_path() . $putCodeUrl);
|
||||
// }
|
||||
return app('json')->successful(['code' => $url]);
|
||||
}
|
||||
break;
|
||||
case 'routine':
|
||||
$name = $id . '_' . $uid . '_' . $is_promoter . '_product.jpg';
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
$url = $qrcodeService->getRoutineQrcodePath($id, (int)$uid, 0, $name);
|
||||
if ($url === false)
|
||||
return app('json')->fail('二维码生成失败');
|
||||
else
|
||||
return app('json')->successful(['code' => $url]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return app('json')->fail($e->getMessage(), [
|
||||
'code' => $e->getCode(),
|
||||
'line' => $e->getLine(),
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function detail(Request $request, $id, $type = 0)
|
||||
{
|
||||
[$promotions_type, $is_channel_product] = $request->getMore([
|
||||
[['promotions_type', 'd'], 0],
|
||||
['is_channel_product', 0]
|
||||
], true);
|
||||
$data = $this->services->productDetail((int)$request->uid(), (int)$id, (int)$type, (int)$promotions_type, (int)$is_channel_product);
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的详情内容
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/28
|
||||
*/
|
||||
public function detailContent($id)
|
||||
{
|
||||
$productInfo = $this->services->getCacheProductInfo((int)$id);
|
||||
return app('json')->success(['description' => $productInfo['description'] ?? '']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推荐商品列表
|
||||
* @param Request $request
|
||||
* @param DiyServices $diyServices
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function recommend(Request $request, DiyServices $diyServices, $id)
|
||||
{
|
||||
$list = [];
|
||||
$diy = $diyServices->getProductDetailDiy();
|
||||
//推荐开启
|
||||
if (isset($diy['showRecommend']) && $diy['showRecommend']) {
|
||||
$num = (int)($diy['recommendNum'] ?? 12);
|
||||
$storeInfo = [];
|
||||
if ($id) {
|
||||
$storeInfo = $this->services->getCacheProductInfo((int)$id);
|
||||
}
|
||||
$uid = $request->uid();
|
||||
$where = [];
|
||||
$where['is_vip_product'] = 0;
|
||||
if ($uid) {
|
||||
$is_vip = $request->user('is_money_level');
|
||||
$where['is_vip_product'] = $is_vip ? -1 : 0;
|
||||
}
|
||||
//推荐
|
||||
if (isset($storeInfo['recommend_list']) && $storeInfo['recommend_list']) {
|
||||
$recommend_list = explode(',', $storeInfo['recommend_list']);
|
||||
$list = get_thumb_water($this->services->getProducts(['ids' => $recommend_list, 'is_del' => 0, 'is_show' => 1] + $where, '', $num, ['couponId']));
|
||||
} else {
|
||||
$list = get_thumb_water($this->services->getProducts(['is_good' => 1, 'is_del' => 0, 'is_show' => 1] + $where, 'rand()', $num, ['couponId']));
|
||||
}
|
||||
}
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品关联活动信息
|
||||
* @param Request $request
|
||||
* @param StoreCouponIssueServices $couponIssueServices
|
||||
* @param StoreDiscountsServices $storeDiscountsServices
|
||||
* @param StorePromotionsServices $storePromotionsServices
|
||||
* @param DiyServices $diyServices
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function activity(Request $request, StoreCouponIssueServices $couponIssueServices, StoreDiscountsServices $storeDiscountsServices, StorePromotionsServices $storePromotionsServices, DiyServices $diyServices, $id)
|
||||
{
|
||||
[$promotions_type, $unique] = $request->getMore([
|
||||
[['promotions_type', 'd'], 0],
|
||||
['unique', '']
|
||||
], true);
|
||||
$storeInfo = [];
|
||||
$id = (int)$id;
|
||||
if ($id) {
|
||||
$storeInfo = $this->services->getCacheProductInfo($id);
|
||||
}
|
||||
$uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
|
||||
$data = ['activity' => [], 'coupons' => [], 'discounts_products' => [], 'promotions' => [], 'activity_background' => [], 'computed' => ['deduction' => []]];
|
||||
//预售不参与
|
||||
if (!$storeInfo || $storeInfo['is_presale_product']) {
|
||||
return app('json')->success($data);
|
||||
}
|
||||
$diy = $diyServices->getProductDetailDiy();
|
||||
if (isset($diy['showService']) && in_array(0, $diy['showService']))
|
||||
$data['activity'] = $this->services->getActivityList($storeInfo, false);
|
||||
$data['coupons'] = $couponIssueServices->getProductCouponList($uid, $id, 'id,type,coupon_type,coupon_title,coupon_price,use_min_price,coupon_time,start_time,end_time,rule', 20);
|
||||
foreach ($data['coupons'] as $key => $item) {
|
||||
if ($item['use_status'] != 1) {
|
||||
unset($data['coupons'][$key]);
|
||||
}
|
||||
}
|
||||
$data['coupons'] = array_values($data['coupons']);
|
||||
if (isset($diy['showMatch']) && $diy['showMatch']) {
|
||||
$num = (int)($diy['matchNum'] ?? 2);
|
||||
$data['discounts_products'] = $storeDiscountsServices->getDiscounts($id, $uid, $num, 'id,type,title,image,is_limit,limit_num,product_ids');
|
||||
if ($data['discounts_products']) {
|
||||
foreach ($data['discounts_products'] as &$item) {
|
||||
$products = [];
|
||||
if (isset($item['products']) && $item['products']) {
|
||||
foreach ($item['products'] as $product) {
|
||||
$products[] = ['id' => $product['id'] ?? '', 'store_name' => $product['store_name'] ?? $product['title'] ?? '', 'image' => $product['image']];
|
||||
}
|
||||
}
|
||||
$item['products'] = $products;
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
}
|
||||
if (isset($diy['showService']) && in_array(0, $diy['showService'])) {//商品详情开启活动
|
||||
$promotions_type = $promotions_type ? [(int)$promotions_type] : [1, 2, 3, 4, 6];
|
||||
} else {
|
||||
$promotions_type = $promotions_type ? [(int)$promotions_type] : [6];
|
||||
}
|
||||
$ids = $storeInfo['pid'] ? [$storeInfo['pid']] : [$id];
|
||||
[$promotions, $productRelation] = $storePromotionsServices->getProductsPromotions($ids, $promotions_type, '*', ['giveProducts' => function ($query) {
|
||||
$query->field('promotions_id,product_id,limit_num,surplus_num')->with(['productInfo' => function ($query) {
|
||||
$query->field('id,store_name,image');
|
||||
}]);
|
||||
}, 'giveCoupon' => function ($query) {
|
||||
$query->field('promotions_id,coupon_id,limit_num,surplus_num')->with(['coupon' => function ($query) {
|
||||
$query->field('id,type,coupon_type,coupon_title,coupon_price,use_min_price');
|
||||
}]);
|
||||
}, 'promotions' => function ($query) {
|
||||
$query->field('id,pid,promotions_type,promotions_cate,threshold_type,threshold,discount_type,n_piece_n_discount,discount,give_integral,give_coupon_id,give_product_id,give_product_unique')->with(['giveProducts' => function ($query) {
|
||||
$query->field('promotions_id, product_id,limit_num,surplus_num')->with(['productInfo' => function ($query) {
|
||||
$query->field('id,store_name');
|
||||
}]);
|
||||
}, 'giveCoupon' => function ($query) {
|
||||
$query->field('promotions_id, coupon_id,limit_num,surplus_num')->with(['coupon' => function ($query) {
|
||||
$query->field('id,type,coupon_type,coupon_title,coupon_price,use_min_price');
|
||||
}]);
|
||||
}]);
|
||||
}], 'promotions_type');
|
||||
if ($promotions) {
|
||||
foreach ($promotions as $key => $item) {
|
||||
|
||||
if ($item['promotions_type'] == 6) {
|
||||
$data['activity_background'] = ['id' => $item['id'], 'name' => $item['name'], 'image' => $item['image']];
|
||||
} else {
|
||||
$data['promotions'][] = [
|
||||
'id' => $item['id'],
|
||||
'type' => $item['type'],
|
||||
'title' => $item['title'],
|
||||
'name' => $item['name'],
|
||||
'give_integral' => $item['give_integral'],
|
||||
'promotions_type' => $item['promotions_type'],
|
||||
'threshold_type' => $item['threshold_type'],
|
||||
'threshold' => $item['threshold'],
|
||||
'discount_type' => $item['discount_type'],
|
||||
'discount' => $item['discount'],
|
||||
'desc' => $item['desc'],
|
||||
'start_time' => $item['start_time'] ? date('Y-m-d', $item['start_time']) : '',
|
||||
'stop_time' => $item['stop_time'] ? date('Y-m-d', $item['stop_time']) : '',
|
||||
'giveProducts' => $item['giveProducts'] ?? [],
|
||||
'giveCoupon' => $item['giveCoupon'] ?? []
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$computed = $this->services->computedProductPayPrice($uid, $id, $unique);
|
||||
$data['computed'] = $computed;
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为你推荐
|
||||
* @param Request $request
|
||||
* @param UserServices $userServices
|
||||
* @return mixed
|
||||
*/
|
||||
public function product_hot(Request $request, UserServices $userServices)
|
||||
{
|
||||
$uid = (int)$request->uid();
|
||||
$vip_user = $userServices->checkUserIsSvip($uid) ? -1 : 0;
|
||||
$where = ['is_show' => 1, 'is_del' => 0, 'is_verify' => 1, 'is_vip_product' => $vip_user];
|
||||
$type = $request->get('type', 0);
|
||||
if ($type == 0) {
|
||||
$where = $where + ['is_hot' => 1];
|
||||
$title = '为您推荐';
|
||||
} else {
|
||||
[$title, $recommendProductIds] = app()->make(SystemRecommendServices::class)->getRecommendProductIds($type, $uid);
|
||||
if (count($recommendProductIds)) {
|
||||
$where = $where + ['ids' => $recommendProductIds];
|
||||
} else {
|
||||
$where = $where + ['is_hot' => 1];
|
||||
}
|
||||
}
|
||||
$list = $this->services->getProducts($where, '', 0, ['couponId']);
|
||||
$count = count($list);
|
||||
$limit = $request->get('limit', 10);
|
||||
$page = $request->get('page', 1);
|
||||
if ($count < $limit && $page == 1) {
|
||||
$where = ['is_show' => 1, 'is_del' => 0, 'is_verify' => 1, 'is_vip_product' => $vip_user, 'is_hot' => 1];
|
||||
$list = array_merge($list, $this->services->getProducts($where, '', 20, ['couponId']));
|
||||
// 用于存储已经处理过的id
|
||||
$seenIds = [];
|
||||
$uniqueData = [];
|
||||
foreach ($list as $item) {
|
||||
$id = $item['id'];
|
||||
if (!isset($seenIds[$id])) {
|
||||
$seenIds[$id] = true;
|
||||
$uniqueData[] = $item;
|
||||
|
||||
// 如果已经取到10个唯一项,提前退出循环
|
||||
if (count($uniqueData) === 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$list = $uniqueData;
|
||||
}
|
||||
$list = get_thumb_water($list, 'mid');
|
||||
return app('json')->success(compact('list', 'title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页推荐不同类型商品的轮播图和商品
|
||||
* @param Request $request
|
||||
* @param $type
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function groom_list(Request $request, $type)
|
||||
{
|
||||
$info['banner'] = [];
|
||||
$info['list'] = [];
|
||||
$uid = (int)$request->uid();
|
||||
$where = [];
|
||||
if ($type == 1) {// 精品推荐
|
||||
$info['banner'] = sys_data('routine_home_bast_banner') ?: [];// 首页精品推荐图片
|
||||
$where['is_best'] = 1;
|
||||
} else if ($type == 2) {// 热门榜单
|
||||
$info['banner'] = sys_data('routine_home_hot_banner') ?: [];// 热门榜单 猜你喜欢推荐图片
|
||||
$where['is_hot'] = 1;
|
||||
} else if ($type == 3) {// 首发新品
|
||||
$info['banner'] = sys_data('routine_home_new_banner') ?: [];// 首发新品推荐图片
|
||||
$where['is_new'] = 1;
|
||||
} else if ($type == 4) {// 促销单品
|
||||
$info['banner'] = sys_data('routine_home_benefit_banner') ?: [];// 促销单品推荐图片
|
||||
$where['is_benefit'] = 1;
|
||||
} else if ($type == 5) {// 会员商品
|
||||
$where['is_vip'] = 1;
|
||||
}
|
||||
$info['list'] = $this->services->getRecommendProduct($uid, $where);
|
||||
return app('json')->successful($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取预售列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function presaleList(Request $request)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['time_type', 'd'], 0],
|
||||
['limit', 0],
|
||||
]);
|
||||
$uid = (int)$request->uid();
|
||||
$limit = (int)$where['limit'];
|
||||
unset($where['limit']);
|
||||
return app('json')->successful($this->services->getPresaleList($uid, $where, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索页面推荐排序商品
|
||||
* @param Request $request
|
||||
* @param $type
|
||||
* @return \think\Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws \throwable
|
||||
*/
|
||||
public function searchRecommendList(Request $request, $type)
|
||||
{
|
||||
$uid = 0;
|
||||
if ($request->hasMacro('uid')) $uid = $request->uid();
|
||||
$order = match ((int)$type) {
|
||||
1 => 'sales desc, sort desc, id desc',//销量
|
||||
2 => 'star desc, sort desc, id desc',//评分
|
||||
3 => 'collect desc, sort desc, id desc',//收藏
|
||||
default => 'sales desc, sort desc, id desc',
|
||||
};
|
||||
return app('json')->successful($this->services->getRecommendProduct($uid, [], 8, 'small', $order));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v1\product;
|
||||
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use think\annotation\Inject;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* Class StoreProductCategory
|
||||
* @package app\api\controller\v1\store
|
||||
*/
|
||||
class StoreProductCategory
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreProductCategoryServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductCategoryServices $services;
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function category(Request $request)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
['pid', 0],
|
||||
]);
|
||||
$category = $this->services->getCategory($where);
|
||||
return app('json')->success($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同级的所有分类
|
||||
* @param Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function levelCategory(Request $request)
|
||||
{
|
||||
[$id] = $request->getMore([
|
||||
['id', 0],
|
||||
], true);
|
||||
if (!$id) {
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
return app('json')->success($this->services->getLevelCategory((int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/11
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCategoryVersion()
|
||||
{
|
||||
return app('json')->success(['version' => $this->services->getCategoryVersion()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v1\product;
|
||||
|
||||
use app\Request;
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use app\services\product\product\StoreProductRankServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use think\annotation\Inject;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* 商品榜单
|
||||
* Class StoreProductRank
|
||||
* @package app\api\controller\product
|
||||
*/
|
||||
class StoreProductRank
|
||||
{
|
||||
/**
|
||||
* 商品services
|
||||
* @var StoreProductServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductServices $services;
|
||||
|
||||
|
||||
/**
|
||||
* 获取绑定分类
|
||||
* @param StoreProductCategoryServices $services
|
||||
* @return \think\Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function rankCategory(StoreProductCategoryServices $services)
|
||||
{
|
||||
return app('json')->successful($services->getRankCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取榜单列表
|
||||
* @param Request $request
|
||||
* @param StoreProductCategoryServices $services
|
||||
* @param StoreProductRankServices $productRankServices
|
||||
* @param $type
|
||||
* @return \think\Response
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws \throwable
|
||||
*/
|
||||
public function rankList(Request $request, StoreProductCategoryServices $services, StoreProductRankServices $productRankServices,$type)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['selectId', 'd'], ''],
|
||||
]);
|
||||
if ($where['selectId']) {
|
||||
$level = $services->value(['id' => (int)$where['selectId']], 'level') ?? 0;
|
||||
$levelArr = $services->cateField;
|
||||
$where[$levelArr[$level] ?? 'cid'] = $where['selectId'];
|
||||
unset($where['selectId']);
|
||||
}
|
||||
$uid = 0;
|
||||
if ($request->hasMacro('uid')) $uid = (int)$request->uid();
|
||||
return app('json')->successful($productRankServices->getProductRankList($uid, (int)$type, $where));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
217
pro_v3.5.1/app/controller/api/v1/product/StoreProductReply.php
Normal file
217
pro_v3.5.1/app/controller/api/v1/product/StoreProductReply.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v1\product;
|
||||
|
||||
use app\Request;
|
||||
use app\services\product\product\StoreProductReplyCommentServices;
|
||||
use app\services\product\product\StoreProductReplyServices;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 商品评价类
|
||||
* Class StoreProductReplyController
|
||||
* @package app\api\controller\store
|
||||
*/
|
||||
class StoreProductReply
|
||||
{
|
||||
/**
|
||||
* 商品services
|
||||
* @var StoreProductReplyServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductReplyServices $services;
|
||||
|
||||
|
||||
/**
|
||||
* 商品评价数量和好评度
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function reply_config($id)
|
||||
{
|
||||
/** @var StoreProductReplyServices $replyService */
|
||||
$replyService = app()->make(StoreProductReplyServices::class);
|
||||
$count = $replyService->productReplyCount((int)$id);
|
||||
return app('json')->successful($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品评论
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function reply_list(Request $request, $id)
|
||||
{
|
||||
[$type] = $request->getMore([
|
||||
[['type', 'd'], 0]
|
||||
], true);
|
||||
/** @var StoreProductReplyServices $replyService */
|
||||
$replyService = app()->make(StoreProductReplyServices::class);
|
||||
$list = $replyService->getProductReplyList((int)$id, (int)$type);
|
||||
return app('json')->successful(get_thumb_water($list, 'small', ['pics']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 评价详情
|
||||
* @param StoreProductReplyServices $services
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function replyInfo(StoreProductReplyServices $services, Request $request, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
return app('json')->success($services->getReplyInfo((int)$id, (int)$request->uid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论回复列表
|
||||
* @param StoreProductReplyCommentServices $services
|
||||
* @param Request $request
|
||||
* @param $id 评论id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function commentList(StoreProductReplyCommentServices $services, Request $request, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
$data = $services->getReplCommenList((int)$id, '', (int)$request->uid(), false);
|
||||
return app('json')->success($data['list']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存评论回复
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyCommentServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function replyComment(Request $request, StoreProductReplyCommentServices $services, $id)
|
||||
{
|
||||
[$content] = $request->postMore([
|
||||
['content', '']
|
||||
], true);
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
if (!$content) {
|
||||
return app('json')->fail('缺少回复内容');
|
||||
}
|
||||
$services->saveComment((int)$request->uid(), (int)$id, $content);
|
||||
return app('json')->success('回复成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复点赞
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyCommentServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function commentPraise(Request $request, StoreProductReplyCommentServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
|
||||
if ($services->commentPraise((int)$id, (int)$request->uid())) {
|
||||
return app('json')->success('点赞成功');
|
||||
} else {
|
||||
return app('json')->fail('点赞失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消回复点赞
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyCommentServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function unCommentPraise(Request $request, StoreProductReplyCommentServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
|
||||
if ($services->unCommentPraise((int)$id, (int)$request->uid())) {
|
||||
return app('json')->success('取消点赞成功');
|
||||
} else {
|
||||
return app('json')->fail('取消点赞失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function replyPraise(Request $request, StoreProductReplyServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
if ($services->replyPraise((int)$id, (int)$request->uid())) {
|
||||
return app('json')->success('点赞成功');
|
||||
} else {
|
||||
return app('json')->fail('点赞失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消点赞
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function unReplyPraise(Request $request, StoreProductReplyServices $services, $id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('缺少参数');
|
||||
}
|
||||
if ($services->unReplyPraise((int)$id, (int)$request->uid())) {
|
||||
return app('json')->success('取消点赞成功');
|
||||
} else {
|
||||
return app('json')->fail('取消点赞失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user