|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.api.action; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.entity.ShopSalesmanGrade; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.component.redis.RedisUserLoginUtils; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Controller; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Collections; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author pengliang | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopProductCommentDao productCommentDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopSalesmanGradeDao shopSalesmanGradeDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据id查询商品信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/getProductById/{shopId}/{id}") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public AjaxResult getProductById(@PathVariable Long shopId, @PathVariable("id") Integer id) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|---|
|  |  |  | ShopProduct shopProduct = shopProductDao.selectById(id); | 
|---|
|  |  |  | if (shopProduct == null) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "没有查询到商品"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ShopProductAttrRef> shopProductAttrRefs = shopProductAttrRefDao.selectByPid(id); | 
|---|
|  |  |  | List<ShopProductImg> shopProductImgs = shopProductImgDao.selectByPid(id); | 
|---|
|  |  |  | List<ShopSku> shopSkus = shopSkuDao.selectByPid(id); | 
|---|
|  |  |  | if(SysVipInfo.IS_SALES==sysVipInfo.getIsSales()){ | 
|---|
|  |  |  | ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectById(sysVipInfo.getSalesmanGrade()); | 
|---|
|  |  |  | //计算产品佣金 | 
|---|
|  |  |  | shopSkus.forEach(shopSku -> { | 
|---|
|  |  |  | if(Objects.isNull(shopSku.getInvitationPrice())){ | 
|---|
|  |  |  | shopSku.setInvitationPrice(shopSku.getPrice().multiply(BigDecimal.valueOf(shopSalesmanGrade.getInvitationCommission())).divide(BigDecimal.valueOf(100))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.isNull(shopSku.getSealesPrice())){ | 
|---|
|  |  |  | shopSku.setSealesPrice(shopSku.getPrice().multiply(BigDecimal.valueOf(shopSalesmanGrade.getSealesCommission())).divide(BigDecimal.valueOf(100))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Objects.isNull(shopSku.getSelfPrice())){ | 
|---|
|  |  |  | shopSku.setSealesPrice(shopSku.getPrice().multiply(BigDecimal.valueOf(shopSalesmanGrade.getSelfCommission())).divide(BigDecimal.valueOf(100))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<ShopProductParamRef> shopProductParamRefs = shopProductParamRefDao.selectByPid(id); | 
|---|
|  |  |  | shopProduct.setAttrRefs(shopProductAttrRefs); | 
|---|
|  |  |  | shopProduct.setProductImgs(shopProductImgs); | 
|---|