Merge branch 'master' of https://gitea.zianxin.com/zax/biz-api-cloud
This commit is contained in:
commit
966d78b41b
2 files changed
+152
-40
No files matched your search
+75
@@ -0,0 +1,75 @@
|
||||
package com.bsd.pjcloud.supermarket.vo.mall;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 移动端商户详情
|
||||
*/
|
||||
@Data
|
||||
public class MallMchManageVo {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Schema(description="主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商户名称
|
||||
*/
|
||||
@Schema(description="商户名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商户简称
|
||||
*/
|
||||
@Schema(description="商户简称")
|
||||
private String shortName;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
@Schema(description="联系人")
|
||||
private String contactName;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Schema(description="联系电话")
|
||||
private String contactPhone;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 营业执照号
|
||||
*/
|
||||
@Schema(description="营业执照号")
|
||||
private String licenseNo;
|
||||
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
@Schema(description="详细地址")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 商户图片URL(逗号分隔)
|
||||
*/
|
||||
@Schema(description="商户图片URL(逗号分隔)")
|
||||
private String images;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 营业时间(格式:HH:mm-HH:mm,如:10:30-22:00)
|
||||
*/
|
||||
@Schema(description="营业时间(格式:HH:mm-HH:mm)")
|
||||
private String businessHours;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+77
-40
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.admin.api.entity.SysRole;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteRoleService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
@@ -30,6 +31,10 @@ import com.bsd.pjcloud.supermarket.vo.app.MallProductSkuAppVo;
|
||||
import com.bsd.pjcloud.supermarket.vo.app.MallMerchantListAppVo;
|
||||
import com.bsd.pjcloud.supermarket.dto.SkuStockChangeDTO;
|
||||
import com.bsd.pjcloud.supermarket.constant.MallConstants;
|
||||
import com.bsd.pjcloud.supermarket.vo.mall.MallMchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.dto.MchManageDto;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -61,6 +66,7 @@ public class MallAppController {
|
||||
private final MallProductService mallProductService;
|
||||
private final MallProductSkuService mallProductSkuService;
|
||||
private final RemoteRoleService remoteRoleService;
|
||||
private final RemoteMchService remoteMchService;
|
||||
|
||||
// ==================== 分类相关接口 ====================
|
||||
|
||||
@@ -103,19 +109,25 @@ public class MallAppController {
|
||||
@Operation(summary = "获取商户列表", description = "获取所有启用的商户列表,包含特色商品")
|
||||
public R<List<MallMerchantListAppVo>> getMerchantList(@RequestParam(defaultValue = "3") Integer productLimit) {
|
||||
// 查询所有启用的商户
|
||||
List<MallMerchantEntity> merchants = mallMerchantService.list(
|
||||
Wrappers.<MallMerchantEntity>lambdaQuery()
|
||||
.eq(MallMerchantEntity::getStatus, MallConstants.Status.ENABLED)
|
||||
.orderByAsc(MallMerchantEntity::getName)
|
||||
);
|
||||
|
||||
// List<MallMerchantEntity> merchants = mallMerchantService.list(
|
||||
// Wrappers.<MallMerchantEntity>lambdaQuery()
|
||||
// .eq(MallMerchantEntity::getStatus, MallConstants.Status.ENABLED)
|
||||
// .orderByAsc(MallMerchantEntity::getName)
|
||||
// );
|
||||
MchManageDto mchManageDto = new MchManageDto();
|
||||
mchManageDto.setTypes(MerchantTypeEnum.FARMER.getType());
|
||||
R<List<MchManageVo>> listR = remoteMchService.list(mchManageDto);
|
||||
if (!listR.isOk()){
|
||||
return R.failed("商户服务异常!");
|
||||
}
|
||||
List<MchManageVo> merchants = listR.getData();
|
||||
if (merchants.isEmpty()) {
|
||||
return R.ok(List.of());
|
||||
}
|
||||
|
||||
// 获取商户ID列表
|
||||
List<Long> merchantIds = merchants.stream()
|
||||
.map(MallMerchantEntity::getId)
|
||||
.map(MchManageVo::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询每个商户的特色商品(按创建时间倒序,取前N个)
|
||||
@@ -158,13 +170,18 @@ public class MallAppController {
|
||||
|
||||
// 转换为VO
|
||||
List<MallMerchantListAppVo> result = merchants.stream().map(merchant -> {
|
||||
MallMerchantListAppVo vo = BeanUtils.toBean(merchant, MallMerchantListAppVo.class);
|
||||
|
||||
MallMerchantListAppVo mallMerchantListAppVo = new MallMerchantListAppVo();
|
||||
mallMerchantListAppVo.setId(merchant.getId());
|
||||
mallMerchantListAppVo.setAddress(merchant.getAddressDes());
|
||||
mallMerchantListAppVo.setImages(merchant.getLogoPic());
|
||||
mallMerchantListAppVo.setName(merchant.getName());
|
||||
mallMerchantListAppVo.setContactPhone(merchant.getPhone());
|
||||
|
||||
// 获取该商户的商品列表
|
||||
List<MallProductEntity> merchantProducts = productMap.getOrDefault(merchant.getId(), List.of());
|
||||
|
||||
// 设置商品总数
|
||||
vo.setProductCount(merchantProducts.size());
|
||||
mallMerchantListAppVo.setProductCount(merchantProducts.size());
|
||||
|
||||
// 获取特色商品(限制数量)
|
||||
List<MallProductListAppVo> featuredProducts = merchantProducts.stream()
|
||||
@@ -192,17 +209,17 @@ public class MallAppController {
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
vo.setFeaturedProducts(featuredProducts);
|
||||
mallMerchantListAppVo.setFeaturedProducts(featuredProducts);
|
||||
|
||||
// 设置商户营业时间
|
||||
if (merchant.getBusinessHours() != null && !merchant.getBusinessHours().trim().isEmpty()) {
|
||||
vo.setBusinessHours(merchant.getBusinessHours());
|
||||
} else {
|
||||
// 默认商户营业时间
|
||||
vo.setBusinessHours("10:00-22:00");
|
||||
}
|
||||
// if (merchant.getBusinessHours() != null && !merchant.getBusinessHours().trim().isEmpty()) {
|
||||
// vo.setBusinessHours(merchant.getBusinessHours());
|
||||
// } else {
|
||||
// // 默认商户营业时间
|
||||
// vo.setBusinessHours("10:00-22:00");
|
||||
// }
|
||||
|
||||
return vo;
|
||||
return mallMerchantListAppVo;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return R.ok(result);
|
||||
@@ -213,12 +230,24 @@ public class MallAppController {
|
||||
*/
|
||||
@GetMapping("/merchant/{id}")
|
||||
@Operation(summary = "获取商户详情", description = "根据ID获取商户详情")
|
||||
public R<MallMerchantEntity> getMerchantDetail(@PathVariable("id") Long id) {
|
||||
MallMerchantEntity merchant = mallMerchantService.getById(id);
|
||||
if (merchant == null) {
|
||||
public R<MallMchManageVo> getMerchantDetail(@PathVariable("id") Long id) {
|
||||
R<MchManageVo> mchManageVoR = remoteMchService.getById(id);
|
||||
if (!mchManageVoR.isOk()){
|
||||
return R.failed("商户服务异常!");
|
||||
}
|
||||
MchManageVo mchManageVo = mchManageVoR.getData();
|
||||
if (mchManageVo == null) {
|
||||
return R.failed("商户不存在");
|
||||
}
|
||||
return R.ok(merchant);
|
||||
MallMchManageVo mallMchManageVo = new MallMchManageVo();
|
||||
mallMchManageVo.setId(mchManageVo.getId());
|
||||
mallMchManageVo.setName(mchManageVo.getName());
|
||||
mallMchManageVo.setImages(mchManageVo.getLogoPic());
|
||||
mallMchManageVo.setContactPhone(mchManageVo.getPhone());
|
||||
mallMchManageVo.setAddress(mchManageVo.getAddressDes());
|
||||
|
||||
|
||||
return R.ok(mallMchManageVo);
|
||||
}
|
||||
|
||||
// ==================== 商品相关接口 ====================
|
||||
@@ -399,31 +428,39 @@ public class MallAppController {
|
||||
*/
|
||||
private Long validateMerchant() {
|
||||
// 获取当前用户ID
|
||||
Long currentUserId = SecurityUtils.getUser().getId();
|
||||
if (currentUserId == null) {
|
||||
Long deptId = SecurityUtils.getUser().getDeptId();
|
||||
if (deptId== null) {
|
||||
throw new BusinessException("用户未登录");
|
||||
}
|
||||
|
||||
Long merchantIdByUserId=null;
|
||||
// Long merchantIdByUserId=null;
|
||||
// 验证用户是否有商户角色
|
||||
List<Long> roleIds = SecurityUtils.getRoleIds();
|
||||
R<List<SysRole>> mallMchUserLists = remoteRoleService.findRolesByCodes(Arrays.asList(MallConstants.RoleCode.MERCHANT_USER));
|
||||
if (mallMchUserLists.isOk()) {
|
||||
List<SysRole> list = mallMchUserLists.getData();
|
||||
if (CollectionUtils.isEmpty(list) || CollUtil.isEmpty(roleIds) || !roleIds.contains(list.get(0).getRoleId())) {
|
||||
throw new BusinessException("请分配商户角色");
|
||||
}
|
||||
//有商户角色,然后查询自己绑定的商户信息
|
||||
merchantIdByUserId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
if (merchantIdByUserId == null){
|
||||
throw new BusinessException("当前用户未绑定商户");
|
||||
}
|
||||
// List<Long> roleIds = SecurityUtils.getRoleIds();
|
||||
R<MchManageVo> mchManageVoR = remoteMchService.getByDeptId(deptId, MerchantTypeEnum.FARMER);
|
||||
if (mchManageVoR.isOk()) {
|
||||
MchManageVo mchManageVo = mchManageVoR.getData();
|
||||
return mchManageVo.getId();
|
||||
|
||||
} else {
|
||||
throw new BusinessException("基础用户服务异常");
|
||||
}else {
|
||||
throw new BusinessException("该用户未分配共富商户");
|
||||
}
|
||||
// R<List<SysRole>> mallMchUserLists = remoteRoleService.findRolesByCodes(Arrays.asList(MallConstants.RoleCode.MERCHANT_USER));
|
||||
// if (mallMchUserLists.isOk()) {
|
||||
// List<SysRole> list = mallMchUserLists.getData();
|
||||
// if (CollectionUtils.isEmpty(list) || CollUtil.isEmpty(roleIds) || !roleIds.contains(list.get(0).getRoleId())) {
|
||||
// throw new BusinessException("请分配商户角色");
|
||||
// }
|
||||
//有商户角色,然后查询自己绑定的商户信息
|
||||
// merchantIdByUserId = mallMerchantUserService.getMerchantIdByUserId(currentUserId);
|
||||
// if (merchantIdByUserId == null){
|
||||
// throw new BusinessException("当前用户未绑定商户");
|
||||
// }
|
||||
|
||||
return merchantIdByUserId;
|
||||
// } else {
|
||||
// throw new BusinessException("基础用户服务异常");
|
||||
// }
|
||||
|
||||
// return merchantIdByUserId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user