|
@@ -0,0 +1,158 @@
|
|
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.entity.CategoryPpoint;
|
|
|
|
|
+import com.etotem.cfc.entity.ProductPpoint;
|
|
|
|
|
+import com.etotem.cfc.service.PpointConfigService;
|
|
|
|
|
+import com.etotem.cfc.service.PpointService;
|
|
|
|
|
+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.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * P点配置管理(品类级比例 + 商品级固定值)
|
|
|
|
|
+ * 管理端接口
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/admin/ppoint-config")
|
|
|
|
|
+public class PpointConfigAdminController {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private PpointConfigService ppointConfigService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private PpointService ppointService;
|
|
|
|
|
+
|
|
|
|
|
+ // ======================== 品类级P点比例 ========================
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/category/list")
|
|
|
|
|
+ public Result<Map<String, Object>> categoryList(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
|
|
+
|
|
|
|
|
+ Page<CategoryPpoint> pageParam = new Page<>(page, size);
|
|
|
|
|
+ Map<String, Object> result = ppointConfigService.adminCategoryList(pageParam, keyword);
|
|
|
|
|
+ return Result.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/category/save")
|
|
|
|
|
+ public Result<Void> categorySave(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long categoryId = Long.valueOf(params.get("categoryId").toString());
|
|
|
|
|
+ Integer ratio = Integer.valueOf(params.get("ratio").toString());
|
|
|
|
|
+ String startDateStr = (String) params.get("startDate");
|
|
|
|
|
+ String endDateStr = (String) params.get("endDate");
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+ java.util.Date startDate = null;
|
|
|
|
|
+ java.util.Date endDate = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (startDateStr != null && !startDateStr.isEmpty()) {
|
|
|
|
|
+ startDate = sdf.parse(startDateStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (endDateStr != null && !endDateStr.isEmpty()) {
|
|
|
|
|
+ endDate = sdf.parse(endDateStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return Result.error("日期格式错误,请使用yyyy-MM-dd");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ratio < 0 || ratio > 1000) {
|
|
|
|
|
+ return Result.error("P点比例取值范围为0-1000(即0%-100%)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ppointConfigService.saveCategoryRatio(categoryId, ratio, startDate, endDate, null);
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/category/delete")
|
|
|
|
|
+ public Result<Void> categoryDelete(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
|
|
+ ppointConfigService.deleteCategoryRatio(id);
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/category/by-category")
|
|
|
|
|
+ public Result<List<CategoryPpoint>> categoryByCategory(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long categoryId = Long.valueOf(params.get("categoryId").toString());
|
|
|
|
|
+ List<CategoryPpoint> records = ppointConfigService.getByCategoryId(categoryId);
|
|
|
|
|
+ return Result.success(records);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ======================== 商品级P点(复用PpointService) ========================
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/product/list")
|
|
|
|
|
+ public Result<Map<String, Object>> productList(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
|
|
+ Long productId = params.get("productId") != null ? Long.valueOf(params.get("productId").toString()) : null;
|
|
|
|
|
+
|
|
|
|
|
+ Page<ProductPpoint> pageParam = new Page<>(page, size);
|
|
|
|
|
+ Map<String, Object> result = ppointService.adminList(pageParam, keyword, productId);
|
|
|
|
|
+ return Result.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/product/save")
|
|
|
|
|
+ public Result<Void> productSave(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long productId = Long.valueOf(params.get("productId").toString());
|
|
|
|
|
+ Integer ppoint = Integer.valueOf(params.get("ppoint").toString());
|
|
|
|
|
+ String startDateStr = (String) params.get("startDate");
|
|
|
|
|
+ String endDateStr = (String) params.get("endDate");
|
|
|
|
|
+
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+ java.util.Date startDate = null;
|
|
|
|
|
+ java.util.Date endDate = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (startDateStr != null && !startDateStr.isEmpty()) {
|
|
|
|
|
+ startDate = sdf.parse(startDateStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (endDateStr != null && !endDateStr.isEmpty()) {
|
|
|
|
|
+ endDate = sdf.parse(endDateStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return Result.error("日期格式错误,请使用yyyy-MM-dd");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ppoint < 0 || ppoint > 10000) {
|
|
|
|
|
+ return Result.error("P点取值范围为0-10000(即0%-100%)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ppointService.savePpoint(productId, ppoint, startDate, endDate, null);
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/product/delete")
|
|
|
|
|
+ public Result<Void> productDelete(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
|
|
+ ppointService.deleteById(id);
|
|
|
|
|
+ return Result.success(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/product/by-product")
|
|
|
|
|
+ public Result<List<ProductPpoint>> productByProduct(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long productId = Long.valueOf(params.get("productId").toString());
|
|
|
|
|
+ List<ProductPpoint> records = ppointService.getByProductId(productId);
|
|
|
|
|
+ return Result.success(records);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ======================== 综合查询 ========================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取商品综合有效的P点值
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/effective")
|
|
|
|
|
+ public Result<Integer> getEffectivePpoint(@RequestBody Map<String, Object> params) {
|
|
|
|
|
+ Long productId = Long.valueOf(params.get("productId").toString());
|
|
|
|
|
+ Long categoryId = params.get("categoryId") != null ? Long.valueOf(params.get("categoryId").toString()) : null;
|
|
|
|
|
+ int ppoint = ppointConfigService.getEffectivePpoint(productId, categoryId);
|
|
|
|
|
+ return Result.success(ppoint);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|