秒杀添加sku
This commit is contained in:
@ -5,12 +5,26 @@
|
||||
*/
|
||||
package co.yixiang.modules.activity.rest;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.enums.SpecTypeEnum;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.activity.domain.YxStoreSeckill;
|
||||
import co.yixiang.modules.activity.domain.YxStoreSeckill;
|
||||
import co.yixiang.modules.activity.service.YxStoreSeckillService;
|
||||
import co.yixiang.modules.activity.service.dto.YxStoreSeckillDto;
|
||||
import co.yixiang.modules.activity.service.dto.YxStoreSeckillDto;
|
||||
import co.yixiang.modules.activity.service.dto.YxStoreSeckillQueryCriteria;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttrResult;
|
||||
import co.yixiang.modules.product.service.YxStoreProductAttrResultService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductRuleService;
|
||||
import co.yixiang.modules.product.service.dto.ProductFormatDto;
|
||||
import co.yixiang.modules.template.domain.YxShippingTemplates;
|
||||
import co.yixiang.modules.template.service.YxShippingTemplatesService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@ -18,13 +32,9 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
@ -36,9 +46,14 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class StoreSeckillController {
|
||||
|
||||
private final YxStoreSeckillService yxStoreSeckillService;
|
||||
|
||||
public StoreSeckillController(YxStoreSeckillService yxStoreSeckillService) {
|
||||
private final YxShippingTemplatesService yxShippingTemplatesService;
|
||||
private final YxStoreProductRuleService yxStoreProductRuleService;
|
||||
private final YxStoreProductAttrResultService yxStoreProductAttrResultService;
|
||||
public StoreSeckillController(YxStoreSeckillService yxStoreSeckillService, YxShippingTemplatesService yxShippingTemplatesService, YxStoreProductRuleService yxStoreProductRuleService, YxStoreProductAttrResultService yxStoreProductAttrResultService) {
|
||||
this.yxStoreSeckillService = yxStoreSeckillService;
|
||||
this.yxShippingTemplatesService = yxShippingTemplatesService;
|
||||
this.yxStoreProductRuleService = yxStoreProductRuleService;
|
||||
this.yxStoreProductAttrResultService = yxStoreProductAttrResultService;
|
||||
}
|
||||
|
||||
@Log("列表")
|
||||
@ -73,4 +88,78 @@ public class StoreSeckillController {
|
||||
yxStoreSeckillService.removeById(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增秒杀")
|
||||
@ApiOperation(value = "新增秒杀")
|
||||
@PostMapping(value = "/yxStoreSeckill")
|
||||
@PreAuthorize("hasAnyRole('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_EDIT')")
|
||||
public ResponseEntity add(@Validated @RequestBody YxStoreSeckillDto resources){
|
||||
return new ResponseEntity<>(yxStoreSeckillService.saveSeckill(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取商品信息")
|
||||
@GetMapping(value = "/yxStoreSecKill/info/{id}")
|
||||
public ResponseEntity info(@PathVariable Long id){
|
||||
Map<String,Object> map = new LinkedHashMap<>(3);
|
||||
|
||||
//运费模板
|
||||
List<YxShippingTemplates> shippingTemplatesList = yxShippingTemplatesService.list();
|
||||
map.put("tempList", shippingTemplatesList);
|
||||
|
||||
// //商品分类
|
||||
// List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery()
|
||||
// .eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
|
||||
// .list();
|
||||
|
||||
// List<Map<String,Object>> cateList = new ArrayList<>();
|
||||
// map.put("cateList", this.makeCate(storeCategories,cateList,0,1));
|
||||
|
||||
//商品规格
|
||||
map.put("ruleList",yxStoreProductRuleService.list());
|
||||
|
||||
|
||||
if(id == 0){
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
//处理商品详情
|
||||
YxStoreSeckill yxStoreSeckill = yxStoreSeckillService.getById(id);
|
||||
YxStoreSeckillDto productDto = new YxStoreSeckillDto();
|
||||
BeanUtil.copyProperties(yxStoreSeckill,productDto,"images");
|
||||
productDto.setSliderImage(Arrays.asList(yxStoreSeckill.getImages().split(",")));
|
||||
YxStoreProductAttrResult storeProductAttrResult = yxStoreProductAttrResultService
|
||||
.getOne(Wrappers.<YxStoreProductAttrResult>lambdaQuery()
|
||||
.eq(YxStoreProductAttrResult::getProductId,yxStoreSeckill.getProductId()).last("limit 1"));
|
||||
JSONObject result = JSON.parseObject(storeProductAttrResult.getResult());
|
||||
|
||||
if(SpecTypeEnum.TYPE_1.getValue().equals(yxStoreSeckill.getSpecType())){
|
||||
productDto.setAttr(new ProductFormatDto());
|
||||
productDto.setAttrs(result.getObject("value", ArrayList.class));
|
||||
productDto.setItems(result.getObject("attr",ArrayList.class));
|
||||
}else{
|
||||
Map<String,Object> mapAttr = (Map<String,Object>)result.getObject("value",ArrayList.class).get(0);
|
||||
ProductFormatDto productFormatDto = ProductFormatDto.builder()
|
||||
.pic(mapAttr.get("pic").toString())
|
||||
.price(Double.valueOf(mapAttr.get("price").toString()))
|
||||
.pinkPrice(Double.valueOf(mapAttr.get("pink_price").toString()))
|
||||
.cost(Double.valueOf(mapAttr.get("cost").toString()))
|
||||
.otPrice(Double.valueOf(mapAttr.get("ot_price").toString()))
|
||||
.stock(Integer.valueOf(mapAttr.get("stock").toString()))
|
||||
.pinkStock(Integer.valueOf(mapAttr.get("pink_stock").toString()))
|
||||
.barCode(mapAttr.get("bar_code").toString())
|
||||
.weight(Double.valueOf(mapAttr.get("weight").toString()))
|
||||
.volume(Double.valueOf(mapAttr.get("volume").toString()))
|
||||
.brokerage(Double.valueOf(mapAttr.get("brokerage").toString()))
|
||||
.brokerageTwo(Double.valueOf(mapAttr.get("brokerage_two").toString()))
|
||||
.brokerageTwo(Double.valueOf(mapAttr.get("brokerage_two").toString()))
|
||||
.brokerageTwo(Double.valueOf(mapAttr.get("brokerage_two").toString()))
|
||||
.build();
|
||||
productDto.setAttr(productFormatDto);
|
||||
}
|
||||
|
||||
|
||||
map.put("productInfo",productDto);
|
||||
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user