From b4932501fca1f15802b8bdc9c301daad6c5a61ba Mon Sep 17 00:00:00 2001 From: xuwenbo <717567226@qq.com> Date: Wed, 19 Aug 2020 17:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E5=90=8E=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E5=B1=9E=E6=80=A7=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/yx_store_combination_update.sql | 116 ++++++++++++++++++ .../co/yixiang/annotation/DataSource.java | 15 +++ .../co/yixiang/aspect/DataSourceAspect.java | 42 +++++++ .../constant/SystemConfigConstants.java | 4 + .../activity/domain/YxStoreCombination.java | 26 ++-- .../service/YxStoreCombinationService.java | 2 + .../service/dto/YxStoreCombinationDto.java | 33 ++++- .../impl/YxStoreCombinationServiceImpl.java | 113 ++++++++++++++++- .../domain/YxStoreProductAttrValue.java | 9 ++ .../service/YxStoreProductService.java | 2 +- .../product/service/dto/ProductFormatDto.java | 8 ++ .../impl/YxStoreProductServiceImpl.java | 33 ++++- .../rest/StoreCombinationController.java | 95 +++++++++++++- .../product/rest/StoreProductController.java | 7 +- .../tools/config/WxMaConfiguration.java | 14 +-- 15 files changed, 485 insertions(+), 34 deletions(-) create mode 100644 sql/yx_store_combination_update.sql create mode 100644 yshop-common/src/main/java/co/yixiang/annotation/DataSource.java create mode 100644 yshop-common/src/main/java/co/yixiang/aspect/DataSourceAspect.java diff --git a/sql/yx_store_combination_update.sql b/sql/yx_store_combination_update.sql new file mode 100644 index 00000000..0aecd30b --- /dev/null +++ b/sql/yx_store_combination_update.sql @@ -0,0 +1,116 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本地 + Source Server Type : MySQL + Source Server Version : 50729 + Source Host : localhost:3306 + Source Schema : yshopb2c + + Target Server Type : MySQL + Target Server Version : 50729 + File Encoding : 65001 + + Date: 19/08/2020 17:07:08 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for yx_store_combination +-- ---------------------------- +DROP TABLE IF EXISTS `yx_store_combination`; +CREATE TABLE `yx_store_combination` ( + `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, + `product_id` bigint(20) UNSIGNED NOT NULL COMMENT '商品id', + `mer_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '商户id', + `image` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '推荐图', + `images` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '轮播图', + `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '活动标题', + `attr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '活动属性', + `people` int(2) UNSIGNED NOT NULL COMMENT '参团人数', + `info` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '简介', + `price` decimal(10, 2) UNSIGNED NOT NULL COMMENT '价格', + `product_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '商品原价', + `sort` int(10) UNSIGNED NOT NULL COMMENT '排序', + `sales` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '销量', + `stock` int(10) UNSIGNED NOT NULL COMMENT '库存', + `create_time` datetime(0) NOT NULL COMMENT '添加时间', + `update_time` datetime(0) NULL DEFAULT NULL, + `is_host` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '推荐', + `is_show` tinyint(1) UNSIGNED NOT NULL COMMENT '产品状态', + `is_del` tinyint(1) UNSIGNED NOT NULL DEFAULT 0, + `combination` tinyint(1) UNSIGNED NOT NULL DEFAULT 1, + `mer_use` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '商户是否可用1可用0不可用', + `description` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '拼团内容', + `start_time` datetime(0) NOT NULL COMMENT '拼团开始时间', + `stop_time` datetime(0) NOT NULL COMMENT '拼团结束时间', + `effective_time` int(11) NOT NULL DEFAULT 0 COMMENT '拼团订单有效时间', + `cost` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '拼图产品成本', + `browse` int(11) NULL DEFAULT 0 COMMENT '浏览量', + `unit_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '单位名', + `spec_type` tinyint(1) NULL DEFAULT NULL COMMENT '规格 0单 1多', + `temp_id` int(10) NULL DEFAULT NULL COMMENT '运费模板ID', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '拼团产品表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of yx_store_combination +-- ---------------------------- +INSERT INTO `yx_store_combination` VALUES (1, 19, 0, 'https://image.dayouqiantu.cn/5ca011a1cd487.jpg', 'https://image.dayouqiantu.cn/5ca01c7fc9238.jpg,https://image.dayouqiantu.cn/5ca01c7676042.jpg', '70gA4黑白打印复印', NULL, 2, '打印复印资料A4黑白彩色印刷画册书本装订图文数码快印服务', 0.10, 100.00, 1, 55, 94, '2020-06-19 16:55:51', '2020-06-25 23:00:45', 1, 1, 0, 1, 0, '1577289600', '2020-06-19 16:55:21', '2020-07-01 16:55:25', 10, 1, 1, '张', NULL, NULL); +INSERT INTO `yx_store_combination` VALUES (2, 24, 0, 'https://image.dayouqiantu.cn/5ca011a1cd487.jpg', 'https://image.dayouqiantu.cn/5ca011a1cd487.jpg', '彩色打印', NULL, 1, '彩色打印', 0.00, NULL, 0, 10, 10, '2020-06-25 23:02:07', NULL, 1, 1, 0, 1, NULL, '

彩色打印

', '2020-06-25 23:01:21', '2020-06-30 00:00:00', 24, 0, 0, '张', NULL, NULL); +INSERT INTO `yx_store_combination` VALUES (3, 29, 0, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg,https://image.dayouqiantu.cn/5ca081af6183f.jpg', '喷绘写真', NULL, 1, '喷绘写真', 0.00, NULL, 0, 0, 331, '2020-07-05 12:23:41', NULL, 1, 1, 0, 1, NULL, '

喷绘写真

', '2020-07-05 12:23:19', '2020-07-29 00:00:00', 24, 0, 0, '平方', NULL, NULL); +INSERT INTO `yx_store_combination` VALUES (4, 29, 0, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg,https://image.dayouqiantu.cn/5ca081af6183f.jpg', 'qwewq', NULL, 3, 'eqweq', 7.00, NULL, 0, 13, 318, '2020-08-19 15:00:28', NULL, 0, 1, 0, 1, NULL, '

测试拼团

', '2020-08-19 14:49:36', '2020-08-28 00:00:00', 33, 0, 0, 'weqweqw', 1, NULL); + +-- ---------------------------- +-- Table structure for yx_store_product_attr_value +-- ---------------------------- +DROP TABLE IF EXISTS `yx_store_product_attr_value`; +CREATE TABLE `yx_store_product_attr_value` ( + `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, + `product_id` bigint(20) UNSIGNED NOT NULL COMMENT '商品ID', + `sku` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '商品属性索引值 (attr_value|attr_value[|....])', + `stock` int(10) UNSIGNED NOT NULL COMMENT '属性对应的库存', + `sales` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '销量', + `price` decimal(8, 2) UNSIGNED NOT NULL COMMENT '属性金额', + `image` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图片', + `unique` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '唯一值', + `cost` decimal(8, 2) UNSIGNED NOT NULL COMMENT '成本价', + `bar_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商品条码', + `ot_price` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '原价', + `weight` decimal(8, 2) NOT NULL DEFAULT 0.00 COMMENT '重量', + `volume` decimal(8, 2) NOT NULL DEFAULT 0.00 COMMENT '体积', + `brokerage` decimal(8, 2) NOT NULL DEFAULT 0.00 COMMENT '一级返佣', + `brokerage_two` decimal(8, 2) NOT NULL DEFAULT 0.00 COMMENT '二级返佣', + `pink_price` decimal(8, 2) NULL DEFAULT NULL COMMENT '拼团价', + `pink_stock` int(10) NULL DEFAULT NULL COMMENT '拼团库存', + `seckill_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '秒杀价', + `seckill_stock` int(10) NULL DEFAULT NULL COMMENT '秒杀库存', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `unique`(`unique`, `sku`) USING BTREE, + INDEX `store_id`(`product_id`, `sku`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '商品属性值表' ROW_FORMAT = DYNAMIC; + +-- ---------------------------- +-- Records of yx_store_product_attr_value +-- ---------------------------- +INSERT INTO `yx_store_product_attr_value` VALUES (58, 28, '默认', 81, 19, 20.00, '', 'cc6bb7e388e54f65838e2635ae9ea0c7', 0.00, '', 0.00, 0.00, 0.00, 2.00, 1.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (60, 30, 'A4,白色', 2997, 0, 100.00, 'http://127.0.0.1:8001/file/pic/20200811184905881166.png', 'e22b36751d804f689c3b8f2890ddebb7', 1.00, '12312313', 200.00, 12.00, 12.00, 0.00, 0.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (61, 30, 'A4,红色', 0, 0, 0.00, 'http://127.0.0.1:8001/file/pic/20200811184905881166.png', '73aaf055b62543159f34a63b5ba08d12', 0.00, '', 0.00, 0.00, 0.00, 0.00, 0.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (62, 30, 'A3,白色', 0, 0, 0.00, 'http://127.0.0.1:8001/file/pic/20200811184905881166.png', '2f35645a0e5e4cc2aa852347a76ad8a9', 0.00, '', 0.00, 0.00, 0.00, 0.00, 0.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (63, 30, 'A3,红色', 0, 0, 0.00, 'http://127.0.0.1:8001/file/pic/20200811184905881166.png', '9b0ba66b83b1423a8bf54332513ba1fa', 0.00, '', 0.00, 0.00, 0.00, 0.00, 0.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (72, 29, 'A4,白色', 87, 0, 10.00, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', 'de1c221ef2a447e3b507cd095b17d76e', 0.00, '', 10.00, 0.00, 0.00, 1.00, 1.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (73, 29, 'A4,红色', 88, 0, 9.00, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', '55b272f734ab4572bd085c456a54eb32', 0.00, '', 10.00, 0.00, 0.00, 1.00, 1.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (74, 29, 'A3,白色', 77, 0, 8.00, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', '560be687e9b942c4adb9cf83c2fa158e', 0.00, '', 10.00, 0.00, 0.00, 1.00, 1.00, NULL, NULL, NULL, NULL); +INSERT INTO `yx_store_product_attr_value` VALUES (75, 29, 'A3,红色', 66, 0, 7.00, 'https://image.dayouqiantu.cn/5ca0786c5d2c1.jpg', '2fdd28d9c98f4e2f9406ed56e81df7c5', 0.00, '', 10.00, 0.00, 0.00, 1.00, 1.00, NULL, NULL, NULL, NULL); + +SET FOREIGN_KEY_CHECKS = 1; + +-- 菜单 +INSERT INTO `menu` VALUES (244, b'0', '拼团商品添加', 'activity/combination/form', 63, 999, NULL, 'combinationAdd', b'0', b'1', 'CombinationAdd', '2020-08-13 21:28:45', 'YXSTORECOMBINATION_EDIT', 1, '2020-08-13 21:31:26', 0); +INSERT INTO `menu` VALUES (245, b'0', '拼团商品修改', 'activity/combination/form', 63, 3, 'anq', 'combinationEdit/:id', b'0', b'1', 'CombinationEdit', '2019-12-24 13:02:23', 'YXSTORECOMBINATION_EDIT', 1, '2020-07-10 16:45:33', 0); + +-- 菜单角色的关系 +INSERT INTO `roles_menus` VALUES (244, 1); +INSERT INTO `roles_menus` VALUES (245, 1); diff --git a/yshop-common/src/main/java/co/yixiang/annotation/DataSource.java b/yshop-common/src/main/java/co/yixiang/annotation/DataSource.java new file mode 100644 index 00000000..f9050ce4 --- /dev/null +++ b/yshop-common/src/main/java/co/yixiang/annotation/DataSource.java @@ -0,0 +1,15 @@ +package co.yixiang.annotation; + +import co.yixiang.enums.DataSourceType; + +import java.lang.annotation.*; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface DataSource { + /** + * 切换数据源名称 + */ + DataSourceType value() default DataSourceType.MASTER; +} diff --git a/yshop-common/src/main/java/co/yixiang/aspect/DataSourceAspect.java b/yshop-common/src/main/java/co/yixiang/aspect/DataSourceAspect.java new file mode 100644 index 00000000..ca72e1da --- /dev/null +++ b/yshop-common/src/main/java/co/yixiang/aspect/DataSourceAspect.java @@ -0,0 +1,42 @@ +package co.yixiang.aspect; + +import co.yixiang.annotation.DataSource; +import co.yixiang.config.datasource.DynamicDataSourceContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; + +@Aspect +@Order(1) +@Component +@Slf4j +public class DataSourceAspect { + + @Pointcut("@annotation(co.yixiang.annotation.DataSource)") + public void dsPointCut() { + + } + + @Around("dsPointCut()") + public Object around(ProceedingJoinPoint point) throws Throwable { + MethodSignature signature = (MethodSignature) point.getSignature(); + Method method = signature.getMethod(); + DataSource dataSource = method.getAnnotation(DataSource.class); + if (dataSource != null) { + DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name()); + } + try { + return point.proceed(); + } finally { + // 销毁数据源 在执行方法之后 + DynamicDataSourceContextHolder.clearDataSourceType(); + } + } +} diff --git a/yshop-common/src/main/java/co/yixiang/constant/SystemConfigConstants.java b/yshop-common/src/main/java/co/yixiang/constant/SystemConfigConstants.java index 635d4c5a..cb489b49 100644 --- a/yshop-common/src/main/java/co/yixiang/constant/SystemConfigConstants.java +++ b/yshop-common/src/main/java/co/yixiang/constant/SystemConfigConstants.java @@ -49,4 +49,8 @@ public class SystemConfigConstants { public final static String WX_NATIVE_APP_APPID="wx_native_app_appId"; public final static String EXP_APPID = "exp_appId"; + + //播放状态变化事件,detail = {code} + public static final String BINDSTATECHANGE = "bindstatechange"; + } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/activity/domain/YxStoreCombination.java b/yshop-mall/src/main/java/co/yixiang/modules/activity/domain/YxStoreCombination.java index 45323afe..fe3274ad 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/activity/domain/YxStoreCombination.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/activity/domain/YxStoreCombination.java @@ -8,14 +8,19 @@ package co.yixiang.modules.activity.domain; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.copier.CopyOptions; import co.yixiang.domain.BaseDomain; +import co.yixiang.modules.product.service.dto.FromatDetailDto; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.EqualsAndHashCode; import javax.validation.constraints.*; import java.math.BigDecimal; import java.util.Date; +import java.util.List; +import java.util.Map; /** * @author hupeng @@ -105,14 +110,6 @@ public class YxStoreCombination extends BaseDomain { private Integer merUse; - /** 是否包邮1是0否 */ - private Integer isPostage; - - - /** 邮费 */ - private BigDecimal postage; - - /** 拼团内容 */ @NotBlank(message = "请填写详情") private String description; @@ -145,10 +142,23 @@ public class YxStoreCombination extends BaseDomain { /** 单位名 */ private String unitName; + private Integer specType; + + /** 运费模板ID */ + @JsonProperty("temp_id") + private Long tempId; + //属性项目 + @TableField(exist = false) + private List items; + + //sku结果集 + @TableField(exist = false) + private List> attrs; public void copy(YxStoreCombination source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } + } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreCombinationService.java b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreCombinationService.java index 1189c141..dcc68d33 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreCombinationService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreCombinationService.java @@ -92,4 +92,6 @@ public interface YxStoreCombinationService extends BaseService sliderImage; + //参与人数 private Integer countPeopleAll; @@ -45,9 +58,6 @@ public class YxStoreCombinationDto implements Serializable { // 活动标题 private String title; - // 活动属性 - private String attr; - // 参团人数 private Integer people; @@ -109,4 +119,15 @@ public class YxStoreCombinationDto implements Serializable { // 单位名 private String unitName; + /** 规格 0单 1多 */ + @JsonProperty("spec_type") + private Integer specType; + + private ProductFormatDto attr; + //属性项目 + private List items; + + //sku结果集 + private List> attrs; + } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCombinationServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCombinationServiceImpl.java index 5f31c30e..5473d7bd 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCombinationServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCombinationServiceImpl.java @@ -8,11 +8,15 @@ */ package co.yixiang.modules.activity.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.map.MapUtil; import co.yixiang.api.YshopException; import co.yixiang.common.service.impl.BaseServiceImpl; import co.yixiang.common.utils.QueryHelpPlus; import co.yixiang.dozer.service.IGenerator; import co.yixiang.enums.ShopCommonEnum; +import co.yixiang.enums.SpecTypeEnum; import co.yixiang.modules.activity.domain.YxStoreCombination; import co.yixiang.modules.activity.domain.YxStorePink; import co.yixiang.modules.activity.domain.YxStoreVisit; @@ -26,7 +30,13 @@ import co.yixiang.modules.activity.service.mapper.YxStorePinkMapper; import co.yixiang.modules.activity.service.mapper.YxStoreVisitMapper; import co.yixiang.modules.activity.vo.StoreCombinationVo; import co.yixiang.modules.activity.vo.YxStoreCombinationQueryVo; +import co.yixiang.modules.product.domain.YxStoreProduct; +import co.yixiang.modules.product.service.YxStoreProductAttrService; +import co.yixiang.modules.product.service.YxStoreProductAttrValueService; import co.yixiang.modules.product.service.YxStoreProductReplyService; +import co.yixiang.modules.product.service.dto.FromatDetailDto; +import co.yixiang.modules.product.service.dto.ProductFormatDto; +import co.yixiang.modules.product.service.dto.ProductResultDto; import co.yixiang.utils.FileUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -39,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.math.BigDecimal; import java.util.*; @@ -48,7 +59,7 @@ import java.util.*; * @date 2020-05-13 */ @Service -@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class) +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class YxStoreCombinationServiceImpl extends BaseServiceImpl implements YxStoreCombinationService { @Autowired @@ -65,6 +76,10 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl> attrs = resources.getAttrs(); + Map map = attrs.get(0); + map.put("value1","规格"); + map.put("detail", MapUtil.of(new String[][] { + {"规格", "默认"} + })); + yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto), + ListUtil.toList(map),resources.getProductId()); + }else{ + yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(), + resources.getAttrs(),resources.getProductId()); + } + return true; + } + + + /** + * 计算产品数据 + * @param attrs attrs + * @return ProductResultDto + */ + private ProductResultDto computedProduct(List> attrs){ + //取最小价格 + Double minPrice = ListMapToListBean(attrs) + .stream() + .map(ProductFormatDto::getPrice) + .min(Comparator.naturalOrder()) + .orElse(0d); + + Double minOtPrice = ListMapToListBean(attrs) + .stream() + .map(ProductFormatDto::getOtPrice) + .min(Comparator.naturalOrder()) + .orElse(0d); + + Double minCost = ListMapToListBean(attrs) + .stream() + .map(ProductFormatDto::getCost) + .min(Comparator.naturalOrder()) + .orElse(0d); + //计算库存 + Integer stock = ListMapToListBean(attrs) + .stream() + .map(ProductFormatDto::getStock) + .reduce(Integer::sum) + .orElse(0); + + if(stock <= 0) throw new YshopException("库存不能低于0"); + + return ProductResultDto.builder() + .minPrice(minPrice) + .minOtPrice(minOtPrice) + .minCost(minCost) + .stock(stock) + .build(); + } + + /** + * mapTobean + * @param listMap listMap + * @return list + */ + private List ListMapToListBean(List> listMap){ + List list = new ArrayList<>(); + // 循环遍历出map对象 + for (Map m : listMap) { + list.add(BeanUtil.mapToBean(m,ProductFormatDto.class,true)); + } + return list; + } } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/domain/YxStoreProductAttrValue.java b/yshop-mall/src/main/java/co/yixiang/modules/product/domain/YxStoreProductAttrValue.java index 06e7f0e0..6ca136fc 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/domain/YxStoreProductAttrValue.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/domain/YxStoreProductAttrValue.java @@ -43,6 +43,11 @@ public class YxStoreProductAttrValue implements Serializable { /** 属性对应的库存 */ private Integer stock; + /** 拼团库存属性对应的库存 */ + private Integer pinkStock; + + /** 秒杀库存属性对应的库存 */ + private Integer seckillStock; /** 销量 */ private Integer sales; @@ -51,7 +56,11 @@ public class YxStoreProductAttrValue implements Serializable { /** 属性金额 */ private BigDecimal price; + /** 拼团属性对应的金额 */ + private BigDecimal pinkPrice; + /** 秒杀属性对应的金额 */ + private BigDecimal seckillPrice; /** 图片 */ private String image; diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductService.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductService.java index b8dbf850..2b434966 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductService.java @@ -126,7 +126,7 @@ public interface YxStoreProductService extends BaseService{ * @param jsonStr jsonStr * @return map */ - Map getFormatAttr(Long id, String jsonStr); + Map getFormatAttr(Long id, String jsonStr,boolean isActivity); diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/ProductFormatDto.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/ProductFormatDto.java index 3e8131be..c8acd385 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/ProductFormatDto.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/ProductFormatDto.java @@ -50,6 +50,14 @@ public class ProductFormatDto { private Double weight = 0d; + private Double pinkPrice = 0d; + + private Integer pinkStock = 0; + + private Double seckillPrice = 0d; + + private Integer seckillStock = 0; + private Map detail; } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java index b4f27a47..8cf1b941 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java @@ -498,7 +498,7 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl getFormatAttr(Long id, String jsonStr) { + public Map getFormatAttr(Long id, String jsonStr,boolean isActivity) { JSONObject jsonObject = JSON.parseObject(jsonStr); Map resultMap = new LinkedHashMap<>(3); @@ -588,7 +588,7 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl headerMap,List> headerMapList,String align){ + private void addMap(Map headerMap,List> headerMapList,String align,boolean isActivity){ headerMap.put("title","图片"); headerMap.put("slot", "pic"); headerMap.put("align",align); @@ -711,7 +711,32 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl(yxStoreCombinationService.saveCombination(resources),HttpStatus.CREATED); + } + @ApiOperation(value = "获取商品信息") + @GetMapping(value = "/yxStoreCombination/info/{id}") + public ResponseEntity info(@PathVariable Long id){ + Map map = new LinkedHashMap<>(3); + + //运费模板 + List shippingTemplatesList = yxShippingTemplatesService.list(); + map.put("tempList", shippingTemplatesList); + +// //商品分类 +// List storeCategories = yxStoreCategoryService.lambdaQuery() +// .eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue()) +// .list(); + +// List> 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); + } + + //处理商品详情 + YxStoreCombination yxStoreCombination = yxStoreCombinationService.getById(id); + YxStoreCombinationDto productDto = new YxStoreCombinationDto(); + BeanUtil.copyProperties(yxStoreCombination,productDto,"images"); + productDto.setSliderImage(Arrays.asList(yxStoreCombination.getImages().split(","))); + YxStoreProductAttrResult storeProductAttrResult = yxStoreProductAttrResultService + .getOne(Wrappers.lambdaQuery() + .eq(YxStoreProductAttrResult::getProductId,yxStoreCombination.getProductId()).last("limit 1")); + JSONObject result = JSON.parseObject(storeProductAttrResult.getResult()); + + if(SpecTypeEnum.TYPE_1.getValue().equals(yxStoreCombination.getSpecType())){ + productDto.setAttr(new ProductFormatDto()); + productDto.setAttrs(result.getObject("value",ArrayList.class)); + productDto.setItems(result.getObject("attr",ArrayList.class)); + }else{ + Map mapAttr = (Map)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); + } @Log("修改拼团") @ApiOperation(value = "新增/修改拼团") @PutMapping(value = "/yxStoreCombination") diff --git a/yshop-shop/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java b/yshop-shop/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java index c9662db5..67c96a53 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java @@ -121,11 +121,16 @@ public class StoreProductController { yxStoreProductService.onSale(id,status); return new ResponseEntity(HttpStatus.OK); } + @ApiOperation(value = "生成属性(添加活动产品专用)") + @PostMapping(value = "/yxStoreProduct/isFormatAttrForActivity/{id}") + public ResponseEntity isFormatAttrForActivity(@PathVariable Long id,@RequestBody String jsonStr){ + return new ResponseEntity<>(yxStoreProductService.getFormatAttr(id,jsonStr,true),HttpStatus.OK); + } @ApiOperation(value = "生成属性") @PostMapping(value = "/yxStoreProduct/isFormatAttr/{id}") public ResponseEntity isFormatAttr(@PathVariable Long id,@RequestBody String jsonStr){ - return new ResponseEntity<>(yxStoreProductService.getFormatAttr(id,jsonStr),HttpStatus.OK); + return new ResponseEntity<>(yxStoreProductService.getFormatAttr(id,jsonStr,false),HttpStatus.OK); } diff --git a/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java b/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java index c678fc1e..acdc4fe7 100644 --- a/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java +++ b/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java @@ -8,6 +8,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.message.WxMaMessageHandler; import cn.binarywang.wx.miniapp.message.WxMaMessageRouter; +import co.yixiang.constant.SystemConfigConstants; import co.yixiang.utils.RedisUtil; import co.yixiang.utils.RedisUtils; import co.yixiang.utils.ShopKeyUtils; @@ -71,17 +72,12 @@ public class WxMaConfiguration { final WxMaMessageRouter router = new WxMaMessageRouter(service); router .rule().handler(wxMaMessageHandler).next() - .rule().async(false).msgType(WxConsts.XmlMsgType.EVENT).event(WxConsts.EventType.SUBSCRIBE).handler(templateMsgHandler).end(); + .rule().async(false).msgType(WxConsts.XmlMsgType.EVENT).event(SystemConfigConstants.BINDSTATECHANGE).handler(bindstatechangeHandler).end(); return router; } - private static final WxMaMessageHandler templateMsgHandler = (wxMessage, context, service, sessionManager) -> { - service.getMsgService().sendSubscribeMsg(WxMaSubscribeMessage.builder() - .templateId("此处更换为自己的模板id") - .page("") - .data(Lists.newArrayList( - new WxMaSubscribeMessage.Data("keyword1", "339208499"))) - .toUser(wxMessage.getFromUser()) - .build()); + private static final WxMaMessageHandler bindstatechangeHandler = (wxMessage, context, service, sessionManager) -> { + wxMessage.getFromUser(); + wxMessage.getContent(); return null; }; }