|
|
@@ -0,0 +1,102 @@
|
|
|
+package com.fs.app.controller;
|
|
|
+
|
|
|
+import com.fs.app.annotation.Login;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductAttrValueScrmService;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
+import com.fs.hisStore.vo.FsStoreProductListVO;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Api("商城产品")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/storeProduct")
|
|
|
+public class StoreProductController extends AppBaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductScrmService fsStoreProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsStoreProductAttrValueScrmService attrValueService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询本公司下的商城产品列表
|
|
|
+ */
|
|
|
+ @Login
|
|
|
+ @ApiOperation("查询本公司下的商城产品列表")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public R list(Integer page, Integer pageSize, String productName) {
|
|
|
+ if (page == null || page < 1) {
|
|
|
+ page = 1;
|
|
|
+ }
|
|
|
+ if (pageSize == null || pageSize < 1) {
|
|
|
+ pageSize = 10;
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page, pageSize);
|
|
|
+ FsStoreProductScrm query = new FsStoreProductScrm();
|
|
|
+ query.setIsDel(0);
|
|
|
+ query.setIsShow(1);
|
|
|
+ query.setIsAudit("1");
|
|
|
+ query.setCompanyIds(String.valueOf(getCompanyId()));
|
|
|
+ if (StringUtils.isNotEmpty(productName)) {
|
|
|
+ query.setProductName(productName);
|
|
|
+ }
|
|
|
+ List<FsStoreProductListVO> list = fsStoreProductService.selectFsStoreProductListVO(query);
|
|
|
+ PageInfo<FsStoreProductListVO> pageInfo = new PageInfo<>(list);
|
|
|
+ return R.ok().put("data", pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看商品详情
|
|
|
+ */
|
|
|
+ @Login
|
|
|
+ @ApiOperation("查看商品详情")
|
|
|
+ @GetMapping("/{productId}")
|
|
|
+ public R getInfo(@PathVariable("productId") Long productId) {
|
|
|
+ FsStoreProductScrm product = fsStoreProductService.selectFsStoreProductById(productId);
|
|
|
+ if (product == null) {
|
|
|
+ return R.error("商品不存在");
|
|
|
+ }
|
|
|
+ // 校验该商品是否属于当前公司
|
|
|
+ String companyIds = product.getCompanyIds();
|
|
|
+ Long companyId = getCompanyId();
|
|
|
+ if (StringUtils.isEmpty(companyIds) || !containsCompanyId(companyIds, companyId)) {
|
|
|
+ return R.error("无权查看该商品");
|
|
|
+ }
|
|
|
+ // 查询商品规格属性值
|
|
|
+ FsStoreProductAttrValueScrm attrQuery = new FsStoreProductAttrValueScrm();
|
|
|
+ attrQuery.setProductId(productId);
|
|
|
+ List<FsStoreProductAttrValueScrm> values = attrValueService.selectFsStoreProductAttrValueList(attrQuery);
|
|
|
+ return R.ok().put("product", product).put("values", values);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断 companyIds 字符串中是否包含指定 companyId
|
|
|
+ * companyIds 格式可能是 "123" 或 "123,456" 等
|
|
|
+ */
|
|
|
+ private boolean containsCompanyId(String companyIds, Long companyId) {
|
|
|
+ if (StringUtils.isEmpty(companyIds)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String[] ids = companyIds.split(",");
|
|
|
+ for (String id : ids) {
|
|
|
+ if (id.trim().equals(String.valueOf(companyId))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|