|
|
@@ -0,0 +1,58 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.GiftConfigVO;
|
|
|
+import com.etotem.cfc.dto.ProductGiftItemDTO;
|
|
|
+import com.etotem.cfc.service.ProductGiftService;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/product-gift")
|
|
|
+public class AdminProductGiftController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProductGiftService giftService;
|
|
|
+
|
|
|
+ /** 保存某商品某等级的赠品配置(幂等:先删后插) */
|
|
|
+ @PostMapping("/save")
|
|
|
+ public Result<Void> save(@RequestBody Map<String, Object> params) {
|
|
|
+ Long productId = Long.parseLong(params.get("productId").toString());
|
|
|
+ String levelCode = params.get("levelCode").toString();
|
|
|
+ Integer status = Integer.parseInt(params.get("status").toString());
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Map<String, Object>> itemsMap = (List<Map<String, Object>>) params.get("items");
|
|
|
+ List<ProductGiftItemDTO> items = null;
|
|
|
+ if (itemsMap != null) {
|
|
|
+ items = new ArrayList<>();
|
|
|
+ for (Map<String, Object> m : itemsMap) {
|
|
|
+ ProductGiftItemDTO dto = new ProductGiftItemDTO();
|
|
|
+ Object id = m.get("id");
|
|
|
+ dto.setId(id != null ? Long.parseLong(id.toString()) : null);
|
|
|
+ dto.setGiftType((String) m.get("giftType"));
|
|
|
+ Object gpId = m.get("giftProductId");
|
|
|
+ dto.setGiftProductId(gpId != null ? Long.parseLong(gpId.toString()) : null);
|
|
|
+ Object cf = m.get("cfValue");
|
|
|
+ dto.setCfValue(cf != null ? Integer.parseInt(cf.toString()) : 0);
|
|
|
+ Object sort = m.get("sortOrder");
|
|
|
+ dto.setSortOrder(sort != null ? Integer.parseInt(sort.toString()) : 0);
|
|
|
+ items.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return giftService.saveGiftConfig(productId, levelCode, status, items);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 查询某商品的全部等级赠品配置(管理端回显) */
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<GiftConfigVO>> list(@RequestBody Map<String, Object> params) {
|
|
|
+ Long productId = Long.parseLong(params.get("productId").toString());
|
|
|
+ return Result.success(giftService.listConfigsByProduct(productId));
|
|
|
+ }
|
|
|
+}
|