From 22bb4c6d15bc3fea998cc7de520c7722ed717eb8 Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Mon, 8 Apr 2024 17:35:32 +0800 Subject: [PATCH 001/134] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/SysDictDetailMapper.java | 4 + .../dao/TagProductDeptsMapper.java | 91 ++++++++++++++ .../entity/TagProductDepts.java | 53 ++++++++ .../cashierservice/entity/TbShopInfo.java | 12 ++ .../cashierservice/entity/vo/HomeVO.java | 16 +++ .../entity/vo/TagProductVO.java | 34 +++++ .../service/HomePageService.java | 28 +++-- .../system/cashierservice/util/DateUtils.java | 35 ++++++ .../mapper/TagProductDeptsMapper.xml | 117 ++++++++++++++++++ .../resources/mapper/TbShopInfoMapper.xml | 2 +- 10 files changed, 380 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java create mode 100644 src/main/resources/mapper/TagProductDeptsMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java index d8fad88..70a1981 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java @@ -2,10 +2,14 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.SysDict; import com.chaozhanggui.system.cashierservice.entity.SysDictDetail; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; import java.util.List; +@Component +@Mapper public interface SysDictDetailMapper { int deleteByPrimaryKey(Long detailId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java new file mode 100644 index 0000000..0b63548 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java @@ -0,0 +1,91 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TagProductDepts; +import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * (TagProductDepts)表数据库访问层 + * + * @author lyf + * @since 2024-04-08 15:03:49 + */ +@Component +@Mapper +public interface TagProductDeptsMapper { + + /** + * 通过ID查询单条数据 + * + * @param tagId 主键 + * @return 实例对象 + */ + TagProductDepts queryById(Integer tagId); + + /** + * 查询指定行数据 + * + * @param tagProductDepts 查询条件 + * @param pageable 分页对象 + * @return 对象列表 + */ + List queryAllByLimit(TagProductDepts tagProductDepts, @Param("pageable") Pageable pageable); + + List queryTagAndProduct(@Param("list") List list); + + /** + * 统计总行数 + * + * @param tagProductDepts 查询条件 + * @return 总行数 + */ + long count(TagProductDepts tagProductDepts); + + /** + * 新增数据 + * + * @param tagProductDepts 实例对象 + * @return 影响行数 + */ + int insert(TagProductDepts tagProductDepts); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tagProductDepts 实例对象 + * @return 影响行数 + */ + int update(TagProductDepts tagProductDepts); + + /** + * 通过主键删除数据 + * + * @param tagId 主键 + * @return 影响行数 + */ + int deleteById(Integer tagId); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java new file mode 100644 index 0000000..37e6904 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java @@ -0,0 +1,53 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.util.Date; +import java.io.Serializable; + +/** + * (TagProductDepts)实体类 + * + * @author lyf + * @since 2024-04-08 14:57:05 + */ +public class TagProductDepts implements Serializable { + private static final long serialVersionUID = -39116122966010022L; + /** + * 标签id + */ + private Integer tagId; + /** + * 商品id + */ + private Integer productId; + /** + * 创建时间 + */ + private Date createTime; + + + public Integer getTagId() { + return tagId; + } + + public void setTagId(Integer tagId) { + this.tagId = tagId; + } + + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java index 54863e8..f257a2b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java @@ -95,6 +95,18 @@ public class TbShopInfo implements Serializable { * 商家二维码 */ private String shopQrcode; + /** + * 商户标签 + */ + private String tag; + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } public String getShopQrcode() { return shopQrcode; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index 8e39f17..bd9350b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -1,6 +1,9 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import org.springframework.format.annotation.DateTimeFormat; + import java.math.BigDecimal; +import java.util.Date; /** * @author lyf @@ -55,6 +58,19 @@ public class HomeVO { private String distances ="100"; private Integer id; + /** + * 结束时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String endTime; + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } public Integer getId() { return id; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java new file mode 100644 index 0000000..939d5cc --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java @@ -0,0 +1,34 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +/** + * @author lyf + */ +public class TagProductVO { + private Integer productId; + private String name; + private String tags; + + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 046a935..9fa2e6d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -6,6 +6,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; import com.chaozhanggui.system.cashierservice.entity.vo.*; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.Threads; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -36,6 +37,8 @@ public class HomePageService { private TbProductMapper productMapper; @Resource private SysDictDetailMapper sysDictDetailMapper; + @Resource + private TagProductDeptsMapper tagProductDeptsMapper; public Result homePage(HomeDto homeDto,String environmen) throws ExecutionException, InterruptedException { @@ -50,9 +53,11 @@ public class HomePageService { //统计shopId,以及productId List shopIds = new ArrayList<>(); List productIds = new ArrayList<>(); + List productIdsInt = new ArrayList<>(); for (TbMerchantCoupon coupon : tbMerchantCoupons) { shopIds.add(coupon.getShopId()); productIds.add(coupon.getRelationIds()); + productIdsInt.add(Integer.valueOf(coupon.getRelationIds())); } CompletableFuture> shopInfo = CompletableFuture.supplyAsync(() -> shopInfoMapper.selectByIds(shopIds)); @@ -60,26 +65,21 @@ public class HomePageService { productMapper.selectByIds((productIds))); CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> productSkuMapper.selectSkus((productIds))); - CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> - platformDictMapper.queryAllByType("proTag",environmen)); - CompletableFuture> dictShop = CompletableFuture.supplyAsync(() -> - platformDictMapper.queryAllByType("shopTag",environmen)); - Threads.call(shopInfo,product,productSku,dictPro,dictShop); - boolean isFirstAdded = true; + CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> + tagProductDeptsMapper.queryTagAndProduct(productIdsInt)); + Threads.call(shopInfo,product,productSku,dictPro); + //组装 List homeVOList = new ArrayList<>(); for (TbMerchantCoupon o :tbMerchantCoupons) { HomeVO homeVO = new HomeVO(); homeVO.setDiscount(o.getRatio()); - if (isFirstAdded){ - homeVO.setShopTag(dictShop.get().get(0).getName()); - homeVO.setProTag(dictPro.get().get(0).getName()); - isFirstAdded = false; - } for (TbShopInfo tbShopInfo : shopInfo.get()) { if (o.getShopId().equals(tbShopInfo.getId().toString())) { homeVO.setShopName(tbShopInfo.getShopName()); homeVO.setImage(tbShopInfo.getLogo()); + TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag())); + homeVO.setShopTag(tbPlatformDict == null?"":tbPlatformDict.getName()); } } for (TbProduct tbProduct :product.get()) { @@ -99,6 +99,12 @@ public class HomePageService { homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice())); } } + for (TagProductVO tagProductVO :dictPro.get()) { + if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){ + homeVO.setProTag(tagProductVO.getTags()); + } + } + homeVO.setEndTime(DateUtils.getTodayEndTimeAsString()); homeVOList.add(homeVO); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java index 040b90e..2b57fa2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -3,8 +3,13 @@ package com.chaozhanggui.system.cashierservice.util; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; /** * Created by SEELE on 2018/4/19. @@ -242,6 +247,36 @@ public class DateUtils { return date; } + /** + * 今天结束时间 + * @return + */ + public static Date getDayEnd() { + Calendar cal = new GregorianCalendar(); + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + cal.set(Calendar.MILLISECOND, 999); + return cal.getTime(); + } + + public static String getTodayEndTimeAsString() { + // 获取今天的日期 + LocalDate today = LocalDate.now(); + + // 创建今天的结束时间(23:59:59.999) + LocalTime endTime = LocalTime.of(23, 59, 59, 999_000_000); + + // 组合日期和时间 + LocalDateTime todayEndTime = LocalDateTime.of(today, endTime); + + // 格式化时间 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + + // 转换为字符串 + return todayEndTime.format(formatter); + } + /** * 得到n天之后是周几 * @param days diff --git a/src/main/resources/mapper/TagProductDeptsMapper.xml b/src/main/resources/mapper/TagProductDeptsMapper.xml new file mode 100644 index 0000000..17e44e5 --- /dev/null +++ b/src/main/resources/mapper/TagProductDeptsMapper.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + insert into tag_product_depts(product_id, create_time) + values (#{productId}, #{createTime}) + + + + insert into tag_product_depts(product_id, create_time) + values + + (#{entity.productId}, #{entity.createTime}) + + + + + insert into tag_product_depts(product_id, create_time) + values + + (#{entity.productId}, #{entity.createTime}) + + on duplicate key update + product_id = values(product_id), + create_time = values(create_time) + + + + + update tag_product_depts + + + product_id = #{productId}, + + + create_time = #{createTime}, + + + where tag_id = #{tagId} + + + + + delete from tag_product_depts where tag_id = #{tagId} + + + + diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index a16fbc7..e5635e9 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -55,7 +55,7 @@ detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, - distribute_level, created_at, updated_at, proxy_id + distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag view From d2550475b48088211b3673626ddab3ab3d74bdcc Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 8 Apr 2024 17:51:10 +0800 Subject: [PATCH 002/134] =?UTF-8?q?=E5=85=A8=E5=B1=80=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E5=A4=84=E7=90=86=20=E5=AD=97=E5=85=B8isChild=20=E5=9B=9E?= =?UTF-8?q?=E6=98=BE=20=E5=AD=97=E5=85=B8=E6=A0=87=E7=AD=BE=E5=9B=9E?= =?UTF-8?q?=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/config/CorsFilter.java | 2 +- .../dao/TbMerchantCouponMapper.java | 5 +++ .../system/cashierservice/entity/SysDict.java | 9 +++++ .../cashierservice/entity/vo/DicDetailVO.java | 15 +++++++-- .../service/HomePageService.java | 33 ++++++++++--------- .../cashierservice/util/LocationUtils.java | 2 +- 6 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java index 31e33e6..7285a31 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java @@ -28,7 +28,7 @@ public class CorsFilter implements Filter { response.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin); response.setHeader("Access-Control-Allow-Methods", "*"); response.setHeader("Access-Control-Max-Age", "3600"); - response.setHeader("Access-Control-Allow-Headers", "x-requested-with,signature"); + response.setHeader("Access-Control-Allow-Headers", "environment,type,version,token"); response.setHeader("Access-Control-Allow-Credentials", "true"); chain.doFilter(req, resp); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java index 572b1fa..96c03c3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java @@ -1,8 +1,11 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; + import java.util.List; /** @@ -11,6 +14,8 @@ import java.util.List; * @author lyf * @since 2024-04-02 09:24:16 */ +@Component +@Mapper public interface TbMerchantCouponMapper { /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java index bc3797d..533f143 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java @@ -5,6 +5,7 @@ import java.util.Date; public class SysDict implements Serializable { private Long dictId; + private String dictName; private String name; @@ -22,6 +23,14 @@ public class SysDict implements Serializable { private static final long serialVersionUID = 1L; + public String getDictName() { + return dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + public Integer getIsChild() { return isChild; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java index 9de0cfa..aa84863 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java @@ -9,18 +9,27 @@ import java.util.List; */ public class DicDetailVO { private String name; + private String dictName; private String description; private List detail; - private Integer isChild; + private Boolean isChild; - public Integer getIsChild() { + public String getDictName() { + return dictName; + } + + public void setDictName(String dictName) { + this.dictName = dictName; + } + + public Boolean getIsChild() { return isChild; } - public void setIsChild(Integer isChild) { + public void setIsChild(Boolean isChild) { this.isChild = isChild; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 9fa2e6d..bc82814 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -41,11 +41,11 @@ public class HomePageService { private TagProductDeptsMapper tagProductDeptsMapper; - public Result homePage(HomeDto homeDto,String environmen) throws ExecutionException, InterruptedException { + public Result homePage(HomeDto homeDto, String environmen) throws ExecutionException, InterruptedException { int beginNo; - if(homeDto.getPage() <=0){ + if (homeDto.getPage() <= 0) { beginNo = 0; - }else{ + } else { beginNo = (homeDto.getPage() - 1) * homeDto.getSize(); } //优惠卷 @@ -71,7 +71,7 @@ public class HomePageService { //组装 List homeVOList = new ArrayList<>(); - for (TbMerchantCoupon o :tbMerchantCoupons) { + for (TbMerchantCoupon o : tbMerchantCoupons) { HomeVO homeVO = new HomeVO(); homeVO.setDiscount(o.getRatio()); for (TbShopInfo tbShopInfo : shopInfo.get()) { @@ -82,17 +82,17 @@ public class HomePageService { homeVO.setShopTag(tbPlatformDict == null?"":tbPlatformDict.getName()); } } - for (TbProduct tbProduct :product.get()) { + for (TbProduct tbProduct : product.get()) { if (o.getRelationIds().equals(tbProduct.getId().toString())) { homeVO.setProductName(tbProduct.getName()); homeVO.setImage(tbProduct.getCoverImg()); homeVO.setId(tbProduct.getId()); } } - for (TbProductSku tbProductSku :productSku.get()) { + for (TbProductSku tbProductSku : productSku.get()) { if (o.getRelationIds().equals(tbProductSku.getProductId())) { homeVO.setOriginPrice(tbProductSku.getSalePrice()); - homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null?BigDecimal.ZERO: new BigDecimal(tbProductSku.getRealSalesNumber())); + homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber())); Float discount = homeVO.getDiscount(); BigDecimal discountDecimal = new BigDecimal(discount); homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1"))))); @@ -108,26 +108,27 @@ public class HomePageService { homeVOList.add(homeVO); } - return Result.success(CodeEnum.SUCCESS,homeVOList); + return Result.success(CodeEnum.SUCCESS, homeVOList); } - public Result homePageUp(String environment){ + public Result homePageUp(String environment) { HomeUpVO homeUpVO = new HomeUpVO(); //轮播图 - List carouselList = platformDictMapper.queryAllByType("carousel",environment); + List carouselList = platformDictMapper.queryAllByType("carousel", environment); homeUpVO.setCarousel(carouselList); //金刚区 - List districtList = platformDictMapper.queryAllByType("homeDistrict",environment); + List districtList = platformDictMapper.queryAllByType("homeDistrict", environment); homeUpVO.setDistrict(districtList); //菜单 List sysDicts = sysDictDetailMapper.selectByAll(); List dicDetailVO = new ArrayList<>(); for (SysDict sysDictsList : sysDicts) { DicDetailVO dicDetailVOList = new DicDetailVO(); + dicDetailVOList.setDictName(sysDictsList.getDictName()); dicDetailVOList.setName(sysDictsList.getName()); dicDetailVOList.setDescription(sysDictsList.getDescription()); dicDetailVOList.setDetail(sysDictDetailMapper.selectByDictId(sysDictsList.getDictId())); - dicDetailVOList.setIsChild(sysDictsList.getIsChild()); + dicDetailVOList.setIsChild((sysDictsList.getIsChild() == null || sysDictsList.getIsChild() == 0) ? false : true); dicDetailVO.add(dicDetailVOList); } homeUpVO.setMenu(dicDetailVO); @@ -137,10 +138,10 @@ public class HomePageService { List homeVOs = productSkuMapper.selectSale(); for (HomeVO o : homeVOs) { BigDecimal originPrice = o.getOriginPrice(); - if (originPrice.compareTo(BigDecimal.ZERO)!= 0){ - BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN); + if (originPrice.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN); o.setDiscount(multiply.floatValue()); - }else { + } else { o.setDiscount(null); } } @@ -155,7 +156,7 @@ public class HomePageService { TodayRankingVO todayRankingVO = new TodayRankingVO(); todayRankingVO.setTodayList(homeVODay); homeUpVO.setTodayList(todayRankingVO); - return Result.success(CodeEnum.SUCCESS,homeUpVO); + return Result.success(CodeEnum.SUCCESS, homeUpVO); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index ad4ccb9..a98a272 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -13,7 +13,7 @@ public class LocationUtils { //超掌柜生活-用户端 param.put("key","7a7f2e4790ea222660a027352ee3af39"); param.put("keywords",keywords); - param.put("subdistrict","1"); + param.put("subdistrict","2"); param.put("extensions","base"); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param); return s; From e93ab9b36a1e2cb800232b496478513baa05eb5a Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Tue, 9 Apr 2024 09:11:01 +0800 Subject: [PATCH 003/134] =?UTF-8?q?=E7=8E=AF=E5=A2=832?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/OrderService.java | 129 ++++++++++++++---- 1 file changed, 101 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 08cb26d..e9127d2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -13,7 +13,12 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.RedisUtils; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,7 +29,10 @@ import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; /** * @author 12847 @@ -33,7 +41,7 @@ import java.util.List; public class OrderService { @Resource - private TbCashierCartMapper cashierCartMapper; + private TbShopUserMapper shopUserMapper; @Resource private TbOrderInfoMapper orderInfoMapper; @@ -48,18 +56,31 @@ public class OrderService { @Resource private TbUserInfoMapper userInfoMapper; + @Autowired + private TbWiningUserMapper tbWiningUserMapper; @Resource - private TbOrderDetailMapper tbOrderDetailMapper; + private TbOrderDetailMapper tbOrderDetailMapper; + @Autowired + private TbIntegralMapper tbIntegralMapper; + @Resource + private TbParamsMapper paramsMapper; @Resource private RedisUtil redisUtil; + @Resource + private RedisUtils redisUtils; + @Resource + private TbUserCouponsMapper userCouponsMapper; + @Resource + private TbSystemCouponsMapper systemCouponsMapper; /** * 创建订单 + * * @param tableId * @return */ @Transactional(rollbackFor = Exception.class) - public Result createOrder(Integer tableId,Integer shopId,Integer userId){ + public Result createOrder(Integer tableId, Integer shopId, Integer userId) { // //查询该台桌是否还有开启的购物车 // List cashierCarVoList = cashierCartMapper.selectByTableIdOpen(tableId); // if (cashierCarVoList.isEmpty()){ @@ -139,26 +160,25 @@ public class OrderService { // orderVo.setOrderType(orderInfo.getOrderType()); // orderVo.setOrderId(orderInfo.getId()); // orderVo.setSendType(orderInfo.getSendType()); - return Result.success(CodeEnum.ENCRYPT,orderVo); + return Result.success(CodeEnum.ENCRYPT, orderVo); } - public Result orderInfo(Integer orderId){ + public Result orderInfo(Integer orderId) { TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - if (orderInfo == null){ + if (orderInfo == null) { return Result.fail("未找到订单"); } - TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); - if (tbShopInfo == null){ + if (tbShopInfo == null) { return Result.fail("未找到订单"); } TbShopTable tbShopTable = shopTableMapper.selectQRcode(orderInfo.getTableId()); - List details= tbOrderDetailMapper.selectAllByOrderId(orderId); - if(ObjectUtil.isEmpty(details)||details.size()<=0){ + List details = tbOrderDetailMapper.selectAllByOrderId(orderId); + if (ObjectUtil.isEmpty(details) || details.size() <= 0) { return Result.fail("未找到订单"); } @@ -170,37 +190,37 @@ public class OrderService { orderVo.setOrderNo(orderInfo.getOrderNo()); orderVo.setTime(orderInfo.getCreatedAt()); orderVo.setPayAmount(orderInfo.getOrderAmount()); - orderVo.setTableName(tbShopTable == null?"":tbShopTable.getName()); + orderVo.setTableName(tbShopTable == null ? "" : tbShopTable.getName()); orderVo.setOrderType(orderInfo.getOrderType()); orderVo.setOrderId(orderInfo.getId()); orderVo.setSendType(orderInfo.getSendType()); - return Result.success(CodeEnum.ENCRYPT,orderVo); + return Result.success(CodeEnum.ENCRYPT, orderVo); } - public Result orderList(Integer userId,Integer page,Integer size,String status){ + public Result orderList(Integer userId, Integer page, Integer size, String status) { TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(userId); - if (tbUserInfo == null){ + if (tbUserInfo == null) { return Result.fail("生成订单失败"); } //获取页码号 int beginNo; - if(page <=0){ + if (page <= 0) { beginNo = 0; - }else{ + } else { beginNo = (page - 1) * size; } - List tbOrderInfos = orderInfoMapper.selectByUserId(userId, beginNo, size,status); + List tbOrderInfos = orderInfoMapper.selectByUserId(userId, beginNo, size, status); - for (TbOrderInfo orderInfo:tbOrderInfos){ - List list = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId()); - int num = 0; - for (TbOrderDetail orderDetail:list){ - num = num+orderDetail.getNum(); - } - orderInfo.setDetailList(list); - orderInfo.setTotalNumber(num); + for (TbOrderInfo orderInfo : tbOrderInfos) { + List list = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId()); + int num = 0; + for (TbOrderDetail orderDetail : list) { + num = num + orderDetail.getNum(); + } + orderInfo.setDetailList(list); + orderInfo.setTotalNumber(num); } // // for (OrderVo date :tbOrderInfos) { @@ -215,7 +235,7 @@ public class OrderService { // date.setTotalNumber(number); // } // } - return Result.success(CodeEnum.ENCRYPT,tbOrderInfos); + return Result.success(CodeEnum.ENCRYPT, tbOrderInfos); } @@ -224,10 +244,63 @@ public class OrderService { // redisUtil.seckill(tableId,message); // AppWebSocketServer.onClosed(tableId); List list = productSkuMapper.selectAll(); - for (TbProductSku productSku:list){ + for (TbProductSku productSku : list) { // productSku.setStockNumber(200.00); - redisUtil.saveMessage("PRODUCT:"+productSku.getShopId()+":"+productSku.getId(),productSku.getStockNumber().intValue()+""); + redisUtil.saveMessage("PRODUCT:" + productSku.getShopId() + ":" + productSku.getId(), productSku.getStockNumber().intValue() + ""); } } + + @Transactional(rollbackFor = Exception.class) + public Result tradeIntegral(String userId, String id) { + updateIntegral(userId, id); + return Result.success(CodeEnum.ENCRYPT); + } + + private void updateIntegral(String userId, String id) { + + boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS); + if (lock_coin) { + TbIntegral integral = tbIntegralMapper.selectByPrimaryKey(Integer.valueOf(id)); + if (Objects.isNull(integral) || !integral.getStatus().equals("1")) { + throw new MsgException("该优惠券已被使用"); + } + TbParams params = paramsMapper.selectByPrimaryKey(1); + BigDecimal jfAmount = params.getTradeRatio().multiply(integral.getNum()); + TbShopUser tbShopUser = shopUserMapper.selectByUserId(userId); + tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(jfAmount)); + shopUserMapper.updateByPrimaryKeySelective(tbShopUser); + integral.setStatus("TRADE"); + integral.setUpdateTime(new Date()); + tbIntegralMapper.updateByPrimaryKeySelective(integral); + redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); + } else { + updateIntegral(userId, id); + } + } + +// public Result mineYhq(String userId) { +// List list = tbIntegralMapper.selectAllByUserId(userId); +// return Result.success(CodeEnum.ENCRYPT, list); +// } + + public Result mineCoupons(String userId, String status, Integer page, Integer size) { + PageHelper.startPage(page, size); + List list = userCouponsMapper.selectByUserId(userId,status); + PageInfo pageInfo = new PageInfo(list); + return Result.success(CodeEnum.SUCCESS, pageInfo); + } + + public Result findCoupons(Integer page, Integer size) { + PageHelper.startPage(page, size); + List list = systemCouponsMapper.selectAll(); + PageInfo pageInfo = new PageInfo(list); + return Result.success(CodeEnum.SUCCESS, pageInfo); + } + + public Result findWiningUser() { + String day = DateUtils.getDay(); + List list = tbWiningUserMapper.selectAllByTrade(day); + return Result.success(CodeEnum.SUCCESS, list); + } } From 342d0d82e19efe914792f1a1ec7f70a404d78b56 Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Tue, 9 Apr 2024 09:29:59 +0800 Subject: [PATCH 004/134] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 24 ++ .../controller/UserContoller.java | 79 +++++ .../dao/TbIntegralFlowMapper.java | 17 + .../cashierservice/dao/TbIntegralMapper.java | 23 ++ .../cashierservice/dao/TbParamsMapper.java | 17 + .../dao/TbReleaseFlowMapper.java | 17 + .../cashierservice/dao/TbShopUserMapper.java | 5 + .../dao/TbSystemCouponsMapper.java | 21 ++ .../dao/TbUserCouponsMapper.java | 22 ++ .../dao/TbWiningUserMapper.java | 26 ++ .../cashierservice/entity/TbIntegral.java | 69 ++++ .../cashierservice/entity/TbIntegralFlow.java | 59 ++++ .../cashierservice/entity/TbOrderInfo.java | 1 + .../cashierservice/entity/TbParams.java | 38 +++ .../cashierservice/entity/TbReleaseFlow.java | 79 +++++ .../entity/TbSystemCoupons.java | 29 ++ .../cashierservice/entity/TbUserCoupons.java | 89 +++++ .../cashierservice/entity/TbWiningUser.java | 25 ++ .../cashierservice/entity/vo/IntegralVo.java | 19 ++ .../interceptor/CustomFilter.java | 1 + .../rabbit/IntegralConsumer.java | 41 +++ .../cashierservice/rabbit/RabbitConfig.java | 13 + .../rabbit/RabbitConstants.java | 9 + .../cashierservice/rabbit/RabbitProducer.java | 5 +- .../system/cashierservice/redis/RedisCst.java | 2 +- .../cashierservice/redis/RedisUtil.java | 129 +++++++- .../cashierservice/service/CartService.java | 282 ++++++++++------ .../service/IntegralService.java | 90 +++++ .../cashierservice/service/UserService.java | 134 ++++++++ .../socket/AppWebSocketServer.java | 37 ++- .../socket/AppWebSocketServerCopy.java | 311 ++++++++++++++++++ .../cashierservice/socket/SocketSession.java | 14 + .../cashierservice/task/TaskScheduler.java | 28 ++ .../system/cashierservice/util/CacheMap.java | 10 + .../cashierservice/util/WiningUtil.java | 50 +++ src/main/resources/application-dev.yml | 2 + src/main/resources/application-prod2.yml | 2 +- src/main/resources/application.yml | 2 +- .../generator-mapper/generatorConfig.xml | 8 +- .../resources/mapper/TbIntegralFlowMapper.xml | 93 ++++++ .../resources/mapper/TbIntegralMapper.xml | 109 ++++++ .../resources/mapper/TbOrderInfoMapper.xml | 18 +- src/main/resources/mapper/TbParamsMapper.xml | 71 ++++ .../resources/mapper/TbShopUserMapper.xml | 6 + .../mapper/TbSystemCouponsMapper.xml | 131 ++++++++ .../resources/mapper/TbUserCouponsMapper.xml | 134 ++++++++ .../resources/mapper/TbWiningUserMapper.xml | 110 +++++++ 47 files changed, 2392 insertions(+), 109 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralFlowMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbParamsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningUserMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegral.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegralFlow.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServerCopy.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/socket/SocketSession.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java create mode 100644 src/main/resources/mapper/TbIntegralFlowMapper.xml create mode 100644 src/main/resources/mapper/TbIntegralMapper.xml create mode 100644 src/main/resources/mapper/TbParamsMapper.xml create mode 100644 src/main/resources/mapper/TbSystemCouponsMapper.xml create mode 100644 src/main/resources/mapper/TbUserCouponsMapper.xml create mode 100644 src/main/resources/mapper/TbWiningUserMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index f2974b1..ef269c5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -50,4 +50,28 @@ public class OrderController { private void testMessage(@RequestParam("tableId") String tableId, @RequestParam("message") String message) throws IOException { orderService.testMessage(tableId,message); } + @GetMapping("/tradeIntegral") + private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException { + return orderService.tradeIntegral(userId,id); + } +// @GetMapping("/我的积分") +// private Result mineYhq(@RequestParam("userId") String userId) throws IOException { +// return orderService.mineYhq(userId); +// } + @GetMapping("/mineCoupons") + private Result mineCoupons(@RequestHeader String token,@RequestParam("userId") String userId,@RequestParam("status") String status, + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "size", required = false, defaultValue = "1") Integer size) throws IOException { + return orderService.mineCoupons(userId,status,page,size); + } + @GetMapping("/findCoupons") + private Result findCoupons(@RequestHeader String token, + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "size", required = false, defaultValue = "1") Integer size) throws IOException { + return orderService.findCoupons(page,size); + } + @GetMapping("/findWiningUser") + private Result findWiningUser(){ + return orderService.findWiningUser(); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java new file mode 100644 index 0000000..d5668b6 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -0,0 +1,79 @@ +package com.chaozhanggui.system.cashierservice.controller; + + +import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper; +import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; +import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; +import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto; +import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; +import com.chaozhanggui.system.cashierservice.service.LoginService; +import com.chaozhanggui.system.cashierservice.service.OnlineUserService; +import com.chaozhanggui.system.cashierservice.service.UserService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.IpUtil; +import com.chaozhanggui.system.cashierservice.util.MD5Utils; +import com.chaozhanggui.system.cashierservice.util.StringUtil; +import com.chaozhanggui.system.cashierservice.util.TokenUtil; +import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +@CrossOrigin(origins = "*") +@RestController +@Slf4j +@RequestMapping("user") +public class UserContoller { + + + @Autowired + UserService userService; + + @Autowired + private TbShopUserMapper shopUserMapper; + + + @GetMapping("/userInfo") + public JSONObject userInfo(@RequestParam("openId") String openId ) throws Exception { + TbShopUser shopUser = shopUserMapper.selectByOpenId(openId); + JSONObject jsonObject = new JSONObject(); + if (Objects.isNull(shopUser)){ + jsonObject.put("status","fail"); + jsonObject.put("msg","用户不存在"); + return jsonObject; + } + String userSign = UUID.randomUUID().toString().replaceAll("-",""); + String token = TokenUtil.generateJfToken(openId,userSign); + JSONObject object = new JSONObject(); + object.put("token",token); + object.put("userSign",userSign); + object.put("num",shopUser.getLevelConsume()); + jsonObject.put("status","success"); + jsonObject.put("msg","成功"); + jsonObject.put("data",object); + return jsonObject; + } + @PostMapping("/modityIntegral") + public JSONObject modityIntegral(@RequestHeader String token,@RequestBody IntegralVo integralVo ) throws Exception { + JSONObject jsonObject = TokenUtil.parseParamFromToken(token); + String userSign = jsonObject.getString("userSign"); + return userService.modityIntegral(integralVo,userSign); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralFlowMapper.java new file mode 100644 index 0000000..cb6f56f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralFlowMapper.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbIntegralFlow; + +public interface TbIntegralFlowMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbIntegralFlow record); + + int insertSelective(TbIntegralFlow record); + + TbIntegralFlow selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbIntegralFlow record); + + int updateByPrimaryKey(TbIntegralFlow record); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralMapper.java new file mode 100644 index 0000000..322cfcd --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbIntegralMapper.java @@ -0,0 +1,23 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbIntegral; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public interface TbIntegralMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbIntegral record); + + int insertSelective(TbIntegral record); + + TbIntegral selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbIntegral record); + + int updateByPrimaryKey(TbIntegral record); + + List selectAllByUserId(String userId); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbParamsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbParamsMapper.java new file mode 100644 index 0000000..f234c90 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbParamsMapper.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbParams; + +public interface TbParamsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbParams record); + + int insertSelective(TbParams record); + + TbParams selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbParams record); + + int updateByPrimaryKey(TbParams record); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java new file mode 100644 index 0000000..8002f56 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; + +public interface TbReleaseFlowMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbReleaseFlow record); + + int insertSelective(TbReleaseFlow record); + + TbReleaseFlow selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbReleaseFlow record); + + int updateByPrimaryKey(TbReleaseFlow record); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java index 1f0e8f8..37b597e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.dao; +import com.chaozhanggui.system.cashierservice.entity.TbParams; import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -25,4 +26,8 @@ public interface TbShopUserMapper { TbShopUser selectByUserId(@Param("userId") String userId); + + TbShopUser selectByOpenId(@Param("openId") String openId); + + TbParams selectParams(); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java new file mode 100644 index 0000000..2f70da0 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; + +import java.util.List; + +public interface TbSystemCouponsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbSystemCoupons record); + + int insertSelective(TbSystemCoupons record); + + TbSystemCoupons selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbSystemCoupons record); + + int updateByPrimaryKey(TbSystemCoupons record); + + List selectAll(); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java new file mode 100644 index 0000000..092ec51 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface TbUserCouponsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbUserCoupons record); + + int insertSelective(TbUserCoupons record); + + TbUserCoupons selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbUserCoupons record); + + int updateByPrimaryKey(TbUserCoupons record); + + List selectByUserId(@Param("userId") String userId,@Param("status") String status); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningUserMapper.java new file mode 100644 index 0000000..8659d34 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningUserMapper.java @@ -0,0 +1,26 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbWiningUser; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@Mapper +public interface TbWiningUserMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbWiningUser record); + + int insertSelective(TbWiningUser record); + + TbWiningUser selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbWiningUser record); + + int updateByPrimaryKey(TbWiningUser record); + + List selectAllByTrade(@Param("day") String day); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegral.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegral.java new file mode 100644 index 0000000..ed52c85 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegral.java @@ -0,0 +1,69 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +public class TbIntegral implements Serializable { + private Integer id; + + private String userId; + + private BigDecimal num; + + private String status; + + private Date createTime; + + private Date updateTime; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId == null ? null : userId.trim(); + } + + public BigDecimal getNum() { + return num; + } + + public void setNum(BigDecimal num) { + this.num = num; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegralFlow.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegralFlow.java new file mode 100644 index 0000000..888295e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbIntegralFlow.java @@ -0,0 +1,59 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +public class TbIntegralFlow implements Serializable { + private Integer id; + + private String userId; + + private BigDecimal num; + + private Date createTime; + + private Date updateTime; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId == null ? null : userId.trim(); + } + + public BigDecimal getNum() { + return num; + } + + public void setNum(BigDecimal num) { + this.num = num; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index c2e8b82..e332732 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -95,6 +95,7 @@ public class TbOrderInfo implements Serializable { private String remark; private String tableName; private String masterId; + private String isBuyCoupon; private Integer totalNumber; private List detailList; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java new file mode 100644 index 0000000..f571e1f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java @@ -0,0 +1,38 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; + +public class TbParams implements Serializable { + private Integer id; + + private BigDecimal integralRatio; + + private BigDecimal tradeRatio; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public BigDecimal getIntegralRatio() { + return integralRatio; + } + + public void setIntegralRatio(BigDecimal integralRatio) { + this.integralRatio = integralRatio; + } + + public BigDecimal getTradeRatio() { + return tradeRatio; + } + + public void setTradeRatio(BigDecimal tradeRatio) { + this.tradeRatio = tradeRatio; + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java new file mode 100644 index 0000000..ecc8c1d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java @@ -0,0 +1,79 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +public class TbReleaseFlow implements Serializable { + private Integer id; + + private String userId; + + private BigDecimal num; + + private String type; + + private String remark; + + private String fromSource; + + private Date createTime; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId == null ? null : userId.trim(); + } + + public BigDecimal getNum() { + return num; + } + + public void setNum(BigDecimal num) { + this.num = num; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type == null ? null : type.trim(); + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark == null ? null : remark.trim(); + } + + public String getFromSource() { + return fromSource; + } + + public void setFromSource(String fromSource) { + this.fromSource = fromSource == null ? null : fromSource.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java new file mode 100644 index 0000000..01cdae9 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java @@ -0,0 +1,29 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class TbSystemCoupons implements Serializable { + private Integer id; + + private String name; + + private BigDecimal couponsPrice; + + private BigDecimal couponsAmount; + + private String status; + + private Date createTime; + + private Date updateTime; + private Integer dayNum; + + private Date endTime; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java new file mode 100644 index 0000000..fe9e9d3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java @@ -0,0 +1,89 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +public class TbUserCoupons implements Serializable { + private Integer id; + + private String userId; + + private BigDecimal couponsPrice; + + private BigDecimal couponsAmount; + + private String status; + + private Date createTime; + + private Date updateTime; + + private Date endTime; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId == null ? null : userId.trim(); + } + + public BigDecimal getCouponsPrice() { + return couponsPrice; + } + + public void setCouponsPrice(BigDecimal couponsPrice) { + this.couponsPrice = couponsPrice; + } + + public BigDecimal getCouponsAmount() { + return couponsAmount; + } + + public void setCouponsAmount(BigDecimal couponsAmount) { + this.couponsAmount = couponsAmount; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java new file mode 100644 index 0000000..f2b6862 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java @@ -0,0 +1,25 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class TbWiningUser implements Serializable { + private Integer id; + + private String userName; + + private String orderNo; + + private BigDecimal orderAmount; + + private String isUser; + private String tradeDay; + + private Date createTime; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java new file mode 100644 index 0000000..ee02a3c --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java @@ -0,0 +1,19 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author lyf + */ +@Data +public class IntegralVo { + private String openId; + private BigDecimal num; + private String type; + private String sign; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java index b89fc6f..2745c1e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.interceptor; import ch.qos.logback.classic.turbo.TurboFilter; +import com.chaozhanggui.system.cashierservice.exception.MsgException; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java new file mode 100644 index 0000000..0cc66d9 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/IntegralConsumer.java @@ -0,0 +1,41 @@ +package com.chaozhanggui.system.cashierservice.rabbit; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.redis.RedisCst; +import com.chaozhanggui.system.cashierservice.redis.RedisUtil; +import com.chaozhanggui.system.cashierservice.service.CartService; +import com.chaozhanggui.system.cashierservice.service.IntegralService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Slf4j +@Component +@RabbitListener(queues = {RabbitConstants.INTEGRAL_QUEUE_PUT}) +@Service +public class IntegralConsumer { + + + @Autowired + private RedisUtil redisUtil; + @Autowired + private IntegralService integralService; + @RabbitHandler + public void listener(String message) { + try { + JSONObject jsonObject = JSON.parseObject(message); + integralService.integralAdd(jsonObject); + } catch (Exception e) { + e.getMessage(); + } + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java index d3380a9..2fcbea8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java @@ -61,7 +61,20 @@ public class RabbitConfig { public Binding bindingPut_Register() { return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT); } + @Bean + public DirectExchange defaultIntegral() { + return new DirectExchange(RabbitConstants.INTEGRAL_PUT); + } + @Bean + public Queue queueIntegral() { + return new Queue(RabbitConstants.INTEGRAL_QUEUE_PUT, true); //队列持久 + } + + @Bean + public Binding bindingIntegral() { + return BindingBuilder.bind(queueIntegral()).to(defaultIntegral()).with(RabbitConstants.INTEGRAL_ROUTINGKEY_PUT); + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java index e9adf1b..89c24fe 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java @@ -29,4 +29,13 @@ public interface RabbitConstants { public static final String PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT = "print_mechine_collect_routingkey_put_wx"; + + + + public static final String INTEGRAL_PUT="integral_put"; + + public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put"; + + + public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 2627adf..8d6eba4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -36,7 +36,10 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, content, correlationId); } - + public void printCoupons(String content){ + CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); + rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_QUEUE_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId); + } @Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { logger.info(" 回调id:" + correlationData); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java index fd7d198..11f9558 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java @@ -15,5 +15,5 @@ public class RedisCst { public static final String TABLE_CART = "TABLE:CART:"; public static final String PRODUCT = "PRODUCT:"; - public static final String INTEGRAL_COIN_KEY = ""; + public static final String INTEGRAL_COIN_KEY = "INTEGRAL:COIN:KEY"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java index 6c87667..d45af0f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java @@ -1,5 +1,7 @@ package com.chaozhanggui.system.cashierservice.redis; +import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -7,6 +9,7 @@ import org.springframework.stereotype.Component; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import java.io.*; import java.util.*; /** @@ -17,7 +20,7 @@ import java.util.*; * @Description redis工具类 */ @Component -public class RedisUtil { +public class RedisUtil{ // 成功标识 private static final int REDIS_SUCCESS = 1; // 失败标识 @@ -480,4 +483,128 @@ public class RedisUtil { } return REDIS_FAILED+""; } + + public byte[] serialize(Object obj) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(obj); + return bos.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public Object deserialize(byte[] bytes) { + try { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis); + return ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + return null; + } + } + +// public String serialize(Object list) { +// try { +// ObjectMapper mapper = new ObjectMapper(); +// return mapper.writeValueAsString(list); +// } catch (Exception e) { +// e.printStackTrace(); +// return null; +// } +// } +// public List deserializeJson(String json, Class clazz) { +// try { +// ObjectMapper mapper = new ObjectMapper(); +// return mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, clazz)); +// } catch (Exception e) { +// e.printStackTrace(); +// return null; +// } +// } + public byte[] getHashAll(String key) { + Jedis jedis = null; + try { + // 从jedis池中获取一个jedis实例 + jedis = pool.getResource(); + if (database!=0) { + jedis.select(database); + } + byte[] serializedList = jedis.get(key.getBytes()); + return serializedList; + + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + + return null; + } + public int saveHashAll(byte[] key,byte[] value) { + Jedis jedis = null; + try { + // 从jedis池中获取一个jedis实例 + jedis = pool.getResource(); + if (database!=0) { + jedis.select(database); + } + jedis.rpush(key,value); + return REDIS_SUCCESS; + + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + + return REDIS_FAILED; + } + + public Set getSet(String key ){ + Jedis jedis = null ; + Set set = null ; + try { + jedis = pool.getResource(); + set = jedis.smembers(key); + }catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + return set ; + } + /** + * 往set中添加数据 + * @param key + * @param values + * @return + */ + public Long addSet(String key , String... values ){ + Jedis jedis = null ; + try { + jedis = pool.getResource(); + return jedis.sadd(key,values); + }catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + return 0L ; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 38ff434..c649946 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; import com.chaozhanggui.system.cashierservice.socket.WebSocketServer; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.JSONUtil; +import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -54,7 +55,10 @@ public class CartService { private TbOrderDetailMapper orderDetailMapper; @Autowired private TbShopTableMapper shopTableMapper; - + @Autowired + private TbUserCouponsMapper userCouponsMapper; + @Autowired + private TbSystemCouponsMapper systemCouponsMapper; // @Transactional(rollbackFor = Exception.class) public void createCart(JSONObject jsonObject) throws Exception { @@ -202,23 +206,35 @@ public class CartService { @Transactional(rollbackFor = Exception.class) public void createOrder(JSONObject jsonObject) throws IOException { try { - String shopId = jsonObject.getString("shopId"); JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - //总金额 List ids = new ArrayList<>(); BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal packAMount = BigDecimal.ZERO; + BigDecimal originAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; + String couponId = ""; + BigDecimal couponAmount = BigDecimal.ZERO; Map skuMap = new HashMap<>(); List orderDetails = new ArrayList<>(); Integer orderId = 0; + TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); + if (tbMerchantAccount == null) { + throw new MsgException("生成订单错误"); + } + + String userId = jsonObject.getString("userId"); + TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + if (tbUserInfo == null) { + throw new MsgException("生成订单失败"); + } for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId())); totalAmount = totalAmount.add(cashierCart.getTotalAmount()); packAMount = packAMount.add(cashierCart.getPackFee()); + originAmount = originAmount.add(cashierCart.getTotalAmount()); if (Objects.nonNull(tbProduct)) { saleAmount = saleAmount.add(tbProduct.getSalePrice()); } @@ -249,108 +265,186 @@ public class CartService { orderId = Integer.valueOf(cashierCart.getOrderId()); } } - - TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); - if (tbMerchantAccount == null) { - throw new MsgException("生成订单错误"); - } - - TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(jsonObject.getInteger("userId")); - if (tbUserInfo == null) { - throw new MsgException("生成订单失败"); - } + //总金额 TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId")); //生成订单 TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - if (Objects.nonNull(orderInfo)) { - log.info("订单状态:" + orderInfo.getStatus()); - if (!"unpaid".equals(orderInfo.getStatus())) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单正在支付中,请稍后再试"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; + String isBuyYhq = "false"; + if (jsonObject.containsKey("isYhq")){ + //1:购买优惠券,0:自己持有优惠券 + Integer couponsId = jsonObject.getInteger("couponsId"); + if (jsonObject.getString("isBuyYhq").equals("1")){ + TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId); + if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")){ + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "优惠券已售空"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + if (N.gt(systemCoupons.getCouponsAmount(),totalAmount)){ + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "订单金额小于优惠价金额"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); + originAmount = originAmount.add(systemCoupons.getCouponsPrice()); + systemCoupons.setStatus("1"); + systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons); + TbUserCoupons userCoupons = new TbUserCoupons(); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,systemCoupons.getDayNum())); + userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount()); + userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice()); + userCoupons.setStatus("1"); + userCoupons.setUserId(userId); + userCoupons.setCreateTime(new Date()); + userCouponsMapper.insert(userCoupons); + couponId = userCoupons.getId()+""; + couponAmount = userCoupons.getCouponsAmount(); + }else { + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")){ + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "优惠券已使用"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + if (N.gt(userCoupons.getCouponsAmount(),totalAmount)){ + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "订单金额小于优惠价金额"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); + userCoupons.setStatus("1"); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(),5,30)); + userCouponsMapper.updateByPrimaryKeySelective(userCoupons); } + }else { + if (Objects.nonNull(orderInfo)) { + log.info("订单状态:" + orderInfo.getStatus()); + if (!"unpaid".equals(orderInfo.getStatus())) { + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "订单正在支付中,请稍后再试"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } - orderDetailMapper.deleteByOUrderId(orderId); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(totalAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setFreightAmount(BigDecimal.ZERO); - orderInfo.setProductAmount(saleAmount); - orderInfoMapper.updateByPrimaryKeySelective(orderInfo); - } else { - - orderInfo = new TbOrderInfo(); - String orderNo = generateOrderNumber(); - orderInfo.setOrderNo(orderNo); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setPackFee(packAMount); - orderInfo.setOriginAmount(totalAmount); - orderInfo.setProductAmount(totalAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setPayAmount(BigDecimal.ZERO); - orderInfo.setRefundAmount(new BigDecimal("0.00")); - orderInfo.setTableId(jsonObject.getString("tableId")); - orderInfo.setSendType("table"); - orderInfo.setOrderType("miniapp"); - orderInfo.setTradeDay(DateUtils.getDay()); - orderInfo.setStatus("unpaid"); - orderInfo.setShopId(jsonObject.getString("shopId")); - orderInfo.setUserId(jsonObject.getString("userId")); - orderInfo.setCreatedAt(Instant.now().toEpochMilli()); - orderInfo.setSystemTime(Instant.now().toEpochMilli()); - orderInfo.setUpdatedAt(Instant.now().toEpochMilli()); - orderInfo.setIsAccepted((byte) 1); - if (Objects.nonNull(shopTable)) { - orderInfo.setTableName(shopTable.getName()); + orderDetailMapper.deleteByOUrderId(orderId); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + orderInfo.setSettlementAmount(totalAmount); + orderInfo.setUserCouponId(couponId); + orderInfo.setUserCouponAmount(couponAmount); + orderInfo.setAmount(totalAmount); + orderInfo.setOriginAmount(originAmount); + orderInfo.setOrderAmount(totalAmount.add(packAMount)); + orderInfo.setFreightAmount(BigDecimal.ZERO); + orderInfo.setProductAmount(saleAmount); + orderInfo.setUserCouponId(couponId); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setUserCouponAmount(couponAmount); + orderInfoMapper.updateByPrimaryKeySelective(orderInfo); + } else { + orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); + orderInfo = getOrder(totalAmount,packAMount,shopTable,tbMerchantAccount.getId().toString(),jsonObject,originAmount); + orderInfo.setUserCouponId(couponId); + orderInfo.setOriginAmount(originAmount); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setUserCouponAmount(couponAmount); + orderInfoMapper.insert(orderInfo); + orderId = orderInfo.getId(); } - orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); - orderInfoMapper.insert(orderInfo); - orderId = orderInfo.getId(); - } - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - orderDetailMapper.insert(orderDetail); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setOrderId(orderId + ""); - cashierCart.setStatus("closed"); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - object.put("updatedAt", System.currentTimeMillis()); - object.put("orderId", orderId + ""); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); - orderInfo.setDetailList(orderDetails); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", orderInfo); - redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - JSONObject jsonObject12 = new JSONObject(); - jsonObject12.put("status", "success"); - jsonObject12.put("msg", "成功"); - jsonObject12.put("type", "order"); - jsonObject12.put("amount", BigDecimal.ZERO); + for (TbOrderDetail orderDetail : orderDetails) { + orderDetail.setOrderId(orderId); + orderDetailMapper.insert(orderDetail); + } + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + cashierCart.setUpdatedAt(System.currentTimeMillis()); + cashierCart.setOrderId(orderId + ""); + cashierCart.setStatus("closed"); + cashierCartMapper.updateByPrimaryKeySelective(cashierCart); + object.put("updatedAt", System.currentTimeMillis()); + object.put("orderId", orderId + ""); + } + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); + orderInfo.setDetailList(orderDetails); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", orderInfo); + redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + JSONObject jsonObject12 = new JSONObject(); + jsonObject12.put("status", "success"); + jsonObject12.put("msg", "成功"); + jsonObject12.put("type", "order"); + jsonObject12.put("amount", BigDecimal.ZERO); - jsonObject12.put("data", new JSONArray()); - AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); + jsonObject12.put("data", new JSONArray()); + AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); + } } catch (Exception e) { e.getMessage(); } } + private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, + TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount){ + TbOrderInfo orderInfo = new TbOrderInfo(); + String orderNo = generateOrderNumber(); + orderInfo.setOrderNo(orderNo); + orderInfo.setSettlementAmount(totalAmount); + orderInfo.setPackFee(packAMount); + orderInfo.setOriginAmount(originAmount); + orderInfo.setProductAmount(totalAmount); + orderInfo.setAmount(totalAmount); + orderInfo.setOrderAmount(totalAmount.add(packAMount)); + orderInfo.setPayAmount(BigDecimal.ZERO); + orderInfo.setRefundAmount(new BigDecimal("0.00")); + orderInfo.setTableId(jsonObject.getString("tableId")); + orderInfo.setSendType("table"); + orderInfo.setOrderType("miniapp"); + orderInfo.setTradeDay(DateUtils.getDay()); + orderInfo.setStatus("unpaid"); + orderInfo.setShopId(jsonObject.getString("shopId")); + orderInfo.setUserId(jsonObject.getString("userId")); + orderInfo.setCreatedAt(Instant.now().toEpochMilli()); + orderInfo.setSystemTime(Instant.now().toEpochMilli()); + orderInfo.setUpdatedAt(Instant.now().toEpochMilli()); + orderInfo.setIsAccepted((byte) 1); + if (Objects.nonNull(shopTable)) { + orderInfo.setTableName(shopTable.getName()); + } + orderInfo.setMerchantId(merchantId); + return orderInfo; + } public String generateOrderNumber() { String date = DateUtils.getSdfTimes(); Random random = new Random(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java new file mode 100644 index 0000000..034f540 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java @@ -0,0 +1,90 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.dao.*; +import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.redis.RedisUtil; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.*; + +/** + * @author lyf + */ +@Service +@Slf4j +public class IntegralService { + @Autowired + private RedisUtil redisUtil; + @Autowired + private TbOrderInfoMapper orderInfoMapper; + @Autowired + private TbCashierCartMapper cashierCartMapper; + @Autowired + private TbProductMapper productMapper; + @Autowired + private TbProductSkuMapper productSkuMapper; + @Autowired + private TbShopInfoMapper shopInfoMapper; + @Autowired + private TbShopUserMapper tbShopUserMapper; + @Resource + private TbReleaseFlowMapper integralFlowMapper; + @Autowired + private TbUserCouponsMapper userCouponsMapper; + + + @Transactional(rollbackFor = Exception.class) + public void integralAdd(JSONObject jsonObject) throws ParseException { + String type = jsonObject.getString("type"); + if (type.equals("trade")){ + //优惠券兑换积分 + Integer integralId = jsonObject.getInteger("integralId"); + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(integralId); + if (Objects.isNull(userCoupons) || !"0".equals(userCoupons.getStatus())){ + throw new MsgException("优惠券已被使用"); + } + userCoupons.setStatus("trade"); + userCoupons.setUpdateTime(new Date()); + userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + TbParams params = tbShopUserMapper.selectParams(); + TbReleaseFlow integralFlow = new TbReleaseFlow(); + integralFlow.setNum(userCoupons.getCouponsAmount().multiply(params.getTradeRatio())); + integralFlow.setCreateTime(new Date()); + integralFlow.setFromSource(userCoupons.getId()+""); + integralFlow.setType("TRADEADD"); + integralFlow.setUserId(userCoupons.getUserId()); + integralFlowMapper.insert(integralFlow); + }else { + Integer orderId = jsonObject.getInteger("orderId"); + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + if (Objects.isNull(orderInfo)) { + throw new MsgException("该订单不存在"); + } + TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); + if (Objects.isNull(shopInfo) || !"true".equals(shopInfo.getIsOpenYhq())){ + throw new MsgException("该店铺未开启优惠券功能"); + } + TbParams params = tbShopUserMapper.selectParams(); + TbUserCoupons userCoupons = new TbUserCoupons(); + userCoupons.setUserId(orderInfo.getUserId()); + userCoupons.setCouponsAmount(orderInfo.getPayAmount().multiply(params.getIntegralRatio())); + userCoupons.setStatus("0"); + userCoupons.setCouponsPrice(userCoupons.getCouponsAmount().multiply(new BigDecimal("0.5"))); + userCoupons.setCreateTime(new Date()); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30)); + //执行插入方法 + userCouponsMapper.insert(userCoupons); + } + + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java new file mode 100644 index 0000000..a29904b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -0,0 +1,134 @@ +package com.chaozhanggui.system.cashierservice.service; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.dao.*; +import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.redis.RedisCst; +import com.chaozhanggui.system.cashierservice.redis.RedisUtil; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.TimeUnit; + +@Service +public class UserService { + + + @Autowired + private TbShopUserMapper shopUserMapper; + @Autowired + private TbReleaseFlowMapper releaseFlowMapper; + + @Autowired + RedisUtils redisUtils; + + public JSONObject modityIntegral(IntegralVo integralVo, String userSign) { + JSONObject object = (JSONObject) JSONObject.toJSON(integralVo); + if (N.gt(BigDecimal.ZERO, integralVo.getNum())) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "积分数量不允许小于0"); + result.put("data", ""); + return result; + } + object.put("userSign", userSign); + + JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map); + System.out.println(jsonObject.toJSONString()); + String sign = MD5Util.encrypt(jsonObject.toJSONString()); + if (!sign.equals(integralVo.getSign())) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "签名验证失败"); + result.put("data", ""); + return result; + } + TbShopUser shopUser = shopUserMapper.selectByOpenId(integralVo.getOpenId()); + if (Objects.isNull(shopUser)) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "用户不存在"); + result.put("data", ""); + return result; + } + boolean falg = updateIntegral(shopUser.getId(), integralVo.getNum(), integralVo.getType()); + if (!falg) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "余额不足"); + result.put("data", ""); + return result; + } + JSONObject result = new JSONObject(); + result.put("status", "success"); + result.put("msg", "操作成功"); + return result; + } + + public static void main(String[] args) { + IntegralVo integralVo = new IntegralVo(); + integralVo.setNum(new BigDecimal("5254")); + integralVo.setOpenId("or1l864NBOoJZhC5x_yeziZ26j6c"); + integralVo.setType("sub"); + JSONObject object = (JSONObject) JSONObject.toJSON(integralVo); + object.put("userSign", "02c03d79c36b4c01b217ffb1baef9009"); + JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map); + System.out.println("加密前字符串:" + jsonObject.toJSONString()); + String sign = MD5Util.encrypt(jsonObject.toJSONString()); + System.out.println("加密后签名:" + sign); + } + + private Boolean updateIntegral(String userId, BigDecimal num, String type) { + + boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS); + if (lock_coin) { + TbShopUser tbShopUser = shopUserMapper.selectByPrimaryKey(userId); + boolean flag = true; + if (type.equals("sub")) { + if (N.gt(num, tbShopUser.getLevelConsume())) { + flag = false; + } else { + tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().subtract(num)); + } + } else if (type.equals("add")) { + tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num)); + } + if (flag) { + if (type.equals("sub")) { + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(num); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setType("BUYSUB"); + releaseFlow.setUserId(userId); + releaseFlowMapper.insert(releaseFlow); + }else if (type.equals("sub")){ + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(num); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setType("THREEADD"); + releaseFlow.setUserId(userId); + releaseFlowMapper.insert(releaseFlow); + } + shopUserMapper.updateByPrimaryKeySelective(tbShopUser); + } + redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); + return flag; + } else { + return updateIntegral(userId, num, type); + } + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index b689660..c53181b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -23,7 +23,7 @@ import javax.annotation.Resource; import javax.websocket.*; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; -import java.io.IOException; +import java.io.*; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -105,11 +105,24 @@ public class AppWebSocketServer { if (webSocketMap.containsKey(tableId + "-" + shopId)) { List serverList = webSocketMap.get(tableId + "-" + shopId); serverList.add(this); + } else { List serverList = new ArrayList<>(); serverList.add(this); webSocketMap.put(tableId + "-" + shopId, serverList); } + SocketSession socketSession = new SocketSession(); + socketSession.setSession(session); + socketSession.setShopId(shopId); + socketSession.setTableId(tableId); + socketSession.setUserId(userId); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(session); + byte[] sessionData = bos.toByteArray(); + + // 将序列化后的会话数据存储到Redis中 + redisUtils.saveHashAll(session.getId().getBytes(), sessionData); if (userMap.containsKey(tableId + "-" + shopId)) { Set userSet = userMap.get(tableId + "-" + shopId); userSet.add(userId); @@ -311,4 +324,26 @@ public class AppWebSocketServer { public static synchronized ConcurrentHashMap> getRecordMap() { return AppWebSocketServer.recordMap; } + private byte[] serialize(Object obj) { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(obj); + return bos.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private Object deserialize(byte[] bytes) { + try { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis); + return ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + return null; + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServerCopy.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServerCopy.java new file mode 100644 index 0000000..d6af3e2 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServerCopy.java @@ -0,0 +1,311 @@ +//package com.chaozhanggui.system.cashierservice.socket; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.JSONArray; +//import com.alibaba.fastjson.JSONObject; +//import com.chaozhanggui.system.cashierservice.config.WebSocketCustomEncoding; +//import com.chaozhanggui.system.cashierservice.dao.TbShopTableMapper; +//import com.chaozhanggui.system.cashierservice.entity.TbShopTable; +//import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; +//import com.chaozhanggui.system.cashierservice.redis.RedisCst; +//import com.chaozhanggui.system.cashierservice.redis.RedisUtil; +//import com.chaozhanggui.system.cashierservice.util.SpringUtils; +//import lombok.Data; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.commons.lang3.StringUtils; +//import org.springframework.stereotype.Component; +// +//import javax.annotation.PostConstruct; +//import javax.annotation.Resource; +//import javax.websocket.*; +//import javax.websocket.server.PathParam; +//import javax.websocket.server.ServerEndpoint; +//import java.io.IOException; +//import java.math.BigDecimal; +//import java.util.*; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.concurrent.atomic.AtomicBoolean; +// +//@ServerEndpoint(value = "/websocket/table/{tableId}/{shopId}/{userId}", encoders = WebSocketCustomEncoding.class) +//@Component +//@Slf4j +//@Data +//public class AppWebSocketServerCopy { +// +// +// @Resource +// private RabbitProducer a; +// +// //注入为空 +// public static RabbitProducer rabbitProducer; +// +// @PostConstruct +// public void b() { +// rabbitProducer = this.a; +// } +// +// +// private RedisUtil redisUtils = SpringUtils.getBean(RedisUtil.class); +// private TbShopTableMapper shopTableMapper = SpringUtils.getBean(TbShopTableMapper.class); +// /** +// * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 +// */ +// //一个 AppWebSocketServer 就是一个用户,一个tableId下有一个 List 也就是多个用户 +// private static ConcurrentHashMap> webSocketMap = new ConcurrentHashMap<>(); +// public static ConcurrentHashMap> userMap = new ConcurrentHashMap<>(); +// private static ConcurrentHashMap userSocketMap = new ConcurrentHashMap<>(); +// //购物车的记录,用于第一次扫码的人同步购物车 +// private static ConcurrentHashMap> recordMap = new ConcurrentHashMap<>(); +// private static ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); +// +// /** +// * 与某个客户端的连接会话,需要通过它来给客户端发送数据 +// */ +// private Session session; +// +// /** +// * 接收tableId +// */ +// private String tableId = ""; +// private String shopId = ""; +// private String userId = ""; +// +// /** +// * 用来标识这个用户需要接收同步的购物车信息 +// */ +// private volatile AtomicBoolean sync = new AtomicBoolean(true); +// +// private volatile AtomicBoolean createOrder = new AtomicBoolean(false); +// +// +// /** +// * 连接建立成功调用的方法 +// */ +// @OnOpen +// public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) { +// this.session = session; +// this.tableId = tableId; +// this.shopId = shopId; +// this.userId = userId; +// try { +// TbShopTable shopTable = shopTableMapper.selectQRcode(tableId); +// if (Objects.isNull(shopTable)) { +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("status", "fail"); +// jsonObject1.put("msg", "桌码不存在"); +// jsonObject1.put("type", "addCart"); +// jsonObject1.put("data", new ArrayList<>()); +// jsonObject1.put("amount", BigDecimal.ZERO); +// sendMessage(jsonObject1); +// onClose(); +// } +// if (webSocketMap.containsKey(tableId + "-" + shopId)) { +// List serverList = webSocketMap.get(tableId + "-" + shopId); +// serverList.add(this); +// } else { +// List serverList = new ArrayList<>(); +// serverList.add(this); +// webSocketMap.put(tableId + "-" + shopId, serverList); +// } +// if (userMap.containsKey(tableId + "-" + shopId)) { +// Set userSet = userMap.get(tableId + "-" + shopId); +// userSet.add(userId); +// } else { +// Set userSet = new HashSet<>(); +// userSet.add(userId); +// userMap.put(tableId + "-" + shopId,userSet); +// } +// +// userSocketMap.put(userId, this); +//// sessionMap.put(userId,session); +// String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId)); +// if (StringUtils.isEmpty(mes)) { +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("status", "success"); +// jsonObject1.put("msg", "成功"); +// jsonObject1.put("type", "addCart"); +// jsonObject1.put("data", new ArrayList<>()); +// jsonObject1.put("amount", BigDecimal.ZERO); +// sendMessage(jsonObject1); +// } else { +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("status", "success"); +// jsonObject1.put("msg", "成功"); +// jsonObject1.put("type", "addCart"); +// BigDecimal amount = BigDecimal.ZERO; +// JSONArray jsonArray = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId))); +// for (int i = 0; i < jsonArray.size(); i++) { +// JSONObject object = jsonArray.getJSONObject(i); +// amount = amount.add(object.getBigDecimal("totalAmount")); +// } +// jsonObject1.put("amount", amount); +// jsonObject1.put("data", jsonArray); +// sendMessage(jsonObject1); +// } +//// sendMessage(recordMap.get(tableId)); +// } catch (IOException e) { +// log.error("用户:" + tableId + ",网络异常!!!!!!"); +// } +// } +// +// /** +// * 连接关闭调用的方法 +// */ +// @OnClose +// public void onClose() { +// if (webSocketMap.containsKey(tableId + "-" + shopId)) { +// List serverList = webSocketMap.get(tableId + "-" + shopId); +// if (serverList.isEmpty()) { +// webSocketMap.remove(tableId + "-" + shopId); +// } +// serverList.remove(this); +// +// } +// if (userMap.containsKey(tableId + "-" + shopId)){ +// Set userSet = userMap.get(tableId + "-" + shopId); +// if (userSet.isEmpty()){ +// userMap.remove(tableId + "-" + shopId); +// } +// userSet.remove(userId); +// } +// } +// public static void onClosed(String user) throws IOException { +// Session session1 = sessionMap.get(user); +// session1.close(); +// } +// /** +// * 收到客户端消息后调用的方法 +// * +// * @param message 客户端发送过来的消息 +// */ +// @OnMessage +// public void onMessage(String message, Session session) { +// +// System.out.println(message); +// //可以群发消息 +// //消息保存到数据库、redis +// if (StringUtils.isNotBlank(message) && !message.equals("undefined")) { +// try { +// //解析发送的报文 +// JSONObject jsonObject = new JSONObject(); +// if (StringUtils.isNotEmpty(message)) { +// jsonObject = JSONObject.parseObject(message); +// } +// //追加发送人(防止串改) +// jsonObject.put("tableId", this.tableId); +// jsonObject.put("shopId", this.shopId); +// +// //这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象 +//// ChangeHandler changeHandler = new ChangeHandler(); +//// CreateOrderHandler createOrderHandler = new CreateOrderHandler(); +//// SyncHandler syncHandler = new SyncHandler(); +//// ClearHandler clearHandler = new ClearHandler(); +//// OtherHandler otherHandler = new OtherHandler(); +//// +//// changeHandler.addNextHandler(syncHandler).addNextHandler(createOrderHandler).addNextHandler(clearHandler).addNextHandler(otherHandler); +//// changeHandler.handleRequest(webSocketMap,jsonObject,recordMap,this); +// if ("sku".equals(jsonObject.getString("type"))){ +// boolean exist = redisUtils.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))); +// Integer num = 0; +// if (exist){ +// JSONArray array = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); +// for (int i = 0; i < array.size(); i++) { +// JSONObject object = array.getJSONObject(i); +// if (object.getString("skuId").equals(jsonObject.getString("skuId"))) { +// num = object.getIntValue("totalNumber"); +// break; +// } +// } +// } +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("status", "success"); +// jsonObject1.put("msg", "成功"); +// jsonObject1.put("type", "sku"); +// jsonObject1.put("data", new ArrayList<>()); +// jsonObject1.put("amount", num); +// sendMessage(jsonObject1); +// }else { +// rabbitProducer.putCart(jsonObject.toJSONString()); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// +// /** +// * 发生错误时候 +// * +// * @param session +// * @param error +// */ +// @OnError +// public void onError(Session session, Throwable error) { +// log.error("用户错误:" + this.tableId + ",原因:" + error.getMessage()); +// error.printStackTrace(); +// } +// +// /** +// * 实现服务器主动推送 +// */ +// public void sendMessage(Object message) throws IOException { +// //加入线程锁 +// synchronized (session) { +// try { +// //同步发送信息 +// this.session.getBasicRemote().sendObject(message); +// } catch (Exception e) { +// log.error("服务器推送失败:" + e.getMessage()); +// } +// } +// } +// +// +// /** +// * 发送自定义消息 +// * */ +// /** +// * 发送自定义消息 +// * +// * @param message 发送的信息 +// * @param tableId 如果为null默认发送所有 +// * @throws IOException +// */ +// public static void AppSendInfo(Object message, String tableId, boolean userFlag) throws IOException { +// if (userFlag) { +// if (userSocketMap.containsKey(tableId)) { +// AppWebSocketServerCopy server = userSocketMap.get(tableId); +// server.sendMessage(message); +// } else { +// log.error("请求的userId:" + tableId + "不在该服务器上"); +// } +// } else { +// if (StringUtils.isEmpty(tableId)) { +// // 向所有用户发送信息 +// for (List serverList : webSocketMap.values()) { +// for (AppWebSocketServerCopy server : serverList) { +// server.sendMessage(message); +// } +// } +// } else if (webSocketMap.containsKey(tableId)) { +// // 发送给指定用户信息 +// List serverList = webSocketMap.get(tableId); +// for (AppWebSocketServerCopy server : serverList) { +// server.sendMessage(message); +// } +// } else { +// log.error("请求的tableId:" + tableId + "不在该服务器上"); +// } +// } +// +// } +// +// +// public static synchronized ConcurrentHashMap> getWebSocketMap() { +// return AppWebSocketServerCopy.webSocketMap; +// } +// +// public static synchronized ConcurrentHashMap> getRecordMap() { +// return AppWebSocketServerCopy.recordMap; +// } +//} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/SocketSession.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/SocketSession.java new file mode 100644 index 0000000..77f6b2e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/SocketSession.java @@ -0,0 +1,14 @@ +package com.chaozhanggui.system.cashierservice.socket; + +import lombok.Data; + +import javax.websocket.Session; +import java.io.Serializable; + +@Data +public class SocketSession implements Serializable { + private Session session; + private String tableId ; + private String shopId ; + private String userId ; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java new file mode 100644 index 0000000..771b43d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -0,0 +1,28 @@ +package com.chaozhanggui.system.cashierservice.task; + +import com.chaozhanggui.system.cashierservice.dao.TbWiningUserMapper; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +public class TaskScheduler { + + @Autowired + private TbWiningUserMapper tbWiningUserMapper; + + //更新订单状态 +// @Scheduled(fixedRate = 1000, initialDelay = 5000) + public void orderStatus() throws InterruptedException { + System.out.println(DateUtils.getTime()); + Thread.sleep(10000); + } + + + +// @Scheduled(fixedRate = 1000) + public void winningUser(){ + System.out.println("恭喜您中奖了"+DateUtils.getTime()); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java new file mode 100644 index 0000000..74b407d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java @@ -0,0 +1,10 @@ +package com.chaozhanggui.system.cashierservice.util; + +import java.util.HashMap; +import java.util.Map; + +public interface CacheMap { + Map map = new HashMap(){{ + put("sign","1"); + }}; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java new file mode 100644 index 0000000..6268b23 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java @@ -0,0 +1,50 @@ +package com.chaozhanggui.system.cashierservice.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + +public class WiningUtil { + private List participants; + private Random random; + + public WiningUtil(List participants) { + this.participants = participants; + this.random = new Random(); + } + + public String drawWinner() { + if (participants.isEmpty()) { + return "No participants to draw from"; + } + + int index = random.nextInt(participants.size()); + return participants.get(index); + } + + public static void main(String[] args) { + // 参与抽奖的人员名单 + List participants = new ArrayList<>(); + participants.add("Alice"); + participants.add("Bob"); + participants.add("Charlie"); + participants.add("David"); + participants.add("Eve"); + + // 创建抽奖对象 + WiningUtil winingUtil = new WiningUtil(participants); + + // 进行抽奖 + String winner = winingUtil.drawWinner(); + System.out.println("Winner: " + winner); + } + public static boolean winingresult(){ + + return false; + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 5cf8b4d..393e40e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -54,6 +54,8 @@ ysk: callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 +server: + port: 9889 diff --git a/src/main/resources/application-prod2.yml b/src/main/resources/application-prod2.yml index f8e8e1d..e8c808b 100644 --- a/src/main/resources/application-prod2.yml +++ b/src/main/resources/application-prod2.yml @@ -1,5 +1,5 @@ server: - port: 9888 + port: 9889 spring: datasource: url: jdbc:mysql://rm-bp1b572nblln4jho2.mysql.rds.aliyuncs.com/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4f818e0..337ac0e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 9889 +# port: 9889 servlet: context-path: /cashierService/ wx: diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index 6f0944f..a31c3b8 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -6,7 +6,7 @@ - + @@ -52,13 +52,9 @@ -
- - - -
\ No newline at end of file diff --git a/src/main/resources/mapper/TbIntegralFlowMapper.xml b/src/main/resources/mapper/TbIntegralFlowMapper.xml new file mode 100644 index 0000000..046f61b --- /dev/null +++ b/src/main/resources/mapper/TbIntegralFlowMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + id, user_id, num, create_time, update_time + + + + delete from tb_integral_flow + where id = #{id,jdbcType=INTEGER} + + + insert into tb_integral_flow (id, user_id, num, + create_time, update_time) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{num,jdbcType=DECIMAL}, + #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) + + + insert into tb_integral_flow + + + id, + + + user_id, + + + num, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=VARCHAR}, + + + #{num,jdbcType=DECIMAL}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + update tb_integral_flow + + + user_id = #{userId,jdbcType=VARCHAR}, + + + num = #{num,jdbcType=DECIMAL}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_integral_flow + set user_id = #{userId,jdbcType=VARCHAR}, + num = #{num,jdbcType=DECIMAL}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbIntegralMapper.xml b/src/main/resources/mapper/TbIntegralMapper.xml new file mode 100644 index 0000000..86c3c68 --- /dev/null +++ b/src/main/resources/mapper/TbIntegralMapper.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + id, user_id, num, status, create_time, update_time + + + + + delete from tb_integral + where id = #{id,jdbcType=INTEGER} + + + insert into tb_integral (id, user_id, num, + status, create_time, update_time + ) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{num,jdbcType=DECIMAL}, + #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_integral + + + id, + + + user_id, + + + num, + + + status, + + + create_time, + + + update_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=VARCHAR}, + + + #{num,jdbcType=DECIMAL}, + + + #{status,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + + + update tb_integral + + + user_id = #{userId,jdbcType=VARCHAR}, + + + num = #{num,jdbcType=DECIMAL}, + + + status = #{status,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_integral + set user_id = #{userId,jdbcType=VARCHAR}, + num = #{num,jdbcType=DECIMAL}, + status = #{status,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index eaa9bc4..0bef918 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -46,6 +46,7 @@ + id, order_no, settlement_amount, pack_fee, origin_amount, product_amount, amount, @@ -53,7 +54,7 @@ discount_amount, table_id, small_change, send_type, order_type, product_type, status, billing_id, merchant_id, shop_id, is_vip, member_id, user_id, product_score, deduct_score, user_coupon_id, user_coupon_amount, refund_able, paid_time, is_effect, is_group, - updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name` + updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name`,is_buy_coupon + select + + from tb_params + where id = #{id,jdbcType=INTEGER} + + + delete from tb_params + where id = #{id,jdbcType=INTEGER} + + + insert into tb_params (id, integral_ratio, trade_ratio + ) + values (#{id,jdbcType=INTEGER}, #{integralRatio,jdbcType=DECIMAL}, #{tradeRatio,jdbcType=DECIMAL} + ) + + + insert into tb_params + + + id, + + + integral_ratio, + + + trade_ratio, + + + + + #{id,jdbcType=INTEGER}, + + + #{integralRatio,jdbcType=DECIMAL}, + + + #{tradeRatio,jdbcType=DECIMAL}, + + + + + update tb_params + + + integral_ratio = #{integralRatio,jdbcType=DECIMAL}, + + + trade_ratio = #{tradeRatio,jdbcType=DECIMAL}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_params + set integral_ratio = #{integralRatio,jdbcType=DECIMAL}, + trade_ratio = #{tradeRatio,jdbcType=DECIMAL} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index 690c5ac..04e272f 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -370,4 +370,10 @@ + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbSystemCouponsMapper.xml b/src/main/resources/mapper/TbSystemCouponsMapper.xml new file mode 100644 index 0000000..54ad7f7 --- /dev/null +++ b/src/main/resources/mapper/TbSystemCouponsMapper.xml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + id, name, coupons_price, coupons_amount, status, create_time, update_time, end_time + + + + + delete from tb_system_coupons + where id = #{id,jdbcType=INTEGER} + + + insert into tb_system_coupons (id, name, coupons_price, + coupons_amount, status, create_time, + update_time, end_time) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL}, + #{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}) + + + insert into tb_system_coupons + + + id, + + + name, + + + coupons_price, + + + coupons_amount, + + + status, + + + create_time, + + + update_time, + + + end_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + #{couponsPrice,jdbcType=DECIMAL}, + + + #{couponsAmount,jdbcType=DECIMAL}, + + + #{status,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{endTime,jdbcType=TIMESTAMP}, + + + + + update tb_system_coupons + + + name = #{name,jdbcType=VARCHAR}, + + + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + + + coupons_amount = #{couponsAmount,jdbcType=DECIMAL}, + + + status = #{status,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + end_time = #{endTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_system_coupons + set name = #{name,jdbcType=VARCHAR}, + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + coupons_amount = #{couponsAmount,jdbcType=DECIMAL}, + status = #{status,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + end_time = #{endTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbUserCouponsMapper.xml b/src/main/resources/mapper/TbUserCouponsMapper.xml new file mode 100644 index 0000000..2fa9b9f --- /dev/null +++ b/src/main/resources/mapper/TbUserCouponsMapper.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time + + + + + delete from tb_user_coupons + where id = #{id,jdbcType=INTEGER} + + + insert into tb_user_coupons (id, user_id, coupons_price, + coupons_amount, status, create_time, + update_time, end_time) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL}, + #{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}) + + + insert into tb_user_coupons + + + id, + + + user_id, + + + coupons_price, + + + coupons_amount, + + + status, + + + create_time, + + + update_time, + + + end_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=VARCHAR}, + + + #{couponsPrice,jdbcType=DECIMAL}, + + + #{couponsAmount,jdbcType=DECIMAL}, + + + #{status,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{endTime,jdbcType=TIMESTAMP}, + + + + + update tb_user_coupons + + + user_id = #{userId,jdbcType=VARCHAR}, + + + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + + + coupons_amount = #{couponsAmount,jdbcType=DECIMAL}, + + + status = #{status,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + end_time = #{endTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_user_coupons + set user_id = #{userId,jdbcType=VARCHAR}, + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + coupons_amount = #{couponsAmount,jdbcType=DECIMAL}, + status = #{status,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + end_time = #{endTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbWiningUserMapper.xml b/src/main/resources/mapper/TbWiningUserMapper.xml new file mode 100644 index 0000000..ab1b7a7 --- /dev/null +++ b/src/main/resources/mapper/TbWiningUserMapper.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + id, user_name, order_no, order_amount, is_user, create_time,trade_day + + + + + delete from tb_wining_user + where id = #{id,jdbcType=INTEGER} + + + insert into tb_wining_user (id, user_name, order_no, + order_amount, is_user, create_time + ) + values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, + #{orderAmount,jdbcType=DECIMAL}, #{isUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_wining_user + + + id, + + + user_name, + + + order_no, + + + order_amount, + + + is_user, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userName,jdbcType=VARCHAR}, + + + #{orderNo,jdbcType=VARCHAR}, + + + #{orderAmount,jdbcType=DECIMAL}, + + + #{isUser,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update tb_wining_user + + + user_name = #{userName,jdbcType=VARCHAR}, + + + order_no = #{orderNo,jdbcType=VARCHAR}, + + + order_amount = #{orderAmount,jdbcType=DECIMAL}, + + + is_user = #{isUser,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_wining_user + set user_name = #{userName,jdbcType=VARCHAR}, + order_no = #{orderNo,jdbcType=VARCHAR}, + order_amount = #{orderAmount,jdbcType=DECIMAL}, + is_user = #{isUser,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file From dd81edb51e05e2b8c551302167f0ec4efb95feec Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Tue, 9 Apr 2024 10:56:26 +0800 Subject: [PATCH 005/134] =?UTF-8?q?=E6=9B=B4=E6=94=B9MQ=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/entity/vo/HomeVO.java | 13 +++++++------ .../system/cashierservice/rabbit/CartConsumer.java | 3 ++- .../system/cashierservice/rabbit/RabbitConfig.java | 9 +++++---- .../cashierservice/rabbit/RabbitProducer.java | 5 ++++- .../cashierservice/service/HomePageService.java | 11 ++++++++--- src/main/resources/application-dev.yml | 6 ++++-- src/main/resources/application-prod.yml | 3 ++- src/main/resources/application-prod2.yml | 5 +++-- 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index bd9350b..06eda3f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -4,6 +4,7 @@ import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * @author lyf @@ -47,11 +48,11 @@ public class HomeVO { /** * 店铺标签 */ - private String shopTag; + private List shopTag; /** * 商品标签 */ - private String proTag; + private List proTag; /** * 距离 */ @@ -88,19 +89,19 @@ public class HomeVO { this.distances = distances; } - public String getShopTag() { + public List getShopTag() { return shopTag; } - public void setShopTag(String shopTag) { + public void setShopTag(List shopTag) { this.shopTag = shopTag; } - public String getProTag() { + public List getProTag() { return proTag; } - public void setProTag(String proTag) { + public void setProTag(List proTag) { this.proTag = proTag; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index a1edf56..97be65c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -29,7 +29,7 @@ import java.util.*; @Slf4j @Component -@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) +//@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) @Service public class CartConsumer { @@ -39,6 +39,7 @@ public class CartConsumer { @Autowired private CartService cartService; @RabbitHandler + @RabbitListener(queues = {"${queue}"}) public void listener(String message) { try { JSONObject jsonObject = JSON.parseObject(message); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java index d3380a9..04b1fb2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java @@ -27,7 +27,8 @@ public class RabbitConfig { @Value("${spring.rabbitmq.password}") private String password; - + @Value("${prod}") + private String prod; @Bean @@ -49,17 +50,17 @@ public class RabbitConfig { } @Bean public DirectExchange defaultExchange_Register() { - return new DirectExchange(RabbitConstants.CART_PUT); + return new DirectExchange(RabbitConstants.CART_PUT+prod); } @Bean public Queue queuePut_Register() { - return new Queue(RabbitConstants.CART_QUEUE_PUT, true); //队列持久 + return new Queue(RabbitConstants.CART_QUEUE_PUT+prod, true); //队列持久 } @Bean public Binding bindingPut_Register() { - return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT); + return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT+prod); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 2627adf..cdd9970 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -17,6 +18,8 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { private RabbitTemplate rabbitTemplate; + @Value("${prod}") + private String prod; @Autowired public RabbitProducer(RabbitTemplate rabbitTemplate) { this.rabbitTemplate = rabbitTemplate; @@ -25,7 +28,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { public void putCart(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); - rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT, RabbitConstants.CART_ROUTINGKEY_PUT, content, correlationId); + rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT+prod, RabbitConstants.CART_ROUTINGKEY_PUT+prod, content, correlationId); } public void putOrderCollect(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index bc82814..3bd90cf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -78,8 +79,12 @@ public class HomePageService { if (o.getShopId().equals(tbShopInfo.getId().toString())) { homeVO.setShopName(tbShopInfo.getShopName()); homeVO.setImage(tbShopInfo.getLogo()); - TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag())); - homeVO.setShopTag(tbPlatformDict == null?"":tbPlatformDict.getName()); + if (tbShopInfo.getTag() == null){ + homeVO.setShopTag(new ArrayList<>()); + }else { + TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag())); + homeVO.setShopTag(tbPlatformDict == null ? new ArrayList<>() : Collections.singletonList(tbPlatformDict.getName())); + } } } for (TbProduct tbProduct : product.get()) { @@ -101,7 +106,7 @@ public class HomePageService { } for (TagProductVO tagProductVO :dictPro.get()) { if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){ - homeVO.setProTag(tagProductVO.getTags()); + homeVO.setProTag(Collections.singletonList(tagProductVO.getTags())); } } homeVO.setEndTime(DateUtils.getTodayEndTimeAsString()); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 5cf8b4d..ca785fb 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -15,7 +15,8 @@ spring: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 database: 5 # redis服务器地址(默认为localhost) - host: 101.37.12.135 +# host: 101.37.12.135 + host: 127.0.0.1 # redis端口(默认为6379) port: 6379 # redis访问密码(默认为空) @@ -54,6 +55,7 @@ ysk: callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 - +prod: prod1 +queue: cart_queue_putprod1 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index f8e8e1d..5491e73 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -56,6 +56,7 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 - +prod: prod1 +queue: cart_queue_put1prod1 diff --git a/src/main/resources/application-prod2.yml b/src/main/resources/application-prod2.yml index f8e8e1d..d88e348 100644 --- a/src/main/resources/application-prod2.yml +++ b/src/main/resources/application-prod2.yml @@ -1,5 +1,5 @@ server: - port: 9888 + port: 9889 spring: datasource: url: jdbc:mysql://rm-bp1b572nblln4jho2.mysql.rds.aliyuncs.com/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false @@ -56,6 +56,7 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 - +prod: prod2 +queue: cart_queue_put1prod2 From 1b9d069bc6675d2a2beccdbe87ab00a1aba338a1 Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Wed, 10 Apr 2024 14:15:41 +0800 Subject: [PATCH 006/134] =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=BC=80=E5=B7=A5=EF=BC=8C=E5=95=86=E5=93=81=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProductController.java | 4 + .../cashierservice/dao/TbProductMapper.java | 3 + .../cashierservice/entity/TbProduct.java | 10 ++ .../entity/TbSystemCoupons.java | 107 ++++++++++++++++++ .../cashierservice/entity/vo/BannerVO.java | 31 +++++ .../cashierservice/entity/vo/HomeUpVO.java | 12 ++ .../cashierservice/entity/vo/HomeVO.java | 7 +- .../entity/vo/productInfoVo.java | 41 +++++++ .../service/HomePageService.java | 27 ++++- .../service/ProductService.java | 5 + .../system/cashierservice/util/DateUtils.java | 13 +++ src/main/resources/application-dev2.yml | 62 ++++++++++ src/main/resources/mapper/TbProductMapper.xml | 3 + 13 files changed, 318 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java create mode 100644 src/main/resources/application-dev2.yml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 07ed28d..5bcca82 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -40,5 +40,9 @@ public class ProductController { return productService.queryProductSku(shopId,productId,spec_tag); } +// @GetMapping("/productInfo") +// public Result productInfo(@RequestParam Integer productId){ +// return productService.productInfo() +// } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java index 91c8f2b..52c6da8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbProduct; import com.chaozhanggui.system.cashierservice.entity.TbProductWithBLOBs; +import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -32,4 +33,6 @@ public interface TbProductMapper { List selectByIds(@Param("list") List ids); Integer selectByQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId); Integer selectByNewQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId,@Param("list") List list); + + TbSystemCoupons selectLimit(); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index c828f9c..9d2e3ea 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -40,6 +40,8 @@ public class TbProduct implements Serializable { private String shareImg; + private String images; + private String videoCoverImg; private Integer sort; @@ -128,6 +130,14 @@ public class TbProduct implements Serializable { private String cartNumber="0"; + public String getImages() { + return images; + } + + public void setImages(String images) { + this.images = images; + } + public String getCartNumber() { return cartNumber; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java new file mode 100644 index 0000000..9c6e0b7 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java @@ -0,0 +1,107 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.util.Date; +import java.io.Serializable; + +/** + * (TbSystemCoupons)实体类 + * + * @author lyf + * @since 2024-04-09 18:27:08 + */ +public class TbSystemCoupons implements Serializable { + private static final long serialVersionUID = -42549701370854624L; + + private Integer id; + + private String name; + + private Double couponsPrice; + + private Double couponsAmount; + + private String status; + + private Date createTime; + + private Date updateTime; + + private Date endTime; + + private Integer dayNum; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getCouponsPrice() { + return couponsPrice; + } + + public void setCouponsPrice(Double couponsPrice) { + this.couponsPrice = couponsPrice; + } + + public Double getCouponsAmount() { + return couponsAmount; + } + + public void setCouponsAmount(Double couponsAmount) { + this.couponsAmount = couponsAmount; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public Integer getDayNum() { + return dayNum; + } + + public void setDayNum(Integer dayNum) { + this.dayNum = dayNum; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java new file mode 100644 index 0000000..efe8b20 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java @@ -0,0 +1,31 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; + +import java.util.List; + +/** + * @author 12847 + */ +public class BannerVO { + + private String coupons; + + private List logo; + + public String getCoupons() { + return coupons; + } + + public void setCoupons(String coupons) { + this.coupons = coupons; + } + + public List getLogo() { + return logo; + } + + public void setLogo(List logo) { + this.logo = logo; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java index b3104e2..d1ea0a6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java @@ -31,6 +31,18 @@ public class HomeUpVO { * 销量飙升 */ HotRankingVO salesList; + /** + * 小横幅 + */ + BannerVO bannerVO; + + public BannerVO getBannerVO() { + return bannerVO; + } + + public void setBannerVO(BannerVO bannerVO) { + this.bannerVO = bannerVO; + } public TodayRankingVO getTodayList() { return todayList; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index 06eda3f..dc77381 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -62,14 +62,13 @@ public class HomeVO { /** * 结束时间 */ - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private String endTime; + private Long endTime; - public String getEndTime() { + public Long getEndTime() { return endTime; } - public void setEndTime(String endTime) { + public void setEndTime(Long endTime) { this.endTime = endTime; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java new file mode 100644 index 0000000..0073c6e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java @@ -0,0 +1,41 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author lyf + */ +public class productInfoVo { + /** + * 商品图片 + */ + private Listimages; + + /** + * 原价 + */ + private BigDecimal originPrice; + /** + * 现价 + */ + private BigDecimal salePrice; + /** + * 折扣 + */ + private Float discount; + /** + * 共省金额 + */ + private BigDecimal save; + + /** + * 销量 + */ + private BigDecimal realSalesNumber; + + /** + * 结束时间 + */ + private Long endTime; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 3bd90cf..2e8773d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -15,6 +15,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -83,7 +84,8 @@ public class HomePageService { homeVO.setShopTag(new ArrayList<>()); }else { TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag())); - homeVO.setShopTag(tbPlatformDict == null ? new ArrayList<>() : Collections.singletonList(tbPlatformDict.getName())); + + homeVO.setShopTag(tbPlatformDict == null ? new ArrayList<>() : Collections.singletonList(tbPlatformDict.getName())); } } } @@ -106,16 +108,25 @@ public class HomePageService { } for (TagProductVO tagProductVO :dictPro.get()) { if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){ - homeVO.setProTag(Collections.singletonList(tagProductVO.getTags())); + homeVO.setProTag(tagList(tagProductVO.getTags())); } } - homeVO.setEndTime(DateUtils.getTodayEndTimeAsString()); + homeVO.setEndTime(DateUtils.getDayEndLong()); homeVOList.add(homeVO); } return Result.success(CodeEnum.SUCCESS, homeVOList); } + private List tagList(String tag){ + if (tag == null){ + return new ArrayList<>(); + }else { + String[] arr = tag.split(","); + return new ArrayList<>(Arrays.asList(arr)); + } + } + public Result homePageUp(String environment) { HomeUpVO homeUpVO = new HomeUpVO(); //轮播图 @@ -161,6 +172,16 @@ public class HomePageService { TodayRankingVO todayRankingVO = new TodayRankingVO(); todayRankingVO.setTodayList(homeVODay); homeUpVO.setTodayList(todayRankingVO); + /** + * 小条幅 + */ + TbSystemCoupons tbSystemCoupons = productMapper.selectLimit(); + BannerVO bannerVO = new BannerVO(); + bannerVO.setCoupons(tbSystemCoupons == null?"":tbSystemCoupons.getName()); + List tbPlatformDicts = platformDictMapper.queryAllByType("icon", environment); + bannerVO.setLogo(tbPlatformDicts); + homeUpVO.setBannerVO(bannerVO); + return Result.success(CodeEnum.SUCCESS, homeUpVO); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 4942b0e..8581305 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -118,4 +118,9 @@ public class ProductService { return Result.success(CodeEnum.SUCCESS,tbProductSkuWithBLOBs); } + + +// public Result productInfo(Integer productId){ +// TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(productId); +// } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java index 2b57fa2..9d910a0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -6,6 +6,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; @@ -259,6 +260,18 @@ public class DateUtils { cal.set(Calendar.MILLISECOND, 999); return cal.getTime(); } + public static Long getDayEndLong() { + // 获取今天的日期和时间(00:00:00) + LocalDateTime todayStart = LocalDateTime.now().toLocalDate().atStartOfDay(); + + // 将时间设置为今天的结束时间(23:59:59.999999999) + LocalDateTime endOfDay = todayStart.plusDays(1).minusNanos(1); + + // 转换为UTC时间戳(毫秒) + long timestampInMillis = endOfDay.toInstant(ZoneOffset.UTC).toEpochMilli(); + + return timestampInMillis; + } public static String getTodayEndTimeAsString() { // 获取今天的日期 diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml new file mode 100644 index 0000000..42f1606 --- /dev/null +++ b/src/main/resources/application-dev2.yml @@ -0,0 +1,62 @@ +spring: + datasource: + url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false + username: root + password: mysqlroot@123 + driver-class-name: com.mysql.cj.jdbc.Driver + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + logging: + level: + com.chaozhanggui.system.openness: info + redis: + # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 + database: 5 + # redis服务器地址(默认为localhost) +# host: 101.37.12.135 + host: 127.0.0.1 + # redis端口(默认为6379) + port: 6379 + # redis访问密码(默认为空) + password: 111111 + # redis连接超时时间(单位为毫秒) + timeout: 1000 + block-when-exhausted: true + # redis连接池配置 + jedis: + pool: + max-active: 8 + max-idle: 1024 + min-idle: 0 + max-wait: -1 + main: + allow-circular-references: true + rabbitmq: + host: 101.37.12.135 + port: 5672 + username: admin + password: Czg666888 +#分页配置 +pagehelper: + supportMethodsArguments: true + reasonable: true + helperDialect: mysql + params: count=countSql + +mybatis: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath:mapper/*.xml +ysk: + url: https://gatewaytestapi.sxczgkj.cn/gate-service/ + callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack + callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack + default: 18710449883 +prod: prod2 +queue: cart_queue_putprod2 + + + diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 3940301..3fb1404 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -933,4 +933,7 @@ #{item} + \ No newline at end of file From 3a90299b6429bb0695fa5fabea621db33fc2cda4 Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Wed, 10 Apr 2024 18:16:28 +0800 Subject: [PATCH 007/134] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8+=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=85=A8=E5=B1=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 15 +- .../controller/UserContoller.java | 7 + .../cashierservice/dao/TbOrderInfoMapper.java | 3 +- .../dao/TbReleaseFlowMapper.java | 5 + .../dao/TbSystemCouponsMapper.java | 3 +- .../dao/TbWiningParamsMapper.java | 21 + .../cashierservice/dao/TbYhqParamsMapper.java | 21 + .../cashierservice/entity/TbShopInfo.java | 367 +----------------- .../entity/TbSystemCoupons.java | 1 + .../cashierservice/entity/TbWiningParams.java | 22 ++ .../cashierservice/entity/TbWiningUser.java | 31 +- .../cashierservice/entity/TbYhqParams.java | 58 +++ .../entity/vo/IntegralFlowVo.java | 17 + .../exception/DefaultError.java | 108 ++++++ .../exception/DefaultExceptionAdvice.java | 155 ++++++++ .../cashierservice/exception/IError.java | 32 ++ .../cashierservice/rabbit/CartConsumer.java | 3 +- .../cashierservice/rabbit/RabbitConfig.java | 9 +- .../rabbit/RabbitConstants.java | 6 +- .../cashierservice/rabbit/RabbitProducer.java | 8 +- .../cashierservice/service/CartService.java | 166 ++++---- .../cashierservice/service/LoginService.java | 11 +- .../cashierservice/service/OrderService.java | 93 ++++- .../cashierservice/service/PayService.java | 6 +- .../cashierservice/service/UserService.java | 51 ++- .../system/cashierservice/sign/Result.java | 9 + .../socket/AppWebSocketServer.java | 12 - .../cashierservice/task/TaskScheduler.java | 101 ++++- .../util/NicknameGenerator.java | 40 ++ .../cashierservice/util/RandomUtil.java | 31 ++ .../cashierservice/util/WiningUtil.java | 50 --- src/main/resources/application-dev.yml | 4 +- src/main/resources/application-dev2.yml | 63 +++ src/main/resources/application-prod.yml | 2 + src/main/resources/application-prod2.yml | 2 + .../generator-mapper/generatorConfig.xml | 2 +- .../resources/mapper/TbOrderInfoMapper.xml | 4 + .../resources/mapper/TbReleaseFlowMapper.xml | 121 ++++++ .../resources/mapper/TbShopInfoMapper.xml | 3 +- .../mapper/TbSystemCouponsMapper.xml | 9 +- .../resources/mapper/TbWiningParamsMapper.xml | 97 +++++ .../resources/mapper/TbWiningUserMapper.xml | 88 ++++- .../resources/mapper/TbYhqParamsMapper.xml | 96 +++++ 43 files changed, 1374 insertions(+), 579 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java create mode 100644 src/main/resources/application-dev2.yml create mode 100644 src/main/resources/mapper/TbReleaseFlowMapper.xml create mode 100644 src/main/resources/mapper/TbWiningParamsMapper.xml create mode 100644 src/main/resources/mapper/TbYhqParamsMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index ef269c5..eb1aa5c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; +import java.text.ParseException; @CrossOrigin(origins = "*") @RestController @@ -51,7 +52,7 @@ public class OrderController { orderService.testMessage(tableId,message); } @GetMapping("/tradeIntegral") - private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException { + private Result tradeIntegral(@RequestParam("userId") String userId, @RequestParam("id") String id) throws IOException, ParseException { return orderService.tradeIntegral(userId,id); } // @GetMapping("/我的积分") @@ -65,13 +66,21 @@ public class OrderController { return orderService.mineCoupons(userId,status,page,size); } @GetMapping("/findCoupons") - private Result findCoupons(@RequestHeader String token, + private Result findCoupons(@RequestHeader String token,@RequestParam String type, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false, defaultValue = "1") Integer size) throws IOException { - return orderService.findCoupons(page,size); + return orderService.findCoupons(type,page,size); } @GetMapping("/findWiningUser") private Result findWiningUser(){ return orderService.findWiningUser(); } + @GetMapping("/getYhqPara") + private Result getYhqPara(){ + return orderService.getYhqPara(); + } + @GetMapping("/testPay") + private Result testPay(@RequestParam Integer orderId){ + return orderService.testPay(orderId); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index d5668b6..c1d21e6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -11,6 +11,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto; import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; import com.chaozhanggui.system.cashierservice.service.LoginService; @@ -76,4 +77,10 @@ public class UserContoller { String userSign = jsonObject.getString("userSign"); return userService.modityIntegral(integralVo,userSign); } + @GetMapping("/userIntegral") + public JSONObject userIntegral(@RequestHeader String token,@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { + JSONObject jsonObject = TokenUtil.parseParamFromToken(token); + String userSign = jsonObject.getString("userSign"); + return userService.userIntegral(integralFlowVo,userSign); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java index bea67e1..bf851e8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.List; @Component @@ -32,5 +33,5 @@ public interface TbOrderInfoMapper { @Param("size")Integer size, @Param("status") String status); - + List selectByTradeDay(@Param("day") String day,@Param("minPrice") BigDecimal minPrice,@Param("maxPrice") BigDecimal maxPrice); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java index 8002f56..b2f02b5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java @@ -1,6 +1,9 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; +import org.apache.ibatis.annotations.Param; + +import java.util.List; public interface TbReleaseFlowMapper { int deleteByPrimaryKey(Integer id); @@ -14,4 +17,6 @@ public interface TbReleaseFlowMapper { int updateByPrimaryKeySelective(TbReleaseFlow record); int updateByPrimaryKey(TbReleaseFlow record); + + List selectByUserId(@Param("userId") String userId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java index 2f70da0..f4bfecf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -17,5 +18,5 @@ public interface TbSystemCouponsMapper { int updateByPrimaryKey(TbSystemCoupons record); - List selectAll(); + List selectAll(@Param("type") String type); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java new file mode 100644 index 0000000..803fc9f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbWiningParamsMapper.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbWiningParams; + +import java.util.List; + +public interface TbWiningParamsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbWiningParams record); + + int insertSelective(TbWiningParams record); + + TbWiningParams selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbWiningParams record); + + int updateByPrimaryKey(TbWiningParams record); + + List selectAll(); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java new file mode 100644 index 0000000..0693c83 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbYhqParamsMapper.java @@ -0,0 +1,21 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbYhqParams; + +import java.util.List; + +public interface TbYhqParamsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbYhqParams record); + + int insertSelective(TbYhqParams record); + + TbYhqParams selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbYhqParams record); + + int updateByPrimaryKey(TbYhqParams record); + + List selectAll(); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java index 54863e8..2073721 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java @@ -1,8 +1,12 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; + +@Data public class TbShopInfo implements Serializable { private Integer id; @@ -95,366 +99,5 @@ public class TbShopInfo implements Serializable { * 商家二维码 */ private String shopQrcode; - - public String getShopQrcode() { - return shopQrcode; - } - - public void setShopQrcode(String shopQrcode) { - this.shopQrcode = shopQrcode; - } - - private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getAccount() { - return account; - } - - public void setAccount(String account) { - this.account = account == null ? null : account.trim(); - } - - public String getShopCode() { - return shopCode; - } - - public void setShopCode(String shopCode) { - this.shopCode = shopCode == null ? null : shopCode.trim(); - } - - public String getSubTitle() { - return subTitle; - } - - public void setSubTitle(String subTitle) { - this.subTitle = subTitle == null ? null : subTitle.trim(); - } - - public String getMerchantId() { - return merchantId; - } - - public void setMerchantId(String merchantId) { - this.merchantId = merchantId == null ? null : merchantId.trim(); - } - - public String getShopName() { - return shopName; - } - - public void setShopName(String shopName) { - this.shopName = shopName == null ? null : shopName.trim(); - } - - public String getChainName() { - return chainName; - } - - public void setChainName(String chainName) { - this.chainName = chainName == null ? null : chainName.trim(); - } - - public String getBackImg() { - return backImg; - } - - public void setBackImg(String backImg) { - this.backImg = backImg == null ? null : backImg.trim(); - } - - public String getFrontImg() { - return frontImg; - } - - public void setFrontImg(String frontImg) { - this.frontImg = frontImg == null ? null : frontImg.trim(); - } - - public String getContactName() { - return contactName; - } - - public void setContactName(String contactName) { - this.contactName = contactName == null ? null : contactName.trim(); - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone == null ? null : phone.trim(); - } - - public String getLogo() { - return logo; - } - - public void setLogo(String logo) { - this.logo = logo == null ? null : logo.trim(); - } - - public Byte getIsDeposit() { - return isDeposit; - } - - public void setIsDeposit(Byte isDeposit) { - this.isDeposit = isDeposit; - } - - public Byte getIsSupply() { - return isSupply; - } - - public void setIsSupply(Byte isSupply) { - this.isSupply = isSupply; - } - - public String getCoverImg() { - return coverImg; - } - - public void setCoverImg(String coverImg) { - this.coverImg = coverImg == null ? null : coverImg.trim(); - } - - public String getShareImg() { - return shareImg; - } - - public void setShareImg(String shareImg) { - this.shareImg = shareImg == null ? null : shareImg.trim(); - } - - public String getDetail() { - return detail; - } - - public void setDetail(String detail) { - this.detail = detail == null ? null : detail.trim(); - } - - public String getLat() { - return lat; - } - - public void setLat(String lat) { - this.lat = lat == null ? null : lat.trim(); - } - - public String getLng() { - return lng; - } - - public void setLng(String lng) { - this.lng = lng == null ? null : lng.trim(); - } - - public String getMchId() { - return mchId; - } - - public void setMchId(String mchId) { - this.mchId = mchId == null ? null : mchId.trim(); - } - - public String getRegisterType() { - return registerType; - } - - public void setRegisterType(String registerType) { - this.registerType = registerType == null ? null : registerType.trim(); - } - - public Byte getIsWxMaIndependent() { - return isWxMaIndependent; - } - - public void setIsWxMaIndependent(Byte isWxMaIndependent) { - this.isWxMaIndependent = isWxMaIndependent; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address == null ? null : address.trim(); - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city == null ? null : city.trim(); - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type == null ? null : type.trim(); - } - - public String getIndustry() { - return industry; - } - - public void setIndustry(String industry) { - this.industry = industry == null ? null : industry.trim(); - } - - public String getIndustryName() { - return industryName; - } - - public void setIndustryName(String industryName) { - this.industryName = industryName == null ? null : industryName.trim(); - } - - public String getBusinessTime() { - return businessTime; - } - - public void setBusinessTime(String businessTime) { - this.businessTime = businessTime == null ? null : businessTime.trim(); - } - - public String getPostTime() { - return postTime; - } - - public void setPostTime(String postTime) { - this.postTime = postTime == null ? null : postTime.trim(); - } - - public BigDecimal getPostAmountLine() { - return postAmountLine; - } - - public void setPostAmountLine(BigDecimal postAmountLine) { - this.postAmountLine = postAmountLine; - } - - public Byte getOnSale() { - return onSale; - } - - public void setOnSale(Byte onSale) { - this.onSale = onSale; - } - - public Byte getSettleType() { - return settleType; - } - - public void setSettleType(Byte settleType) { - this.settleType = settleType; - } - - public String getSettleTime() { - return settleTime; - } - - public void setSettleTime(String settleTime) { - this.settleTime = settleTime == null ? null : settleTime.trim(); - } - - public Integer getEnterAt() { - return enterAt; - } - - public void setEnterAt(Integer enterAt) { - this.enterAt = enterAt; - } - - public Long getExpireAt() { - return expireAt; - } - - public void setExpireAt(Long expireAt) { - this.expireAt = expireAt; - } - - public Byte getStatus() { - return status; - } - - public void setStatus(Byte status) { - this.status = status; - } - - public Float getAverage() { - return average; - } - - public void setAverage(Float average) { - this.average = average; - } - - public Integer getOrderWaitPayMinute() { - return orderWaitPayMinute; - } - - public void setOrderWaitPayMinute(Integer orderWaitPayMinute) { - this.orderWaitPayMinute = orderWaitPayMinute; - } - - public Integer getSupportDeviceNumber() { - return supportDeviceNumber; - } - - public void setSupportDeviceNumber(Integer supportDeviceNumber) { - this.supportDeviceNumber = supportDeviceNumber; - } - - public Byte getDistributeLevel() { - return distributeLevel; - } - - public void setDistributeLevel(Byte distributeLevel) { - this.distributeLevel = distributeLevel; - } - - public Long getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Long createdAt) { - this.createdAt = createdAt; - } - - public Long getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Long updatedAt) { - this.updatedAt = updatedAt; - } - - public String getProxyId() { - return proxyId; - } - - public void setProxyId(String proxyId) { - this.proxyId = proxyId == null ? null : proxyId.trim(); - } - - public String getView() { - return view; - } - - public void setView(String view) { - this.view = view == null ? null : view.trim(); - } + private String isOpenYhq; } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java index 01cdae9..6f03d88 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSystemCoupons.java @@ -17,6 +17,7 @@ public class TbSystemCoupons implements Serializable { private BigDecimal couponsAmount; private String status; + private String typeName; private Date createTime; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java new file mode 100644 index 0000000..6c513c1 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningParams.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; + +@Data +public class TbWiningParams implements Serializable { + private Integer id; + + private BigDecimal minPrice; + + private BigDecimal maxPrice; + + private Integer winingNum; + + private Integer winingUserNum; + private String status; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java index f2b6862..6fdc83b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java @@ -17,9 +17,38 @@ public class TbWiningUser implements Serializable { private BigDecimal orderAmount; private String isUser; - private String tradeDay; private Date createTime; + private String isRefund; + + private BigDecimal refundAmount; + + private String refundNo; + + private String refundPayType; + + private String tradeDay; + + private Date refundTime; + + private static final long serialVersionUID = 1L; + public TbWiningUser(){ + super(); + } + public TbWiningUser(String userName,String orderNo,BigDecimal orderAmount, + String isUser,String tradeDay){ + this.createTime = new Date(); + this.userName = userName; + this.orderNo = orderNo; + this.orderAmount = orderAmount; + this.isUser = isUser; + this.tradeDay = tradeDay; + this.isRefund = "false"; + this.refundAmount = BigDecimal.ZERO; + this.refundPayType = "WX"; + + + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java new file mode 100644 index 0000000..0c6bd92 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java @@ -0,0 +1,58 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; + +public class TbYhqParams implements Serializable { + private Integer id; + + private String name; + + private BigDecimal minPrice; + + private BigDecimal maxPrice; + + private String status; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public BigDecimal getMinPrice() { + return minPrice; + } + + public void setMinPrice(BigDecimal minPrice) { + this.minPrice = minPrice; + } + + public BigDecimal getMaxPrice() { + return maxPrice; + } + + public void setMaxPrice(BigDecimal maxPrice) { + this.maxPrice = maxPrice; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java new file mode 100644 index 0000000..12cfe06 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralFlowVo.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author lyf + */ +@Data +public class IntegralFlowVo { + private String openId; + private Integer page; + private Integer pageSize; + private String sign; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java new file mode 100644 index 0000000..da542b9 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultError.java @@ -0,0 +1,108 @@ +package com.chaozhanggui.system.cashierservice.exception; + + +public enum DefaultError implements IError { + /** + * 系统内部错误 + */ + SYSTEM_INTERNAL_ERROR("0000", "系统错误"), + /** + * 无效参数 + */ + INVALID_PARAMETER("0001", "参数验证失败"), + /** + * 服务不存在 + */ + SERVICE_NOT_FOUND("0002", "服务不存在"), + /** + * 参数不全 + */ + PARAMETER_REQUIRED("0003", "参数不全"), + /** + * 参数过长 + */ + PARAMETER_MAX_LENGTH("0004", "参数过长"), + /** + * 参数过短 + */ + PARAMETER_MIN_LENGTH("0005", "参数过短"), + /** + * 认证失败 + */ + AUTHENTICATION_ERROR("0006", "认证失败"), + /** + * 认证动作失败 + */ + AUTHENTICATION_OPTION_ERROR("0007", "认证失败"), + /** + * 请求方法出错 + */ + METHOD_NOT_SUPPORTED("0008", "请求方法出错"), + /** + * 不支持的content类型 + */ + CONTENT_TYPE_NOT_SUPPORT("0009", "不支持的content类型"), + /** + * json格式化出错 + */ + JSON_FORMAT_ERROR("0010", "json格式化出错"), + /** + * 远程调用出错 + */ + CALL_REMOTE_ERROR("0011", "远程调用出错"), + /** + * 服务运行SQLException异常 + */ + SQL_EXCEPTION("0012", "服务运行SQL异常"), + /** + * 客户端异常 给调用者 app,移动端调用 + */ + CLIENT_EXCEPTION("0013", "客户端异常"), + /** + * 服务端异常, 微服务服务端产生的异常 + */ + SERVER_EXCEPTION("0014", "服务端异常"), + /** + * 授权失败 禁止访问 + */ + ACCESS_DENIED("0015", "没有访问权限"), + /** + * 演示环境 没有权限访问 + */ + SHOW_AUTH_CONTROL("0016", "演示环境,没有权限访问"), + /** + * 业务异常 + */ + BUSINESS_ERROR("0017", "业务异常"), + + NO_USER("0018","用户不存在"); + + String errorCode; + String errorMessage; + private static final String NS = "SYS"; + + DefaultError(String errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + @Override + public String getNameSpace() { + return NS; + } + + @Override + public String getErrorCode() { + return NS + "." + this.errorCode; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } + + @Override + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java new file mode 100644 index 0000000..083db51 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -0,0 +1,155 @@ +package com.chaozhanggui.system.cashierservice.exception; + +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.validation.BindException; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; +import org.springframework.web.HttpMediaTypeNotSupportedException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.NoHandlerFoundException; + +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.validation.UnexpectedTypeException; +import java.sql.SQLException; +import java.util.List; +import java.util.Set; + +@ControllerAdvice +@ResponseBody +public class DefaultExceptionAdvice { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionAdvice.class); + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler({HttpMessageNotReadableException.class, }) + public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { + LOGGER.error("参数解析失败", e); + Result response = Result.failure(DefaultError.INVALID_PARAMETER); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @ExceptionHandler({HttpRequestMethodNotSupportedException.class}) + public ResponseEntity handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { + LOGGER.error("不支持当前请求方法", e); + Result response = Result.failure(DefaultError.METHOD_NOT_SUPPORTED); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.METHOD_NOT_ALLOWED); + } + + @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE) + @ExceptionHandler({HttpMediaTypeNotSupportedException.class}) + public ResponseEntity handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) { + LOGGER.error("不支持当前媒体类型", e); + Result response = Result.failure(DefaultError.CONTENT_TYPE_NOT_SUPPORT); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.UNSUPPORTED_MEDIA_TYPE); + } + + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler({SQLException.class}) + public ResponseEntity handleSQLException(SQLException e) { + LOGGER.error("服务运行SQLException异常", e); + Result response = Result.failure(DefaultError.SQL_EXCEPTION); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * 所有异常统一处理 + * + * @return ResponseEntity + */ + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception ex) { + LOGGER.error("未知异常", ex); + IError error; + String extMessage = null; + if (ex instanceof BindException) { + error = DefaultError.INVALID_PARAMETER; + List errors = ((BindException) ex).getAllErrors(); + if (errors.size() != 0) { + StringBuilder msg = new StringBuilder(); + for (ObjectError objectError : errors) { + msg.append("Field error in object '").append(objectError.getObjectName()).append(" "); + if (objectError instanceof FieldError) { + msg.append("on field ").append(((FieldError) objectError).getField()).append(" "); + } + msg.append(objectError.getDefaultMessage()).append(" "); + } + extMessage = msg.toString(); + } + } else if (ex instanceof MissingServletRequestParameterException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof ConstraintViolationException) { + error = DefaultError.INVALID_PARAMETER; + Set> violations = ((ConstraintViolationException) ex).getConstraintViolations(); + final StringBuilder msg = new StringBuilder(); + for (ConstraintViolation constraintViolation : violations) { + msg.append(constraintViolation.getPropertyPath()).append(":").append(constraintViolation.getMessage()).append("\n"); + } + extMessage = msg.toString(); + } else if (ex instanceof HttpMediaTypeNotSupportedException) { + error = DefaultError.CONTENT_TYPE_NOT_SUPPORT; + extMessage = ex.getMessage(); + } else if (ex instanceof HttpMessageNotReadableException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof MethodArgumentNotValidException) { + error = DefaultError.INVALID_PARAMETER; + final BindingResult result = ((MethodArgumentNotValidException) ex).getBindingResult(); + if (result.hasErrors()) { + extMessage = result.getAllErrors().get(0).getDefaultMessage(); + } else { + extMessage = ex.getMessage(); + } + } else if (ex instanceof HttpRequestMethodNotSupportedException) { + error = DefaultError.METHOD_NOT_SUPPORTED; + extMessage = ex.getMessage(); + } else if (ex instanceof UnexpectedTypeException) { + error = DefaultError.INVALID_PARAMETER; + extMessage = ex.getMessage(); + } else if (ex instanceof NoHandlerFoundException) { + error = DefaultError.SERVICE_NOT_FOUND; + extMessage = ex.getMessage(); + } else { + error = DefaultError.SYSTEM_INTERNAL_ERROR; + extMessage = ex.getMessage(); + } + + + Result response = Result.failure(error); + response.setMsg(extMessage); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * BusinessException 业务异常处理 + * + * @return ResponseEntity + */ + @ResponseStatus(HttpStatus.OK) + @ExceptionHandler(MsgException.class) + public ResponseEntity handleException(MsgException e) { + LOGGER.error("业务异常", e); + Result response = Result.failure(DefaultError.BUSINESS_ERROR); + response.setMsg(e.getMessage()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java new file mode 100644 index 0000000..56d1d1b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/IError.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.exception; + +public interface IError { + + /** + * 获取nameSpace + * + * @return nameSpace + */ + String getNameSpace(); + + /** + * 获取错误码 + + * @return 错误码 + */ + String getErrorCode(); + + /** + * 获取错误信息 + + * @return 错误信息 + */ + String getErrorMessage(); + + /** + * 设置错误信息 + * + * @param errorMessage 错误信息 + */ + void setErrorMessage(String errorMessage); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index a1edf56..97be65c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -29,7 +29,7 @@ import java.util.*; @Slf4j @Component -@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) +//@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) @Service public class CartConsumer { @@ -39,6 +39,7 @@ public class CartConsumer { @Autowired private CartService cartService; @RabbitHandler + @RabbitListener(queues = {"${queue}"}) public void listener(String message) { try { JSONObject jsonObject = JSON.parseObject(message); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java index 2fcbea8..2e1f20c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConfig.java @@ -27,7 +27,8 @@ public class RabbitConfig { @Value("${spring.rabbitmq.password}") private String password; - + @Value("${prod}") + private String prod; @Bean @@ -49,17 +50,17 @@ public class RabbitConfig { } @Bean public DirectExchange defaultExchange_Register() { - return new DirectExchange(RabbitConstants.CART_PUT); + return new DirectExchange(RabbitConstants.CART_PUT+prod); } @Bean public Queue queuePut_Register() { - return new Queue(RabbitConstants.CART_QUEUE_PUT, true); //队列持久 + return new Queue(RabbitConstants.CART_QUEUE_PUT+prod, true); //队列持久 } @Bean public Binding bindingPut_Register() { - return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT); + return BindingBuilder.bind(queuePut_Register()).to(defaultExchange_Register()).with(RabbitConstants.CART_ROUTINGKEY_PUT+prod); } @Bean public DirectExchange defaultIntegral() { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java index 89c24fe..1e44c86 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java @@ -32,10 +32,10 @@ public interface RabbitConstants { - public static final String INTEGRAL_PUT="integral_put"; + public static final String INTEGRAL_PUT="integral_put1"; - public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put"; + public static final String INTEGRAL_QUEUE_PUT = "integral_queue_put1"; - public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put"; + public static final String INTEGRAL_ROUTINGKEY_PUT = "integral_routingkey_put1"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java index 8d6eba4..5498148 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitProducer.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -16,7 +17,8 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private RabbitTemplate rabbitTemplate; - + @Value("${prod}") + private String prod; @Autowired public RabbitProducer(RabbitTemplate rabbitTemplate) { this.rabbitTemplate = rabbitTemplate; @@ -25,7 +27,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { public void putCart(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); - rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT, RabbitConstants.CART_ROUTINGKEY_PUT, content, correlationId); + rabbitTemplate.convertAndSend(RabbitConstants.CART_PUT+prod, RabbitConstants.CART_ROUTINGKEY_PUT+prod, content, correlationId); } public void putOrderCollect(String content) { CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); @@ -38,7 +40,7 @@ public class RabbitProducer implements RabbitTemplate.ConfirmCallback { } public void printCoupons(String content){ CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString()); - rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_QUEUE_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId); + rabbitTemplate.convertAndSend(RabbitConstants.INTEGRAL_PUT, RabbitConstants.INTEGRAL_ROUTINGKEY_PUT, content, correlationId); } @Override public void confirm(CorrelationData correlationData, boolean ack, String cause) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index c649946..b8640f5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -213,7 +213,7 @@ public class CartService { BigDecimal packAMount = BigDecimal.ZERO; BigDecimal originAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; - String couponId = ""; + String couponId = jsonObject.getString("couponsId"); BigDecimal couponAmount = BigDecimal.ZERO; Map skuMap = new HashMap<>(); List orderDetails = new ArrayList<>(); @@ -270,12 +270,12 @@ public class CartService { //生成订单 TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); String isBuyYhq = "false"; - if (jsonObject.containsKey("isYhq")){ + if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { //1:购买优惠券,0:自己持有优惠券 Integer couponsId = jsonObject.getInteger("couponsId"); - if (jsonObject.getString("isBuyYhq").equals("1")){ + if (jsonObject.getString("isBuyYhq").equals("1")) { TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")){ + if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -286,7 +286,7 @@ public class CartService { log.info("消息推送"); return; } - if (N.gt(systemCoupons.getCouponsAmount(),totalAmount)){ + if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -299,21 +299,22 @@ public class CartService { } totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); originAmount = originAmount.add(systemCoupons.getCouponsPrice()); + couponAmount = systemCoupons.getCouponsAmount(); systemCoupons.setStatus("1"); systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons); TbUserCoupons userCoupons = new TbUserCoupons(); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,systemCoupons.getDayNum())); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum())); userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount()); userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice()); userCoupons.setStatus("1"); userCoupons.setUserId(userId); userCoupons.setCreateTime(new Date()); userCouponsMapper.insert(userCoupons); - couponId = userCoupons.getId()+""; + couponId = userCoupons.getId() + ""; couponAmount = userCoupons.getCouponsAmount(); - }else { + } else { TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")){ + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -324,7 +325,7 @@ public class CartService { log.info("消息推送"); return; } - if (N.gt(userCoupons.getCouponsAmount(),totalAmount)){ + if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { log.info("开始处理订单"); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); @@ -337,93 +338,94 @@ public class CartService { } totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); userCoupons.setStatus("1"); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(),5,30)); + userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + couponAmount = userCoupons.getCouponsAmount(); } - }else { - if (Objects.nonNull(orderInfo)) { - log.info("订单状态:" + orderInfo.getStatus()); - if (!"unpaid".equals(orderInfo.getStatus())) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单正在支付中,请稍后再试"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - orderDetailMapper.deleteByOUrderId(orderId); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setUserCouponAmount(couponAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(originAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setFreightAmount(BigDecimal.ZERO); - orderInfo.setProductAmount(saleAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setUserCouponAmount(couponAmount); - orderInfoMapper.updateByPrimaryKeySelective(orderInfo); - } else { - orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); - orderInfo = getOrder(totalAmount,packAMount,shopTable,tbMerchantAccount.getId().toString(),jsonObject,originAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setOriginAmount(originAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setUserCouponAmount(couponAmount); - orderInfoMapper.insert(orderInfo); - orderId = orderInfo.getId(); - } - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - orderDetailMapper.insert(orderDetail); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setOrderId(orderId + ""); - cashierCart.setStatus("closed"); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - object.put("updatedAt", System.currentTimeMillis()); - object.put("orderId", orderId + ""); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); - orderInfo.setDetailList(orderDetails); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", orderInfo); - redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); - JSONObject jsonObject12 = new JSONObject(); - jsonObject12.put("status", "success"); - jsonObject12.put("msg", "成功"); - jsonObject12.put("type", "order"); - jsonObject12.put("amount", BigDecimal.ZERO); - jsonObject12.put("data", new JSONArray()); - AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); } + if (Objects.nonNull(orderInfo)) { + log.info("订单状态:" + orderInfo.getStatus()); + if (!"unpaid".equals(orderInfo.getStatus())) { + log.info("开始处理订单"); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "订单正在支付中,请稍后再试"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", ""); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + log.info("消息推送"); + return; + } + + orderDetailMapper.deleteByOUrderId(orderId); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + orderInfo.setSettlementAmount(totalAmount); + orderInfo.setUserCouponId(couponId); + orderInfo.setUserCouponAmount(couponAmount); + orderInfo.setAmount(totalAmount); + orderInfo.setOriginAmount(originAmount); + orderInfo.setOrderAmount(totalAmount.add(packAMount)); + orderInfo.setFreightAmount(BigDecimal.ZERO); + orderInfo.setProductAmount(saleAmount); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfoMapper.updateByPrimaryKeySelective(orderInfo); + } else { + orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount); + orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); + orderInfo.setUserCouponId(couponId); + orderInfo.setOriginAmount(originAmount); + orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setUserCouponAmount(couponAmount); + orderInfoMapper.insert(orderInfo); + orderId = orderInfo.getId(); + } + for (TbOrderDetail orderDetail : orderDetails) { + orderDetail.setOrderId(orderId); + orderDetailMapper.insert(orderDetail); + } + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + cashierCart.setUpdatedAt(System.currentTimeMillis()); + cashierCart.setOrderId(orderId + ""); + cashierCart.setStatus("closed"); + cashierCartMapper.updateByPrimaryKeySelective(cashierCart); + object.put("updatedAt", System.currentTimeMillis()); + object.put("orderId", orderId + ""); + } + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); + orderInfo.setDetailList(orderDetails); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", orderInfo); + redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + JSONObject jsonObject12 = new JSONObject(); + jsonObject12.put("status", "success"); + jsonObject12.put("msg", "成功"); + jsonObject12.put("type", "order"); + jsonObject12.put("amount", BigDecimal.ZERO); + + jsonObject12.put("data", new JSONArray()); + AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); } catch (Exception e) { e.getMessage(); } } + private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, - TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount){ + TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount) { TbOrderInfo orderInfo = new TbOrderInfo(); String orderNo = generateOrderNumber(); orderInfo.setOrderNo(orderNo); orderInfo.setSettlementAmount(totalAmount); orderInfo.setPackFee(packAMount); orderInfo.setOriginAmount(originAmount); - orderInfo.setProductAmount(totalAmount); + orderInfo.setProductAmount(originAmount); orderInfo.setAmount(totalAmount); orderInfo.setOrderAmount(totalAmount.add(packAMount)); orderInfo.setPayAmount(BigDecimal.ZERO); @@ -445,12 +447,14 @@ public class CartService { orderInfo.setMerchantId(merchantId); return orderInfo; } + public String generateOrderNumber() { String date = DateUtils.getSdfTimes(); Random random = new Random(); int randomNum = random.nextInt(900) + 100; return "WX" + date + randomNum; } + public void clearCart(JSONObject jsonObject) throws IOException { String shopId = jsonObject.getString("shopId"); if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 0e9532c..21ffb9a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -156,6 +156,11 @@ public class LoginService { } return Result.fail("登录失败"); } + public static void main(String[] args) throws Exception { + String token = TokenUtil.generateToken(19, "or1l8654IFK6GIBQjK1ZKaPH3x0M", + "19191703856", "微信用户"); + System.out.println(token); + } public TbUserInfo register(String phone, String password, String nickName) { @@ -304,9 +309,5 @@ public class LoginService { return Result.success(CodeEnum.ENCRYPT, map); } - public static void main(String[] args) { - for (int i = 0; i < 10; i++) { - System.out.println(RandomUtil.randomNumbers(10)); - } - } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index e158128..c6352fd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -3,17 +3,20 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo; import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.RedisUtils; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import com.github.pagehelper.PageHelper; @@ -27,6 +30,7 @@ import javax.annotation.Resource; import java.awt.print.Pageable; import java.io.IOException; import java.math.BigDecimal; +import java.text.ParseException; import java.time.Instant; import java.util.ArrayList; import java.util.Date; @@ -41,7 +45,7 @@ import java.util.concurrent.TimeUnit; public class OrderService { @Resource - private TbShopUserMapper shopUserMapper; + private RabbitProducer producer; @Resource private TbOrderInfoMapper orderInfoMapper; @@ -62,7 +66,7 @@ public class OrderService { @Resource private TbOrderDetailMapper tbOrderDetailMapper; @Autowired - private TbIntegralMapper tbIntegralMapper; + private TbReleaseFlowMapper releaseFlowMapper; @Resource private TbParamsMapper paramsMapper; @Resource @@ -73,6 +77,8 @@ public class OrderService { private TbUserCouponsMapper userCouponsMapper; @Resource private TbSystemCouponsMapper systemCouponsMapper; + @Autowired + private TbYhqParamsMapper yhqParamsMapper; /** * 创建订单 * @@ -253,37 +259,62 @@ public class OrderService { } @Transactional(rollbackFor = Exception.class) - public Result tradeIntegral(String userId, String id) { + public Result tradeIntegral(String userId, String id) throws ParseException { updateIntegral(userId, id); return Result.success(CodeEnum.ENCRYPT); } - private void updateIntegral(String userId, String id) { + private void updateIntegral(String userId, String id) throws ParseException { boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS); if (lock_coin) { - TbIntegral integral = tbIntegralMapper.selectByPrimaryKey(Integer.valueOf(id)); - if (Objects.isNull(integral) || !integral.getStatus().equals("1")) { + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(id)); + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { throw new MsgException("该优惠券已被使用"); } TbParams params = paramsMapper.selectByPrimaryKey(1); - BigDecimal jfAmount = params.getTradeRatio().multiply(integral.getNum()); - TbShopUser tbShopUser = shopUserMapper.selectByUserId(userId); - tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(jfAmount)); - shopUserMapper.updateByPrimaryKeySelective(tbShopUser); - integral.setStatus("TRADE"); - integral.setUpdateTime(new Date()); - tbIntegralMapper.updateByPrimaryKeySelective(integral); + BigDecimal jfAmount = params.getTradeRatio().multiply(userCoupons.getCouponsAmount()); + TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + tbShopUser.setTotalScore(tbShopUser.getTotalScore()+jfAmount.intValue()); + userInfoMapper.updateByPrimaryKeySelective(tbShopUser); + userCoupons.setStatus("2"); + userCoupons.setUpdateTime(new Date()); + userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + TbSystemCoupons systemCoupons = new TbSystemCoupons(); + systemCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30)); + systemCoupons.setCouponsAmount(userCoupons.getCouponsAmount()); + systemCoupons.setCouponsPrice(userCoupons.getCouponsPrice()); + systemCoupons.setStatus("0"); + systemCoupons.setName(userCoupons.getCouponsAmount()+"无门槛优惠券"); + systemCoupons.setCreateTime(new Date()); + String typeName = findName(userCoupons.getCouponsAmount()); + systemCoupons.setTypeName(typeName); + systemCouponsMapper.insert(systemCoupons); + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(jfAmount); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId(userId); + releaseFlow.setType("EXCHANGEADD"); + releaseFlowMapper.insert(releaseFlow); redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); } else { updateIntegral(userId, id); } } -// public Result mineYhq(String userId) { -// List list = tbIntegralMapper.selectAllByUserId(userId); -// return Result.success(CodeEnum.ENCRYPT, list); -// } + private String findName(BigDecimal amount) { + List list = yhqParamsMapper.selectAll(); + String typeName = ""; + for (TbYhqParams yhqParams:list){ + if (N.egt(amount,yhqParams.getMinPrice()) && N.gt(yhqParams.getMaxPrice(),amount)){ + typeName = yhqParams.getName(); + break; + } + } + return typeName; + } + public Result mineCoupons(String userId, String status, Integer page, Integer size) { PageHelper.startPage(page, size); @@ -292,9 +323,9 @@ public class OrderService { return Result.success(CodeEnum.SUCCESS, pageInfo); } - public Result findCoupons(Integer page, Integer size) { + public Result findCoupons(String type, Integer page, Integer size) { PageHelper.startPage(page, size); - List list = systemCouponsMapper.selectAll(); + List list = systemCouponsMapper.selectAll(type); PageInfo pageInfo = new PageInfo(list); return Result.success(CodeEnum.SUCCESS, pageInfo); } @@ -304,4 +335,28 @@ public class OrderService { List list = tbWiningUserMapper.selectAllByTrade(day); return Result.success(CodeEnum.SUCCESS, list); } + + public Result getYhqPara() { + List list = yhqParamsMapper.selectAll(); + return Result.success(CodeEnum.SUCCESS, list); + } + + public Result testPay(Integer orderId) { + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + orderInfo.setStatus("closed"); + orderInfo.setPayType("wx_lite"); + orderInfo.setPayOrderNo("test"); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfoMapper.updateByPrimaryKeySelective(orderInfo); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderId.toString()); + producer.putOrderCollect(jsonObject.toJSONString()); + JSONObject coupons = new JSONObject(); + coupons.put("type","buy"); + coupons.put("orderId",orderId); + producer.printCoupons(coupons.toJSONString()); + return Result.success(CodeEnum.SUCCESS); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 1dcefcb..0162190 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -246,7 +246,11 @@ public class PayService { log.info("发送打印数据"); producer.printMechine(orderInfo.getId() + ""); - + log.info("发送赠送购物券"); + JSONObject coupons = new JSONObject(); + coupons.put("type","buy"); + coupons.put("orderId",orderId); + producer.printCoupons(coupons.toJSONString()); return Result.success(CodeEnum.SUCCESS,orderId); case "2": //退款成功 cartStatus="refund"; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index a29904b..42c957b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -13,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; +import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -106,23 +108,17 @@ public class UserService { tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num)); } if (flag) { + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + releaseFlow.setNum(num); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId(userId); if (type.equals("sub")) { - TbReleaseFlow releaseFlow = new TbReleaseFlow(); - releaseFlow.setNum(num); - releaseFlow.setCreateTime(new Date()); - releaseFlow.setFromSource("OWER"); releaseFlow.setType("BUYSUB"); - releaseFlow.setUserId(userId); - releaseFlowMapper.insert(releaseFlow); }else if (type.equals("sub")){ - TbReleaseFlow releaseFlow = new TbReleaseFlow(); - releaseFlow.setNum(num); - releaseFlow.setCreateTime(new Date()); - releaseFlow.setFromSource("OWER"); releaseFlow.setType("THREEADD"); - releaseFlow.setUserId(userId); - releaseFlowMapper.insert(releaseFlow); } + releaseFlowMapper.insert(releaseFlow); shopUserMapper.updateByPrimaryKeySelective(tbShopUser); } redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); @@ -131,4 +127,35 @@ public class UserService { return updateIntegral(userId, num, type); } } + + public JSONObject userIntegral(IntegralFlowVo integralFlowVo, String userSign) { + JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo); + object.put("userSign", userSign); + JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map); + System.out.println(jsonObject.toJSONString()); + String sign = MD5Util.encrypt(jsonObject.toJSONString()); + if (!sign.equals(integralFlowVo.getSign())) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "签名验证失败"); + result.put("data", ""); + return result; + } + TbShopUser shopUser = shopUserMapper.selectByOpenId(integralFlowVo.getOpenId()); + if (Objects.isNull(shopUser)) { + JSONObject result = new JSONObject(); + result.put("status", "fail"); + result.put("msg", "用户不存在"); + result.put("data", ""); + return result; + } + PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize()); + PageHelper.orderBy("id DESC"); + List list = releaseFlowMapper.selectByUserId(shopUser.getId()); + JSONObject result = new JSONObject(); + result.put("status", "success"); + result.put("msg", "成功"); + result.put("data",list); + return result; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java index 114d58a..a47ee5a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.sign; import cn.hutool.json.JSONUtil; +import com.chaozhanggui.system.cashierservice.exception.IError; import com.chaozhanggui.system.cashierservice.util.DESUtil; import java.util.List; @@ -143,4 +144,12 @@ public class Result { dto.setIcon(CodeEnum.FAIL.getIcon()); return dto; } + public static Result failure(IError error) { + Result dto = new Result(); + dto.setMsg(error.getErrorMessage()); + dto.setEncrypt(false); + dto.setCode(error.getErrorCode()); + dto.setIcon(CodeEnum.FAIL.getIcon()); + return dto; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index c53181b..eac5be3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -111,18 +111,6 @@ public class AppWebSocketServer { serverList.add(this); webSocketMap.put(tableId + "-" + shopId, serverList); } - SocketSession socketSession = new SocketSession(); - socketSession.setSession(session); - socketSession.setShopId(shopId); - socketSession.setTableId(tableId); - socketSession.setUserId(userId); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(session); - byte[] sessionData = bos.toByteArray(); - - // 将序列化后的会话数据存储到Redis中 - redisUtils.saveHashAll(session.getId().getBytes(), sessionData); if (userMap.containsKey(tableId + "-" + shopId)) { Set userSet = userMap.get(tableId + "-" + shopId); userSet.add(userId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java index 771b43d..88eead9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -1,17 +1,38 @@ package com.chaozhanggui.system.cashierservice.task; +import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper; +import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper; +import com.chaozhanggui.system.cashierservice.dao.TbWiningParamsMapper; import com.chaozhanggui.system.cashierservice.dao.TbWiningUserMapper; +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; +import com.chaozhanggui.system.cashierservice.entity.TbWiningParams; +import com.chaozhanggui.system.cashierservice.entity.TbWiningUser; import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.NicknameGenerator; +import com.chaozhanggui.system.cashierservice.util.RandomUtil; +import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.ParseException; +import java.util.*; +import java.util.concurrent.*; + @Component public class TaskScheduler { @Autowired private TbWiningUserMapper tbWiningUserMapper; - + @Autowired + private TbOrderInfoMapper orderInfoMapper; + @Autowired + private TbWiningParamsMapper winingParamsMapper; + @Autowired + private TbUserInfoMapper userInfoMapper; //更新订单状态 // @Scheduled(fixedRate = 1000, initialDelay = 5000) public void orderStatus() throws InterruptedException { @@ -20,9 +41,81 @@ public class TaskScheduler { } - // @Scheduled(fixedRate = 1000) - public void winningUser(){ - System.out.println("恭喜您中奖了"+DateUtils.getTime()); + public void winningUser() { + String day = DateUtils.getDay(); + List list = winingParamsMapper.selectAll(); + ThreadPoolExecutor es = new ThreadPoolExecutor(5, 10, 60L, TimeUnit.SECONDS, + new LinkedBlockingQueue(), new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }); + for (TbWiningParams winingParams : list) { + es.submit(new winingUser(winingParams, day)); + } + es.shutdown(); + + } + + class winingUser implements Runnable { + private TbWiningParams winingParams; + private String day; + + public winingUser(TbWiningParams winingParams, String day) { + this.winingParams = winingParams; + this.day = day; + } + + @Override + public void run() { + try { + List list = orderInfoMapper.selectByTradeDay(day, winingParams.getMinPrice(), winingParams.getMaxPrice()); + int num = winingParams.getWiningUserNum(); + List newList = new ArrayList<>(); + Map map = new HashMap<>(); + int noUserNum = winingParams.getWiningNum() - num; + if (list.size() < num) { + noUserNum = winingParams.getWiningNum(); + } else { + for (int i = 0; i < num; i++) { + TbOrderInfo orderInfo = RandomUtil.selectWinner(list, map); + newList.add(orderInfo); + map.put(orderInfo.getId(), 1); + } + } + for (int i = 0; i < noUserNum; i++) { + long endDate = DateUtils.convertDate1(day + " 00:00:00").getTime(); + long startDate = DateUtils.convertDate1(DateUtils.getTimes(DateUtils.getNewDate(new Date(), 3, -1)) + " 00:00:00").getTime(); + String orderNo = generateOrderNumber(startDate, endDate); + String userName = NicknameGenerator.generateRandomWeChatNickname(); + BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(winingParams.getMinPrice(), winingParams.getMaxPrice()); + TbWiningUser winingUser = new TbWiningUser(userName, orderNo, orderAmount, "false", day); + tbWiningUserMapper.insert(winingUser); + } + for (TbOrderInfo orderInfo:newList){ + TbUserInfo userInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserId())); + TbWiningUser winingUser = new TbWiningUser(userInfo.getNickName(), orderInfo.getOrderNo(), orderInfo.getPayAmount(), "true", day); + tbWiningUserMapper.insert(winingUser); + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + } + + public String generateOrderNumber(long startTimestamp, long endTimestamp) { + long date = getRandomTimestamp(startTimestamp, endTimestamp); + Random random = new Random(); + int randomNum = random.nextInt(900) + 100; + return "WX" + date + randomNum; + } + + public static long getRandomTimestamp(long startTimestamp, long endTimestamp) { + long randomMilliseconds = ThreadLocalRandom.current().nextLong(startTimestamp, endTimestamp); + return randomMilliseconds; } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java new file mode 100644 index 0000000..f50d390 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/NicknameGenerator.java @@ -0,0 +1,40 @@ +package com.chaozhanggui.system.cashierservice.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Random; + +public class NicknameGenerator { + private static final String[] FIRST_NAMES = { + "晓", "小", "云", "飞", "宝", "琳", "静", "翔", "晨", "昊", "若", "萌", "悦", "舒", "婷", "紫", "凡", "佳", "雨", "阳" + }; + + private static final String[] LAST_NAMES = { + "天", "星", "月", "琪", "雪", "梦", "婷", "晨", "宇", "瑞", "颖", "欣", "莹", "妍", "娜", "辰", "楠", "妮", "欢", "瑶" + }; + + private static final String[] WORDS = { + "烟火", "夜景", "小巷", "阳光", "雨滴", "星空", "花海", "梦境", "魔法", "飞翔", "童话", "温柔", "快乐", "微笑", "甜蜜", "浪漫", "幸福" + }; + + private static final String[] EMOJIS = { + "(^-^)", "( ̄▽ ̄)~■干杯□~( ̄▽ ̄)", "(*^▽^*)", "≧◡≦", "ヾ(≧▽≦*)o", + "(*^3^)/~☆", "(*^▽^*)", "╰( ̄▽ ̄)╮", "(o^^)o", "(づ ̄ 3 ̄)づ" + }; + + public static String generateRandomWeChatNickname() { + Random random = new Random(); + String firstName = FIRST_NAMES[random.nextInt(FIRST_NAMES.length)]; + String lastName = LAST_NAMES[random.nextInt(LAST_NAMES.length)]; + String word = WORDS[random.nextInt(WORDS.length)]; + String emoji = EMOJIS[random.nextInt(EMOJIS.length)]; + return firstName + lastName + word + emoji; + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java new file mode 100644 index 0000000..c89b72e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java @@ -0,0 +1,31 @@ +package com.chaozhanggui.system.cashierservice.util; + +import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class RandomUtil { + //获取BigDeciaml随机数 + public static BigDecimal getRandomBigDecimal(BigDecimal minAmount, BigDecimal maxAmount) { + BigDecimal randomBigDecimal = maxAmount.subtract(minAmount).multiply(new BigDecimal(Math.random())).add(minAmount); + return randomBigDecimal.setScale(2, RoundingMode.HALF_UP); // 设置保留两位小数并四舍五入 + } + //获取中奖随机数 + public static TbOrderInfo selectWinner(List list, Map map) { + if (list == null || list.isEmpty()) { + return null; // 如果用户列表为空,则返回null + } + + Random random = new Random(); + int randomIndex = random.nextInt(list.size()); // 生成一个随机的索引值 + TbOrderInfo orderInfo = list.get(randomIndex); + if (map.containsKey(orderInfo.getId())){ + return selectWinner(list,map); + } + return list.get(randomIndex); // 返回对应索引的用户 + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java deleted file mode 100644 index 6268b23..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/WiningUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.chaozhanggui.system.cashierservice.util; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Random; - -public class WiningUtil { - private List participants; - private Random random; - - public WiningUtil(List participants) { - this.participants = participants; - this.random = new Random(); - } - - public String drawWinner() { - if (participants.isEmpty()) { - return "No participants to draw from"; - } - - int index = random.nextInt(participants.size()); - return participants.get(index); - } - - public static void main(String[] args) { - // 参与抽奖的人员名单 - List participants = new ArrayList<>(); - participants.add("Alice"); - participants.add("Bob"); - participants.add("Charlie"); - participants.add("David"); - participants.add("Eve"); - - // 创建抽奖对象 - WiningUtil winingUtil = new WiningUtil(participants); - - // 进行抽奖 - String winner = winingUtil.drawWinner(); - System.out.println("Winner: " + winner); - } - public static boolean winingresult(){ - - return false; - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 393e40e..f0a4eef 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -55,7 +55,9 @@ ysk: callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 server: - port: 9889 + port: 9888 +prod: dev1 +queue: cart_queue_putdev1 diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml new file mode 100644 index 0000000..022ca33 --- /dev/null +++ b/src/main/resources/application-dev2.yml @@ -0,0 +1,63 @@ +spring: + datasource: + url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false + username: root + password: mysqlroot@123 + driver-class-name: com.mysql.cj.jdbc.Driver + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + logging: + level: + com.chaozhanggui.system.openness: info + redis: + # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 + database: 5 + # redis服务器地址(默认为localhost) + host: 101.37.12.135 + # redis端口(默认为6379) + port: 6379 + # redis访问密码(默认为空) + password: 111111 + # redis连接超时时间(单位为毫秒) + timeout: 1000 + block-when-exhausted: true + # redis连接池配置 + jedis: + pool: + max-active: 8 + max-idle: 1024 + min-idle: 0 + max-wait: -1 + main: + allow-circular-references: true + rabbitmq: + host: 101.37.12.135 + port: 5672 + username: admin + password: Czg666888 +#分页配置 +pagehelper: + supportMethodsArguments: true + reasonable: true + helperDialect: mysql + params: count=countSql + +mybatis: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath:mapper/*.xml +ysk: + url: https://gatewaytestapi.sxczgkj.cn/gate-service/ + callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack + callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack + default: 18710449883 +server: + port: 9889 +prod: devyhq +queue: cart_queue_putdevyhq + + + diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index f8e8e1d..767ea64 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -56,6 +56,8 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +prod: prod1 +queue: cart_queue_putprod1 diff --git a/src/main/resources/application-prod2.yml b/src/main/resources/application-prod2.yml index e8c808b..22f552f 100644 --- a/src/main/resources/application-prod2.yml +++ b/src/main/resources/application-prod2.yml @@ -56,6 +56,8 @@ ysk: callBackurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBack callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +prod: prod2 +queue: cart_queue_putprod2 diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index a31c3b8..c908550 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -52,7 +52,7 @@ -
diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index 0bef918..8b61660 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -552,4 +552,8 @@ + \ No newline at end of file diff --git a/src/main/resources/mapper/TbReleaseFlowMapper.xml b/src/main/resources/mapper/TbReleaseFlowMapper.xml new file mode 100644 index 0000000..597c801 --- /dev/null +++ b/src/main/resources/mapper/TbReleaseFlowMapper.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + id, user_id, num, type, remark, from_source, create_time + + + + + delete from tb_release_flow + where id = #{id,jdbcType=INTEGER} + + + insert into tb_release_flow (id, user_id, num, + type, remark, from_source, + create_time) + values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{num,jdbcType=DECIMAL}, + #{type,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{fromSource,jdbcType=VARCHAR}, + #{createTime,jdbcType=TIMESTAMP}) + + + insert into tb_release_flow + + + id, + + + user_id, + + + num, + + + type, + + + remark, + + + from_source, + + + create_time, + + + + + #{id,jdbcType=INTEGER}, + + + #{userId,jdbcType=VARCHAR}, + + + #{num,jdbcType=DECIMAL}, + + + #{type,jdbcType=VARCHAR}, + + + #{remark,jdbcType=VARCHAR}, + + + #{fromSource,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update tb_release_flow + + + user_id = #{userId,jdbcType=VARCHAR}, + + + num = #{num,jdbcType=DECIMAL}, + + + type = #{type,jdbcType=VARCHAR}, + + + remark = #{remark,jdbcType=VARCHAR}, + + + from_source = #{fromSource,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_release_flow + set user_id = #{userId,jdbcType=VARCHAR}, + num = #{num,jdbcType=DECIMAL}, + type = #{type,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR}, + from_source = #{fromSource,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index a16fbc7..42dbfa5 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -45,6 +45,7 @@ + @@ -55,7 +56,7 @@ detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, - distribute_level, created_at, updated_at, proxy_id + distribute_level, created_at, updated_at, proxy_id,is_open_yhq
view diff --git a/src/main/resources/mapper/TbSystemCouponsMapper.xml b/src/main/resources/mapper/TbSystemCouponsMapper.xml index 54ad7f7..2185fbf 100644 --- a/src/main/resources/mapper/TbSystemCouponsMapper.xml +++ b/src/main/resources/mapper/TbSystemCouponsMapper.xml @@ -7,12 +7,13 @@ + - id, name, coupons_price, coupons_amount, status, create_time, update_time, end_time + id, name, coupons_price, coupons_amount, status, create_time, update_time, end_time,type_name delete from tb_system_coupons @@ -30,10 +31,10 @@ insert into tb_system_coupons (id, name, coupons_price, coupons_amount, status, create_time, - update_time, end_time) + update_time, end_time,type_name) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL}, #{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}) + #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{typeName,jdbcType=VARCHAR}) insert into tb_system_coupons diff --git a/src/main/resources/mapper/TbWiningParamsMapper.xml b/src/main/resources/mapper/TbWiningParamsMapper.xml new file mode 100644 index 0000000..00f9f38 --- /dev/null +++ b/src/main/resources/mapper/TbWiningParamsMapper.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + id, min_price, max_price, wining_num, wining_user_num,status + + + + + delete from tb_wining_params + where id = #{id,jdbcType=INTEGER} + + + insert into tb_wining_params (id, min_price, max_price, + wining_num, wining_user_num) + values (#{id,jdbcType=INTEGER}, #{minPrice,jdbcType=DECIMAL}, #{maxPrice,jdbcType=DECIMAL}, + #{winingNum,jdbcType=INTEGER}, #{winingUserNum,jdbcType=INTEGER}) + + + insert into tb_wining_params + + + id, + + + min_price, + + + max_price, + + + wining_num, + + + wining_user_num, + + + + + #{id,jdbcType=INTEGER}, + + + #{minPrice,jdbcType=DECIMAL}, + + + #{maxPrice,jdbcType=DECIMAL}, + + + #{winingNum,jdbcType=INTEGER}, + + + #{winingUserNum,jdbcType=INTEGER}, + + + + + update tb_wining_params + + + min_price = #{minPrice,jdbcType=DECIMAL}, + + + max_price = #{maxPrice,jdbcType=DECIMAL}, + + + wining_num = #{winingNum,jdbcType=INTEGER}, + + + wining_user_num = #{winingUserNum,jdbcType=INTEGER}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_wining_params + set min_price = #{minPrice,jdbcType=DECIMAL}, + max_price = #{maxPrice,jdbcType=DECIMAL}, + wining_num = #{winingNum,jdbcType=INTEGER}, + wining_user_num = #{winingUserNum,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbWiningUserMapper.xml b/src/main/resources/mapper/TbWiningUserMapper.xml index ab1b7a7..99bc24d 100644 --- a/src/main/resources/mapper/TbWiningUserMapper.xml +++ b/src/main/resources/mapper/TbWiningUserMapper.xml @@ -7,11 +7,17 @@ - + + + + + + - id, user_name, order_no, order_amount, is_user, create_time,trade_day + id, user_name, order_no, order_amount, is_user, create_time, is_refund, refund_amount, + refund_no, refund_pay_type, trade_day, refund_time - - + delete from tb_wining_user where id = #{id,jdbcType=INTEGER} insert into tb_wining_user (id, user_name, order_no, - order_amount, is_user, create_time + order_amount, is_user, create_time, + is_refund, refund_amount, refund_no, + refund_pay_type, trade_day, refund_time ) values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, - #{orderAmount,jdbcType=DECIMAL}, #{isUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + #{orderAmount,jdbcType=DECIMAL}, #{isUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{isRefund,jdbcType=VARCHAR}, #{refundAmount,jdbcType=DECIMAL}, #{refundNo,jdbcType=VARCHAR}, + #{refundPayType,jdbcType=VARCHAR}, #{tradeDay,jdbcType=VARCHAR}, #{refundTime,jdbcType=TIMESTAMP} ) @@ -55,6 +62,24 @@ create_time, + + is_refund, + + + refund_amount, + + + refund_no, + + + refund_pay_type, + + + trade_day, + + + refund_time, + @@ -75,6 +100,24 @@ #{createTime,jdbcType=TIMESTAMP}, + + #{isRefund,jdbcType=VARCHAR}, + + + #{refundAmount,jdbcType=DECIMAL}, + + + #{refundNo,jdbcType=VARCHAR}, + + + #{refundPayType,jdbcType=VARCHAR}, + + + #{tradeDay,jdbcType=VARCHAR}, + + + #{refundTime,jdbcType=TIMESTAMP}, + @@ -95,6 +138,24 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, + + is_refund = #{isRefund,jdbcType=VARCHAR}, + + + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + + + refund_no = #{refundNo,jdbcType=VARCHAR}, + + + refund_pay_type = #{refundPayType,jdbcType=VARCHAR}, + + + trade_day = #{tradeDay,jdbcType=VARCHAR}, + + + refund_time = #{refundTime,jdbcType=TIMESTAMP}, + where id = #{id,jdbcType=INTEGER} @@ -104,7 +165,16 @@ order_no = #{orderNo,jdbcType=VARCHAR}, order_amount = #{orderAmount,jdbcType=DECIMAL}, is_user = #{isUser,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=TIMESTAMP} + create_time = #{createTime,jdbcType=TIMESTAMP}, + is_refund = #{isRefund,jdbcType=VARCHAR}, + refund_amount = #{refundAmount,jdbcType=DECIMAL}, + refund_no = #{refundNo,jdbcType=VARCHAR}, + refund_pay_type = #{refundPayType,jdbcType=VARCHAR}, + trade_day = #{tradeDay,jdbcType=VARCHAR}, + refund_time = #{refundTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} + \ No newline at end of file diff --git a/src/main/resources/mapper/TbYhqParamsMapper.xml b/src/main/resources/mapper/TbYhqParamsMapper.xml new file mode 100644 index 0000000..6636929 --- /dev/null +++ b/src/main/resources/mapper/TbYhqParamsMapper.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + id, name, min_price, max_price, status + + + + + delete from tb_yhq_params + where id = #{id,jdbcType=INTEGER} + + + insert into tb_yhq_params (id, name, min_price, + max_price, status) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{minPrice,jdbcType=DECIMAL}, + #{maxPrice,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}) + + + insert into tb_yhq_params + + + id, + + + name, + + + min_price, + + + max_price, + + + status, + + + + + #{id,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + #{minPrice,jdbcType=DECIMAL}, + + + #{maxPrice,jdbcType=DECIMAL}, + + + #{status,jdbcType=VARCHAR}, + + + + + update tb_yhq_params + + + name = #{name,jdbcType=VARCHAR}, + + + min_price = #{minPrice,jdbcType=DECIMAL}, + + + max_price = #{maxPrice,jdbcType=DECIMAL}, + + + status = #{status,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_yhq_params + set name = #{name,jdbcType=VARCHAR}, + min_price = #{minPrice,jdbcType=DECIMAL}, + max_price = #{maxPrice,jdbcType=DECIMAL}, + status = #{status,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file From 9a6f6eb5b6e2bcd88946bb165165083e79d2f109 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 11 Apr 2024 14:26:35 +0800 Subject: [PATCH 008/134] =?UTF-8?q?=E9=A6=96=E9=A1=B5=20=E9=87=91=E5=88=9A?= =?UTF-8?q?=E5=8C=BA=20=E6=A0=87=E7=AD=BE=20=E8=AF=A6=E6=83=85=20=E6=A0=87?= =?UTF-8?q?=E7=AD=BEVO=E4=B8=80=E5=A0=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProductController.java | 9 +- .../dao/TagProductDeptsMapper.java | 73 +----- .../dao/TbPlatformDictMapper.java | 57 +---- .../dao/TbProductSkuMapper.java | 1 + .../dao/TbPurchaseNoticeMapper.java | 22 ++ .../entity/TagProductDepts.java | 53 ----- .../cashierservice/entity/TbPlatformDict.java | 40 +++- .../entity/TbPurchaseNotice.java | 160 +++++++++++++ .../cashierservice/entity/vo/HomeUpVO.java | 14 +- .../cashierservice/entity/vo/HomeVO.java | 16 +- .../entity/vo/ProductInfoVo.java | 73 ++++++ .../cashierservice/entity/vo/ProductVo.java | 30 +++ .../entity/vo/TagProductVO.java | 36 +-- .../entity/vo/productInfoVo.java | 41 ---- .../service/HomePageService.java | 20 +- .../service/ProductService.java | 176 +++++++++++---- .../system/cashierservice/util/JSONUtil.java | 20 ++ .../mapper/TagProductDeptsMapper.xml | 129 +++-------- .../resources/mapper/TbPlatformDictMapper.xml | 213 ++---------------- .../resources/mapper/TbProductSkuMapper.xml | 8 + .../mapper/TbPurchaseNoticeMapper.xml | 34 +++ 21 files changed, 592 insertions(+), 633 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java create mode 100644 src/main/resources/mapper/TbPurchaseNoticeMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 5bcca82..2af5a4f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Map; +import java.util.concurrent.ExecutionException; @CrossOrigin(origins = "*") @RestController @@ -40,9 +41,9 @@ public class ProductController { return productService.queryProductSku(shopId,productId,spec_tag); } -// @GetMapping("/productInfo") -// public Result productInfo(@RequestParam Integer productId){ -// return productService.productInfo() -// } + @GetMapping("/productInfo") + public Result productInfo(@RequestParam Integer productId) throws Exception { + return productService.productInfo(productId); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java index 0b63548..d595e87 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java @@ -1,16 +1,14 @@ package com.chaozhanggui.system.cashierservice.dao; -import com.chaozhanggui.system.cashierservice.entity.TagProductDepts; import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import java.util.List; /** - * (TagProductDepts)表数据库访问层 + * (TagProductDepts) 商品标签 表数据库访问层 * * @author lyf * @since 2024-04-08 15:03:49 @@ -18,74 +16,7 @@ import java.util.List; @Component @Mapper public interface TagProductDeptsMapper { - - /** - * 通过ID查询单条数据 - * - * @param tagId 主键 - * @return 实例对象 - */ - TagProductDepts queryById(Integer tagId); - - /** - * 查询指定行数据 - * - * @param tagProductDepts 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(TagProductDepts tagProductDepts, @Param("pageable") Pageable pageable); - List queryTagAndProduct(@Param("list") List list); - - /** - * 统计总行数 - * - * @param tagProductDepts 查询条件 - * @return 总行数 - */ - long count(TagProductDepts tagProductDepts); - - /** - * 新增数据 - * - * @param tagProductDepts 实例对象 - * @return 影响行数 - */ - int insert(TagProductDepts tagProductDepts); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 批量新增或按主键更新数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 - */ - int insertOrUpdateBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tagProductDepts 实例对象 - * @return 影响行数 - */ - int update(TagProductDepts tagProductDepts); - - /** - * 通过主键删除数据 - * - * @param tagId 主键 - * @return 影响行数 - */ - int deleteById(Integer tagId); - + List queryTagByProductId(@Param("productId") String productId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java index fa1ce5b..3c7cd23 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java @@ -22,64 +22,9 @@ public interface TbPlatformDictMapper { */ TbPlatformDict queryById(Integer id); - /** - * 查询指定行数据 - * - * @param tbPlatformDict 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(TbPlatformDict tbPlatformDict, @Param("pageable") Pageable pageable); + List queryByIdList(List idList); List queryAllByType(@Param("type") String type,@Param("environment") String environment); - /** - * 统计总行数 - * - * @param tbPlatformDict 查询条件 - * @return 总行数 - */ - long count(TbPlatformDict tbPlatformDict); - - /** - * 新增数据 - * - * @param tbPlatformDict 实例对象 - * @return 影响行数 - */ - int insert(TbPlatformDict tbPlatformDict); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 批量新增或按主键更新数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 - */ - int insertOrUpdateBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tbPlatformDict 实例对象 - * @return 影响行数 - */ - int update(TbPlatformDict tbPlatformDict); - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 影响行数 - */ - int deleteById(Integer id); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java index 018ec3e..7edb951 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java @@ -38,4 +38,5 @@ public interface TbProductSkuMapper { List selectDownSku(@Param("list") List productId); List selectSkus(@Param("list") List productId); + List selectSku(@Param("productId") String productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java new file mode 100644 index 0000000..d1fa563 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbPurchaseNotice; + +/** + * 购买须知(关联tb_merchant_coupon)(TbPurchaseNotice)表数据库访问层 + * + * @author ww + * @since 2024-04-11 10:00:23 + */ +public interface TbPurchaseNoticeMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbPurchaseNotice queryById(Integer id); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java deleted file mode 100644 index 37e6904..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity; - -import java.util.Date; -import java.io.Serializable; - -/** - * (TagProductDepts)实体类 - * - * @author lyf - * @since 2024-04-08 14:57:05 - */ -public class TagProductDepts implements Serializable { - private static final long serialVersionUID = -39116122966010022L; - /** - * 标签id - */ - private Integer tagId; - /** - * 商品id - */ - private Integer productId; - /** - * 创建时间 - */ - private Date createTime; - - - public Integer getTagId() { - return tagId; - } - - public void setTagId(Integer tagId) { - this.tagId = tagId; - } - - public Integer getProductId() { - return productId; - } - - public void setProductId(Integer productId) { - this.productId = productId; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - -} - diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java index 55e42cf..9dbb00a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java @@ -12,10 +12,16 @@ public class TbPlatformDict implements Serializable { private static final long serialVersionUID = -34581903392247717L; private Integer id; + /** + * 标签前图标 + */ + private String shareImg; /** * 描述 同类型下 name唯一 */ private String name; + private String fontColor; + private String backColor; /** * homeDistrict--金刚区(首页) carousel--轮播图 tag--标签 */ @@ -24,10 +30,6 @@ public class TbPlatformDict implements Serializable { * 封面图 */ private String coverImg; - /** - * 分享图 - */ - private String shareImg; /** * 视频URL地址 */ @@ -36,10 +38,8 @@ public class TbPlatformDict implements Serializable { * 视频封面图 */ private String videoCoverImg; - /** - * 相对跳转地址 - */ - private String relUrl; + + private String jumpType; /** * 绝对跳转地址 */ @@ -78,6 +78,22 @@ public class TbPlatformDict implements Serializable { this.id = id; } + public String getFontColor() { + return fontColor; + } + + public void setFontColor(String fontColor) { + this.fontColor = fontColor; + } + + public String getBackColor() { + return backColor; + } + + public void setBackColor(String backColor) { + this.backColor = backColor; + } + public String getName() { return name; } @@ -126,12 +142,12 @@ public class TbPlatformDict implements Serializable { this.videoCoverImg = videoCoverImg; } - public String getRelUrl() { - return relUrl; + public String getJumpType() { + return jumpType; } - public void setRelUrl(String relUrl) { - this.relUrl = relUrl; + public void setJumpType(String jumpType) { + this.jumpType = jumpType; } public String getAbsUrl() { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java new file mode 100644 index 0000000..1085810 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java @@ -0,0 +1,160 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; + +/** + * 购买须知(关联tb_merchant_coupon)(TbPurchaseNotice)实体类 + * + * @author ww + * @since 2024-04-11 10:00:23 + */ +public class TbPurchaseNotice implements Serializable { + private static final long serialVersionUID = 811103518413221387L; + /** + * 自增 + */ + private Integer id; + /** + * 商户卷Id + */ + private Integer couponId; + /** + * 使用日期说明 + */ + private String dateUsed; + /** + * 可用时间说明 + */ + private String availableTime; + /** + * 预约方式 + */ + private String bookingType; + /** + * 退款说明 + */ + private String refundPolicy; + /** + * 使用规则 + */ + private String usageRules; + /** + * 发票说明 + */ + private String invoiceInfo; + /** + * 团购价说明 + */ + private String groupPurInfo; + /** + * 门市价/划线价说明 + */ + private String marketPriceInfo; + /** + * 折扣说明 + */ + private String discountInfo; + /** + * 平台温馨提示 + */ + private String platformTips; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCouponId() { + return couponId; + } + + public void setCouponId(Integer couponId) { + this.couponId = couponId; + } + + public String getDateUsed() { + return dateUsed; + } + + public void setDateUsed(String dateUsed) { + this.dateUsed = dateUsed; + } + + public String getAvailableTime() { + return availableTime; + } + + public void setAvailableTime(String availableTime) { + this.availableTime = availableTime; + } + + public String getBookingType() { + return bookingType; + } + + public void setBookingType(String bookingType) { + this.bookingType = bookingType; + } + + public String getRefundPolicy() { + return refundPolicy; + } + + public void setRefundPolicy(String refundPolicy) { + this.refundPolicy = refundPolicy; + } + + public String getUsageRules() { + return usageRules; + } + + public void setUsageRules(String usageRules) { + this.usageRules = usageRules; + } + + public String getInvoiceInfo() { + return invoiceInfo; + } + + public void setInvoiceInfo(String invoiceInfo) { + this.invoiceInfo = invoiceInfo; + } + + public String getGroupPurInfo() { + return groupPurInfo; + } + + public void setGroupPurInfo(String groupPurInfo) { + this.groupPurInfo = groupPurInfo; + } + + public String getMarketPriceInfo() { + return marketPriceInfo; + } + + public void setMarketPriceInfo(String marketPriceInfo) { + this.marketPriceInfo = marketPriceInfo; + } + + public String getDiscountInfo() { + return discountInfo; + } + + public void setDiscountInfo(String discountInfo) { + this.discountInfo = discountInfo; + } + + public String getPlatformTips() { + return platformTips; + } + + public void setPlatformTips(String platformTips) { + this.platformTips = platformTips; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java index d1ea0a6..02728f4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java @@ -1,8 +1,6 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.SysDict; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; -import lombok.Data; import java.util.List; @@ -14,11 +12,11 @@ public class HomeUpVO { /** * 轮播图 */ - List carousel; + List carousel; /** * 金刚区 */ - List district; + List district; /** * 条件查询 */ @@ -60,19 +58,19 @@ public class HomeUpVO { this.salesList = salesList; } - public List getCarousel() { + public List getCarousel() { return carousel; } - public void setCarousel(List carousel) { + public void setCarousel(List carousel) { this.carousel = carousel; } - public List getDistrict() { + public List getDistrict() { return district; } - public void setDistrict(List district) { + public void setDistrict(List district) { this.district = district; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index dc77381..a97c41a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -1,9 +1,7 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import org.springframework.format.annotation.DateTimeFormat; - import java.math.BigDecimal; -import java.util.Date; +import java.util.ArrayList; import java.util.List; /** @@ -48,11 +46,11 @@ public class HomeVO { /** * 店铺标签 */ - private List shopTag; + private List shopTag; /** * 商品标签 */ - private List proTag; + private List proTag=new ArrayList<>(); /** * 距离 */ @@ -88,19 +86,19 @@ public class HomeVO { this.distances = distances; } - public List getShopTag() { + public List getShopTag() { return shopTag; } - public void setShopTag(List shopTag) { + public void setShopTag(List shopTag) { this.shopTag = shopTag; } - public List getProTag() { + public List getProTag() { return proTag; } - public void setProTag(List proTag) { + public void setProTag(List proTag) { this.proTag = proTag; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java new file mode 100644 index 0000000..394eca8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java @@ -0,0 +1,73 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import com.alibaba.fastjson.JSONArray; +import com.chaozhanggui.system.cashierservice.entity.TbPurchaseNotice; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author lyf + */ +@Data +public class ProductInfoVo { + /** + * 商品图片 + */ + private JSONArray images; + + /** + * 现价 + */ + private BigDecimal salePrice; + /** + * 折扣 + */ + private Float discount; + /** + * 原价 + */ + private BigDecimal originPrice; + + /** + * 销量 + */ + private BigDecimal realSalesNumber; + + /** + * 商品名称 + */ + private String productName; + /** + * 店铺名称 + */ + private String shopName; + /** + * 联系方式 + */ + private String phone; + /** + * 营业时间 + */ + private String businessTime; + /** + * 距离 + */ + private String distances = "100"; + /** + * 地址 + */ + private String address; + + /** + * 套餐详情 + */ + List productList = new ArrayList<>(); + + /** + * 购买须知/价格说明 + */ + private TbPurchaseNotice purchaseNotice; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java new file mode 100644 index 0000000..05c9af4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java @@ -0,0 +1,30 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Data +public class ProductVo { + //选几个 + private Integer number; + + //类别 + private String title; + + //食物 + private List foods=new ArrayList<>(); // 食品列表 + + @Data + public static class Food { + private String name; // 商品名称 + private BigDecimal price; // 售价 + private String unit; // 单位 + /** + * 商品标签 + */ + private List proTag=new ArrayList<>(); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java index 939d5cc..1fbda4d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java @@ -1,34 +1,22 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import lombok.Data; + /** + * 商品 标签 * @author lyf */ +@Data public class TagProductVO { + //商品id private Integer productId; + //标签前 小图标 + private String shareImg; + //标签 名称 private String name; - private String tags; + //字体颜色 + private String fontColor; + //背景色 + private String backColor; - public Integer getProductId() { - return productId; - } - - public void setProductId(Integer productId) { - this.productId = productId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java deleted file mode 100644 index 0073c6e..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -import java.math.BigDecimal; -import java.util.List; - -/** - * @author lyf - */ -public class productInfoVo { - /** - * 商品图片 - */ - private Listimages; - - /** - * 原价 - */ - private BigDecimal originPrice; - /** - * 现价 - */ - private BigDecimal salePrice; - /** - * 折扣 - */ - private Float discount; - /** - * 共省金额 - */ - private BigDecimal save; - - /** - * 销量 - */ - private BigDecimal realSalesNumber; - - /** - * 结束时间 - */ - private Long endTime; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 2e8773d..f59fd8a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -7,8 +7,10 @@ import com.chaozhanggui.system.cashierservice.entity.vo.*; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.Threads; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -20,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; /** * @author lyf @@ -80,12 +83,14 @@ public class HomePageService { if (o.getShopId().equals(tbShopInfo.getId().toString())) { homeVO.setShopName(tbShopInfo.getShopName()); homeVO.setImage(tbShopInfo.getLogo()); - if (tbShopInfo.getTag() == null){ + if (StringUtils.isBlank(tbShopInfo.getTag())){ homeVO.setShopTag(new ArrayList<>()); }else { - TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag())); - - homeVO.setShopTag(tbPlatformDict == null ? new ArrayList<>() : Collections.singletonList(tbPlatformDict.getName())); + List shopTagIds = Arrays.stream(tbShopInfo.getTag().split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + List tbPlatformDicts = platformDictMapper.queryByIdList(shopTagIds); + homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); } } } @@ -108,7 +113,7 @@ public class HomePageService { } for (TagProductVO tagProductVO :dictPro.get()) { if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){ - homeVO.setProTag(tagList(tagProductVO.getTags())); + homeVO.getProTag().add(tagProductVO); } } homeVO.setEndTime(DateUtils.getDayEndLong()); @@ -131,10 +136,11 @@ public class HomePageService { HomeUpVO homeUpVO = new HomeUpVO(); //轮播图 List carouselList = platformDictMapper.queryAllByType("carousel", environment); - homeUpVO.setCarousel(carouselList); + homeUpVO.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); //金刚区 List districtList = platformDictMapper.queryAllByType("homeDistrict", environment); - homeUpVO.setDistrict(districtList); + homeUpVO.setDistrict(JSONUtil.parseListTNewList(districtList, HomeDistrictVo.class)); + //菜单 List sysDicts = sysDictDetailMapper.selectByAll(); List dicDetailVO = new ArrayList<>(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 8581305..53cfa05 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -2,21 +2,32 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.vo.ProductInfoVo; +import com.chaozhanggui.system.cashierservice.entity.vo.ProductVo; +import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; +import com.chaozhanggui.system.cashierservice.util.Threads; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutionException; @Service @Slf4j @@ -37,90 +48,165 @@ public class ProductService { @Autowired private TbShopTableMapper tbShopTableMapper; - - + @Resource + private TagProductDeptsMapper tagProductDeptsMapper; + @Resource + private TbMerchantCouponMapper merchantCouponMapper; + @Resource + private TbPlatformDictMapper platformDictMapper; + @Resource + private TbShopUnitMapper unitMapper; + @Resource + private TbShopCategoryMapper categoryMapper; + @Resource + private TbPurchaseNoticeMapper purchaseNoticeMapper; @Autowired TbProductSkuMapper tbProductSkuMapper; + public Result queryProduct(String code, String productGroupId) { + ConcurrentMap concurrentMap = new ConcurrentHashMap<>(); - - - - public Result queryProduct(String code,String productGroupId){ - - ConcurrentMap concurrentMap=new ConcurrentHashMap<>(); - - TbShopTable tbShopTable= tbShopTableMapper.selectQRcode(code); - if(ObjectUtil.isEmpty(tbShopTable)||ObjectUtil.isNull(tbShopTable)){ + TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code); + if (ObjectUtil.isEmpty(tbShopTable) || ObjectUtil.isNull(tbShopTable)) { return Result.fail("台桌信息不存在"); } - Integer id= ObjectUtil.isNotEmpty(productGroupId)?Integer.valueOf(productGroupId):null; - List groupList=tbProductGroupMapper.selectByQrcode(code,id); - if(ObjectUtil.isNotEmpty(groupList)&&groupList.size()>0){ + Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; + List groupList = tbProductGroupMapper.selectByQrcode(code, id); + if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { - TbProductGroup group= groupList.get(0); - TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(group.getShopId()) ; - concurrentMap.put("shopTableInfo",tbShopTable); - concurrentMap.put("storeInfo",shopInfo); - groupList.parallelStream().forEach(g->{ - String in=g.getProductIds().substring(1,g.getProductIds().length()-1); + TbProductGroup group = groupList.get(0); + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(group.getShopId()); + concurrentMap.put("shopTableInfo", tbShopTable); + concurrentMap.put("storeInfo", shopInfo); + groupList.parallelStream().forEach(g -> { + String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); - if(ObjectUtil.isNotEmpty(in)&&ObjectUtil.isNotNull(in)){ - log.info("请求参数:{}",in); - List products= tbProductMapper.selectByIdIn(in); - if(ObjectUtil.isNotEmpty(products)&&products.size()>0){ - products.parallelStream().forEach(it->{ + if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) { + log.info("请求参数:{}", in); + List products = tbProductMapper.selectByIdIn(in); + if (ObjectUtil.isNotEmpty(products) && products.size() > 0) { + products.parallelStream().forEach(it -> { Integer sum = 0; - if (AppWebSocketServer.userMap.containsKey(code)){ + if (AppWebSocketServer.userMap.containsKey(code)) { Set userSet = AppWebSocketServer.userMap.get(code); - if (userSet.isEmpty()){ - sum= tbProductMapper.selectByQcode(code,it.getId(),it.getShopId()); - }else { + if (userSet.isEmpty()) { + sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId()); + } else { List userList = new ArrayList<>(userSet); - sum= tbProductMapper.selectByNewQcode(code,it.getId(),it.getShopId(),userList); + sum = tbProductMapper.selectByNewQcode(code, it.getId(), it.getShopId(), userList); } - }else { - sum= tbProductMapper.selectByQcode(code,it.getId(),it.getShopId()); + } else { + sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId()); } - it.setCartNumber(sum==null?"0":String.valueOf(sum)); - TbProductSkuResult skuResult= tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); + it.setCartNumber(sum == null ? "0" : String.valueOf(sum)); + TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); it.setProductSkuResult(skuResult); }); g.setProducts(products); - }else { + } else { g.setProducts(new ArrayList<>()); } - }else { + } else { g.setProducts(new ArrayList<>()); } }); - concurrentMap.put("productInfo",groupList); + concurrentMap.put("productInfo", groupList); } - return Result.success(CodeEnum.SUCCESS,concurrentMap); + return Result.success(CodeEnum.SUCCESS, concurrentMap); } - public Result queryProductSku(String shopId, String productId, String spec_tag){ - if(ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(productId)){ + public Result queryProductSku(String shopId, String productId, String spec_tag) { + if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) { return Result.fail("参数错误"); } - TbProductSkuWithBLOBs tbProductSkuWithBLOBs= tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId,productId,spec_tag); - return Result.success(CodeEnum.SUCCESS,tbProductSkuWithBLOBs); + TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag); + return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs); } -// public Result productInfo(Integer productId){ -// TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(productId); -// } + public Result productInfo(Integer productId) throws Exception { + TbMerchantCoupon tbMerchantCoupon = merchantCouponMapper.queryById(productId); + + CompletableFuture shopInfo = CompletableFuture.supplyAsync(() -> + tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantCoupon.getShopId()))); + CompletableFuture product = CompletableFuture.supplyAsync(() -> + tbProductMapper.selectById(Integer.valueOf(tbMerchantCoupon.getRelationIds()))); + CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> + tbProductSkuMapper.selectSku(tbMerchantCoupon.getRelationIds())); + CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> + tagProductDeptsMapper.queryTagByProductId(tbMerchantCoupon.getRelationIds())); + CompletableFuture purchaseNotice = CompletableFuture.supplyAsync(() -> + purchaseNoticeMapper.queryById(tbMerchantCoupon.getId())); + Threads.call(shopInfo, product, productSku, dictPro); + + ProductInfoVo productInfo = new ProductInfoVo(); + // 图片组装 + TbProduct tbProduct = product.get(); + TbShopInfo tbShopInfo = shopInfo.get(); + if (StringUtils.isNotBlank(tbProduct.getImages())) { + productInfo.setImages(JSON.parseArray(tbProduct.getImages())); + } else { + productInfo.setImages(new JSONArray()); + } + //折扣 + productInfo.setDiscount(tbMerchantCoupon.getRatio()); + //价格组装 + for (TbProductSku tbProductSku : productSku.get()) { + productInfo.setOriginPrice(tbProductSku.getSalePrice()); + productInfo.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber())); + Float discount = productInfo.getDiscount(); + BigDecimal discountDecimal = new BigDecimal(discount); + productInfo.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1"))))); + } + //名称 + productInfo.setProductName(tbProduct.getName()); + //店铺 + productInfo.setShopName(tbShopInfo.getShopName() + (StringUtils.isNotBlank(tbShopInfo.getChainName()) ? "(" + tbShopInfo.getChainName() + ")" : "")); + productInfo.setPhone(tbShopInfo.getPhone()); + productInfo.setBusinessTime(tbShopInfo.getBusinessTime()); +// productInfo.setDistances();//距离 + productInfo.setAddress(tbShopInfo.getAddress()); + + //商品 暂时只做单商品 + ProductVo productVo = new ProductVo(); + TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(tbProduct.getUnitId())); + TbShopCategory tbShopCategory = categoryMapper.selectByPrimaryKey(Integer.valueOf(tbProduct.getCategoryId())); + productVo.setTitle(tbShopCategory.getName()); + productVo.setNumber(1); + ProductVo.Food food = new ProductVo.Food(); + food.setName(tbProduct.getName()); + food.setUnit(tbShopUnit.getName()); + food.setPrice(tbProduct.getLowPrice()); + + for (TagProductVO tagProductVO : dictPro.get()) { + food.getProTag().add(tagProductVO); + } + productVo.getFoods().add(food); + productInfo.getProductList().add(productVo); + + productInfo.setPurchaseNotice(purchaseNotice.get()); + + return Result.success(CodeEnum.SUCCESS, productInfo); + } + + private List tagList(String tag) { + if (tag == null) { + return new ArrayList<>(); + } else { + String[] arr = tag.split(","); + return new ArrayList<>(Arrays.asList(arr)); + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java index 69ff2ee..0020938 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializerFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.*; @@ -172,6 +173,25 @@ public class JSONUtil { } } + /** + * @param list 某集合 + * @param clazz 要转成的实体 + * @return + * @param + */ + public static List parseListTNewList(List list, Class clazz) { + ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器 + try { + // 将List转换为JSON字符串 + String json = objectMapper.writeValueAsString(list); + // 将JSON字符串转换为List + return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static class JSONEntity { public JSONEntity() { } diff --git a/src/main/resources/mapper/TagProductDeptsMapper.xml b/src/main/resources/mapper/TagProductDeptsMapper.xml index 17e44e5..3501c77 100644 --- a/src/main/resources/mapper/TagProductDeptsMapper.xml +++ b/src/main/resources/mapper/TagProductDeptsMapper.xml @@ -2,116 +2,39 @@ - - - - - - - - - - - - - - - - - insert into tag_product_depts(product_id, create_time) - values (#{productId}, #{createTime}) - - - - insert into tag_product_depts(product_id, create_time) - values - - (#{entity.productId}, #{entity.createTime}) - - - - - insert into tag_product_depts(product_id, create_time) - values - - (#{entity.productId}, #{entity.createTime}) - - on duplicate key update - product_id = values(product_id), - create_time = values(create_time) - - - - - update tag_product_depts - - - product_id = #{productId}, - - - create_time = #{createTime}, - - - where tag_id = #{tagId} - - - - - delete from tag_product_depts where tag_id = #{tagId} - + diff --git a/src/main/resources/mapper/TbPlatformDictMapper.xml b/src/main/resources/mapper/TbPlatformDictMapper.xml index bac90db..46e3530 100644 --- a/src/main/resources/mapper/TbPlatformDictMapper.xml +++ b/src/main/resources/mapper/TbPlatformDictMapper.xml @@ -4,13 +4,15 @@ + + + - - + @@ -23,121 +25,25 @@ - - select - id, name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort + id, name, type, font_color, back_color, cover_img, share_img, video, video_cover_img, jump_type, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort from tb_platform_dict - - - and id = #{id} - - - and name = #{name} - - - and type = #{type} - - - and cover_img = #{coverImg} - - - and share_img = #{shareImg} - - - and video = #{video} - - - and video_cover_img = #{videoCoverImg} - - - and rel_url = #{relUrl} - - - and abs_url = #{absUrl} - - - and created_at = #{createdAt} - - - and updated_at = #{updatedAt} - - - and is_show_cash = #{isShowCash} - - - and is_show_mall = #{isShowMall} - - - and is_show_app = #{isShowApp} - - - and sort = #{sort} - - - limit #{pageable.offset}, #{pageable.pageSize} + where id IN + + #{id} + - - - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values (#{name}, #{type}, #{coverImg}, #{shareImg}, #{video}, #{videoCoverImg}, #{relUrl}, #{absUrl}, #{createdAt}, #{updatedAt}, #{isShowCash}, #{isShowMall}, #{isShowApp}, #{sort}) - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values - - (#{entity.name}, #{entity.type}, #{entity.coverImg}, #{entity.shareImg}, #{entity.video}, #{entity.videoCoverImg}, #{entity.relUrl}, #{entity.absUrl}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.isShowCash}, #{entity.isShowMall}, #{entity.isShowApp}, #{entity.sort}) - - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values - - (#{entity.name}, #{entity.type}, #{entity.coverImg}, #{entity.shareImg}, #{entity.video}, #{entity.videoCoverImg}, #{entity.relUrl}, #{entity.absUrl}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.isShowCash}, #{entity.isShowMall}, #{entity.isShowApp}, #{entity.sort}) - - on duplicate key update - name = values(name), - type = values(type), - cover_img = values(cover_img), - share_img = values(share_img), - video = values(video), - video_cover_img = values(video_cover_img), - rel_url = values(rel_url), - abs_url = values(abs_url), - created_at = values(created_at), - updated_at = values(updated_at), - is_show_cash = values(is_show_cash), - is_show_mall = values(is_show_mall), - is_show_app = values(is_show_app), - sort = values(sort) - - - - - update tb_platform_dict - - - name = #{name}, - - - type = #{type}, - - - cover_img = #{coverImg}, - - - share_img = #{shareImg}, - - - video = #{video}, - - - video_cover_img = #{videoCoverImg}, - - - rel_url = #{relUrl}, - - - abs_url = #{absUrl}, - - - created_at = #{createdAt}, - - - updated_at = #{updatedAt}, - - - is_show_cash = #{isShowCash}, - - - is_show_mall = #{isShowMall}, - - - is_show_app = #{isShowApp}, - - - sort = #{sort}, - - - where id = #{id} - - - - - delete from tb_platform_dict where id = #{id} - - diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 2f30e56..44b1a0d 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -381,6 +381,14 @@ GROUP BY product_id + + select + + + from tb_purchase_notice + where id = #{id} + + + + From f71e1af8234106402c1ec883b0b945b5eb9fb3ff Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 11 Apr 2024 14:26:54 +0800 Subject: [PATCH 009/134] =?UTF-8?q?=E6=A0=87=E7=AD=BEVO=E4=B8=80=E5=A0=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vo/HomeCarouselVo.java | 29 +++++++++++++++++ .../entity/vo/HomeDistrictVo.java | 31 +++++++++++++++++++ .../cashierservice/entity/vo/TagVo.java | 23 ++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java new file mode 100644 index 0000000..8822002 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java @@ -0,0 +1,29 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +/** + * 轮播图VO + */ +@Data +public class HomeCarouselVo { + + /** + * 描述 同类型下 name唯一 + */ + private String name; + /** + * 轮播图url + */ + private String coverImg; + /** + * 跳转类型 如 拉起相机 跳转小程序 跳转第三方url + */ + private String jumpType; + /** + * 绝对跳转地址 + */ + private String absUrl; + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java new file mode 100644 index 0000000..d0626bf --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java @@ -0,0 +1,31 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +/** + * 首页金刚区Vo + */ +@Data +public class HomeDistrictVo{ + /** + * 展示图url + */ + private String coverImg; + /** + * 描述 同类型下 name唯一 + */ + private String name; + /** + * 字体颜色 + */ + private String fontColor; + /** + * 类型: scan:拉起相机;relative:内部页面;absolute:外链url + */ + private String jumpType; + /** + * 绝对跳转地址 + */ + private String absUrl; +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java new file mode 100644 index 0000000..cc63339 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java @@ -0,0 +1,23 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +@Data +public class TagVo { + /** + * 标签前 小图标 + */ + private String shareImg; + /** + * 描述 同类型下 name唯一 + */ + private String name; + /** + * 字体颜色 + */ + private String fontColor; + /** + * 背景色 + */ + private String backColor; +} From ae61959743f35ab04d80487f3d2eae2e32bf7094 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 11 Apr 2024 14:51:44 +0800 Subject: [PATCH 010/134] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E7=9A=84bug=20sql=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/dao/TbPlatformDictMapper.java | 2 +- .../system/cashierservice/entity/vo/HomeCarouselVo.java | 2 ++ .../system/cashierservice/entity/vo/HomeDistrictVo.java | 2 ++ .../com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java | 2 ++ .../com/chaozhanggui/system/cashierservice/util/JSONUtil.java | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java index 3c7cd23..eaaae04 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java @@ -22,7 +22,7 @@ public interface TbPlatformDictMapper { */ TbPlatformDict queryById(Integer id); - List queryByIdList(List idList); + List queryByIdList(@Param("idList")List idList); List queryAllByType(@Param("type") String type,@Param("environment") String environment); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java index 8822002..8e71a04 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeCarouselVo.java @@ -1,11 +1,13 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; /** * 轮播图VO */ @Data +@JsonIgnoreProperties(ignoreUnknown = true) public class HomeCarouselVo { /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java index d0626bf..7acaead 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeDistrictVo.java @@ -1,11 +1,13 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; /** * 首页金刚区Vo */ @Data +@JsonIgnoreProperties(ignoreUnknown = true) public class HomeDistrictVo{ /** * 展示图url diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java index cc63339..24885d6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagVo.java @@ -1,8 +1,10 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; @Data +@JsonIgnoreProperties(ignoreUnknown = true) public class TagVo { /** * 标签前 小图标 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java index 0020938..ba451d2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java @@ -176,6 +176,7 @@ public class JSONUtil { /** * @param list 某集合 * @param clazz 要转成的实体 + * 需要在目标实体增加注解 忽略未知属性 @JsonIgnoreProperties(ignoreUnknown = true) * @return * @param */ From 05bf58173444feed6d55fd41c7f41b299ef938c0 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 11 Apr 2024 15:59:54 +0800 Subject: [PATCH 011/134] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=8B=E5=8D=8A?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/HomePageService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index f59fd8a..c86702c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -78,6 +78,7 @@ public class HomePageService { List homeVOList = new ArrayList<>(); for (TbMerchantCoupon o : tbMerchantCoupons) { HomeVO homeVO = new HomeVO(); + homeVO.setId(o.getId()); homeVO.setDiscount(o.getRatio()); for (TbShopInfo tbShopInfo : shopInfo.get()) { if (o.getShopId().equals(tbShopInfo.getId().toString())) { @@ -98,7 +99,7 @@ public class HomePageService { if (o.getRelationIds().equals(tbProduct.getId().toString())) { homeVO.setProductName(tbProduct.getName()); homeVO.setImage(tbProduct.getCoverImg()); - homeVO.setId(tbProduct.getId()); + homeVO.setProductId(tbProduct.getId()); } } for (TbProductSku tbProductSku : productSku.get()) { From 5946c78cf99eab5436399460c86c3197680ad709 Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Thu, 11 Apr 2024 16:31:59 +0800 Subject: [PATCH 012/134] =?UTF-8?q?=E5=B0=8F=E6=A8=AA=E5=B9=85=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E6=9B=B4=E6=94=B9=E6=9D=A1=E4=BB=B6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/Enum/LogoEnum.java | 87 +++++++++++++++++++ .../cashierservice/entity/dto/HomeDto.java | 17 ++-- .../entity/vo/BannerInfoVo.java | 43 +++++++++ .../cashierservice/entity/vo/BannerVO.java | 14 +-- .../cashierservice/entity/vo/HomeVO.java | 13 +++ .../service/HomePageService.java | 34 ++++++-- .../cashierservice/util/RandomUtil.java | 36 ++++++++ .../cashierservice/util/StringUtil.java | 22 +++++ 8 files changed, 246 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/LogoEnum.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerInfoVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/LogoEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/LogoEnum.java new file mode 100644 index 0000000..4c04b56 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/LogoEnum.java @@ -0,0 +1,87 @@ +package com.chaozhanggui.system.cashierservice.entity.Enum; + +import com.github.pagehelper.util.StringUtil; + +/** + * @author 12847 + */ + +public enum LogoEnum { + url1(1,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/IMG_0299.PNG"), + url2(2,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/ffaab08f6a62103593646bf36dbaa24c.jpeg"), + url3(3,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/fe6c4572004f9aa7716bff89c4c56783.jpeg"), + url4(4,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/fb56ef7c59d46835e6ff4b5c494aed5a.jpeg"), + url5(5,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/f8469a7760c7f584ab55e47b60cd3829.jpeg"), + url6(6,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/f73810e20530a70dd068e0e0a82677d4.jpeg"), + url7(7,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/f66361c48515ba9b2a03d9d72829d675.jpeg"), + url8(8,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/f2be456f85849922ba838e7eb4694272.jpeg"), + url9(9,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e9fca54f0320644291848338184b6c08.jpeg"), + url10(10,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e9e574fdedb43831801697a610603044.jpeg"), + url11(11,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e913ec3afe3520b9a638e16d298b401f.jpeg"), + url12(12,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e87d19da0cb5af9b53f485117b665cc9.jpeg"), + url13(13,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e847667f37d86dc4a48ffcf69bb1a964.jpeg"), + url14(14,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e731f8a883ab1ef2a71487f2eb5b0e38.jpeg"), + url15(15,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e681a9a281760f275f4b9d11c01a5869.jpeg"), + url16(16,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e41fa3916c86d43904a66d1174b81080.jpeg"), + url17(17,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e138425037e7ba3eded9ab828e3f39d2.jpeg"), + url18(18,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e0d4e933083418e6c4795fb6bf5db628.jpeg"), + url19(19,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e07b1933b0ad75f428339ffc79ee4fef.jpeg"), + url20(20,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/d4ac63680f417b49210aa54cf6e03e77.jpeg"), + url21(21,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/d44a8bccd46f4fa6c340e825bba5c338.jpeg"), + url22(22,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/cd794c0c5dd3b212e7c46eaa7c3a85cc.jpeg"), + url23(23,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/ccf1f255cd30c2aed0b421213df01863.jpeg"), + url24(24,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/cbe7897bee2d057eaaeaa1604d5bd167.jpeg"), + url25(25,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/cae19ed2c2c1c749e388730ef1cbb596.jpeg"), + url26(26,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c90a7e5d7a9a95a48dac8aecfab5c8e1.jpeg"), + url27(27,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c72ec32dbb7c0a42ca6a0a483a0d99ab.jpeg"), + url28(28,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c72ec32dbb7c0a42ca6a0a483a0d99ab.jpeg"), + url29(29,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c451f57dde1fcbbe4afe5766184084da.jpeg"), + url30(30,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a9a9e9eb047009f79bc22290470c2932.jpeg"), + url31(31,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/aef489a444793e37e2f33aeb3fe1fe13.jpeg"), + url32(32,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/b0f4a2d7ab851fb2ea01446b722c5631.jpeg"), + url33(33,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/b2d643c11850042ff2932451c84940c3.jpeg"), + url34(34,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/bdf1ebd620f759f703631b805216ca11.jpeg"), + url35(35,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/be1e70097583d1a08a9951925d66ef33.jpeg"), + url36(36,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c3f38f6604713f13474a5e2f1145e481.jpeg"), + url37(37,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c27da8b2c154998ebf7300c49cef649a.jpeg"), + url38(38,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c26400a670209b60abcd28bfc6d22171.jpeg"), + url39(39,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a906414986b1bee60cec709dabf2103b.jpeg"), + url40(40,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a6d8629c155b59814e4d772fb5e6ec6a.jpeg"), + url41(41,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a6a78d2a64c49cf62e37475eb66e351c.jpeg"), + url42(42,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a571ccde02b075656f354b593533b00c.jpeg"), + url43(43,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a0be3632c238d1a8e24e51ff8942efc6.jpeg"), + url44(44,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/9fca88b43ed09ddbeb4803ceab4f356f.jpeg"), + url45(45,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/86ad712e29369b9f56ca93a94f7a5d67.jpeg"), + url46(46,"https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/88d4ca4146196992b48a52f62a690bf0.jpeg"), + ; + + private Integer key; + + private String url; + + public Integer getKey() { + return key; + } + + public String getUrl() { + return url; + } + + LogoEnum(Integer key, String url) { + this.key = key; + this.url = url; + } + + public static String getValueByKey(Integer key) { + if(key == null){ + return ""; + } + LogoEnum[] urlEnums = values(); + for (LogoEnum logo : urlEnums) { + if (logo.key.equals(key)) { + return logo.getUrl(); + } + } + return ""; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java index abbcbbb..74f70e2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java @@ -1,8 +1,11 @@ package com.chaozhanggui.system.cashierservice.entity.dto; +import lombok.Data; + /** * @author 12847 */ +@Data public class HomeDto { /** * 地址 @@ -17,10 +20,8 @@ public class HomeDto { * 1.理我最近 2.销量优先 3.价格优先 */ private Integer orderBy; - /** - * 附近1KM 1选中 0未选中 - */ - private Integer distance; + + private Integer other; private Integer page; @@ -50,12 +51,12 @@ public class HomeDto { this.orderBy = orderBy; } - public Integer getDistance() { - return distance; + public Integer getOther() { + return other; } - public void setDistance(Integer distance) { - this.distance = distance; + public void setOther(Integer other) { + this.other = other; } public Integer getPage() { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerInfoVo.java new file mode 100644 index 0000000..f34831f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerInfoVo.java @@ -0,0 +1,43 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author lyf + */ +@Data +public class BannerInfoVo { + /** + * 昵称 + */ + private String name; + /** + * 昵称 + */ + private String logo; + + /** + * 免单了多少钱 + */ + private BigDecimal money; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLogo() { + return logo; + } + + public void setLogo(String logo) { + this.logo = logo; + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java index efe8b20..b98784c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java @@ -8,10 +8,12 @@ import java.util.List; * @author 12847 */ public class BannerVO { - + /** + * 有多少人参与了免单 + */ private String coupons; - private List logo; + private List counponsInfo; public String getCoupons() { return coupons; @@ -21,11 +23,11 @@ public class BannerVO { this.coupons = coupons; } - public List getLogo() { - return logo; + public List getCounponsInfo() { + return counponsInfo; } - public void setLogo(List logo) { - this.logo = logo; + public void setCounponsInfo(List counponsInfo) { + this.counponsInfo = counponsInfo; } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index a97c41a..aa73d32 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -12,6 +12,11 @@ public class HomeVO { * 店铺名称 */ private String shopName; + + /** + * 店铺名称 + */ + private String shopImage; /** * 商品名称 */ @@ -62,6 +67,14 @@ public class HomeVO { */ private Long endTime; + public String getShopImage() { + return shopImage; + } + + public void setShopImage(String shopImage) { + this.shopImage = shopImage; + } + public Long getEndTime() { return endTime; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index c86702c..a21a61d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -2,14 +2,18 @@ package com.chaozhanggui.system.cashierservice.service; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.Enum.LogoEnum; import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; import com.chaozhanggui.system.cashierservice.entity.vo.*; +import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.Threads; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -44,6 +48,8 @@ public class HomePageService { private SysDictDetailMapper sysDictDetailMapper; @Resource private TagProductDeptsMapper tagProductDeptsMapper; + @Autowired + private RedisUtil redisUtil; public Result homePage(HomeDto homeDto, String environmen) throws ExecutionException, InterruptedException { @@ -182,15 +188,31 @@ public class HomePageService { /** * 小条幅 */ - TbSystemCoupons tbSystemCoupons = productMapper.selectLimit(); - BannerVO bannerVO = new BannerVO(); - bannerVO.setCoupons(tbSystemCoupons == null?"":tbSystemCoupons.getName()); - List tbPlatformDicts = platformDictMapper.queryAllByType("icon", environment); - bannerVO.setLogo(tbPlatformDicts); - homeUpVO.setBannerVO(bannerVO); + homeUpVO.setBannerVO(bannerVoRandom()); return Result.success(CodeEnum.SUCCESS, homeUpVO); } + /** + * 小条幅随机数据 + * @return + */ + + private BannerVO bannerVoRandom(){ + BannerVO bannerVO = new BannerVO(); + List bannerInfoList = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + BannerInfoVo bannerInfoVo = new BannerInfoVo(); + bannerInfoVo.setName(StringUtil.generateRandomNickname(5)); + bannerInfoVo.setLogo(LogoEnum.getValueByKey(RandomUtil.randomInt())); + bannerInfoVo.setMoney(RandomUtil.randomDecimalGenerator()); + bannerInfoList.add(bannerInfoVo); + } + bannerVO.setCounponsInfo(bannerInfoList); + bannerVO.setCoupons(redisUtil.getMessage("num")); + return bannerVO; + } + + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java new file mode 100644 index 0000000..8b3a124 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java @@ -0,0 +1,36 @@ +package com.chaozhanggui.system.cashierservice.util; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Random; +/** + * @author lyf + */ +public class RandomUtil { + public static BigDecimal randomDecimalGenerator(){ + + double number = generateRandomInt(2, 40); + BigDecimal bdNumber = BigDecimal.valueOf(number); + BigDecimal bdMultiplier = BigDecimal.valueOf(5); + + BigDecimal result = bdNumber.setScale(1, RoundingMode.HALF_UP); + BigDecimal multiply = result.multiply(bdMultiplier); + return multiply; + } + private static double generateRandomInt(double min, double max) { + Random random = new Random(); + return min + (max-min) * random.nextDouble(); + } + public static void main(String[] args) { + for (int i = 0; i < 20; i++) { + System.out.println("随机数为"+randomDecimalGenerator()); + } + } + + public static Integer randomInt() { + Random random = new Random(); + + // 生成1到27之间的随机整数(包括1和27) + + return random.nextInt(46) + 1; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/StringUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/StringUtil.java index 922be6c..f54a858 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/StringUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/StringUtil.java @@ -61,4 +61,26 @@ public class StringUtil { return result; } + private static final String CHINESE_CHARS = "你我他她它们这里那里多少是否好坏快慢上下左右前后高低大小长短方圆胖瘦黑白红绿蓝黄紫粉红桔红橙黄棕灰褐"; + + // 生成随机中文昵称 + public static String generateRandomNickname(int length) { + StringBuilder sb = new StringBuilder(); + Random random = new Random(); + for (int i = 0; i < length; i++) { + int index = random.nextInt(CHINESE_CHARS.length()); + char randomChar = CHINESE_CHARS.charAt(index); + sb.append(randomChar); + } + return desensitizeNickname(sb.toString()); + } + + // 对昵称进行脱敏处理 + public static String desensitizeNickname(String nickname) { + if (nickname == null || nickname.length() != 5) { + return nickname; + } + return nickname.charAt(0) + "***" + nickname.charAt(4); + } + } From f8c53d35485b9bdb4bf843563a0b66756c97d597 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 11 Apr 2024 16:55:40 +0800 Subject: [PATCH 013/134] =?UTF-8?q?=E8=8F=9C=E5=8D=95=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20=E7=94=A8=E6=88=B7=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/SysDictDetailMapper.java | 13 -- .../system/cashierservice/entity/SysDict.java | 86 +---------- .../cashierservice/entity/SysDictDetail.java | 91 +---------- .../service/HomePageService.java | 9 -- .../cashierservice/service/LoginService.java | 2 +- .../resources/mapper/SysDictDetailMapper.xml | 146 +----------------- 6 files changed, 11 insertions(+), 336 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java index 70a1981..61e55c5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java @@ -11,21 +11,8 @@ import java.util.List; @Component @Mapper public interface SysDictDetailMapper { - int deleteByPrimaryKey(Long detailId); - - int insert(SysDictDetail record); - - int insertSelective(SysDictDetail record); - - SysDictDetail selectByPrimaryKey(Long detailId); - List selectByAll(); - List selectByAllDetail(@Param("list") List dictId); - List selectByDictId(@Param("dictId") Long dictId); - int updateByPrimaryKeySelective(SysDictDetail record); - - int updateByPrimaryKey(SysDictDetail record); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java index 533f143..4ef8a18 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDict.java @@ -1,97 +1,19 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.util.Date; +@Data public class SysDict implements Serializable { private Long dictId; + private String dictName; private String name; private String description; - private String createBy; - - private String updateBy; - - private Date createTime; - - private Date updateTime; - private Integer isChild; - - private static final long serialVersionUID = 1L; - - public String getDictName() { - return dictName; - } - - public void setDictName(String dictName) { - this.dictName = dictName; - } - - public Integer getIsChild() { - return isChild; - } - - public void setIsChild(Integer isChild) { - this.isChild = isChild; - } - - public Long getDictId() { - return dictId; - } - - public void setDictId(Long dictId) { - this.dictId = dictId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description == null ? null : description.trim(); - } - - public String getCreateBy() { - return createBy; - } - - public void setCreateBy(String createBy) { - this.createBy = createBy == null ? null : createBy.trim(); - } - - public String getUpdateBy() { - return updateBy; - } - - public void setUpdateBy(String updateBy) { - this.updateBy = updateBy == null ? null : updateBy.trim(); - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDictDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDictDetail.java index 6e74012..7a43ee2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDictDetail.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/SysDictDetail.java @@ -1,98 +1,15 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.util.Date; +@Data public class SysDictDetail implements Serializable { - private Long detailId; - - private Long dictId; + private String dictName; private String label; private String value; - - private Integer dictSort; - - private String createBy; - - private String updateBy; - - private Date createTime; - - private Date updateTime; - - private static final long serialVersionUID = 1L; - - public Long getDetailId() { - return detailId; - } - - public void setDetailId(Long detailId) { - this.detailId = detailId; - } - - public Long getDictId() { - return dictId; - } - - public void setDictId(Long dictId) { - this.dictId = dictId; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label == null ? null : label.trim(); - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value == null ? null : value.trim(); - } - - public Integer getDictSort() { - return dictSort; - } - - public void setDictSort(Integer dictSort) { - this.dictSort = dictSort; - } - - public String getCreateBy() { - return createBy; - } - - public void setCreateBy(String createBy) { - this.createBy = createBy == null ? null : createBy.trim(); - } - - public String getUpdateBy() { - return updateBy; - } - - public void setUpdateBy(String updateBy) { - this.updateBy = updateBy == null ? null : updateBy.trim(); - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index a21a61d..fee0efe 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -130,15 +130,6 @@ public class HomePageService { return Result.success(CodeEnum.SUCCESS, homeVOList); } - private List tagList(String tag){ - if (tag == null){ - return new ArrayList<>(); - }else { - String[] arr = tag.split(","); - return new ArrayList<>(Arrays.asList(arr)); - } - } - public Result homePageUp(String environment) { HomeUpVO homeUpVO = new HomeUpVO(); //轮播图 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 0e9532c..d8127b8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -167,7 +167,7 @@ public class LoginService { userInfo.setConsumeAmount(BigDecimal.ZERO); userInfo.setTotalScore(0); userInfo.setLockScore(0); - userInfo.setHeadImg(""); + userInfo.setHeadImg("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240411/a2be5869bfa24d72a4782f695cc53ed1.png");//默认头像 userInfo.setNickName(nickName); userInfo.setTelephone(phone); userInfo.setStatus(Byte.parseByte("1")); diff --git a/src/main/resources/mapper/SysDictDetailMapper.xml b/src/main/resources/mapper/SysDictDetailMapper.xml index 4fb74ac..3201417 100644 --- a/src/main/resources/mapper/SysDictDetailMapper.xml +++ b/src/main/resources/mapper/SysDictDetailMapper.xml @@ -1,155 +1,13 @@ - - - - - - - - - - - - - detail_id, dict_id, label, value, dict_sort, create_by, update_by, create_time, update_time - - + - + - - delete from sys_dict_detail - where detail_id = #{detailId,jdbcType=BIGINT} - - - insert into sys_dict_detail (detail_id, dict_id, label, - value, dict_sort, create_by, - update_by, create_time, update_time - ) - values (#{detailId,jdbcType=BIGINT}, #{dictId,jdbcType=BIGINT}, #{label,jdbcType=VARCHAR}, - #{value,jdbcType=VARCHAR}, #{dictSort,jdbcType=INTEGER}, #{createBy,jdbcType=VARCHAR}, - #{updateBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} - ) - - - insert into sys_dict_detail - - - detail_id, - - - dict_id, - - - label, - - - value, - - - dict_sort, - - - create_by, - - - update_by, - - - create_time, - - - update_time, - - - - - #{detailId,jdbcType=BIGINT}, - - - #{dictId,jdbcType=BIGINT}, - - - #{label,jdbcType=VARCHAR}, - - - #{value,jdbcType=VARCHAR}, - - - #{dictSort,jdbcType=INTEGER}, - - - #{createBy,jdbcType=VARCHAR}, - - - #{updateBy,jdbcType=VARCHAR}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{updateTime,jdbcType=TIMESTAMP}, - - - - - update sys_dict_detail - - - dict_id = #{dictId,jdbcType=BIGINT}, - - - label = #{label,jdbcType=VARCHAR}, - - - value = #{value,jdbcType=VARCHAR}, - - - dict_sort = #{dictSort,jdbcType=INTEGER}, - - - create_by = #{createBy,jdbcType=VARCHAR}, - - - update_by = #{updateBy,jdbcType=VARCHAR}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - update_time = #{updateTime,jdbcType=TIMESTAMP}, - - - where detail_id = #{detailId,jdbcType=BIGINT} - - - update sys_dict_detail - set dict_id = #{dictId,jdbcType=BIGINT}, - label = #{label,jdbcType=VARCHAR}, - value = #{value,jdbcType=VARCHAR}, - dict_sort = #{dictSort,jdbcType=INTEGER}, - create_by = #{createBy,jdbcType=VARCHAR}, - update_by = #{updateBy,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - update_time = #{updateTime,jdbcType=TIMESTAMP} - where detail_id = #{detailId,jdbcType=BIGINT} - \ No newline at end of file From 7d3fe9deb7e930b9211a26d7c5c796829d0e6da7 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 12 Apr 2024 09:56:32 +0800 Subject: [PATCH 014/134] =?UTF-8?q?=E7=BB=8F=E7=BA=AC=E5=BA=A6=20=E8=A7=92?= =?UTF-8?q?=E7=82=B9=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 2 +- .../service/HomePageService.java | 1 + .../cashierservice/util/LocationUtils.java | 78 +++++++++++++------ 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 23e64c9..2c96100 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -78,7 +78,7 @@ public class LoginFilter implements Filter { // 判断用户TOKEN是否存在 String token = request.getHeader("token"); if (StringUtils.isBlank(token)) { - Result result = new Result(CodeEnum.TOKEN_EXEIST); + Result result = new Result(CodeEnum.TOKEN_EXPIRED); String jsonString = JSONObject.toJSONString(result); JSONObject jsonObject = JSONObject.parseObject(jsonString, JSONObject.class); response.getWriter().print(jsonObject); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index fee0efe..9f6c2c4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -99,6 +99,7 @@ public class HomePageService { List tbPlatformDicts = platformDictMapper.queryByIdList(shopTagIds); homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); } + } } for (TbProduct tbProduct : product.get()) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index a98a272..791eb32 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -9,30 +9,18 @@ import static java.lang.Math.sin; public class LocationUtils { public static String district(String keywords) { - Map param=new HashMap<>(); + Map param = new HashMap<>(); //超掌柜生活-用户端 - param.put("key","7a7f2e4790ea222660a027352ee3af39"); - param.put("keywords",keywords); - param.put("subdistrict","2"); - param.put("extensions","base"); + param.put("key", "7a7f2e4790ea222660a027352ee3af39"); + param.put("keywords", keywords); + param.put("subdistrict", "2"); + param.put("extensions", "base"); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param); return s; } - /** - * 将角度转化为弧度 - */ - public static double radians(double d) { - return d * Math.PI / 180.0; - } /** * 根据两点经纬度坐标计算直线距离 - *

- * S = 2arcsin√sin²(a/2)+cos(lat1)*cos(lat2)*sin²(b/2) ̄*6378.137 - *

- * 1. lng1 lat1 表示A点经纬度,lng2 lat2 表示B点经纬度;
- * 2. a=lat1 – lat2 为两点纬度之差 b=lng1 -lng2 为两点经度之差;
- * 3. 6378.137为地球赤道半径,单位为千米; * * @param lng1 点1经度 * @param lat1 点1纬度 @@ -43,7 +31,7 @@ public class LocationUtils { */ public static double getDistanceFrom2LngLat(double lng1, double lat1, double lng2, double lat2) { //将角度转化为弧度 - double radLng1 = radians(lng1); + double radLng1 = radians(lng1);//d * Math.PI / 180.0; double radLat1 = radians(lat1); double radLng2 = radians(lng2); double radLat2 = radians(lat2); @@ -54,16 +42,56 @@ public class LocationUtils { return 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137; } + /** + * @param longitude 经度 + * @param latitude 纬度 + * @param distanceInKm 范围(千米) + * return Map stringMap + * 右顶点 double[] leftTopPoints = stringMap.get("rightTopPoint"); + * 左顶点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); + */ + public static Map returnLLSquarePoint(double longitude, double latitude, double distanceInKm) { + Map squareMap = new HashMap<>(); + // 地球平均半径,单位:千米 + double earthRadius = 6378.137; + // 将距离转换为弧度 + double radialDistance = distanceInKm / earthRadius; + // 计算纬度上变化对应的角度 + double dLatitude = Math.toDegrees(2 * Math.asin(Math.sin(radialDistance / 2) / Math.cos(Math.toRadians(latitude)))); + // 计算经度上变化对应的角度,这里需要考虑纬度对距离的影响 + // 使用Haversine公式来估算在给定纬度上,距离对应的经度变化 + double estimatedLongitudeDistance = getDistanceFrom2LngLat(latitude, longitude, latitude, longitude + 0.01); // 假设0.01度经度变化对应的距离 + double dLongitude = distanceInKm / estimatedLongitudeDistance * 0.0192736; // 根据比例计算经度变化 + // 正方形四个顶点的坐标 + double[] rightTopPoint = {latitude + dLatitude / 2, longitude + dLongitude / 2}; + double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2}; + squareMap.put("rightTopPoint", rightTopPoint); + squareMap.put("leftBottomPoint", leftBottomPoint); + // 打印结果 +// System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]); +// System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]); + return squareMap; + } + + /** + * 将角度转化为弧度 + */ + public static double radians(double d) { + return d * Math.PI / 180.0; + } + // public static void main(String[] args) { -// // 示例经纬度坐标 -// double lat1 = 108.954398; -// double lon1 = 34.308687; +// Map stringMap = returnLLSquarePoint(108.954398, 34.308687, 1); +// double[] leftTopPoints = stringMap.get("rightTopPoint"); +// double[] leftBottomPoints = stringMap.get("leftBottomPoint"); // -// double lat2 = 108.953555; -// double lon2 = 34.276169; +// double lat2 = 108.954398; +// double lon2 = 34.308687; // // // 计算距离 -// double distance = getDistanceFrom2LngLat(lat1, lon1, lat2, lon2); -// System.out.println("Distance between the two points is: " + distance + " km"); +// double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2); +// double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2); +// System.out.println("Distance between the two points is: " + distance1 + " km"); +// System.out.println("Distance between the two points is: " + distance2 + " km"); // } } From e86ec29a33abe420ab89352d9957536c69690dd4 Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Fri, 12 Apr 2024 13:35:02 +0800 Subject: [PATCH 015/134] =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 14 +++- .../controller/UserContoller.java | 23 +++++- .../dao/TbReleaseFlowMapper.java | 2 + .../dao/TbUserCouponsMapper.java | 6 ++ .../cashierservice/dao/TbUserInfoMapper.java | 3 + .../cashierservice/entity/TbParams.java | 29 ++----- .../cashierservice/entity/TbReleaseFlow.java | 63 ++------------ .../cashierservice/entity/TbUserCoupons.java | 69 ++-------------- .../system/cashierservice/redis/RedisCst.java | 1 + .../service/IntegralService.java | 27 +++++- .../cashierservice/service/OrderService.java | 38 +++++++++ .../cashierservice/service/UserService.java | 82 ++++++++++++++++--- .../cashierservice/task/TaskScheduler.java | 54 +++++++++--- .../system/cashierservice/util/CacheMap.java | 4 + .../system/cashierservice/util/DateUtils.java | 4 +- .../resources/mapper/TbReleaseFlowMapper.xml | 12 ++- .../resources/mapper/TbUserCouponsMapper.xml | 10 ++- .../resources/mapper/TbUserInfoMapper.xml | 3 + 18 files changed, 259 insertions(+), 185 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index eb1aa5c..4815f7c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -79,8 +79,16 @@ public class OrderController { private Result getYhqPara(){ return orderService.getYhqPara(); } - @GetMapping("/testPay") - private Result testPay(@RequestParam Integer orderId){ - return orderService.testPay(orderId); + @GetMapping("/getYhqDouble") + private Result getYhqDouble(@RequestParam Integer orderId){ + return orderService.getYhqDouble(orderId); } + @PostMapping("/yhqDouble") + private Result yhqDouble(@RequestParam Integer conponsId){ + return orderService.yhqDouble(conponsId); + } +// @GetMapping("/testPay") +// private Result testPay(@RequestParam Integer orderId){ +// return orderService.testPay(orderId); +// } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index c1d21e6..8dbdfd3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -7,8 +7,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper; import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; +import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper; import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto; import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; @@ -49,11 +51,12 @@ public class UserContoller { @Autowired private TbShopUserMapper shopUserMapper; - + @Autowired + private TbUserInfoMapper userInfoMapper; @GetMapping("/userInfo") public JSONObject userInfo(@RequestParam("openId") String openId ) throws Exception { - TbShopUser shopUser = shopUserMapper.selectByOpenId(openId); + TbUserInfo shopUser = userInfoMapper.selectByOpenId(openId); JSONObject jsonObject = new JSONObject(); if (Objects.isNull(shopUser)){ jsonObject.put("status","fail"); @@ -65,7 +68,7 @@ public class UserContoller { JSONObject object = new JSONObject(); object.put("token",token); object.put("userSign",userSign); - object.put("num",shopUser.getLevelConsume()); + object.put("num",shopUser.getTotalScore()); jsonObject.put("status","success"); jsonObject.put("msg","成功"); jsonObject.put("data",object); @@ -77,10 +80,22 @@ public class UserContoller { String userSign = jsonObject.getString("userSign"); return userService.modityIntegral(integralVo,userSign); } - @GetMapping("/userIntegral") + @PostMapping("/userIntegral") public JSONObject userIntegral(@RequestHeader String token,@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { JSONObject jsonObject = TokenUtil.parseParamFromToken(token); String userSign = jsonObject.getString("userSign"); return userService.userIntegral(integralFlowVo,userSign); } + @PostMapping("/userAllIntegral") + public JSONObject userAllIntegral(@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { +// JSONObject jsonObject = TokenUtil.parseParamFromToken(token); +// String userSign = jsonObject.getString("userSign"); + return userService.userAllIntegral(integralFlowVo,"userSign"); + } + @PostMapping("/userAll") + public JSONObject userAll(@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { +// JSONObject jsonObject = TokenUtil.parseParamFromToken(token); +// String userSign = jsonObject.getString("userSign"); + return userService.userAll(integralFlowVo,"userSign"); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java index b2f02b5..0cce4bd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbReleaseFlowMapper.java @@ -19,4 +19,6 @@ public interface TbReleaseFlowMapper { int updateByPrimaryKey(TbReleaseFlow record); List selectByUserId(@Param("userId") String userId); + + List selectAll(); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java index 092ec51..6ea8997 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java @@ -1,10 +1,14 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; import java.util.List; +@Component +@Mapper public interface TbUserCouponsMapper { int deleteByPrimaryKey(Integer id); @@ -19,4 +23,6 @@ public interface TbUserCouponsMapper { int updateByPrimaryKey(TbUserCoupons record); List selectByUserId(@Param("userId") String userId,@Param("status") String status); + + TbUserCoupons selectByOrderId(@Param("orderId") Integer orderId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java index 841dfa6..17c47fe 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java @@ -4,6 +4,8 @@ import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Component; +import java.util.List; + @Component @Mapper public interface TbUserInfoMapper { @@ -38,4 +40,5 @@ public interface TbUserInfoMapper { TbUserInfo selectByPhone(String phone); + List selectAll(); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java index f571e1f..5aa9414 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbParams.java @@ -1,38 +1,19 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; + +@Data public class TbParams implements Serializable { private Integer id; private BigDecimal integralRatio; + private BigDecimal twoRatio; private BigDecimal tradeRatio; private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public BigDecimal getIntegralRatio() { - return integralRatio; - } - - public void setIntegralRatio(BigDecimal integralRatio) { - this.integralRatio = integralRatio; - } - - public BigDecimal getTradeRatio() { - return tradeRatio; - } - - public void setTradeRatio(BigDecimal tradeRatio) { - this.tradeRatio = tradeRatio; - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java index ecc8c1d..34414ed 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbReleaseFlow.java @@ -1,9 +1,12 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +@Data public class TbReleaseFlow implements Serializable { private Integer id; @@ -12,68 +15,16 @@ public class TbReleaseFlow implements Serializable { private BigDecimal num; private String type; + private String operationType; private String remark; + private String nickName; private String fromSource; private Date createTime; + private String createTr; + private String openId; private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId == null ? null : userId.trim(); - } - - public BigDecimal getNum() { - return num; - } - - public void setNum(BigDecimal num) { - this.num = num; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type == null ? null : type.trim(); - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark == null ? null : remark.trim(); - } - - public String getFromSource() { - return fromSource; - } - - public void setFromSource(String fromSource) { - this.fromSource = fromSource == null ? null : fromSource.trim(); - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java index fe9e9d3..18f065c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java @@ -1,19 +1,24 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +@Data public class TbUserCoupons implements Serializable { private Integer id; private String userId; + private Integer orderId; private BigDecimal couponsPrice; private BigDecimal couponsAmount; private String status; + private String isDouble; private Date createTime; @@ -22,68 +27,4 @@ public class TbUserCoupons implements Serializable { private Date endTime; private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId == null ? null : userId.trim(); - } - - public BigDecimal getCouponsPrice() { - return couponsPrice; - } - - public void setCouponsPrice(BigDecimal couponsPrice) { - this.couponsPrice = couponsPrice; - } - - public BigDecimal getCouponsAmount() { - return couponsAmount; - } - - public void setCouponsAmount(BigDecimal couponsAmount) { - this.couponsAmount = couponsAmount; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status == null ? null : status.trim(); - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - - public Date getEndTime() { - return endTime; - } - - public void setEndTime(Date endTime) { - this.endTime = endTime; - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java index 11f9558..110918c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java @@ -16,4 +16,5 @@ public class RedisCst { public static final String PRODUCT = "PRODUCT:"; public static final String INTEGRAL_COIN_KEY = "INTEGRAL:COIN:KEY"; + public static final String COUPONS_COIN_KEY = "COUPONS:COIN:KEY"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java index 034f540..a0f7d56 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java @@ -7,6 +7,7 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.util.DateUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +41,8 @@ public class IntegralService { private TbReleaseFlowMapper integralFlowMapper; @Autowired private TbUserCouponsMapper userCouponsMapper; - + @Autowired + private TbSplitAccountsMapper splitAccountsMapper; @Transactional(rollbackFor = Exception.class) public void integralAdd(JSONObject jsonObject) throws ParseException { @@ -66,18 +68,37 @@ public class IntegralService { }else { Integer orderId = jsonObject.getInteger("orderId"); TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + if (StringUtils.isNotBlank(orderInfo.getUserCouponId())){ + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserCouponId())); + if (Objects.nonNull(userCoupons)){ + TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); + TbSplitAccounts splitAccounts = new TbSplitAccounts(); + splitAccounts.setConponsAmount(userCoupons.getCouponsAmount()); + splitAccounts.setCreateTime(new Date()); + splitAccounts.setIsSplit("false"); + splitAccounts.setMerchantId(Integer.valueOf(shopInfo.getMerchantId())); + splitAccounts.setShopId(shopInfo.getId()); + splitAccounts.setOrderAmount(orderInfo.getPayAmount()); + splitAccounts.setTradeDay(DateUtils.getDay()); + splitAccounts.setOriginAmount(orderInfo.getOriginAmount()); + splitAccountsMapper.insert(splitAccounts); + } + } if (Objects.isNull(orderInfo)) { - throw new MsgException("该订单不存在"); + log.error("该订单不存在"); + return; } TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); if (Objects.isNull(shopInfo) || !"true".equals(shopInfo.getIsOpenYhq())){ - throw new MsgException("该店铺未开启优惠券功能"); + log.error("该店铺未开启优惠券功能"); + return; } TbParams params = tbShopUserMapper.selectParams(); TbUserCoupons userCoupons = new TbUserCoupons(); userCoupons.setUserId(orderInfo.getUserId()); userCoupons.setCouponsAmount(orderInfo.getPayAmount().multiply(params.getIntegralRatio())); userCoupons.setStatus("0"); + userCoupons.setOrderId(orderId); userCoupons.setCouponsPrice(userCoupons.getCouponsAmount().multiply(new BigDecimal("0.5"))); userCoupons.setCreateTime(new Date()); userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30)); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index c6352fd..9bc241d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -79,6 +79,8 @@ public class OrderService { private TbSystemCouponsMapper systemCouponsMapper; @Autowired private TbYhqParamsMapper yhqParamsMapper; + @Autowired + private TbShopUserMapper shopUserMapper; /** * 创建订单 * @@ -295,7 +297,9 @@ public class OrderService { releaseFlow.setCreateTime(new Date()); releaseFlow.setFromSource("OWER"); releaseFlow.setUserId(userId); + releaseFlow.setOperationType("ADD"); releaseFlow.setType("EXCHANGEADD"); + releaseFlow.setRemark("兑换增加"); releaseFlowMapper.insert(releaseFlow); redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); } else { @@ -359,4 +363,38 @@ public class OrderService { producer.printCoupons(coupons.toJSONString()); return Result.success(CodeEnum.SUCCESS); } + + public Result getYhqDouble(Integer orderId) { + TbUserCoupons userCoupons = userCouponsMapper.selectByOrderId(orderId); + return Result.success(CodeEnum.SUCCESS,userCoupons); + } + @Transactional(rollbackFor = Exception.class) + public Result yhqDouble(Integer conponsId) { + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId); + if (Objects.isNull(userCoupons) || userCoupons.getIsDouble().equals("true")){ + throw new MsgException("该优惠券翻倍已领取"); + } + return Result.success(CodeEnum.SUCCESS); + } + + + private void modityDouble(Integer conponsId) throws ParseException { + + boolean lock_coin = redisUtils.lock(RedisCst.COUPONS_COIN_KEY + conponsId, 5000, TimeUnit.MILLISECONDS); + if (lock_coin) { + TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId); + if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0") || userCoupons.getIsDouble().equals("true")) { + throw new MsgException("该优惠券已翻倍"); + } + TbParams params = shopUserMapper.selectParams(); + userCoupons.setIsDouble("true"); + userCoupons.setCouponsAmount(userCoupons.getCouponsAmount().multiply(params.getTwoRatio())); + userCoupons.setCouponsPrice(userCoupons.getCouponsPrice().multiply(params.getTwoRatio())); + userCoupons.setUpdateTime(new Date()); + userCouponsMapper.updateByPrimaryKeySelective(userCoupons); + redisUtils.releaseLock(RedisCst.COUPONS_COIN_KEY + conponsId); + } else { + modityDouble(conponsId); + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 42c957b..f722e9e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -32,7 +33,8 @@ public class UserService { private TbShopUserMapper shopUserMapper; @Autowired private TbReleaseFlowMapper releaseFlowMapper; - + @Autowired + private TbUserInfoMapper userInfoMapper; @Autowired RedisUtils redisUtils; @@ -65,7 +67,7 @@ public class UserService { result.put("data", ""); return result; } - boolean falg = updateIntegral(shopUser.getId(), integralVo.getNum(), integralVo.getType()); + boolean falg = updateIntegral(shopUser.getUserId(), integralVo.getNum(), integralVo.getType()); if (!falg) { JSONObject result = new JSONObject(); result.put("status", "fail"); @@ -96,16 +98,16 @@ public class UserService { boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS); if (lock_coin) { - TbShopUser tbShopUser = shopUserMapper.selectByPrimaryKey(userId); + TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); boolean flag = true; if (type.equals("sub")) { - if (N.gt(num, tbShopUser.getLevelConsume())) { + if (num.intValue() < tbShopUser.getTotalScore()) { flag = false; } else { - tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().subtract(num)); + tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue()); } } else if (type.equals("add")) { - tbShopUser.setLevelConsume(tbShopUser.getLevelConsume().add(num)); + tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue()); } if (flag) { TbReleaseFlow releaseFlow = new TbReleaseFlow(); @@ -115,11 +117,15 @@ public class UserService { releaseFlow.setUserId(userId); if (type.equals("sub")) { releaseFlow.setType("BUYSUB"); - }else if (type.equals("sub")){ + releaseFlow.setOperationType("SUB"); + releaseFlow.setRemark("购买商品扣除"); + } else if (type.equals("sub")) { releaseFlow.setType("THREEADD"); + releaseFlow.setOperationType("ADD"); + releaseFlow.setRemark("退货增加"); } releaseFlowMapper.insert(releaseFlow); - shopUserMapper.updateByPrimaryKeySelective(tbShopUser); + userInfoMapper.updateByPrimaryKeySelective(tbShopUser); } redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId); return flag; @@ -141,7 +147,7 @@ public class UserService { result.put("data", ""); return result; } - TbShopUser shopUser = shopUserMapper.selectByOpenId(integralFlowVo.getOpenId()); + TbUserInfo shopUser = userInfoMapper.selectByOpenId(integralFlowVo.getOpenId()); if (Objects.isNull(shopUser)) { JSONObject result = new JSONObject(); result.put("status", "fail"); @@ -151,11 +157,65 @@ public class UserService { } PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize()); PageHelper.orderBy("id DESC"); - List list = releaseFlowMapper.selectByUserId(shopUser.getId()); + List list = releaseFlowMapper.selectByUserId(shopUser.getId().toString()); + for (TbReleaseFlow tbReleaseFlow:list){ + tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime())); + } JSONObject result = new JSONObject(); result.put("status", "success"); result.put("msg", "成功"); - result.put("data",list); + result.put("data", list); + return result; + } + + public JSONObject userAllIntegral(IntegralFlowVo integralFlowVo, String userSign) { +// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo); +// object.put("userSign", userSign); +// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap); +// System.out.println(jsonObject.toJSONString()); +// String sign = MD5Util.encrypt(jsonObject.toJSONString()); +// if (!sign.equals(integralFlowVo.getSign())) { +// JSONObject result = new JSONObject(); +// result.put("status", "fail"); +// result.put("msg", "签名验证失败"); +// result.put("data", ""); +// return result; +// } + PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize()); + PageHelper.orderBy("id DESC"); + List list = releaseFlowMapper.selectAll(); + for (TbReleaseFlow tbReleaseFlow:list){ + tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime())); + } + PageInfo pageInfo = new PageInfo(list); + JSONObject result = new JSONObject(); + result.put("status", "success"); + result.put("msg", "成功"); + result.put("data", pageInfo); + return result; + } + + public JSONObject userAll(IntegralFlowVo integralFlowVo, String userSign) { +// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo); +// object.put("userSign", userSign); +// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap); +// System.out.println(jsonObject.toJSONString()); +// String sign = MD5Util.encrypt(jsonObject.toJSONString()); +// if (!sign.equals(integralFlowVo.getSign())) { +// JSONObject result = new JSONObject(); +// result.put("status", "fail"); +// result.put("msg", "签名验证失败"); +// result.put("data", ""); +// return result; +// } + PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize()); + PageHelper.orderBy("id DESC"); + List list = userInfoMapper.selectAll(); + PageInfo pageInfo = new PageInfo(list); + JSONObject result = new JSONObject(); + result.put("status", "success"); + result.put("msg", "成功"); + result.put("data", pageInfo); return result; } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java index 88eead9..3e12626 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -1,13 +1,7 @@ package com.chaozhanggui.system.cashierservice.task; -import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper; -import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper; -import com.chaozhanggui.system.cashierservice.dao.TbWiningParamsMapper; -import com.chaozhanggui.system.cashierservice.dao.TbWiningUserMapper; -import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo; -import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; -import com.chaozhanggui.system.cashierservice.entity.TbWiningParams; -import com.chaozhanggui.system.cashierservice.entity.TbWiningUser; +import com.chaozhanggui.system.cashierservice.dao.*; +import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.NicknameGenerator; import com.chaozhanggui.system.cashierservice.util.RandomUtil; @@ -33,15 +27,51 @@ public class TaskScheduler { private TbWiningParamsMapper winingParamsMapper; @Autowired private TbUserInfoMapper userInfoMapper; + @Autowired + private TbReleaseFlowMapper releaseFlowMapper; //更新订单状态 -// @Scheduled(fixedRate = 1000, initialDelay = 5000) +// @Scheduled(fixedRate = 1000000) public void orderStatus() throws InterruptedException { - System.out.println(DateUtils.getTime()); - Thread.sleep(10000); + for (int i = 0;i<10;i++){ + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(BigDecimal.ONE, new BigDecimal("100")); + releaseFlow.setNum(orderAmount); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId("15"); + releaseFlow.setOperationType("ADD"); + releaseFlow.setType("EXCHANGEADD"); + releaseFlow.setRemark("兑换增加"); + releaseFlowMapper.insert(releaseFlow); + } + for (int i = 0;i<10;i++){ + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(BigDecimal.ONE, new BigDecimal("100")); + releaseFlow.setNum(orderAmount); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setUserId("15"); + releaseFlow.setOperationType("SUB"); + releaseFlow.setType("BUYSUB"); + releaseFlow.setRemark("购买商品扣除"); + releaseFlowMapper.insert(releaseFlow); + } + for (int i = 0;i<10;i++){ + TbReleaseFlow releaseFlow = new TbReleaseFlow(); + BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(BigDecimal.ONE, new BigDecimal("100")); + releaseFlow.setNum(orderAmount); + releaseFlow.setCreateTime(new Date()); + releaseFlow.setFromSource("OWER"); + releaseFlow.setOperationType("ADD"); + releaseFlow.setUserId("15"); + releaseFlow.setType("THREEADD"); + releaseFlow.setRemark("退货增加"); + releaseFlowMapper.insert(releaseFlow); + } } -// @Scheduled(fixedRate = 1000) + @Scheduled(fixedRate = 200000) public void winningUser() { String day = DateUtils.getDay(); List list = winingParamsMapper.selectAll(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java index 74b407d..512987f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/CacheMap.java @@ -7,4 +7,8 @@ public interface CacheMap { Map map = new HashMap(){{ put("sign","1"); }}; + Map notOpenMap = new HashMap(){{ + put("sign","1"); + put("openId","1"); + }}; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java index 040b90e..163aca6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -99,7 +99,9 @@ public class DateUtils { public static String getTime() { return sdfTime.format(new Date()); } - + public static String getStrTime(Date date) { + return sdfTime.format(date); + } /** * @Title: compareDate * @Description: TODO(日期比较,如果s>=e 返回true 否则返回false) diff --git a/src/main/resources/mapper/TbReleaseFlowMapper.xml b/src/main/resources/mapper/TbReleaseFlowMapper.xml index 597c801..4d7f97b 100644 --- a/src/main/resources/mapper/TbReleaseFlowMapper.xml +++ b/src/main/resources/mapper/TbReleaseFlowMapper.xml @@ -8,10 +8,11 @@ + - id, user_id, num, type, remark, from_source, create_time + id, user_id, num, type, remark, from_source, create_time,operation_type - + + delete from tb_release_flow where id = #{id,jdbcType=INTEGER} insert into tb_release_flow (id, user_id, num, type, remark, from_source, - create_time) + create_time,operation_type) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{num,jdbcType=DECIMAL}, #{type,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{fromSource,jdbcType=VARCHAR}, - #{createTime,jdbcType=TIMESTAMP}) + #{createTime,jdbcType=TIMESTAMP}, #{operationType,jdbcType=VARCHAR}) insert into tb_release_flow diff --git a/src/main/resources/mapper/TbUserCouponsMapper.xml b/src/main/resources/mapper/TbUserCouponsMapper.xml index 2fa9b9f..3c5c1c0 100644 --- a/src/main/resources/mapper/TbUserCouponsMapper.xml +++ b/src/main/resources/mapper/TbUserCouponsMapper.xml @@ -7,12 +7,13 @@ + - id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time + id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double + delete from tb_user_coupons where id = #{id,jdbcType=INTEGER} @@ -33,10 +37,10 @@ insert into tb_user_coupons (id, user_id, coupons_price, coupons_amount, status, create_time, - update_time, end_time) + update_time, end_time,is_double) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=VARCHAR}, #{couponsPrice,jdbcType=DECIMAL}, #{couponsAmount,jdbcType=DECIMAL}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}) + #{updateTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{isDouble,jdbcType=VARCHAR}) insert into tb_user_coupons diff --git a/src/main/resources/mapper/TbUserInfoMapper.xml b/src/main/resources/mapper/TbUserInfoMapper.xml index 4e494b9..ad343cb 100644 --- a/src/main/resources/mapper/TbUserInfoMapper.xml +++ b/src/main/resources/mapper/TbUserInfoMapper.xml @@ -600,5 +600,8 @@ + \ No newline at end of file From f203d7bccc39036c849b65c236e716f309dc83ac Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Sat, 13 Apr 2024 10:39:47 +0800 Subject: [PATCH 016/134] =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/OrderService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 9bc241d..5e687bf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -374,11 +374,12 @@ public class OrderService { if (Objects.isNull(userCoupons) || userCoupons.getIsDouble().equals("true")){ throw new MsgException("该优惠券翻倍已领取"); } + modityDouble(conponsId); return Result.success(CodeEnum.SUCCESS); } - private void modityDouble(Integer conponsId) throws ParseException { + private void modityDouble(Integer conponsId) { boolean lock_coin = redisUtils.lock(RedisCst.COUPONS_COIN_KEY + conponsId, 5000, TimeUnit.MILLISECONDS); if (lock_coin) { From d7dfeee1592155d9580966cfdaa2b79d57b84bf4 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 15 Apr 2024 10:07:53 +0800 Subject: [PATCH 017/134] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20=E5=A4=B4=E5=83=8F/=E6=98=B5=E7=A7=B0=20?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=8F=B7/=E5=B0=8F=E7=A8=8B=E5=BA=8F/?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=8F=B7mapper=20=20=E6=9A=82=E6=9C=AA?= =?UTF-8?q?=E6=8A=95=E5=85=A5=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 16 +- .../controller/LoginContoller.java | 9 + .../cashierservice/dao/TbShopVideoMapper.java | 32 ++++ .../cashierservice/entity/TbShopVideo.java | 159 ++++++++++++++++++ .../cashierservice/service/LoginService.java | 9 + .../service/TbShopVideoService.java | 38 +++++ .../resources/mapper/TbShopVideoMapper.xml | 78 +++++++++ 7 files changed, 337 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopVideoMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopVideo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopVideoService.java create mode 100644 src/main/resources/mapper/TbShopVideoMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 2c96100..ad78a3c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -67,6 +67,7 @@ public class LoginFilter implements Filter { chain.doFilter(req, resp); return; } + //environment 环境标识 wx app 后续environment不可为空 String environment = request.getHeader("environment"); //token校验目前只对app生效 @@ -85,10 +86,17 @@ public class LoginFilter implements Filter { response.getWriter().flush();//流里边的缓存刷出 return; } - //获取当前登录人的用户id - String loginName = TokenUtil.parseParamFromToken(token).getString("userId"); - //获取redis中的token - String message = redisUtil.getMessage(RedisCst.ONLINE_APP_USER.concat(loginName)); + String message = ""; + if(environment.equals("app")){ + //获取当前登录人的用户id + String loginName = TokenUtil.parseParamFromToken(token).getString("userId"); + //获取redis中的token + message = redisUtil.getMessage(RedisCst.ONLINE_APP_USER.concat(loginName)); + }else if(environment.equals("wx")){ + //获取当前登录人的用户id + String openId = TokenUtil.parseParamFromToken(token).getString("openId"); + message = redisUtil.getMessage(RedisCst.ONLINE_USER.concat(openId)); + } if (StringUtils.isBlank(message)) { Result result = new Result(CodeEnum.TOKEN_EXPIRED); String jsonString = JSONObject.toJSONString(result); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 1e669b3..c6bbeb9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper; import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto; import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -221,6 +222,14 @@ public class LoginContoller { return loginService.userInfo(userId, shopId); } + @PostMapping("/upUserInfo") + public Result userInfo(@RequestHeader String token, @RequestBody TbUserInfo userInfo) { + String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + userInfo.setId(Integer.valueOf(userId)); + userInfo.setUpdatedAt(System.currentTimeMillis()); + return loginService.upUserInfo(userInfo); + } + /** * 用户注册 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopVideoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopVideoMapper.java new file mode 100644 index 0000000..7fa42de --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopVideoMapper.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbShopVideo; + +import java.util.List; + +/** + * (TbShopVideo)表数据库访问层 + * + * @author ww + * @since 2024-04-12 14:50:09 + */ +public interface TbShopVideoMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbShopVideo queryById(Integer id); + + /** + * 查询数据 + * + * @param tbShopVideo 查询条件 + * @return 对象列表 + */ + List queryAll(TbShopVideo tbShopVideo); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopVideo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopVideo.java new file mode 100644 index 0000000..6123ff4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopVideo.java @@ -0,0 +1,159 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.util.Date; +import java.io.Serializable; + +/** + * 商户视频号(TbShopVideo)实体类 + * + * @author ww + * @since 2024-04-12 14:50:09 + */ +public class TbShopVideo implements Serializable { + private static final long serialVersionUID = 521986900418854409L; + + private Integer id; + /** + * 店铺id + */ + private Integer shopId; + /** + * 1-公众号;2-小程序;3-视频号 + */ + private Integer type; + /** + * 描述信息 + */ + private String name; + /** + * 渠道id(视频号id) + */ + private Integer channelId; + /** + * 创建时间 + */ + private Date createdTime; + /** + * 更新时间 + */ + private Date updateTime; + /** + * 资源Id(视频号id)(公众号id) + */ + private Integer sourceId; + /** + * 资源地址 + */ + private String sourceUrl; + /** + * 0:关闭;1:开启; + */ + private Integer status; + /** + * 视频id + */ + private Integer videoId; + /** + * 视频地址 + */ + private String videoUrl; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getShopId() { + return shopId; + } + + public void setShopId(Integer shopId) { + this.shopId = shopId; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getChannelId() { + return channelId; + } + + public void setChannelId(Integer channelId) { + this.channelId = channelId; + } + + public Date getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Date createdTime) { + this.createdTime = createdTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Integer getSourceId() { + return sourceId; + } + + public void setSourceId(Integer sourceId) { + this.sourceId = sourceId; + } + + public String getSourceUrl() { + return sourceUrl; + } + + public void setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Integer getVideoId() { + return videoId; + } + + public void setVideoId(Integer videoId) { + this.videoId = videoId; + } + + public String getVideoUrl() { + return videoUrl; + } + + public void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index d8127b8..57217a6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -123,7 +123,11 @@ public class LoginService { tbShopUser.setUserId(userInfo.getId().toString()); tbShopUser.setMiniOpenId(openId); tbShopUser.setCreatedAt(System.currentTimeMillis()); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.insert(tbShopUser); + }else { + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); } shopMap.put("shopId", tbShopUser.getShopId()); shopMap.put("name", tbShopInfo.getShopName()); @@ -304,6 +308,11 @@ public class LoginService { return Result.success(CodeEnum.ENCRYPT, map); } + public Result upUserInfo(TbUserInfo userInfo){ + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + return Result.success(CodeEnum.SUCCESS); + } + public static void main(String[] args) { for (int i = 0; i < 10; i++) { System.out.println(RandomUtil.randomNumbers(10)); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopVideoService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopVideoService.java new file mode 100644 index 0000000..4ef257f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopVideoService.java @@ -0,0 +1,38 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.dao.TbShopVideoMapper; +import com.chaozhanggui.system.cashierservice.entity.TbShopVideo; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; + +import javax.annotation.Resource; + +/** + * 视频号 公众号 + * @author ww + * @since 2024-04-12 14:50:10 + */ +public class TbShopVideoService { + + @Resource + private TbShopVideoMapper tbShopVideoMapper; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + public Result queryById(Integer id) { + return Result.success(CodeEnum.ENCRYPT,tbShopVideoMapper.queryById(id)); + } + + /** + * @param tbShopVideo 筛选条件 + * @return 查询结果 + */ + public Result queryAll(TbShopVideo tbShopVideo) { + tbShopVideo.setStatus(1); + return Result.success(CodeEnum.ENCRYPT,tbShopVideoMapper.queryAll(tbShopVideo)); + } +} diff --git a/src/main/resources/mapper/TbShopVideoMapper.xml b/src/main/resources/mapper/TbShopVideoMapper.xml new file mode 100644 index 0000000..bf6fc25 --- /dev/null +++ b/src/main/resources/mapper/TbShopVideoMapper.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + id + , shop_id, type, name, channel_id, source_id, source_url, status ,created_time, update_time + + + + + + + + + From 46cd954abf568dae505ec70a32c64bf66b54f76b Mon Sep 17 00:00:00 2001 From: liuyingfang <1357764963@qq.com> Date: Mon, 15 Apr 2024 10:15:16 +0800 Subject: [PATCH 018/134] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=8B=E5=8D=8A?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbMerchantCouponMapper.java | 6 +- .../entity/TbMerchantCoupon.java | 1 + .../cashierservice/entity/dto/HomeDto.java | 60 ++++--------------- .../entity/vo/CouAndShopVo.java | 41 +++++++++++++ .../cashierservice/entity/vo/HomeVO.java | 6 +- .../service/HomePageService.java | 47 ++++++++++----- .../cashierservice/util/LocationUtils.java | 45 ++++++++------ .../mapper/TbMerchantCouponMapper.xml | 46 +++++++++++--- 8 files changed, 157 insertions(+), 95 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CouAndShopVo.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java index 96c03c3..76d881b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java @@ -1,6 +1,8 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon; +import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; +import com.chaozhanggui.system.cashierservice.entity.vo.CouAndShopVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; @@ -36,7 +38,9 @@ public interface TbMerchantCouponMapper { List queryAllByLimit(TbMerchantCoupon tbMerchantCoupon, @Param("pageable") Pageable pageable); - List queryAllByPage(@Param("page")Integer page, @Param("size")Integer size); + List queryAllByPage(@Param("pageable")Integer page, @Param("sizeable")Integer size, @Param("rightTopLng") Double rightTopLng, + @Param("rightTopLat")Double rightTopLat, @Param("leftBottomLng")Double leftBottomLng, @Param("leftBottomLat")Double leftBottomLat, + @Param("cities")String cities, @Param("order")String order,@Param("lng")String lng,@Param("lat")String lat); /** * 统计总行数 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java index 8e922e5..c71db04 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java @@ -135,6 +135,7 @@ public class TbMerchantCoupon implements Serializable { private String merchantId; + public Integer getId() { return id; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java index 74f70e2..a0a4a63 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java @@ -12,12 +12,20 @@ public class HomeDto { */ private String address; /** - * 品类 + * 经度 + */ + private String lat; + /** + * 纬度 + */ + private String lng; + /** + * 品类 1.附近1Km */ private String type; /** - * 1.理我最近 2.销量优先 3.价格优先 + * 1.离我最近 2.销量优先 3.价格优先 */ private Integer orderBy; @@ -26,52 +34,4 @@ public class HomeDto { private Integer page; private Integer size; - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Integer getOrderBy() { - return orderBy; - } - - public void setOrderBy(Integer orderBy) { - this.orderBy = orderBy; - } - - public Integer getOther() { - return other; - } - - public void setOther(Integer other) { - this.other = other; - } - - public Integer getPage() { - return page; - } - - public void setPage(Integer page) { - this.page = page; - } - - public Integer getSize() { - return size; - } - - public void setSize(Integer size) { - this.size = size; - } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CouAndShopVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CouAndShopVo.java new file mode 100644 index 0000000..1610d4f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CouAndShopVo.java @@ -0,0 +1,41 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +/** + * @author lyf + */ +@Data +public class CouAndShopVo { + /** + * 自增 + */ + private Integer id; + /** + * 优惠券名称 + */ + private String title; + + private String shopId; + /** + * 优惠金额 + */ + private Double amount; + /** + * 发放数量 + */ + private Integer number; + /** + * 折扣 ,一位小数 + */ + private Float ratio; + + /** + * 关联商品Id + */ + private String relationIds; + + private String shopName; + + private String logo; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index aa73d32..fb05d93 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -36,7 +36,7 @@ public class HomeVO { /** * 折扣 */ - private Float discount; + private BigDecimal discount; /** * 共省金额 */ @@ -164,11 +164,11 @@ public class HomeVO { this.salePrice = salePrice; } - public Float getDiscount() { + public BigDecimal getDiscount() { return discount; } - public void setDiscount(Float discount) { + public void setDiscount(BigDecimal discount) { this.discount = discount; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 9f6c2c4..b4267bc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -19,11 +19,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.BigInteger; import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -59,13 +57,23 @@ public class HomePageService { } else { beginNo = (homeDto.getPage() - 1) * homeDto.getSize(); } - //优惠卷 - List tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize()); + //经纬度(附近一km) + Map topAndBottomMap = new HashMap<>(); + List tbMerchantCoupons = new ArrayList<>(); + if (homeDto.getOther() != null && homeDto.getOther() == 1){ + topAndBottomMap = LocationUtils.returnLLSquarePoint(Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), 1); + tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), topAndBottomMap.get("rightTopPoint")[0],topAndBottomMap.get("rightTopPoint")[1], + topAndBottomMap.get("leftBottomPoint")[0],topAndBottomMap.get("leftBottomPoint")[1],homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat()); + }else { + tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), null,null,null,null, + homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat()); + } + //统计shopId,以及productId List shopIds = new ArrayList<>(); List productIds = new ArrayList<>(); List productIdsInt = new ArrayList<>(); - for (TbMerchantCoupon coupon : tbMerchantCoupons) { + for (CouAndShopVo coupon : tbMerchantCoupons) { shopIds.add(coupon.getShopId()); productIds.add(coupon.getRelationIds()); productIdsInt.add(Integer.valueOf(coupon.getRelationIds())); @@ -82,10 +90,9 @@ public class HomePageService { //组装 List homeVOList = new ArrayList<>(); - for (TbMerchantCoupon o : tbMerchantCoupons) { + for (CouAndShopVo o : tbMerchantCoupons) { HomeVO homeVO = new HomeVO(); homeVO.setId(o.getId()); - homeVO.setDiscount(o.getRatio()); for (TbShopInfo tbShopInfo : shopInfo.get()) { if (o.getShopId().equals(tbShopInfo.getId().toString())) { homeVO.setShopName(tbShopInfo.getShopName()); @@ -104,18 +111,26 @@ public class HomePageService { } for (TbProduct tbProduct : product.get()) { if (o.getRelationIds().equals(tbProduct.getId().toString())) { - homeVO.setProductName(tbProduct.getName()); + homeVO.setProductName(o.getTitle()); homeVO.setImage(tbProduct.getCoverImg()); homeVO.setProductId(tbProduct.getId()); } } for (TbProductSku tbProductSku : productSku.get()) { if (o.getRelationIds().equals(tbProductSku.getProductId())) { - homeVO.setOriginPrice(tbProductSku.getSalePrice()); - homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber())); - Float discount = homeVO.getDiscount(); - BigDecimal discountDecimal = new BigDecimal(discount); - homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1"))))); + //原价 + if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO)==0){ + homeVO.setOriginPrice(BigDecimal.ZERO); + homeVO.setDiscount(BigDecimal.ZERO); + }else { + homeVO.setOriginPrice(tbProductSku.getSalePrice()); + homeVO.setDiscount(new BigDecimal(o.getAmount()).divide(tbProductSku.getSalePrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN)); + } + //销量 + homeVO.setRealSalesNumber(new BigDecimal(o.getNumber())); + //现价 + homeVO.setSalePrice(new BigDecimal(o.getAmount().toString())); + // 共省金额 homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice())); } } @@ -161,7 +176,7 @@ public class HomePageService { BigDecimal originPrice = o.getOriginPrice(); if (originPrice.compareTo(BigDecimal.ZERO) != 0) { BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN); - o.setDiscount(multiply.floatValue()); + o.setDiscount(multiply); } else { o.setDiscount(null); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index 791eb32..8066463 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -43,12 +43,14 @@ public class LocationUtils { } /** - * @param longitude 经度 - * @param latitude 纬度 + * @param longitude 经度 108 + * @param latitude 纬度 34 * @param distanceInKm 范围(千米) + * 大于左下的经度lat,小于右上的经度lat + * 大于左下的纬度lng,小于右上的纬度lng * return Map stringMap - * 右顶点 double[] leftTopPoints = stringMap.get("rightTopPoint"); - * 左顶点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); + * 右上顶点 double[] leftTopPoints = stringMap.get("rightTopPoint"); + * 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); */ public static Map returnLLSquarePoint(double longitude, double latitude, double distanceInKm) { Map squareMap = new HashMap<>(); @@ -67,31 +69,38 @@ public class LocationUtils { double[] leftBottomPoint = {latitude - dLatitude / 2, longitude - dLongitude / 2}; squareMap.put("rightTopPoint", rightTopPoint); squareMap.put("leftBottomPoint", leftBottomPoint); - // 打印结果 -// System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]); -// System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]); + // 打印结果rightTopPoint[0]纬度lng,rightTopPoint[1]经度lat + System.out.println("rightTop:" + rightTopPoint[0] + "======" + rightTopPoint[1]); + System.out.println("leftBottom:" + leftBottomPoint[0] + "======" + leftBottomPoint[1]); return squareMap; } + /** * 将角度转化为弧度 */ public static double radians(double d) { return d * Math.PI / 180.0; } + //1KM + public static void main(String[] args) { + Map stringMap = returnLLSquarePoint(108.954398, 34.308687, 1); + double[] leftTopPoints = stringMap.get("rightTopPoint"); + double[] leftBottomPoints = stringMap.get("leftBottomPoint"); + double lat2 = 108.975418; + double lon2 = 34.280890; + double distance3 = getDistanceFrom2LngLat(109.019993, 34.342849, lat2, lon2); + System.out.println(distance3); + + // 计算距离 + double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2); + double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2); + System.out.println("Distance between the two points is: " + distance1 + " km"); + System.out.println("Distance between the two points is: " + distance2 + " km"); + } // public static void main(String[] args) { -// Map stringMap = returnLLSquarePoint(108.954398, 34.308687, 1); -// double[] leftTopPoints = stringMap.get("rightTopPoint"); -// double[] leftBottomPoints = stringMap.get("leftBottomPoint"); +// Map stringMap = returnLLSquarePoint(34.342849, 109.019993, 1); // -// double lat2 = 108.954398; -// double lon2 = 34.308687; -// -// // 计算距离 -// double distance1 = getDistanceFrom2LngLat(leftTopPoints[1], leftTopPoints[0], lat2, lon2); -// double distance2 = getDistanceFrom2LngLat(leftBottomPoints[1], leftBottomPoints[0], lat2, lon2); -// System.out.println("Distance between the two points is: " + distance1 + " km"); -// System.out.println("Distance between the two points is: " + distance2 + " km"); // } } diff --git a/src/main/resources/mapper/TbMerchantCouponMapper.xml b/src/main/resources/mapper/TbMerchantCouponMapper.xml index 5dbcdc5..85c3d5d 100644 --- a/src/main/resources/mapper/TbMerchantCouponMapper.xml +++ b/src/main/resources/mapper/TbMerchantCouponMapper.xml @@ -268,13 +268,45 @@ - + SELECT + cou.id as id, + cou.title as title, + cou.shop_id as shopId, + cou.amount as amount, + cou.number as number, + cou.ratio as ratio, + cou.relation_ids as relationIds, + info.shop_name as shopName, + info.logo + FROM + tb_merchant_coupon as cou + LEFT JOIN tb_shop_info as info ON cou.shop_id = info.id + + cou.class_type = 'product' + AND cou.`status` = 1 + AND info.cities =#{cities} + + AND info.lng BETWEEN #{leftBottomLng} AND #{rightTopLng} + AND info.lat BETWEEN #{leftBottomLat} AND #{rightTopLat} + + + + + + ORDER BY (ABS(info.lat - #{lat}) + ABS(info.lng - #{lng})) ASC + + + ORDER BY cou.number ASC + + + ORDER BY cou.amount ASC + + + ORDER BY cou.id ASC + + + limit #{pageable}, #{sizeable} From 2cd2ef8c071f50871238b9396b3570909018b759 Mon Sep 17 00:00:00 2001 From: 19991905653 Date: Mon, 15 Apr 2024 14:36:46 +0800 Subject: [PATCH 019/134] =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbSplitAccountsMapper.java | 17 ++ .../cashierservice/entity/TbOrderInfo.java | 1 + .../entity/TbSplitAccounts.java | 33 ++++ .../cashierservice/service/CartService.java | 8 +- .../resources/mapper/TbOrderInfoMapper.xml | 23 ++- .../mapper/TbSplitAccountsMapper.xml | 154 ++++++++++++++++++ 6 files changed, 225 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSplitAccountsMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSplitAccounts.java create mode 100644 src/main/resources/mapper/TbSplitAccountsMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSplitAccountsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSplitAccountsMapper.java new file mode 100644 index 0000000..70ee67a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSplitAccountsMapper.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbSplitAccounts; + +public interface TbSplitAccountsMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbSplitAccounts record); + + int insertSelective(TbSplitAccounts record); + + TbSplitAccounts selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbSplitAccounts record); + + int updateByPrimaryKey(TbSplitAccounts record); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index e332732..4ca654d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -96,6 +96,7 @@ public class TbOrderInfo implements Serializable { private String tableName; private String masterId; private String isBuyCoupon; + private String isUseCoupon; private Integer totalNumber; private List detailList; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSplitAccounts.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSplitAccounts.java new file mode 100644 index 0000000..69ddb3d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbSplitAccounts.java @@ -0,0 +1,33 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class TbSplitAccounts implements Serializable { + private Integer id; + + private Integer merchantId; + + private Integer shopId; + + private BigDecimal couponsPrice; + + private BigDecimal conponsAmount; + private BigDecimal originAmount; + + private String isSplit; + + private BigDecimal orderAmount; + + private Date createTime; + + private Date splitTime; + + private String tradeDay; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index b8640f5..62ad053 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -213,7 +213,7 @@ public class CartService { BigDecimal packAMount = BigDecimal.ZERO; BigDecimal originAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; - String couponId = jsonObject.getString("couponsId"); + String couponId = ""; BigDecimal couponAmount = BigDecimal.ZERO; Map skuMap = new HashMap<>(); List orderDetails = new ArrayList<>(); @@ -270,7 +270,9 @@ public class CartService { //生成订单 TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); String isBuyYhq = "false"; + String isuseYhq = "false"; if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { + couponId =jsonObject.getString("couponsId"); //1:购买优惠券,0:自己持有优惠券 Integer couponsId = jsonObject.getInteger("couponsId"); if (jsonObject.getString("isBuyYhq").equals("1")) { @@ -342,7 +344,7 @@ public class CartService { userCouponsMapper.updateByPrimaryKeySelective(userCoupons); couponAmount = userCoupons.getCouponsAmount(); } - + isuseYhq = "true"; } if (Objects.nonNull(orderInfo)) { @@ -370,6 +372,7 @@ public class CartService { orderInfo.setFreightAmount(BigDecimal.ZERO); orderInfo.setProductAmount(saleAmount); orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setIsUseCoupon(isuseYhq); orderInfoMapper.updateByPrimaryKeySelective(orderInfo); } else { orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount); @@ -377,6 +380,7 @@ public class CartService { orderInfo.setUserCouponId(couponId); orderInfo.setOriginAmount(originAmount); orderInfo.setIsBuyCoupon(isBuyYhq); + orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setUserCouponAmount(couponAmount); orderInfoMapper.insert(orderInfo); orderId = orderInfo.getId(); diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index 8b61660..a3f9a9c 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -47,6 +47,7 @@ + id, order_no, settlement_amount, pack_fee, origin_amount, product_amount, amount, @@ -54,7 +55,8 @@ discount_amount, table_id, small_change, send_type, order_type, product_type, status, billing_id, merchant_id, shop_id, is_vip, member_id, user_id, product_score, deduct_score, user_coupon_id, user_coupon_amount, refund_able, paid_time, is_effect, is_group, - updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name`,is_buy_coupon + updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`, + remark,master_id,`table_name`,is_buy_coupon,is_use_coupon + select + + from tb_split_accounts + where id = #{id,jdbcType=INTEGER} + + + delete from tb_split_accounts + where id = #{id,jdbcType=INTEGER} + + + insert into tb_split_accounts (id, merchant_id, shop_id, + coupons_price, conpons_amount, is_split, + order_amount, create_time, split_time, + trade_day,origin_amount) + values (#{id,jdbcType=INTEGER}, #{merchantId,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, + #{couponsPrice,jdbcType=DECIMAL}, #{conponsAmount,jdbcType=DECIMAL}, #{isSplit,jdbcType=VARCHAR}, + #{orderAmount,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP}, #{splitTime,jdbcType=TIMESTAMP}, + #{tradeDay,jdbcType=VARCHAR},#{originAmount,jdbcType=DECIMAL}) + + + insert into tb_split_accounts + + + id, + + + merchant_id, + + + shop_id, + + + coupons_price, + + + conpons_amount, + + + is_split, + + + order_amount, + + + create_time, + + + split_time, + + + trade_day, + + + + + #{id,jdbcType=INTEGER}, + + + #{merchantId,jdbcType=INTEGER}, + + + #{shopId,jdbcType=INTEGER}, + + + #{couponsPrice,jdbcType=DECIMAL}, + + + #{conponsAmount,jdbcType=DECIMAL}, + + + #{isSplit,jdbcType=VARCHAR}, + + + #{orderAmount,jdbcType=DECIMAL}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{splitTime,jdbcType=TIMESTAMP}, + + + #{tradeDay,jdbcType=VARCHAR}, + + + + + update tb_split_accounts + + + merchant_id = #{merchantId,jdbcType=INTEGER}, + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + + + conpons_amount = #{conponsAmount,jdbcType=DECIMAL}, + + + is_split = #{isSplit,jdbcType=VARCHAR}, + + + order_amount = #{orderAmount,jdbcType=DECIMAL}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + split_time = #{splitTime,jdbcType=TIMESTAMP}, + + + trade_day = #{tradeDay,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_split_accounts + set merchant_id = #{merchantId,jdbcType=INTEGER}, + shop_id = #{shopId,jdbcType=INTEGER}, + coupons_price = #{couponsPrice,jdbcType=DECIMAL}, + conpons_amount = #{conponsAmount,jdbcType=DECIMAL}, + is_split = #{isSplit,jdbcType=VARCHAR}, + order_amount = #{orderAmount,jdbcType=DECIMAL}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + split_time = #{splitTime,jdbcType=TIMESTAMP}, + trade_day = #{tradeDay,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file From ca1cdd545cbdc869757f052df9810df5f6d0fe28 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 15 Apr 2024 15:22:24 +0800 Subject: [PATCH 020/134] =?UTF-8?q?=E5=90=88=E5=B9=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/dao/TbProductMapper.java | 3 --- .../chaozhanggui/system/cashierservice/entity/dto/HomeDto.java | 2 +- src/main/resources/mapper/TbProductMapper.xml | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java index 52c6da8..91c8f2b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java @@ -2,7 +2,6 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbProduct; import com.chaozhanggui.system.cashierservice.entity.TbProductWithBLOBs; -import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -33,6 +32,4 @@ public interface TbProductMapper { List selectByIds(@Param("list") List ids); Integer selectByQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId); Integer selectByNewQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId,@Param("list") List list); - - TbSystemCoupons selectLimit(); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java index a0a4a63..0602412 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java @@ -20,7 +20,7 @@ public class HomeDto { */ private String lng; /** - * 品类 1.附近1Km + * 品类 */ private String type; diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 3fb1404..3940301 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -933,7 +933,4 @@ #{item} - \ No newline at end of file From 8458da333f28e73c8b1e52ed2eb37512179678ac Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 15 Apr 2024 17:32:26 +0800 Subject: [PATCH 021/134] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f0a4eef..f5b99f0 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,8 +1,11 @@ spring: datasource: - url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false - username: root - password: mysqlroot@123 +# url: jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false +# username: root +# password: mysqlroot@123 + url: jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true + username: fycashier + password: Twc6MrzzjBiWSsjh driver-class-name: com.mysql.cj.jdbc.Driver initialSize: 5 minIdle: 5 From 83a08265c37c92503b2163d6377c7ae1ce5fa55c Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 16 Apr 2024 16:25:08 +0800 Subject: [PATCH 022/134] =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/config/CorsFilter.java | 2 +- .../controller/LoginContoller.java | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java index 7285a31..6690f7b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/CorsFilter.java @@ -28,7 +28,7 @@ public class CorsFilter implements Filter { response.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin); response.setHeader("Access-Control-Allow-Methods", "*"); response.setHeader("Access-Control-Max-Age", "3600"); - response.setHeader("Access-Control-Allow-Headers", "environment,type,version,token"); + response.setHeader("Access-Control-Allow-Headers", "environment,openId,type,version,token"); response.setHeader("Access-Control-Allow-Credentials", "true"); chain.doFilter(req, resp); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index c6bbeb9..1dce6f1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -15,10 +15,7 @@ import com.chaozhanggui.system.cashierservice.service.LoginService; import com.chaozhanggui.system.cashierservice.service.OnlineUserService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; -import com.chaozhanggui.system.cashierservice.util.IpUtil; -import com.chaozhanggui.system.cashierservice.util.MD5Utils; -import com.chaozhanggui.system.cashierservice.util.StringUtil; -import com.chaozhanggui.system.cashierservice.util.TokenUtil; +import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; @@ -158,13 +155,14 @@ public class LoginContoller { String encryptedData = map.get("encryptedData"); String ivStr = map.get("iv"); - + if (StringUtils.isBlank(encryptedData) || StringUtils.isBlank(ivStr)) { + return Result.fail("请授权后使用"); + } JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete); // 3.接收微信接口服务 获取返回的参数 String openid = SessionKeyOpenId.getString("openid"); String sessionKey = SessionKeyOpenId.getString("session_key"); - String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber")); @@ -253,15 +251,16 @@ public class LoginContoller { /** * App登录用户端的请求接口 登录即注册 * 查看 {@link com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto} - * username 手机号 - * password 密码登录时使用 - * code 验证码登录时使用 + * username 手机号 + * password 密码登录时使用 + * code 验证码登录时使用 + * * @return */ @PostMapping("/app/login") public Result applogin(@RequestBody AuthUserDto authUserDto) { if (ObjectUtil.isNull(authUserDto.getCode())) { - if(StringUtils.isBlank(authUserDto.getPassword())){ + if (StringUtils.isBlank(authUserDto.getPassword())) { return Result.fail("请输入密码,或使用验证码登录"); } //验证密码 From 4fc29e3ad8df087a0ee68d97e41da07bf67ef427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 18 Apr 2024 13:59:16 +0800 Subject: [PATCH 023/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 9 +- .../controller/PayController.java | 11 ++ .../dao/TbShopPayTypeMapper.java | 7 ++ .../cashierservice/entity/TbShopUser.java | 31 +++++ .../cashierservice/service/LoginService.java | 24 ++-- .../cashierservice/service/PayService.java | 107 +++++++++++++++++- .../resources/mapper/TbShopPayTypeMapper.xml | 5 + .../resources/mapper/TbShopUserMapper.xml | 13 +++ 8 files changed, 192 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 1dce6f1..2fa566b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -210,9 +210,12 @@ public class LoginContoller { * @param id * @return */ - @RequestMapping("createCardNo") - public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id) { - return loginService.createCardNo(id, openId); + @GetMapping("createCardNo") + public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id, + + @RequestParam("shopId") String shopId + ) { + return loginService.createCardNo(id, openId,shopId); } @GetMapping("/wx/userInfo") diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index fee5b56..6d20ad5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -46,6 +46,17 @@ public class PayController { } +// +// public Result memberAccountPay(@RequestHeader("openId") String openId, +// @RequestParam("orderId") String orderId, +// @RequestParam("userId") Integer userId, +// @RequestParam("shopId") String shopId, +// @RequestParam("pwd") String pwd +// ){ +// +// } + + /** * 修改订单状态 * @param map diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPayTypeMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPayTypeMapper.java index e656808..6990b03 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPayTypeMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopPayTypeMapper.java @@ -1,7 +1,12 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbShopPayType; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; +@Component +@Mapper public interface TbShopPayTypeMapper { int deleteByPrimaryKey(Integer id); @@ -14,4 +19,6 @@ public interface TbShopPayTypeMapper { int updateByPrimaryKeySelective(TbShopPayType record); int updateByPrimaryKey(TbShopPayType record); + + int countSelectByShopIdAndPayType(@Param("shopId") String shopId, @Param("payType") String payType ); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java index c1a688d..f447e2d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java @@ -42,6 +42,13 @@ public class TbShopUser implements Serializable { private String code; + + private String dynamicCode; + + private String isPwd; + + private String pwd; + private Byte isAttention; private Integer attentionAt; @@ -214,6 +221,30 @@ public class TbShopUser implements Serializable { this.code = code == null ? null : code.trim(); } + public String getDynamicCode() { + return dynamicCode; + } + + public void setDynamicCode(String dynamicCode) { + this.dynamicCode = dynamicCode; + } + + public String getIsPwd() { + return isPwd; + } + + public void setIsPwd(String isPwd) { + this.isPwd = isPwd; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } + public Byte getIsAttention() { return isAttention; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 57217a6..1adb333 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -122,6 +122,7 @@ public class LoginService { tbShopUser.setShopId(tbShopInfo.getId().toString()); tbShopUser.setUserId(userInfo.getId().toString()); tbShopUser.setMiniOpenId(openId); + tbShopUser.setIsPwd("1"); tbShopUser.setCreatedAt(System.currentTimeMillis()); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.insert(tbShopUser); @@ -250,12 +251,11 @@ public class LoginService { return Result.fail("登录失败"); } - public Result createCardNo(String id, String openId) { + public Result createCardNo(String id, String openId,String shopId) { if (ObjectUtil.isEmpty(id) || ObjectUtil.isEmpty(openId)) { return Result.fail("head 信息不允许为空"); } - TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(id)); if (userInfo == null || ObjectUtil.isEmpty(userInfo)) { userInfo = tbUserInfoMapper.selectByOpenId(openId); @@ -265,12 +265,22 @@ public class LoginService { return Result.fail("用户信息不存在"); } - String cardNo = RandomUtil.randomNumbers(10); - userInfo.setCardNo(cardNo); - userInfo.setUpdatedAt(System.currentTimeMillis()); - tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); - return Result.success(CodeEnum.SUCCESS, cardNo); + TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId); + if(ObjectUtil.isEmpty(tbShopUser)||tbShopUser==null){ + return Result.fail("用户信息错误"); + } + + String dynamicCode = RandomUtil.randomNumbers(8); + dynamicCode= StringUtils.rightPad(tbShopUser.getId(),6,"0").concat(dynamicCode); + + tbShopUser.setDynamicCode(dynamicCode); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); + + + + return Result.success(CodeEnum.SUCCESS, dynamicCode); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 0162190..8810012 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; import com.chaozhanggui.system.cashierservice.util.BeanUtil; import com.chaozhanggui.system.cashierservice.util.MD5Util; +import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -54,6 +55,11 @@ public class PayService { TbOrderDetailMapper tbOrderDetailMapper; + + @Autowired + TbShopPayTypeMapper tbShopPayTypeMapper; + + @Value("${ysk.url}") private String url; @@ -182,6 +188,100 @@ public class PayService { + @Transactional(rollbackFor = Exception.class) + public Result accountPay(String orderId, String userId, String shopId,String pwd) { + if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(pwd)) { + return Result.fail("参数错误"); + } + + TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); + if (ObjectUtil.isEmpty(orderInfo)) { + return Result.fail("订单信息不存在"); + } + + + if (!"unpaid".equals(orderInfo.getStatus())) { + return Result.fail("订单状态异常"); + } + + + int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "deposit"); + if (count < 1) { + return Result.fail("当前店铺未开通储值卡支付"); + } + + TbShopUser user = tbShopUserMapper.selectByUserIdAndShopId(userId,shopId); + + if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { + return Result.fail("此用户非会员用户"); + } + + + if("1".equals(user.getIsPwd())){ + return Result.fail("会员支付密码为初始化密码"); + } + + if(!MD5Util.encrypt(pwd).equals(user.getPwd())){ + return Result.fail("会员支付密码错误"); + } + + if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { + return Result.fail("会员卡余额不足"); + } + + user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); + user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount())); + user.setConsumeNumber(user.getConsumeNumber() + 1); + user.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(user); + + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(Integer.valueOf(user.getId())); + flow.setBizCode("accountPay"); + flow.setBizName("会员储值卡支付"); + flow.setAmount(orderInfo.getOrderAmount()); + flow.setBalance(user.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfo.setMemberId(userId); + orderInfo.setPayType("deposit"); + orderInfo.setStatus("closed"); + orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo())); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + + + int cartCount= tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); + + log.info("更新购物车:{}",cartCount); + + //更新子单状态 + tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId),"closed"); + + //修改主单状态 + orderInfo.setStatus("closed"); + orderInfo.setPayType("deposit"); + orderInfo.setPayOrderNo(user.getDynamicCode()); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + + + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderInfo.getId().toString()); + + producer.putOrderCollect(jsonObject.toJSONString()); + + producer.printMechine(orderInfo.getId() + ""); + + return Result.success(CodeEnum.SUCCESS); + } + + @Transactional(rollbackFor = Exception.class) public Result modifyOrderStatus(Integer orderId) throws IOException { TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); @@ -289,10 +389,6 @@ public class PayService { return Result.fail("对应的用户信息不存在"); } - if(ObjectUtil.isEmpty(tbShopUser.getIsVip())||!"1".equals(tbShopUser.getIsVip().toString())){ - return Result.fail("非会员用户不允许充值"); - } - TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); if(ObjectUtil.isEmpty(shopInfo)){ @@ -311,7 +407,7 @@ public class PayService { TbMemberIn memberIn=new TbMemberIn(); memberIn.setAmount(payAmount); memberIn.setUserId(Integer.valueOf(tbShopUser.getUserId())); - memberIn.setCode(tbShopUser.getCode()); + memberIn.setCode(tbShopUser.getDynamicCode()); memberIn.setShopId(shopInfo.getId()); memberIn.setStatus("7"); memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId())); @@ -414,6 +510,7 @@ public class PayService { } //修改客户资金 + tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setAmount(tbShopUser.getAmount().add(memberIn.getAmount())); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); diff --git a/src/main/resources/mapper/TbShopPayTypeMapper.xml b/src/main/resources/mapper/TbShopPayTypeMapper.xml index 9b2c36c..10527de 100644 --- a/src/main/resources/mapper/TbShopPayTypeMapper.xml +++ b/src/main/resources/mapper/TbShopPayTypeMapper.xml @@ -185,4 +185,9 @@ updated_at = #{updatedAt,jdbcType=BIGINT} where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index 04e272f..9716cd0 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -301,6 +301,19 @@ code = #{code,jdbcType=VARCHAR}, + + + dynamic_code = #{dynamicCode,jdbcType=VARCHAR}, + + + + + is_pwd = #{isPwd,jdbcType=VARCHAR}, + + + + pwd = #{pwd,jdbcType=VARCHAR}, + is_attention = #{isAttention,jdbcType=TINYINT}, From ea1252ecc093d605df37e41dcb37545e00e1de1e Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Wed, 24 Apr 2024 17:55:55 +0800 Subject: [PATCH 024/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=85=8D=E5=8D=95?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 7 +-- .../cashierservice/entity/TbYhqParams.java | 44 ++----------------- .../cashierservice/entity/vo/IntegralVo.java | 9 ++++ .../cashierservice/task/TaskScheduler.java | 4 +- .../system/cashierservice/util/DateUtils.java | 3 ++ 5 files changed, 19 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 4815f7c..c47df9f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -66,11 +66,12 @@ public class OrderController { return orderService.mineCoupons(userId,status,page,size); } @GetMapping("/findCoupons") - private Result findCoupons(@RequestHeader String token,@RequestParam String type, + private Result findCoupons(@RequestHeader String token,String type, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, @RequestParam(value = "size", required = false, defaultValue = "1") Integer size) throws IOException { return orderService.findCoupons(type,page,size); } + @GetMapping("/findWiningUser") private Result findWiningUser(){ return orderService.findWiningUser(); @@ -87,8 +88,4 @@ public class OrderController { private Result yhqDouble(@RequestParam Integer conponsId){ return orderService.yhqDouble(conponsId); } -// @GetMapping("/testPay") -// private Result testPay(@RequestParam Integer orderId){ -// return orderService.testPay(orderId); -// } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java index 0c6bd92..41e19af 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbYhqParams.java @@ -1,8 +1,11 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.io.Serializable; import java.math.BigDecimal; +@Data public class TbYhqParams implements Serializable { private Integer id; @@ -13,46 +16,5 @@ public class TbYhqParams implements Serializable { private BigDecimal maxPrice; private String status; - private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public BigDecimal getMinPrice() { - return minPrice; - } - - public void setMinPrice(BigDecimal minPrice) { - this.minPrice = minPrice; - } - - public BigDecimal getMaxPrice() { - return maxPrice; - } - - public void setMaxPrice(BigDecimal maxPrice) { - this.maxPrice = maxPrice; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status == null ? null : status.trim(); - } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java index ee02a3c..f03a086 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import com.chaozhanggui.system.cashierservice.config.FieldDescription; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import lombok.Data; @@ -11,9 +12,17 @@ import java.util.List; */ @Data public class IntegralVo { + //openId + @FieldDescription("用户openId") private String openId; + //数量 + @FieldDescription("数量") private BigDecimal num; + //类型 + @FieldDescription("类型") private String type; + //签名 + @FieldDescription("签名") private String sign; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java index 3e12626..9b470ed 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -71,7 +71,7 @@ public class TaskScheduler { } - @Scheduled(fixedRate = 200000) + @Scheduled(cron = "0 1 0 * * ?") public void winningUser() { String day = DateUtils.getDay(); List list = winingParamsMapper.selectAll(); @@ -119,7 +119,7 @@ public class TaskScheduler { } for (int i = 0; i < noUserNum; i++) { long endDate = DateUtils.convertDate1(day + " 00:00:00").getTime(); - long startDate = DateUtils.convertDate1(DateUtils.getTimes(DateUtils.getNewDate(new Date(), 3, -1)) + " 00:00:00").getTime(); + long startDate = DateUtils.convertDate1(DateUtils.getSdfDayTimes(DateUtils.getNewDate(new Date(), 3, -1))+" 00:00:00").getTime(); String orderNo = generateOrderNumber(startDate, endDate); String userName = NicknameGenerator.generateRandomWeChatNickname(); BigDecimal orderAmount = RandomUtil.getRandomBigDecimal(winingParams.getMinPrice(), winingParams.getMaxPrice()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java index 41df0e8..de1dafe 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -59,6 +59,9 @@ public class DateUtils { public static String getTimes(Date date){ return sdfday.format(date); } + public static String getSdfDayTimes(Date date){ + return sdfDay.format(date); + } /** From ff26b0d4ba68775a7c262a63252fd183716c8c6a Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Wed, 24 Apr 2024 17:58:25 +0800 Subject: [PATCH 025/134] =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/entity/vo/IntegralVo.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java index f03a086..c26ab36 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/IntegralVo.java @@ -1,11 +1,8 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.config.FieldDescription; -import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import lombok.Data; import java.math.BigDecimal; -import java.util.List; /** * @author lyf @@ -13,16 +10,12 @@ import java.util.List; @Data public class IntegralVo { //openId - @FieldDescription("用户openId") private String openId; //数量 - @FieldDescription("数量") private BigDecimal num; //类型 - @FieldDescription("类型") private String type; //签名 - @FieldDescription("签名") private String sign; } From d86506da76fd1d067c7692cfa5d806ad96f80f27 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 25 Apr 2024 09:34:06 +0800 Subject: [PATCH 026/134] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=20=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83-=E8=8F=9C=E5=8D=95=E9=A1=B5=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3=20=E9=A2=84=E7=BA=A6?= =?UTF-8?q?=E5=88=B0=E5=BA=97(=E5=BA=97=E9=93=BA=E5=88=97=E8=A1=A8)=20?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E7=99=BB=E5=BD=95=20=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=20?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85(=E7=BC=BA=E5=B0=91?= =?UTF-8?q?=E8=AF=84=E4=BB=B7=E9=83=A8=E5=88=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 23 +- ...eController.java => CommonController.java} | 26 +- .../controller/HomeController.java | 9 +- .../controller/HomeDistrictController.java | 45 + .../controller/LoginContoller.java | 83 +- .../controller/ProductController.java | 4 +- .../dao/SysDictDetailMapper.java | 5 +- .../dao/TbCouponCategoryMapper.java | 20 + .../dao/TbMerchantCouponMapper.java | 64 +- .../dao/TbPurchaseNoticeMapper.java | 2 +- .../cashierservice/dao/TbShopInfoMapper.java | 8 +- .../cashierservice/dao/TbUserInfoMapper.java | 8 - .../entity/TbCouponCategory.java | 71 + .../entity/TbMerchantCoupon.java | 8 + .../entity/dto/HomeBaseDto.java | 34 + .../cashierservice/entity/dto/HomeDto.java | 26 +- .../entity/vo/CommonListVo.java | 23 + .../entity/vo/CommonPageVo.java | 10 + .../cashierservice/entity/vo/CommonVo.java | 24 + .../entity/vo/ProductInfoVo.java | 6 + .../cashierservice/entity/vo/SubShopVo.java | 39 + .../service/HomeDistrictService.java | 141 ++ .../service/HomePageService.java | 116 +- .../cashierservice/service/LoginService.java | 217 +-- .../service/ProductService.java | 147 +- .../resources/mapper/SysDictDetailMapper.xml | 15 +- .../mapper/TbCouponCategoryMapper.xml | 26 + .../mapper/TbMerchantCouponMapper.xml | 404 +---- .../mapper/TbPurchaseNoticeMapper.xml | 4 +- .../resources/mapper/TbShopInfoMapper.xml | 1320 +++++++++-------- .../resources/mapper/TbUserInfoMapper.xml | 2 +- 31 files changed, 1473 insertions(+), 1457 deletions(-) rename src/main/java/com/chaozhanggui/system/cashierservice/controller/{PhoneValidateCodeController.java => CommonController.java} (67%) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeDistrictController.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponCategoryMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponCategory.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonListVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonPageVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/SubShopVo.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java create mode 100644 src/main/resources/mapper/TbCouponCategoryMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index ad78a3c..e1436e5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -34,13 +34,16 @@ public class LoginFilter implements Filter { */ private static final List NOT_LOGIN_URL = Arrays.asList( // 忽略静态资源 - "css/**", - "js/**", - "cashierService/phoneValidateCode",//验证码 - "cashierService/location/**",//高德 获取行政区域 - "cashierService/home/homePageUp",//首页上半 - "cashierService/home",//首页 - "cashierService/login/**"//登录部分接口不校验 +// "css/**", +// "js/**", +// "cashierService/phoneValidateCode",//验证码 +// "cashierService/tbPlatformDict",//获取菜单 +// "cashierService/location/**",//高德 获取行政区域 +// "cashierService/home/homePageUp",//首页上半 +// "cashierService/home",//首页 +// "cashierService/distirict/subShopList",//首页 +// "cashierService/product/productInfo",//商品详情 +// "cashierService/login/**"//登录部分接口不校验 ); @Autowired @@ -62,8 +65,9 @@ public class LoginFilter implements Filter { } // 获取请求地址 String url = request.getRequestURI(); + // 不需要授权的接口直接访问的地址 - if (containsUrl(NOT_LOGIN_URL, url)) { + if (!containsUrl(NOT_LOGIN_URL, url)) { chain.doFilter(req, resp); return; } @@ -130,6 +134,9 @@ public class LoginFilter implements Filter { return true; } } else { + if (url.equals(s)) { + return true; + } if (url.equals("/" + s)) { return true; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PhoneValidateCodeController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java similarity index 67% rename from src/main/java/com/chaozhanggui/system/cashierservice/controller/PhoneValidateCodeController.java rename to src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index b37cd13..397833c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PhoneValidateCodeController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -1,5 +1,7 @@ package com.chaozhanggui.system.cashierservice.controller; +import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; +import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -8,25 +10,26 @@ import com.chaozhanggui.system.cashierservice.util.StringUtil; import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; import java.util.concurrent.TimeUnit; /** + * 通用接口 * @author lyf */ @RestController -@RequestMapping("/phoneValidateCode") +@RequestMapping @RequiredArgsConstructor -public class PhoneValidateCodeController { +public class CommonController { private final ValidateCodeUtil validateCodeUtil; @Resource private RedisUtils redisUtils; + @Resource + private TbPlatformDictMapper platformDictMapper; /** * 一分钟 */ @@ -37,7 +40,7 @@ public class PhoneValidateCodeController { * @param phone * @return */ - @GetMapping + @GetMapping("/phoneValidateCode") public Result verifyPhoneIsExist(@RequestParam String phone) { if (StringUtils.isBlank(phone)) { return Result.fail("手机号不可为空!"); @@ -52,4 +55,13 @@ public class PhoneValidateCodeController { } return Result.success(CodeEnum.SUCCESS); } + + /** + * 获取菜单 + */ + @GetMapping("/tbPlatformDict") + public Result getPlatformDict(@RequestParam String type, @RequestHeader String environment) { + List carouselList = platformDictMapper.queryAllByType(type, environment); + return Result.success(CodeEnum.SUCCESS,carouselList); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeController.java index 0a26bbe..605eee5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeController.java @@ -20,12 +20,13 @@ public class HomeController { @Resource private HomePageService homePageService; - @PostMapping - public Result homePage(@RequestBody HomeDto homeDto,@RequestHeader("environment") String environmen)throws Exception{ - return homePageService.homePage(homeDto, environmen); - } @PostMapping("/homePageUp") public Result homePageUp(@RequestHeader("environment") String environment){ return homePageService.homePageUp(environment); } + + @PostMapping + public Result homePage(@RequestBody HomeDto homeDto,@RequestHeader("environment") String environmen)throws Exception{ + return homePageService.proList(homeDto, environmen); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeDistrictController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeDistrictController.java new file mode 100644 index 0000000..287fc07 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/HomeDistrictController.java @@ -0,0 +1,45 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.dto.HomeBaseDto; +import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; +import com.chaozhanggui.system.cashierservice.service.HomeDistrictService; +import com.chaozhanggui.system.cashierservice.sign.Result; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import java.util.concurrent.ExecutionException; + +/** + * 首页其它接口 + */ +@RestController +@RequestMapping("/distirict") +@RequiredArgsConstructor +public class HomeDistrictController { + + @Resource + private HomeDistrictService districtService; + + /** + * 预约到店(店铺列表) + */ + @RequestMapping("/subShopList") + public Result subShopList(HomeBaseDto param,@RequestHeader("environment") String environment){ + return districtService.queryShopListByPage(param,environment); + } + + + /** + * 品类 + * + * 今日上新 + * 热榜推荐 + * 咖啡饮品 + */ + @RequestMapping("/productCate") + public Result productCate(HomeDto param, @RequestHeader("environment") String environment) throws ExecutionException, InterruptedException { + return districtService.proList(param,environment); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 2fa566b..7e90758 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -87,7 +87,12 @@ public class LoginContoller { } - + /** + * 小程序登录 + * @param request + * @param map + * @return + */ @RequestMapping("/wx/custom/login") public Result wxCustomLogin(HttpServletRequest request, @RequestBody Map map // , @@ -102,15 +107,15 @@ public class LoginContoller { String code = map.get("code").toString(); - String qrCode = map.get("qrCode"); +// String qrCode = map.get("qrCode"); String rawData = map.get("rawData"); String signature = map.get("signature"); - String encryptedData = map.get("encryptedData"); - - String ivStr = map.get("iv"); +// String encryptedData = map.get("encryptedData"); +// +// String ivStr = map.get("iv"); String phone = map.get("phone"); @@ -134,7 +139,8 @@ public class LoginContoller { String avatarUrl = rawDataJson.getString("avatarUrl"); try { - return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone, qrCode, IpUtil.getIpAddr(request)); +// return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone, qrCode, IpUtil.getIpAddr(request)); + return loginService.wxCustomLogin(openid, avatarUrl, nickName, phone, IpUtil.getIpAddr(request)); } catch (Exception e) { e.printStackTrace(); } @@ -144,6 +150,11 @@ public class LoginContoller { } + /** + * 小程序获取手机号 + * @param map + * @return + */ @RequestMapping("getPhoneNumber") public Result getPhoneNumber(@RequestBody Map map) { @@ -202,27 +213,33 @@ public class LoginContoller { } +// /** +// * 获取会员码 +// * +// * @param openId +// * @param token +// * @param id +// * @return +// */ +// @GetMapping("createCardNo") +// public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id, +// +// @RequestParam("shopId") String shopId +// ) { +// return loginService.createCardNo(id, openId,shopId); +// } + + @GetMapping("/userInfo") + public Result userInfo(@RequestParam("userId") Integer userId) { + return loginService.userInfo(userId); + } + /** - * 获取会员码 - * - * @param openId + * 更新用户信息 * @param token - * @param id + * @param userInfo * @return */ - @GetMapping("createCardNo") - public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id, - - @RequestParam("shopId") String shopId - ) { - return loginService.createCardNo(id, openId,shopId); - } - - @GetMapping("/wx/userInfo") - public Result userInfo(@RequestParam("userId") Integer userId, @RequestParam("shopId") String shopId) { - return loginService.userInfo(userId, shopId); - } - @PostMapping("/upUserInfo") public Result userInfo(@RequestHeader String token, @RequestBody TbUserInfo userInfo) { String userId = TokenUtil.parseParamFromToken(token).getString("userId"); @@ -262,6 +279,7 @@ public class LoginContoller { */ @PostMapping("/app/login") public Result applogin(@RequestBody AuthUserDto authUserDto) { + boolean tf = false; if (ObjectUtil.isNull(authUserDto.getCode())) { if (StringUtils.isBlank(authUserDto.getPassword())) { return Result.fail("请输入密码,或使用验证码登录"); @@ -270,7 +288,7 @@ public class LoginContoller { String mdPasswordString = MD5Utils.MD5Encode(authUserDto.getPassword(), "utf-8"); return loginService.appLogin(authUserDto.getUsername(), mdPasswordString); } else { - boolean tf = loginService.validate(authUserDto.getCode(), authUserDto.getUsername()); + tf = loginService.validate(authUserDto.getCode(), authUserDto.getUsername()); if (tf) { return loginService.appLogin(authUserDto.getUsername(), null); } else { @@ -279,14 +297,21 @@ public class LoginContoller { } } - - //退出登录的接口 + /** + * APP退出登录 + * @header token + * @return + */ @PostMapping("/loginOut") - public Result loginOut(HttpServletRequest request) { - String token = request.getHeader("token"); + public Result loginOut(@RequestHeader String token,@RequestHeader String environment,HttpServletRequest request) { //获取当前登录人的账号 String userId = TokenUtil.parseParamFromToken(token).getString("userId"); - redisUtil.deleteByKey(RedisCst.ONLINE_APP_USER.concat(userId)); + if(environment.equals("wx")){ + String openId = request.getHeader("openId"); + redisUtil.deleteByKey(RedisCst.ONLINE_USER.concat(openId)); + }else if(environment.equals("app")){ + redisUtil.deleteByKey(RedisCst.ONLINE_APP_USER.concat(userId)); + } return Result.success(CodeEnum.SUCCESS); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 2af5a4f..59048e5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -42,8 +42,8 @@ public class ProductController { } @GetMapping("/productInfo") - public Result productInfo(@RequestParam Integer productId) throws Exception { - return productService.productInfo(productId); + public Result productInfo(@RequestParam Integer productId,@RequestHeader String environment) throws Exception { + return productService.productInfo(productId,environment); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java index 61e55c5..54a9b6e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/SysDictDetailMapper.java @@ -11,7 +11,10 @@ import java.util.List; @Component @Mapper public interface SysDictDetailMapper { - List selectByAll(); + + List selectHot(); + + List selectByType(@Param("type") String type); List selectByDictId(@Param("dictId") Long dictId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponCategoryMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponCategoryMapper.java new file mode 100644 index 0000000..abfb9d0 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponCategoryMapper.java @@ -0,0 +1,20 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbCouponCategory; +/** + * 团购卷分类(TbCouponCategory)表数据库访问层 + * + * @author ww + * @since 2024-04-24 14:09:16 + */ +public interface TbCouponCategoryMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbCouponCategory queryById(Integer id); +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java index 76d881b..00c6e70 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantCouponMapper.java @@ -28,67 +28,11 @@ public interface TbMerchantCouponMapper { */ TbMerchantCoupon queryById(Integer id); - /** - * 查询指定行数据 - * - * @param tbMerchantCoupon 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(TbMerchantCoupon tbMerchantCoupon, @Param("pageable") Pageable pageable); - - List queryAllByPage(@Param("pageable")Integer page, @Param("sizeable")Integer size, @Param("rightTopLng") Double rightTopLng, - @Param("rightTopLat")Double rightTopLat, @Param("leftBottomLng")Double leftBottomLng, @Param("leftBottomLat")Double leftBottomLat, - @Param("cities")String cities, @Param("order")String order,@Param("lng")String lng,@Param("lat")String lat); - /** - * 统计总行数 - * - * @param tbMerchantCoupon 查询条件 - * @return 总行数 - */ - long count(TbMerchantCoupon tbMerchantCoupon); - - /** - * 新增数据 - * - * @param tbMerchantCoupon 实例对象 - * @return 影响行数 - */ - int insert(TbMerchantCoupon tbMerchantCoupon); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 批量新增或按主键更新数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 - */ - int insertOrUpdateBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tbMerchantCoupon 实例对象 - * @return 影响行数 - */ - int update(TbMerchantCoupon tbMerchantCoupon); - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 影响行数 - */ - int deleteById(Integer id); + List queryAllByPage(@Param("type") String type, + @Param("rightTopLng") Double rightTopLng, @Param("rightTopLat") Double rightTopLat, + @Param("leftBottomLng") Double leftBottomLng, @Param("leftBottomLat") Double leftBottomLat, + @Param("cities") String cities, @Param("orderBy") String orderBy, @Param("lng") String lng, @Param("lat") String lat); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java index d1fa563..d6bcca5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java @@ -16,7 +16,7 @@ public interface TbPurchaseNoticeMapper { * @param id 主键 * @return 实例对象 */ - TbPurchaseNotice queryById(Integer id); + TbPurchaseNotice queryByCouponId(Integer id); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopInfoMapper.java index 7567a21..eb117e4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopInfoMapper.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; import com.chaozhanggui.system.cashierservice.entity.vo.HomeVO; +import com.chaozhanggui.system.cashierservice.entity.vo.SubShopVo; import com.chaozhanggui.system.cashierservice.entity.vo.UserDutyVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -18,7 +19,12 @@ public interface TbShopInfoMapper { int insertSelective(TbShopInfo record); + List selShopInfoByGps(@Param("rightTopLng") Double rightTopLng, @Param("rightTopLat") Double rightTopLat, + @Param("leftBottomLng") Double leftBottomLng, @Param("leftBottomLat") Double leftBottomLat, + @Param("cities") String cities, @Param("lng") String lng, @Param("lat") String lat); + TbShopInfo selectByPrimaryKey(Integer id); + List selectByIds(@Param("list") List ids); int updateByPrimaryKeySelective(TbShopInfo record); @@ -31,7 +37,7 @@ public interface TbShopInfoMapper { TbShopInfo selectByPhone(String phone); - List selectShopInfo(@Param("page")Integer page, @Param("size")Integer size); + List selectShopInfo(@Param("page") Integer page, @Param("size") Integer size); List searchUserDutyDetail(@Param("list") List productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java index 17c47fe..975d431 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserInfoMapper.java @@ -24,14 +24,6 @@ public interface TbUserInfoMapper { TbUserInfo selectByOpenId(String openId); - /** - * 通过手机号查询 - * @param phone - * @param source 公众号 WECHAT 小程序 WECHAT-APP 手机注册 TELEPHONE 移动端 APP - * @return - */ - TbUserInfo selectUserByPhone(String phone,String source); - /** * 查询来源为APP 未绑定微信用户的 用户数据 * @param phone diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponCategory.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponCategory.java new file mode 100644 index 0000000..3afa452 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponCategory.java @@ -0,0 +1,71 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.util.Date; +import java.io.Serializable; + +/** + * 团购卷分类(TbCouponCategory)实体类 + * + * @author ww + * @since 2024-04-24 14:09:16 + */ +public class TbCouponCategory implements Serializable { + private static final long serialVersionUID = -45350278241700844L; + + private Integer id; + /** + * 分类名称 + */ + private String name; + + private Date createTime; + + private Date updateTime; + /** + * 0:不展示;1:展示; + */ + private Integer status; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java index c71db04..4f5bee0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantCoupon.java @@ -41,6 +41,7 @@ public class TbMerchantCoupon implements Serializable { * 限领数量 */ private String limitNumber; + private String useNumber; /** * 发放数量 */ @@ -135,6 +136,13 @@ public class TbMerchantCoupon implements Serializable { private String merchantId; + public String getUseNumber() { + return useNumber; + } + + public void setUseNumber(String useNumber) { + this.useNumber = useNumber; + } public Integer getId() { return id; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java new file mode 100644 index 0000000..a9296f4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java @@ -0,0 +1,34 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +/** + * 查询通用核心类 + * 经纬度 + * 城市信息 + * 分页数据 + */ +@Data +public class HomeBaseDto { + /** + * 经度 + */ + private String lat; + /** + * 纬度 + */ + private String lng; + /** + * 地址 + */ + private String address; + + private double distanceInKm = 10; + + //是否分页 1分页 + private Integer isPage = 1; + + private Integer page = 1; + + private Integer size = 10; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java index 0602412..27fe03f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java @@ -6,32 +6,18 @@ import lombok.Data; * @author 12847 */ @Data -public class HomeDto { - /** - * 地址 - */ - private String address; - /** - * 经度 - */ - private String lat; - /** - * 纬度 - */ - private String lng; +public class HomeDto extends HomeBaseDto { /** * 品类 */ private String type; /** - * 1.离我最近 2.销量优先 3.价格优先 + * 0.今日上新 + * 1.离我最近 + * 2.销量优先/热榜推荐 + * 3.价格优先 */ - private Integer orderBy; + private Integer orderBy = 0; - private Integer other; - - private Integer page; - - private Integer size; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonListVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonListVo.java new file mode 100644 index 0000000..9956697 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonListVo.java @@ -0,0 +1,23 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CommonListVo extends CommonVo{ + private Map result=new HashMap<>(); + + public Map getResult() { + return result; + } + + public void setResult(List list) { + this.result.put("list",list); + } + + public void setResult(Map result) { + this.result = result; + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonPageVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonPageVo.java new file mode 100644 index 0000000..7d73f88 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonPageVo.java @@ -0,0 +1,10 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import com.github.pagehelper.PageInfo; +import lombok.Data; + + +@Data +public class CommonPageVo extends CommonVo{ + private PageInfo result; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonVo.java new file mode 100644 index 0000000..3a79f4e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CommonVo.java @@ -0,0 +1,24 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.util.List; + +/** + * 顶部图 + * 预约到店 + * 每日上新 + * 热榜推荐 + * 咖啡饮品 + */ +@Data +public class CommonVo { + + private String title; + + private List carousel; + /** + * 菜单列表 不一定有 + */ + private List menu; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java index 394eca8..d1b2bd1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java @@ -40,6 +40,12 @@ public class ProductInfoVo { * 商品名称 */ private String productName; + + /** + * 购买须知标签 + */ + private List noticeTag; + /** * 店铺名称 */ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/SubShopVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/SubShopVo.java new file mode 100644 index 0000000..6a7bbca --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/SubShopVo.java @@ -0,0 +1,39 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +/** + * 预约到店列表页Vo + */ +@Data +public class SubShopVo{ + private Integer id; + /** + * 店铺名称 + */ + private String shopName; + /** + * 连锁店扩展名 + */ + private String chainName; + /** + * Logo图 + */ + private String logo; + /** + * 封面图 + */ + private String coverImg; + /** + * 地址 + */ + private String address; + /** + * 距离 + */ + private String distances ="100"; + + private String lat; + + private String lng; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java new file mode 100644 index 0000000..8d2e39c --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java @@ -0,0 +1,141 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.dao.SysDictDetailMapper; +import com.chaozhanggui.system.cashierservice.dao.TbCouponCategoryMapper; +import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; +import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper; +import com.chaozhanggui.system.cashierservice.entity.SysDict; +import com.chaozhanggui.system.cashierservice.entity.TbCouponCategory; +import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; +import com.chaozhanggui.system.cashierservice.entity.dto.HomeBaseDto; +import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; +import com.chaozhanggui.system.cashierservice.entity.vo.*; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; +import com.chaozhanggui.system.cashierservice.util.LocationUtils; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.RequestHeader; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +@Service +@Slf4j +public class HomeDistrictService { + @Resource + private ProductService productService; + + @Resource + private TbShopInfoMapper shopInfoMapper; + @Resource + private TbPlatformDictMapper platformDictMapper; + @Resource + private TbCouponCategoryMapper couponCategoryMapper; + @Resource + private SysDictDetailMapper sysDictDetailMapper; + + public Result queryShopListByPage(HomeBaseDto param, String environment) { + PageHelper.startPage(param.getPage(), param.getSize()); + List carouselList = platformDictMapper.queryAllByType("subShop", environment); + + Map topAndBottomMap = LocationUtils.returnLLSquarePoint( + Double.parseDouble(param.getLng()), + Double.parseDouble(param.getLat()), + param.getDistanceInKm()); + List subShopVos = shopInfoMapper.selShopInfoByGps( + topAndBottomMap.get("rightTopPoint")[1],//109.06198684730003 + topAndBottomMap.get("rightTopPoint")[0],//34.39724773780949 + topAndBottomMap.get("leftBottomPoint")[1],//108.88884915269998 + topAndBottomMap.get("leftBottomPoint")[0],//34.288450262190516 + param.getAddress(), param.getLng(), param.getLat());//西安市 + for (SubShopVo subShopVo : subShopVos) {//距离计算 + if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) { + double distance = LocationUtils.getDistanceFrom2LngLat( + Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()), + Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat())); + subShopVo.setDistances(Double.toString(distance)); + } + } + + CommonPageVo result = new CommonPageVo(); + PageInfo pageInfo = new PageInfo(); + pageInfo.setList(subShopVos); + result.setResult(pageInfo); + + result.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); + result.setTitle("预约到店"); + return Result.success(CodeEnum.SUCCESS, result); + + } + + /** + * 通用商品页 + */ + public Result proList(HomeDto param, String environment) throws ExecutionException, InterruptedException { + CommonPageVo result = new CommonPageVo(); + // title + 顶部图 + if (StringUtils.isNotBlank(param.getType())) { + TbCouponCategory tbCouponCategory = couponCategoryMapper.queryById(Integer.valueOf(param.getType())); + result.setTitle(tbCouponCategory.getName()); + List carouselList = platformDictMapper.queryAllByType(param.getType(), environment); + if (!CollectionUtils.isEmpty(carouselList)) { + result.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); + } + List sysDicts = sysDictDetailMapper.selectByType(null); + List dicDetailVO = new ArrayList<>(); + for (SysDict sysDictsList : sysDicts) { + DicDetailVO dicDetailVOList = new DicDetailVO(); + dicDetailVOList.setDictName(sysDictsList.getDictName()); + dicDetailVOList.setName(sysDictsList.getName()); + dicDetailVOList.setDescription(sysDictsList.getDescription()); + dicDetailVOList.setDetail(sysDictDetailMapper.selectByDictId(sysDictsList.getDictId())); + dicDetailVOList.setIsChild((sysDictsList.getIsChild() == null || sysDictsList.getIsChild() == 0) ? false : true); + dicDetailVO.add(dicDetailVOList); + } + result.setMenu(dicDetailVO); + } else { + if (param.getOrderBy() != null) { + if (param.getOrderBy() == 0) { + List carouselList = platformDictMapper.queryAllByType("newCoupon", environment); + if (!CollectionUtils.isEmpty(carouselList)) { + result.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); + } + result.setTitle("今日上新"); + } else if (param.getOrderBy() == 2) { + List carouselList = platformDictMapper.queryAllByType("hotCoupon", environment); + if (!CollectionUtils.isEmpty(carouselList)) { + result.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); + } + result.setTitle("热榜推荐"); + List sysDicts = sysDictDetailMapper.selectHot(); + List dicDetailVO = new ArrayList<>(); + for (SysDict sysDictsList : sysDicts) { + DicDetailVO dicDetailVOList = new DicDetailVO(); + dicDetailVOList.setDictName(sysDictsList.getDictName()); + dicDetailVOList.setName(sysDictsList.getName()); + dicDetailVOList.setDescription(sysDictsList.getDescription()); + dicDetailVOList.setIsChild((sysDictsList.getIsChild() == null || sysDictsList.getIsChild() == 0) ? false : true); + dicDetailVO.add(dicDetailVOList); + } + result.setMenu(dicDetailVO); + } + } + } + + List products = productService.products(param); + + PageInfo pageInfo = new PageInfo(); + pageInfo.setList(products); + result.setResult(pageInfo); + return Result.success(CodeEnum.SUCCESS, result); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index b4267bc..7bb00ef 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -32,120 +32,17 @@ import java.util.stream.Collectors; @Service @Slf4j public class HomePageService { - @Resource - private TbShopInfoMapper shopInfoMapper; @Resource private TbProductSkuMapper productSkuMapper; @Resource private TbPlatformDictMapper platformDictMapper; @Resource - private TbMerchantCouponMapper merchantCouponMapper; - @Resource - private TbProductMapper productMapper; - @Resource private SysDictDetailMapper sysDictDetailMapper; @Resource - private TagProductDeptsMapper tagProductDeptsMapper; + private ProductService productService; @Autowired private RedisUtil redisUtil; - - public Result homePage(HomeDto homeDto, String environmen) throws ExecutionException, InterruptedException { - int beginNo; - if (homeDto.getPage() <= 0) { - beginNo = 0; - } else { - beginNo = (homeDto.getPage() - 1) * homeDto.getSize(); - } - //经纬度(附近一km) - Map topAndBottomMap = new HashMap<>(); - List tbMerchantCoupons = new ArrayList<>(); - if (homeDto.getOther() != null && homeDto.getOther() == 1){ - topAndBottomMap = LocationUtils.returnLLSquarePoint(Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), 1); - tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), topAndBottomMap.get("rightTopPoint")[0],topAndBottomMap.get("rightTopPoint")[1], - topAndBottomMap.get("leftBottomPoint")[0],topAndBottomMap.get("leftBottomPoint")[1],homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat()); - }else { - tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), null,null,null,null, - homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat()); - } - - //统计shopId,以及productId - List shopIds = new ArrayList<>(); - List productIds = new ArrayList<>(); - List productIdsInt = new ArrayList<>(); - for (CouAndShopVo coupon : tbMerchantCoupons) { - shopIds.add(coupon.getShopId()); - productIds.add(coupon.getRelationIds()); - productIdsInt.add(Integer.valueOf(coupon.getRelationIds())); - } - CompletableFuture> shopInfo = CompletableFuture.supplyAsync(() -> - shopInfoMapper.selectByIds(shopIds)); - CompletableFuture> product = CompletableFuture.supplyAsync(() -> - productMapper.selectByIds((productIds))); - CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> - productSkuMapper.selectSkus((productIds))); - CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> - tagProductDeptsMapper.queryTagAndProduct(productIdsInt)); - Threads.call(shopInfo,product,productSku,dictPro); - - //组装 - List homeVOList = new ArrayList<>(); - for (CouAndShopVo o : tbMerchantCoupons) { - HomeVO homeVO = new HomeVO(); - homeVO.setId(o.getId()); - for (TbShopInfo tbShopInfo : shopInfo.get()) { - if (o.getShopId().equals(tbShopInfo.getId().toString())) { - homeVO.setShopName(tbShopInfo.getShopName()); - homeVO.setImage(tbShopInfo.getLogo()); - if (StringUtils.isBlank(tbShopInfo.getTag())){ - homeVO.setShopTag(new ArrayList<>()); - }else { - List shopTagIds = Arrays.stream(tbShopInfo.getTag().split(",")) - .map(Integer::parseInt) - .collect(Collectors.toList()); - List tbPlatformDicts = platformDictMapper.queryByIdList(shopTagIds); - homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); - } - - } - } - for (TbProduct tbProduct : product.get()) { - if (o.getRelationIds().equals(tbProduct.getId().toString())) { - homeVO.setProductName(o.getTitle()); - homeVO.setImage(tbProduct.getCoverImg()); - homeVO.setProductId(tbProduct.getId()); - } - } - for (TbProductSku tbProductSku : productSku.get()) { - if (o.getRelationIds().equals(tbProductSku.getProductId())) { - //原价 - if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO)==0){ - homeVO.setOriginPrice(BigDecimal.ZERO); - homeVO.setDiscount(BigDecimal.ZERO); - }else { - homeVO.setOriginPrice(tbProductSku.getSalePrice()); - homeVO.setDiscount(new BigDecimal(o.getAmount()).divide(tbProductSku.getSalePrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN)); - } - //销量 - homeVO.setRealSalesNumber(new BigDecimal(o.getNumber())); - //现价 - homeVO.setSalePrice(new BigDecimal(o.getAmount().toString())); - // 共省金额 - homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice())); - } - } - for (TagProductVO tagProductVO :dictPro.get()) { - if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){ - homeVO.getProTag().add(tagProductVO); - } - } - homeVO.setEndTime(DateUtils.getDayEndLong()); - homeVOList.add(homeVO); - } - - return Result.success(CodeEnum.SUCCESS, homeVOList); - } - public Result homePageUp(String environment) { HomeUpVO homeUpVO = new HomeUpVO(); //轮播图 @@ -156,7 +53,7 @@ public class HomePageService { homeUpVO.setDistrict(JSONUtil.parseListTNewList(districtList, HomeDistrictVo.class)); //菜单 - List sysDicts = sysDictDetailMapper.selectByAll(); + List sysDicts = sysDictDetailMapper.selectByType("home"); List dicDetailVO = new ArrayList<>(); for (SysDict sysDictsList : sysDicts) { DicDetailVO dicDetailVOList = new DicDetailVO(); @@ -200,11 +97,18 @@ public class HomePageService { return Result.success(CodeEnum.SUCCESS, homeUpVO); } + /** + * 商品列表 + */ + public Result proList(HomeDto homeDto, String environmen) throws ExecutionException, InterruptedException { + List products = productService.products(homeDto); + return Result.success(CodeEnum.SUCCESS, products); + } + /** * 小条幅随机数据 * @return */ - private BannerVO bannerVoRandom(){ BannerVO bannerVO = new BannerVO(); List bannerInfoList = new ArrayList<>(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 1adb333..c98c7d5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -11,6 +11,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.MD5Utils; import com.chaozhanggui.system.cashierservice.util.TokenUtil; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -21,6 +22,7 @@ import java.math.BigDecimal; import java.util.*; @Service +@Slf4j public class LoginService { @@ -50,110 +52,58 @@ public class LoginService { @Transactional(rollbackFor = Exception.class) - public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String qrCode, String ip) throws Exception { - + public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String ip) throws Exception { TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId); if (ObjectUtil.isNull(userInfo)) { - userInfo = new TbUserInfo(); - - userInfo.setAmount(BigDecimal.ZERO); - userInfo.setChargeAmount(BigDecimal.ZERO); - userInfo.setLineOfCredit(BigDecimal.ZERO); - userInfo.setConsumeNumber(0); - userInfo.setConsumeAmount(BigDecimal.ZERO); - userInfo.setTotalScore(0); - userInfo.setLockScore(0); - userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : ""); - userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户"); - userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : ""); - userInfo.setMiniAppOpenId(openId); - userInfo.setStatus(Byte.parseByte("1")); - userInfo.setParentType("PERSON"); - userInfo.setIsResource(Byte.parseByte("0")); - userInfo.setIsOnline(Byte.parseByte("0")); - userInfo.setIsVip(Byte.parseByte("0")); - userInfo.setSourcePath("WECHAT-APP"); - userInfo.setIsAttentionMp(Byte.parseByte("0")); - userInfo.setSearchWord("||微信用户"); - userInfo.setLastLogInAt(System.currentTimeMillis()); - userInfo.setCreatedAt(System.currentTimeMillis()); - userInfo.setUpdatedAt(System.currentTimeMillis()); - tbUserInfoMapper.insert(userInfo); - - } else { - userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : ""); - userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户"); - userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : ""); - tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); - } - //app与微信用户 互相关联 - if (ObjectUtil.isNotNull(telephone)) { - TbUserInfo appUser = tbUserInfoMapper.selectByPhone(telephone); - if (appUser != null) { - TbUserInfo wechatUser = tbUserInfoMapper.selectByOpenId(openId); - appUser.setUserId(wechatUser.getId()); - tbUserInfoMapper.updateByPrimaryKey(appUser); - wechatUser.setUserId(appUser.getId()); - tbUserInfoMapper.updateByPrimaryKey(wechatUser); + userInfo = tbUserInfoMapper.selectByPhone(telephone); + if (ObjectUtil.isNull(userInfo)) { + userInfo = new TbUserInfo(); + userInfo.setAmount(BigDecimal.ZERO); + userInfo.setChargeAmount(BigDecimal.ZERO); + userInfo.setLineOfCredit(BigDecimal.ZERO); + userInfo.setConsumeNumber(0); + userInfo.setConsumeAmount(BigDecimal.ZERO); + userInfo.setTotalScore(0); + userInfo.setLockScore(0); + userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : ""); + userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户"); + userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : ""); + userInfo.setMiniAppOpenId(openId); + userInfo.setStatus(Byte.parseByte("1")); + userInfo.setParentType("PERSON"); + userInfo.setIsResource(Byte.parseByte("0")); + userInfo.setIsOnline(Byte.parseByte("0")); + userInfo.setIsVip(Byte.parseByte("0")); + userInfo.setSourcePath("WECHAT-APP"); + userInfo.setIsAttentionMp(Byte.parseByte("0")); + userInfo.setSearchWord("||微信用户"); + userInfo.setLastLogInAt(System.currentTimeMillis()); + userInfo.setCreatedAt(System.currentTimeMillis()); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.insert(userInfo); + } else { + userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); + userInfo.setMiniAppOpenId(openId); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); } } - TbShopInfo tbShopInfo = null; - if (ObjectUtil.isEmpty(qrCode)) { - tbShopInfo = tbShopInfoMapper.selectByPhone(defaultPhone); - - - } else { - tbShopInfo = tbShopInfoMapper.selectByQrCode(qrCode); - } - - - TbShopUser tbShopUser = null; - Map shopMap = new HashMap<>(); - if (ObjectUtil.isNotEmpty(tbShopInfo)) { - tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), tbShopInfo.getId().toString()); - if (ObjectUtil.isEmpty(tbShopUser)) { - tbShopUser = new TbShopUser(); - tbShopUser.setAmount(BigDecimal.ZERO); - tbShopUser.setCreditAmount(BigDecimal.ZERO); - tbShopUser.setConsumeAmount(BigDecimal.ZERO); - tbShopUser.setConsumeNumber(0); - tbShopUser.setLevelConsume(BigDecimal.ZERO); - tbShopUser.setStatus(Byte.parseByte("1")); - tbShopUser.setShopId(tbShopInfo.getId().toString()); - tbShopUser.setUserId(userInfo.getId().toString()); - tbShopUser.setMiniOpenId(openId); - tbShopUser.setIsPwd("1"); - tbShopUser.setCreatedAt(System.currentTimeMillis()); - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.insert(tbShopUser); - }else { - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(tbShopUser); - } - shopMap.put("shopId", tbShopUser.getShopId()); - shopMap.put("name", tbShopInfo.getShopName()); - shopMap.put("amount", BigDecimal.ZERO.toPlainString()); - shopMap.put("levelConsume", BigDecimal.ZERO.toPlainString()); - - } - - //生成token 信息 String token = TokenUtil.generateToken(userInfo.getId(), userInfo.getMiniAppOpenId(), userInfo.getTelephone(), userInfo.getNickName()); - - //存储登录记录 - TbToken tbToken = new TbToken(tbShopInfo.getId(), userInfo.getId(), "wx_lite", token, ip, "1", new Date()); - tbTokenMapper.insert(tbToken); - - Map map = new HashMap<>(); try { map.put("token", token); map.put("userInfo", userInfo); - map.put("shopUser", shopMap); - map.put("shopInfo", tbShopInfo); redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(openId), JSON.toJSONString(map)); + //redis里 获取要关注的公众号信息 + //userInfo 某字段存储关注公众号的标识 +// userInfo.get + //公众号 appid + //展示描述 + //图标 +// map.put("", ); +// log.info("登录结果:"+ JSONUtil.toJSONString(map)); return Result.success(CodeEnum.SUCCESS, map); } catch (Exception e) { e.printStackTrace(); @@ -162,6 +112,14 @@ public class LoginService { return Result.fail("登录失败"); } + /** + * APP注册 + * + * @param phone + * @param password + * @param nickName + * @return + */ public TbUserInfo register(String phone, String password, String nickName) { TbUserInfo userInfo = new TbUserInfo(); @@ -186,19 +144,11 @@ public class LoginService { userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); - if(StringUtils.isNotBlank(password)){ + if (StringUtils.isNotBlank(password)) { userInfo.setPassword(MD5Utils.MD5Encode(password, "UTF-8")); } tbUserInfoMapper.insert(userInfo); - //注册时 app与微信小程序用户关联 - TbUserInfo wechatUser = tbUserInfoMapper.selectUserByPhone(phone, "WECHAT-APP"); TbUserInfo appUser = tbUserInfoMapper.selectByPhone(phone); - if (wechatUser != null) { - appUser.setUserId(wechatUser.getId()); - tbUserInfoMapper.updateByPrimaryKey(appUser); - wechatUser.setUserId(appUser.getId()); - tbUserInfoMapper.updateByPrimaryKey(wechatUser); - } return appUser; } @@ -223,14 +173,28 @@ public class LoginService { @Transactional(rollbackFor = Exception.class) public Result appLogin(String username, String password) { - TbUserInfo userInfo = tbUserInfoMapper.selectUserByPhone(username, "APP"); + TbUserInfo userInfo = tbUserInfoMapper.selectByPhone(username); if (ObjectUtil.isNull(userInfo)) { - //注册 - userInfo=register(username, password, username); + if (StringUtils.isNotBlank(password)) { + return Result.fail("暂未设置密码,请使用验证码登录"); + } + userInfo = register(username, password, username); + }else { + String searchWord = userInfo.getSearchWord(); + if(!searchWord.contains("移动端用户")){ + userInfo.setSearchWord(userInfo.getSearchWord() + "||移动端用户"); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + } } - if (StringUtils.isNotBlank(password) && !password.equalsIgnoreCase(userInfo.getPassword())) { - return Result.fail("密码错误"); + if (StringUtils.isNotBlank(password)) {//未使用验证码 + if (StringUtils.isBlank(userInfo.getPassword())) { + return Result.fail("暂未设置密码,请使用验证码登录"); + } else if (!password.equalsIgnoreCase(userInfo.getPassword())) { + return Result.fail("用户名或密码错误"); + } } + //生成token 信息 String token = null; try { @@ -251,7 +215,7 @@ public class LoginService { return Result.fail("登录失败"); } - public Result createCardNo(String id, String openId,String shopId) { + public Result createCardNo(String id, String openId, String shopId) { if (ObjectUtil.isEmpty(id) || ObjectUtil.isEmpty(openId)) { return Result.fail("head 信息不允许为空"); } @@ -266,59 +230,32 @@ public class LoginService { } - TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId); - if(ObjectUtil.isEmpty(tbShopUser)||tbShopUser==null){ + TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId); + if (ObjectUtil.isEmpty(tbShopUser) || tbShopUser == null) { return Result.fail("用户信息错误"); } String dynamicCode = RandomUtil.randomNumbers(8); - dynamicCode= StringUtils.rightPad(tbShopUser.getId(),6,"0").concat(dynamicCode); + dynamicCode = StringUtils.rightPad(tbShopUser.getId(), 6, "0").concat(dynamicCode); tbShopUser.setDynamicCode(dynamicCode); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); - return Result.success(CodeEnum.SUCCESS, dynamicCode); } - public Result userInfo(Integer userId, String shopId) { + public Result userInfo(Integer userId) { TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(userId); - if (tbUserInfo == null) { return Result.success(CodeEnum.ENCRYPT, new ArrayList()); } - - - TbShopInfo tbShopInfo = null; - if (ObjectUtil.isEmpty(shopId)) { - tbShopInfo = tbShopInfoMapper.selectByPhone(defaultPhone); - } else { - tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); - } - - TbShopUser tbShopUser = null; - Map shopMap = new HashMap<>(); - if (ObjectUtil.isNotEmpty(tbShopInfo)) { - tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(tbUserInfo.getId().toString(), tbShopInfo.getId().toString()); - shopMap.put("shopId", tbShopUser.getShopId()); - shopMap.put("name", tbShopInfo.getShopName()); - shopMap.put("amount", BigDecimal.ZERO.toPlainString()); - shopMap.put("levelConsume", BigDecimal.ZERO.toPlainString()); - } - - Map map = new HashMap<>(); - map.put("userInfo", tbUserInfo); - map.put("shopUser", shopMap); - map.put("shopInfo", tbShopInfo); - - - return Result.success(CodeEnum.ENCRYPT, map); + return Result.success(CodeEnum.ENCRYPT, tbUserInfo); } - public Result upUserInfo(TbUserInfo userInfo){ + public Result upUserInfo(TbUserInfo userInfo) { tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); return Result.success(CodeEnum.SUCCESS); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 53cfa05..f1e57d3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -6,13 +6,16 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; -import com.chaozhanggui.system.cashierservice.entity.vo.ProductInfoVo; -import com.chaozhanggui.system.cashierservice.entity.vo.ProductVo; -import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO; +import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; +import com.chaozhanggui.system.cashierservice.entity.vo.*; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; +import com.chaozhanggui.system.cashierservice.util.LocationUtils; import com.chaozhanggui.system.cashierservice.util.Threads; +import com.github.pagehelper.PageHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -20,14 +23,13 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.math.RoundingMode; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; @Service @Slf4j @@ -135,8 +137,116 @@ public class ProductService { } + /** + * 商品列表 + * 首页底部列表 + * 爆品上新 + * 销量榜 + * 咖啡饮品 + */ + public List products(HomeDto homeDto) throws ExecutionException, InterruptedException { + PageHelper.startPage(homeDto.getPage(), homeDto.getSize()); - public Result productInfo(Integer productId) throws Exception { + //经纬度(附近一km) + Map topAndBottomMap = LocationUtils.returnLLSquarePoint( + Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), homeDto.getDistanceInKm()); + List tbMerchantCoupons = merchantCouponMapper.queryAllByPage( + homeDto.getType(), + topAndBottomMap.get("rightTopPoint")[1], topAndBottomMap.get("rightTopPoint")[0], + topAndBottomMap.get("leftBottomPoint")[1], topAndBottomMap.get("leftBottomPoint")[0], + homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat()); + + + //统计shopId,以及productId + List shopIds = new ArrayList<>(); + List productIds = new ArrayList<>(); + List productIdsInt = new ArrayList<>(); + for (CouAndShopVo coupon : tbMerchantCoupons) { + shopIds.add(coupon.getShopId()); + productIds.add(coupon.getRelationIds()); + productIdsInt.add(Integer.valueOf(coupon.getRelationIds())); + } + CompletableFuture> shopInfo = CompletableFuture.supplyAsync(() -> + tbShopInfoMapper.selectByIds(shopIds)); + CompletableFuture> product = CompletableFuture.supplyAsync(() -> + tbProductMapper.selectByIds((productIds))); + CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> + tbProductSkuMapper.selectSkus((productIds))); + CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> + tagProductDeptsMapper.queryTagAndProduct(productIdsInt)); + Threads.call(shopInfo, product, productSku, dictPro); + + //组装 + List homeVOList = new ArrayList<>(); + for (CouAndShopVo o : tbMerchantCoupons) { + HomeVO homeVO = new HomeVO(); + homeVO.setId(o.getId()); + for (TbShopInfo tbShopInfo : shopInfo.get()) { + if (o.getShopId().equals(tbShopInfo.getId().toString())) { + homeVO.setShopName(tbShopInfo.getShopName()); + homeVO.setImage(tbShopInfo.getLogo()); + if (StringUtils.isBlank(tbShopInfo.getTag())) { + homeVO.setShopTag(new ArrayList<>()); + } else { + List shopTagIds = Arrays.stream(tbShopInfo.getTag().split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + List tbPlatformDicts = platformDictMapper.queryByIdList(shopTagIds); + homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); + } + if (StringUtils.isNotBlank(tbShopInfo.getLat()) && StringUtils.isNotBlank(tbShopInfo.getLng())) { + double distance = LocationUtils.getDistanceFrom2LngLat( + Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), + Double.parseDouble(tbShopInfo.getLng()), Double.parseDouble(tbShopInfo.getLat())); + homeVO.setDistances(Double.toString(distance)); + } + + } + } + for (TbProduct tbProduct : product.get()) { + if (o.getRelationIds().equals(tbProduct.getId().toString())) { + homeVO.setProductName(o.getTitle()); + homeVO.setImage(tbProduct.getCoverImg()); + homeVO.setProductId(tbProduct.getId()); + } + } + for (TbProductSku tbProductSku : productSku.get()) { + if (o.getRelationIds().equals(tbProductSku.getProductId())) { + //原价 + if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO) == 0) { + homeVO.setOriginPrice(BigDecimal.ZERO); + homeVO.setDiscount(BigDecimal.ZERO); + } else { + homeVO.setOriginPrice(tbProductSku.getSalePrice()); + homeVO.setDiscount(new BigDecimal(o.getAmount()).divide(tbProductSku.getSalePrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN)); + } + //销量 + homeVO.setRealSalesNumber(new BigDecimal(o.getNumber())); + //现价 + homeVO.setSalePrice(new BigDecimal(o.getAmount().toString())); + // 共省金额 + homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice())); + } + } + for (TagProductVO tagProductVO : dictPro.get()) { + if (o.getRelationIds().equals(tagProductVO.getProductId().toString())) { + homeVO.getProTag().add(tagProductVO); + } + } + homeVO.setEndTime(DateUtils.getDayEndLong()); + homeVOList.add(homeVO); + } + return homeVOList; + } + + /** + * 团购卷详情 + * + * @param productId 团购卷Id + * @return + * @throws Exception + */ + public Result productInfo(Integer productId,String environment) throws Exception { TbMerchantCoupon tbMerchantCoupon = merchantCouponMapper.queryById(productId); CompletableFuture shopInfo = CompletableFuture.supplyAsync(() -> @@ -148,7 +258,7 @@ public class ProductService { CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> tagProductDeptsMapper.queryTagByProductId(tbMerchantCoupon.getRelationIds())); CompletableFuture purchaseNotice = CompletableFuture.supplyAsync(() -> - purchaseNoticeMapper.queryById(tbMerchantCoupon.getId())); + purchaseNoticeMapper.queryByCouponId(tbMerchantCoupon.getId())); Threads.call(shopInfo, product, productSku, dictPro); ProductInfoVo productInfo = new ProductInfoVo(); @@ -195,18 +305,15 @@ public class ProductService { } productVo.getFoods().add(food); productInfo.getProductList().add(productVo); - - productInfo.setPurchaseNotice(purchaseNotice.get()); + TbPurchaseNotice tbPurchaseNotice = purchaseNotice.get(); + productInfo.setPurchaseNotice(tbPurchaseNotice); + List tbPlatformDicts = platformDictMapper.queryAllByType("prodetail", environment); + if(tbPurchaseNotice.getBookingType().startsWith("无需预约")){ + List book = platformDictMapper.queryAllByType("prodetail-book", environment); + tbPlatformDicts.addAll(book); + } + productInfo.setNoticeTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); return Result.success(CodeEnum.SUCCESS, productInfo); } - - private List tagList(String tag) { - if (tag == null) { - return new ArrayList<>(); - } else { - String[] arr = tag.split(","); - return new ArrayList<>(Arrays.asList(arr)); - } - } } diff --git a/src/main/resources/mapper/SysDictDetailMapper.xml b/src/main/resources/mapper/SysDictDetailMapper.xml index 3201417..501bf87 100644 --- a/src/main/resources/mapper/SysDictDetailMapper.xml +++ b/src/main/resources/mapper/SysDictDetailMapper.xml @@ -2,8 +2,19 @@ - + select * + from sys_dict + where type = 'hot' + + + + select + + + from tb_coupon_category + where id = #{id} + + + diff --git a/src/main/resources/mapper/TbMerchantCouponMapper.xml b/src/main/resources/mapper/TbMerchantCouponMapper.xml index 85c3d5d..c6a5100 100644 --- a/src/main/resources/mapper/TbMerchantCouponMapper.xml +++ b/src/main/resources/mapper/TbMerchantCouponMapper.xml @@ -12,6 +12,7 @@ + @@ -42,232 +43,11 @@ - - - - - - - - insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id) - values (#{status}, #{title}, #{templateId}, #{shopId}, #{shopSnap}, #{fromTime}, #{toTime}, #{limitNumber}, #{number}, #{leftNumber}, #{amount}, #{limitAmount}, #{isShow}, #{pic}, #{type}, #{ratio}, #{maxRatioAmount}, #{track}, #{classType}, #{effectType}, #{effectDays}, #{relationIds}, #{relationList}, #{editor}, #{note}, #{createdAt}, #{updatedAt}, #{furnishMeal}, #{furnishExpress}, #{furnishDraw}, #{furnishVir}, #{disableDistribute}, #{merchantId}) - - - - insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id) - values - - (#{entity.status}, #{entity.title}, #{entity.templateId}, #{entity.shopId}, #{entity.shopSnap}, #{entity.fromTime}, #{entity.toTime}, #{entity.limitNumber}, #{entity.number}, #{entity.leftNumber}, #{entity.amount}, #{entity.limitAmount}, #{entity.isShow}, #{entity.pic}, #{entity.type}, #{entity.ratio}, #{entity.maxRatioAmount}, #{entity.track}, #{entity.classType}, #{entity.effectType}, #{entity.effectDays}, #{entity.relationIds}, #{entity.relationList}, #{entity.editor}, #{entity.note}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.furnishMeal}, #{entity.furnishExpress}, #{entity.furnishDraw}, #{entity.furnishVir}, #{entity.disableDistribute}, #{entity.merchantId}) - - - - - insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id) - values - - (#{entity.status}, #{entity.title}, #{entity.templateId}, #{entity.shopId}, #{entity.shopSnap}, #{entity.fromTime}, #{entity.toTime}, #{entity.limitNumber}, #{entity.number}, #{entity.leftNumber}, #{entity.amount}, #{entity.limitAmount}, #{entity.isShow}, #{entity.pic}, #{entity.type}, #{entity.ratio}, #{entity.maxRatioAmount}, #{entity.track}, #{entity.classType}, #{entity.effectType}, #{entity.effectDays}, #{entity.relationIds}, #{entity.relationList}, #{entity.editor}, #{entity.note}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.furnishMeal}, #{entity.furnishExpress}, #{entity.furnishDraw}, #{entity.furnishVir}, #{entity.disableDistribute}, #{entity.merchantId}) - - on duplicate key update - status = values(status), - title = values(title), - template_id = values(template_id), - shop_id = values(shop_id), - shop_snap = values(shop_snap), - from_time = values(from_time), - to_time = values(to_time), - limit_number = values(limit_number), - number = values(number), - left_number = values(left_number), - amount = values(amount), - limit_amount = values(limit_amount), - is_show = values(is_show), - pic = values(pic), - type = values(type), - ratio = values(ratio), - max_ratio_amount = values(max_ratio_amount), - track = values(track), - class_type = values(class_type), - effect_type = values(effect_type), - effect_days = values(effect_days), - relation_ids = values(relation_ids), - relation_list = values(relation_list), - editor = values(editor), - note = values(note), - created_at = values(created_at), - updated_at = values(updated_at), - furnish_meal = values(furnish_meal), - furnish_express = values(furnish_express), - furnish_draw = values(furnish_draw), - furnish_vir = values(furnish_vir), - disable_distribute = values(disable_distribute), - merchant_id = values(merchant_id) - - - - - update tb_merchant_coupon - - - status = #{status}, - - - title = #{title}, - - - template_id = #{templateId}, - - - shop_id = #{shopId}, - - - shop_snap = #{shopSnap}, - - - from_time = #{fromTime}, - - - to_time = #{toTime}, - - - limit_number = #{limitNumber}, - - - number = #{number}, - - - left_number = #{leftNumber}, - - - amount = #{amount}, - - - limit_amount = #{limitAmount}, - - - is_show = #{isShow}, - - - pic = #{pic}, - - - type = #{type}, - - - ratio = #{ratio}, - - - max_ratio_amount = #{maxRatioAmount}, - - - track = #{track}, - - - class_type = #{classType}, - - - effect_type = #{effectType}, - - - effect_days = #{effectDays}, - - - relation_ids = #{relationIds}, - - - relation_list = #{relationList}, - - - editor = #{editor}, - - - note = #{note}, - - - created_at = #{createdAt}, - - - updated_at = #{updatedAt}, - - - furnish_meal = #{furnishMeal}, - - - furnish_express = #{furnishExpress}, - - - furnish_draw = #{furnishDraw}, - - - furnish_vir = #{furnishVir}, - - - disable_distribute = #{disableDistribute}, - - - merchant_id = #{merchantId}, - - - where id = #{id} - - - - - delete from tb_merchant_coupon where id = #{id} - diff --git a/src/main/resources/mapper/TbPurchaseNoticeMapper.xml b/src/main/resources/mapper/TbPurchaseNoticeMapper.xml index f1c18fd..f7d81ac 100644 --- a/src/main/resources/mapper/TbPurchaseNoticeMapper.xml +++ b/src/main/resources/mapper/TbPurchaseNoticeMapper.xml @@ -22,12 +22,12 @@ , coupon_id, date_used, available_time, booking_type, refund_policy, usage_rules, invoice_info, group_pur_info, market_price_Info, discount_Info, platform_tips - select from tb_purchase_notice - where id = #{id} + where coupon_id = #{couponId} diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index bf2b361..41185f0 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -1,662 +1,680 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id, account, shop_code, sub_title, merchant_id, shop_name, chain_name, back_img, + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + , account, shop_code, sub_title, merchant_id, shop_name, chain_name, back_img, front_img, contact_name, phone, logo, is_deposit, is_supply, cover_img, share_img, detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq - - - view - - - - - - - delete from tb_shop_info - where id = #{id,jdbcType=INTEGER} - - - insert into tb_shop_info (id, account, shop_code, - sub_title, merchant_id, shop_name, - chain_name, back_img, front_img, - contact_name, phone, logo, - is_deposit, is_supply, cover_img, - share_img, detail, lat, - lng, mch_id, register_type, - is_wx_ma_independent, address, city, - type, industry, industry_name, - business_time, post_time, post_amount_line, - on_sale, settle_type, settle_time, - enter_at, expire_at, status, - average, order_wait_pay_minute, support_device_number, - distribute_level, created_at, updated_at, - proxy_id, view) - values (#{id,jdbcType=INTEGER}, #{account,jdbcType=VARCHAR}, #{shopCode,jdbcType=VARCHAR}, - #{subTitle,jdbcType=VARCHAR}, #{merchantId,jdbcType=VARCHAR}, #{shopName,jdbcType=VARCHAR}, - #{chainName,jdbcType=VARCHAR}, #{backImg,jdbcType=VARCHAR}, #{frontImg,jdbcType=VARCHAR}, - #{contactName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{logo,jdbcType=VARCHAR}, - #{isDeposit,jdbcType=TINYINT}, #{isSupply,jdbcType=TINYINT}, #{coverImg,jdbcType=VARCHAR}, - #{shareImg,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, #{lat,jdbcType=VARCHAR}, - #{lng,jdbcType=VARCHAR}, #{mchId,jdbcType=VARCHAR}, #{registerType,jdbcType=VARCHAR}, - #{isWxMaIndependent,jdbcType=TINYINT}, #{address,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, - #{type,jdbcType=VARCHAR}, #{industry,jdbcType=VARCHAR}, #{industryName,jdbcType=VARCHAR}, - #{businessTime,jdbcType=VARCHAR}, #{postTime,jdbcType=VARCHAR}, #{postAmountLine,jdbcType=DECIMAL}, - #{onSale,jdbcType=TINYINT}, #{settleType,jdbcType=TINYINT}, #{settleTime,jdbcType=VARCHAR}, - #{enterAt,jdbcType=INTEGER}, #{expireAt,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, - #{average,jdbcType=REAL}, #{orderWaitPayMinute,jdbcType=INTEGER}, #{supportDeviceNumber,jdbcType=INTEGER}, - #{distributeLevel,jdbcType=TINYINT}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, - #{proxyId,jdbcType=VARCHAR}, #{view,jdbcType=LONGVARCHAR}) - - - insert into tb_shop_info - - - id, - - - account, - - - shop_code, - - - sub_title, - - - merchant_id, - - - shop_name, - - - chain_name, - - - back_img, - - - front_img, - - - contact_name, - - - phone, - - - logo, - - - is_deposit, - - - is_supply, - - - cover_img, - - - share_img, - - - detail, - - - lat, - - - lng, - - - mch_id, - - - register_type, - - - is_wx_ma_independent, - - - address, - - - city, - - - type, - - - industry, - - - industry_name, - - - business_time, - - - post_time, - - - post_amount_line, - - - on_sale, - - - settle_type, - - - settle_time, - - - enter_at, - - - expire_at, - - - status, - - - average, - - - order_wait_pay_minute, - - - support_device_number, - - - distribute_level, - - - created_at, - - - updated_at, - - - proxy_id, - - - view, - - - - - #{id,jdbcType=INTEGER}, - - - #{account,jdbcType=VARCHAR}, - - - #{shopCode,jdbcType=VARCHAR}, - - - #{subTitle,jdbcType=VARCHAR}, - - - #{merchantId,jdbcType=VARCHAR}, - - - #{shopName,jdbcType=VARCHAR}, - - - #{chainName,jdbcType=VARCHAR}, - - - #{backImg,jdbcType=VARCHAR}, - - - #{frontImg,jdbcType=VARCHAR}, - - - #{contactName,jdbcType=VARCHAR}, - - - #{phone,jdbcType=VARCHAR}, - - - #{logo,jdbcType=VARCHAR}, - - - #{isDeposit,jdbcType=TINYINT}, - - - #{isSupply,jdbcType=TINYINT}, - - - #{coverImg,jdbcType=VARCHAR}, - - - #{shareImg,jdbcType=VARCHAR}, - - - #{detail,jdbcType=VARCHAR}, - - - #{lat,jdbcType=VARCHAR}, - - - #{lng,jdbcType=VARCHAR}, - - - #{mchId,jdbcType=VARCHAR}, - - - #{registerType,jdbcType=VARCHAR}, - - - #{isWxMaIndependent,jdbcType=TINYINT}, - - - #{address,jdbcType=VARCHAR}, - - - #{city,jdbcType=VARCHAR}, - - - #{type,jdbcType=VARCHAR}, - - - #{industry,jdbcType=VARCHAR}, - - - #{industryName,jdbcType=VARCHAR}, - - - #{businessTime,jdbcType=VARCHAR}, - - - #{postTime,jdbcType=VARCHAR}, - - - #{postAmountLine,jdbcType=DECIMAL}, - - - #{onSale,jdbcType=TINYINT}, - - - #{settleType,jdbcType=TINYINT}, - - - #{settleTime,jdbcType=VARCHAR}, - - - #{enterAt,jdbcType=INTEGER}, - - - #{expireAt,jdbcType=BIGINT}, - - - #{status,jdbcType=TINYINT}, - - - #{average,jdbcType=REAL}, - - - #{orderWaitPayMinute,jdbcType=INTEGER}, - - - #{supportDeviceNumber,jdbcType=INTEGER}, - - - #{distributeLevel,jdbcType=TINYINT}, - - - #{createdAt,jdbcType=BIGINT}, - - - #{updatedAt,jdbcType=BIGINT}, - - - #{proxyId,jdbcType=VARCHAR}, - - - #{view,jdbcType=LONGVARCHAR}, - - - - - update tb_shop_info - - - account = #{account,jdbcType=VARCHAR}, - - - shop_code = #{shopCode,jdbcType=VARCHAR}, - - - sub_title = #{subTitle,jdbcType=VARCHAR}, - - - merchant_id = #{merchantId,jdbcType=VARCHAR}, - - - shop_name = #{shopName,jdbcType=VARCHAR}, - - - chain_name = #{chainName,jdbcType=VARCHAR}, - - - back_img = #{backImg,jdbcType=VARCHAR}, - - - front_img = #{frontImg,jdbcType=VARCHAR}, - - - contact_name = #{contactName,jdbcType=VARCHAR}, - - - phone = #{phone,jdbcType=VARCHAR}, - - - logo = #{logo,jdbcType=VARCHAR}, - - - is_deposit = #{isDeposit,jdbcType=TINYINT}, - - - is_supply = #{isSupply,jdbcType=TINYINT}, - - - cover_img = #{coverImg,jdbcType=VARCHAR}, - - - share_img = #{shareImg,jdbcType=VARCHAR}, - - - detail = #{detail,jdbcType=VARCHAR}, - - - lat = #{lat,jdbcType=VARCHAR}, - - - lng = #{lng,jdbcType=VARCHAR}, - - - mch_id = #{mchId,jdbcType=VARCHAR}, - - - register_type = #{registerType,jdbcType=VARCHAR}, - - - is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, - - - address = #{address,jdbcType=VARCHAR}, - - - city = #{city,jdbcType=VARCHAR}, - - - type = #{type,jdbcType=VARCHAR}, - - - industry = #{industry,jdbcType=VARCHAR}, - - - industry_name = #{industryName,jdbcType=VARCHAR}, - - - business_time = #{businessTime,jdbcType=VARCHAR}, - - - post_time = #{postTime,jdbcType=VARCHAR}, - - - post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, - - - on_sale = #{onSale,jdbcType=TINYINT}, - - - settle_type = #{settleType,jdbcType=TINYINT}, - - - settle_time = #{settleTime,jdbcType=VARCHAR}, - - - enter_at = #{enterAt,jdbcType=INTEGER}, - - - expire_at = #{expireAt,jdbcType=BIGINT}, - - - status = #{status,jdbcType=TINYINT}, - - - average = #{average,jdbcType=REAL}, - - - order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, - - - support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, - - - distribute_level = #{distributeLevel,jdbcType=TINYINT}, - - - created_at = #{createdAt,jdbcType=BIGINT}, - - - updated_at = #{updatedAt,jdbcType=BIGINT}, - - - proxy_id = #{proxyId,jdbcType=VARCHAR}, - - - view = #{view,jdbcType=LONGVARCHAR}, - - - where id = #{id,jdbcType=INTEGER} - - - update tb_shop_info - set account = #{account,jdbcType=VARCHAR}, - shop_code = #{shopCode,jdbcType=VARCHAR}, - sub_title = #{subTitle,jdbcType=VARCHAR}, - merchant_id = #{merchantId,jdbcType=VARCHAR}, - shop_name = #{shopName,jdbcType=VARCHAR}, - chain_name = #{chainName,jdbcType=VARCHAR}, - back_img = #{backImg,jdbcType=VARCHAR}, - front_img = #{frontImg,jdbcType=VARCHAR}, - contact_name = #{contactName,jdbcType=VARCHAR}, - phone = #{phone,jdbcType=VARCHAR}, - logo = #{logo,jdbcType=VARCHAR}, - is_deposit = #{isDeposit,jdbcType=TINYINT}, - is_supply = #{isSupply,jdbcType=TINYINT}, - cover_img = #{coverImg,jdbcType=VARCHAR}, - share_img = #{shareImg,jdbcType=VARCHAR}, - detail = #{detail,jdbcType=VARCHAR}, - lat = #{lat,jdbcType=VARCHAR}, - lng = #{lng,jdbcType=VARCHAR}, - mch_id = #{mchId,jdbcType=VARCHAR}, - register_type = #{registerType,jdbcType=VARCHAR}, - is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, - address = #{address,jdbcType=VARCHAR}, - city = #{city,jdbcType=VARCHAR}, - type = #{type,jdbcType=VARCHAR}, - industry = #{industry,jdbcType=VARCHAR}, - industry_name = #{industryName,jdbcType=VARCHAR}, - business_time = #{businessTime,jdbcType=VARCHAR}, - post_time = #{postTime,jdbcType=VARCHAR}, - post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, - on_sale = #{onSale,jdbcType=TINYINT}, - settle_type = #{settleType,jdbcType=TINYINT}, - settle_time = #{settleTime,jdbcType=VARCHAR}, - enter_at = #{enterAt,jdbcType=INTEGER}, - expire_at = #{expireAt,jdbcType=BIGINT}, - status = #{status,jdbcType=TINYINT}, - average = #{average,jdbcType=REAL}, - order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, - support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, - distribute_level = #{distributeLevel,jdbcType=TINYINT}, - created_at = #{createdAt,jdbcType=BIGINT}, - updated_at = #{updatedAt,jdbcType=BIGINT}, - proxy_id = #{proxyId,jdbcType=VARCHAR}, - view = #{view,jdbcType=LONGVARCHAR} - where id = #{id,jdbcType=INTEGER} - - - update tb_shop_info - set account = #{account,jdbcType=VARCHAR}, - shop_code = #{shopCode,jdbcType=VARCHAR}, - sub_title = #{subTitle,jdbcType=VARCHAR}, - merchant_id = #{merchantId,jdbcType=VARCHAR}, - shop_name = #{shopName,jdbcType=VARCHAR}, - chain_name = #{chainName,jdbcType=VARCHAR}, - back_img = #{backImg,jdbcType=VARCHAR}, - front_img = #{frontImg,jdbcType=VARCHAR}, - contact_name = #{contactName,jdbcType=VARCHAR}, - phone = #{phone,jdbcType=VARCHAR}, - logo = #{logo,jdbcType=VARCHAR}, - is_deposit = #{isDeposit,jdbcType=TINYINT}, - is_supply = #{isSupply,jdbcType=TINYINT}, - cover_img = #{coverImg,jdbcType=VARCHAR}, - share_img = #{shareImg,jdbcType=VARCHAR}, - detail = #{detail,jdbcType=VARCHAR}, - lat = #{lat,jdbcType=VARCHAR}, - lng = #{lng,jdbcType=VARCHAR}, - mch_id = #{mchId,jdbcType=VARCHAR}, - register_type = #{registerType,jdbcType=VARCHAR}, - is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, - address = #{address,jdbcType=VARCHAR}, - city = #{city,jdbcType=VARCHAR}, - type = #{type,jdbcType=VARCHAR}, - industry = #{industry,jdbcType=VARCHAR}, - industry_name = #{industryName,jdbcType=VARCHAR}, - business_time = #{businessTime,jdbcType=VARCHAR}, - post_time = #{postTime,jdbcType=VARCHAR}, - post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, - on_sale = #{onSale,jdbcType=TINYINT}, - settle_type = #{settleType,jdbcType=TINYINT}, - settle_time = #{settleTime,jdbcType=VARCHAR}, - enter_at = #{enterAt,jdbcType=INTEGER}, - expire_at = #{expireAt,jdbcType=BIGINT}, - status = #{status,jdbcType=TINYINT}, - average = #{average,jdbcType=REAL}, - order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, - support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, - distribute_level = #{distributeLevel,jdbcType=TINYINT}, - created_at = #{createdAt,jdbcType=BIGINT}, - updated_at = #{updatedAt,jdbcType=BIGINT}, - proxy_id = #{proxyId,jdbcType=VARCHAR} - where id = #{id,jdbcType=INTEGER} - - - + select + + , + + from tb_shop_info + where id = #{id,jdbcType=INTEGER} - - - - + + + + + + delete + from tb_shop_info + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_info (id, account, shop_code, + sub_title, merchant_id, shop_name, + chain_name, back_img, front_img, + contact_name, phone, logo, + is_deposit, is_supply, cover_img, + share_img, detail, lat, + lng, mch_id, register_type, + is_wx_ma_independent, address, city, + type, industry, industry_name, + business_time, post_time, post_amount_line, + on_sale, settle_type, settle_time, + enter_at, expire_at, status, + average, order_wait_pay_minute, support_device_number, + distribute_level, created_at, updated_at, + proxy_id, view) + values (#{id,jdbcType=INTEGER}, #{account,jdbcType=VARCHAR}, #{shopCode,jdbcType=VARCHAR}, + #{subTitle,jdbcType=VARCHAR}, #{merchantId,jdbcType=VARCHAR}, #{shopName,jdbcType=VARCHAR}, + #{chainName,jdbcType=VARCHAR}, #{backImg,jdbcType=VARCHAR}, #{frontImg,jdbcType=VARCHAR}, + #{contactName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{logo,jdbcType=VARCHAR}, + #{isDeposit,jdbcType=TINYINT}, #{isSupply,jdbcType=TINYINT}, #{coverImg,jdbcType=VARCHAR}, + #{shareImg,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, #{lat,jdbcType=VARCHAR}, + #{lng,jdbcType=VARCHAR}, #{mchId,jdbcType=VARCHAR}, #{registerType,jdbcType=VARCHAR}, + #{isWxMaIndependent,jdbcType=TINYINT}, #{address,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, + #{type,jdbcType=VARCHAR}, #{industry,jdbcType=VARCHAR}, #{industryName,jdbcType=VARCHAR}, + #{businessTime,jdbcType=VARCHAR}, #{postTime,jdbcType=VARCHAR}, #{postAmountLine,jdbcType=DECIMAL}, + #{onSale,jdbcType=TINYINT}, #{settleType,jdbcType=TINYINT}, #{settleTime,jdbcType=VARCHAR}, + #{enterAt,jdbcType=INTEGER}, #{expireAt,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, + #{average,jdbcType=REAL}, #{orderWaitPayMinute,jdbcType=INTEGER}, + #{supportDeviceNumber,jdbcType=INTEGER}, + #{distributeLevel,jdbcType=TINYINT}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, + #{proxyId,jdbcType=VARCHAR}, #{view,jdbcType=LONGVARCHAR}) + + + insert into tb_shop_info + + + id, + + + account, + + + shop_code, + + + sub_title, + + + merchant_id, + + + shop_name, + + + chain_name, + + + back_img, + + + front_img, + + + contact_name, + + + phone, + + + logo, + + + is_deposit, + + + is_supply, + + + cover_img, + + + share_img, + + + detail, + + + lat, + + + lng, + + + mch_id, + + + register_type, + + + is_wx_ma_independent, + + + address, + + + city, + + + type, + + + industry, + + + industry_name, + + + business_time, + + + post_time, + + + post_amount_line, + + + on_sale, + + + settle_type, + + + settle_time, + + + enter_at, + + + expire_at, + + + status, + + + average, + + + order_wait_pay_minute, + + + support_device_number, + + + distribute_level, + + + created_at, + + + updated_at, + + + proxy_id, + + + view, + + + + + #{id,jdbcType=INTEGER}, + + + #{account,jdbcType=VARCHAR}, + + + #{shopCode,jdbcType=VARCHAR}, + + + #{subTitle,jdbcType=VARCHAR}, + + + #{merchantId,jdbcType=VARCHAR}, + + + #{shopName,jdbcType=VARCHAR}, + + + #{chainName,jdbcType=VARCHAR}, + + + #{backImg,jdbcType=VARCHAR}, + + + #{frontImg,jdbcType=VARCHAR}, + + + #{contactName,jdbcType=VARCHAR}, + + + #{phone,jdbcType=VARCHAR}, + + + #{logo,jdbcType=VARCHAR}, + + + #{isDeposit,jdbcType=TINYINT}, + + + #{isSupply,jdbcType=TINYINT}, + + + #{coverImg,jdbcType=VARCHAR}, + + + #{shareImg,jdbcType=VARCHAR}, + + + #{detail,jdbcType=VARCHAR}, + + + #{lat,jdbcType=VARCHAR}, + + + #{lng,jdbcType=VARCHAR}, + + + #{mchId,jdbcType=VARCHAR}, + + + #{registerType,jdbcType=VARCHAR}, + + + #{isWxMaIndependent,jdbcType=TINYINT}, + + + #{address,jdbcType=VARCHAR}, + + + #{city,jdbcType=VARCHAR}, + + + #{type,jdbcType=VARCHAR}, + + + #{industry,jdbcType=VARCHAR}, + + + #{industryName,jdbcType=VARCHAR}, + + + #{businessTime,jdbcType=VARCHAR}, + + + #{postTime,jdbcType=VARCHAR}, + + + #{postAmountLine,jdbcType=DECIMAL}, + + + #{onSale,jdbcType=TINYINT}, + + + #{settleType,jdbcType=TINYINT}, + + + #{settleTime,jdbcType=VARCHAR}, + + + #{enterAt,jdbcType=INTEGER}, + + + #{expireAt,jdbcType=BIGINT}, + + + #{status,jdbcType=TINYINT}, + + + #{average,jdbcType=REAL}, + + + #{orderWaitPayMinute,jdbcType=INTEGER}, + + + #{supportDeviceNumber,jdbcType=INTEGER}, + + + #{distributeLevel,jdbcType=TINYINT}, + + + #{createdAt,jdbcType=BIGINT}, + + + #{updatedAt,jdbcType=BIGINT}, + + + #{proxyId,jdbcType=VARCHAR}, + + + #{view,jdbcType=LONGVARCHAR}, + + + + + update tb_shop_info + + + account = #{account,jdbcType=VARCHAR}, + + + shop_code = #{shopCode,jdbcType=VARCHAR}, + + + sub_title = #{subTitle,jdbcType=VARCHAR}, + + + merchant_id = #{merchantId,jdbcType=VARCHAR}, + + + shop_name = #{shopName,jdbcType=VARCHAR}, + + + chain_name = #{chainName,jdbcType=VARCHAR}, + + + back_img = #{backImg,jdbcType=VARCHAR}, + + + front_img = #{frontImg,jdbcType=VARCHAR}, + + + contact_name = #{contactName,jdbcType=VARCHAR}, + + + phone = #{phone,jdbcType=VARCHAR}, + + + logo = #{logo,jdbcType=VARCHAR}, + + + is_deposit = #{isDeposit,jdbcType=TINYINT}, + + + is_supply = #{isSupply,jdbcType=TINYINT}, + + + cover_img = #{coverImg,jdbcType=VARCHAR}, + + + share_img = #{shareImg,jdbcType=VARCHAR}, + + + detail = #{detail,jdbcType=VARCHAR}, + + + lat = #{lat,jdbcType=VARCHAR}, + + + lng = #{lng,jdbcType=VARCHAR}, + + + mch_id = #{mchId,jdbcType=VARCHAR}, + + + register_type = #{registerType,jdbcType=VARCHAR}, + + + is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, + + + address = #{address,jdbcType=VARCHAR}, + + + city = #{city,jdbcType=VARCHAR}, + + + type = #{type,jdbcType=VARCHAR}, + + + industry = #{industry,jdbcType=VARCHAR}, + + + industry_name = #{industryName,jdbcType=VARCHAR}, + + + business_time = #{businessTime,jdbcType=VARCHAR}, + + + post_time = #{postTime,jdbcType=VARCHAR}, + + + post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, + + + on_sale = #{onSale,jdbcType=TINYINT}, + + + settle_type = #{settleType,jdbcType=TINYINT}, + + + settle_time = #{settleTime,jdbcType=VARCHAR}, + + + enter_at = #{enterAt,jdbcType=INTEGER}, + + + expire_at = #{expireAt,jdbcType=BIGINT}, + + + status = #{status,jdbcType=TINYINT}, + + + average = #{average,jdbcType=REAL}, + + + order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, + + + support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, + + + distribute_level = #{distributeLevel,jdbcType=TINYINT}, + + + created_at = #{createdAt,jdbcType=BIGINT}, + + + updated_at = #{updatedAt,jdbcType=BIGINT}, + + + proxy_id = #{proxyId,jdbcType=VARCHAR}, + + + view = #{view,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_info + set account = #{account,jdbcType=VARCHAR}, + shop_code = #{shopCode,jdbcType=VARCHAR}, + sub_title = #{subTitle,jdbcType=VARCHAR}, + merchant_id = #{merchantId,jdbcType=VARCHAR}, + shop_name = #{shopName,jdbcType=VARCHAR}, + chain_name = #{chainName,jdbcType=VARCHAR}, + back_img = #{backImg,jdbcType=VARCHAR}, + front_img = #{frontImg,jdbcType=VARCHAR}, + contact_name = #{contactName,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, + logo = #{logo,jdbcType=VARCHAR}, + is_deposit = #{isDeposit,jdbcType=TINYINT}, + is_supply = #{isSupply,jdbcType=TINYINT}, + cover_img = #{coverImg,jdbcType=VARCHAR}, + share_img = #{shareImg,jdbcType=VARCHAR}, + detail = #{detail,jdbcType=VARCHAR}, + lat = #{lat,jdbcType=VARCHAR}, + lng = #{lng,jdbcType=VARCHAR}, + mch_id = #{mchId,jdbcType=VARCHAR}, + register_type = #{registerType,jdbcType=VARCHAR}, + is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, + address = #{address,jdbcType=VARCHAR}, + city = #{city,jdbcType=VARCHAR}, + type = #{type,jdbcType=VARCHAR}, + industry = #{industry,jdbcType=VARCHAR}, + industry_name = #{industryName,jdbcType=VARCHAR}, + business_time = #{businessTime,jdbcType=VARCHAR}, + post_time = #{postTime,jdbcType=VARCHAR}, + post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, + on_sale = #{onSale,jdbcType=TINYINT}, + settle_type = #{settleType,jdbcType=TINYINT}, + settle_time = #{settleTime,jdbcType=VARCHAR}, + enter_at = #{enterAt,jdbcType=INTEGER}, + expire_at = #{expireAt,jdbcType=BIGINT}, + status = #{status,jdbcType=TINYINT}, + average = #{average,jdbcType=REAL}, + order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, + support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, + distribute_level = #{distributeLevel,jdbcType=TINYINT}, + created_at = #{createdAt,jdbcType=BIGINT}, + updated_at = #{updatedAt,jdbcType=BIGINT}, + proxy_id = #{proxyId,jdbcType=VARCHAR}, + view = #{view,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_info + set account = #{account,jdbcType=VARCHAR}, + shop_code = #{shopCode,jdbcType=VARCHAR}, + sub_title = #{subTitle,jdbcType=VARCHAR}, + merchant_id = #{merchantId,jdbcType=VARCHAR}, + shop_name = #{shopName,jdbcType=VARCHAR}, + chain_name = #{chainName,jdbcType=VARCHAR}, + back_img = #{backImg,jdbcType=VARCHAR}, + front_img = #{frontImg,jdbcType=VARCHAR}, + contact_name = #{contactName,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, + logo = #{logo,jdbcType=VARCHAR}, + is_deposit = #{isDeposit,jdbcType=TINYINT}, + is_supply = #{isSupply,jdbcType=TINYINT}, + cover_img = #{coverImg,jdbcType=VARCHAR}, + share_img = #{shareImg,jdbcType=VARCHAR}, + detail = #{detail,jdbcType=VARCHAR}, + lat = #{lat,jdbcType=VARCHAR}, + lng = #{lng,jdbcType=VARCHAR}, + mch_id = #{mchId,jdbcType=VARCHAR}, + register_type = #{registerType,jdbcType=VARCHAR}, + is_wx_ma_independent = #{isWxMaIndependent,jdbcType=TINYINT}, + address = #{address,jdbcType=VARCHAR}, + city = #{city,jdbcType=VARCHAR}, + type = #{type,jdbcType=VARCHAR}, + industry = #{industry,jdbcType=VARCHAR}, + industry_name = #{industryName,jdbcType=VARCHAR}, + business_time = #{businessTime,jdbcType=VARCHAR}, + post_time = #{postTime,jdbcType=VARCHAR}, + post_amount_line = #{postAmountLine,jdbcType=DECIMAL}, + on_sale = #{onSale,jdbcType=TINYINT}, + settle_type = #{settleType,jdbcType=TINYINT}, + settle_time = #{settleTime,jdbcType=VARCHAR}, + enter_at = #{enterAt,jdbcType=INTEGER}, + expire_at = #{expireAt,jdbcType=BIGINT}, + status = #{status,jdbcType=TINYINT}, + average = #{average,jdbcType=REAL}, + order_wait_pay_minute = #{orderWaitPayMinute,jdbcType=INTEGER}, + support_device_number = #{supportDeviceNumber,jdbcType=INTEGER}, + distribute_level = #{distributeLevel,jdbcType=TINYINT}, + created_at = #{createdAt,jdbcType=BIGINT}, + updated_at = #{updatedAt,jdbcType=BIGINT}, + proxy_id = #{proxyId,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbUserInfoMapper.xml b/src/main/resources/mapper/TbUserInfoMapper.xml index ad343cb..e04acc4 100644 --- a/src/main/resources/mapper/TbUserInfoMapper.xml +++ b/src/main/resources/mapper/TbUserInfoMapper.xml @@ -598,7 +598,7 @@ + select + + + from tb_group_order_info + where id = #{id} + + + + + + + + + insert into tb_group_order_info(order_no, shop_id, user_id, pro_id, pro_name, pro_img, coupon_no, coupon_url, + exp_date, order_type, order_amount, save_amount, pay_amount, number, status, + remark, phone, pay_time, refund_able, create_time, update_time, pay_order_no, + trade_day, source) + values (#{orderNo}, #{shopId}, #{userId}, #{proId}, #{proName}, #{proImg}, #{couponNo}, #{couponUrl}, + #{expDate}, #{orderType}, #{orderAmount}, #{saveAmount}, #{payAmount}, #{number}, #{status}, #{remark}, + #{phone}, #{payTime}, #{refundAble}, #{createTime}, #{updateTime}, #{payOrderNo}, #{tradeDay}, + #{source}) + + + + insert into tb_group_order_info(order_no, shop_id, user_id, pro_id, pro_name, pro_img, coupon_no, coupon_url, + exp_date, order_type, order_amount, save_amount, pay_amount, number, status, remark, phone, pay_time, + refund_able, create_time, update_time, pay_order_no, trade_day, source) + values + + (#{entity.orderNo}, #{entity.shopId}, #{entity.userId}, #{entity.proId}, #{entity.proName},#{entity.proImg} + #{entity.couponNo}, #{entity.couponUrl}, #{entity.expDate}, #{entity.orderType}, + #{entity.orderAmount}, #{entity.saveAmount}, #{entity.payAmount}, #{entity.number}, #{entity.status}, + #{entity.remark}, #{entity.phone}, #{entity.payTime}, #{entity.refundAble}, #{entity.createTime}, + #{entity.updateTime}, #{entity.payOrderNo}, #{entity.tradeDay}, #{entity.source}) + + + + + + update tb_group_order_info + + + order_no = #{orderNo}, + + + shop_id = #{shopId}, + + + user_id = #{userId}, + + + pro_id = #{proId}, + + + pro_name = #{proName}, + + + pro_img = #{proImg}, + + + coupon_no = #{couponNo}, + + + coupon_url = #{couponUrl}, + + + exp_date = #{expDate}, + + + order_type = #{orderType}, + + + order_amount = #{orderAmount}, + + + save_amount = #{saveAmount}, + + + pay_amount = #{payAmount}, + + + number = #{number}, + + + status = #{status}, + + + remark = #{remark}, + + + phone = #{phone}, + + + pay_time = #{payTime}, + + + refund_able = #{refundAble}, + + + create_time = #{createTime}, + + + update_time = #{updateTime}, + + + pay_order_no = #{payOrderNo}, + + + trade_day = #{tradeDay}, + + + source = #{source}, + + + where id = #{id} + + + + + delete + from tb_group_order_info + where id = #{id} + + + + diff --git a/src/main/resources/mapper/TbMerchantCouponMapper.xml b/src/main/resources/mapper/TbMerchantCouponMapper.xml index c6a5100..37ceb45 100644 --- a/src/main/resources/mapper/TbMerchantCouponMapper.xml +++ b/src/main/resources/mapper/TbMerchantCouponMapper.xml @@ -48,49 +48,6 @@ where id = #{id} - diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 3940301..d405e1d 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -62,6 +62,7 @@ + @@ -80,7 +81,7 @@ created_at, updated_at, base_sales_number, real_sales_number, sales_number, thumb_count, store_count, furnish_meal, furnish_express, furnish_draw, furnish_vir, is_combo, is_show_cash, is_show_mall, is_need_examine, show_on_mall_status, show_on_mall_time, - show_on_mall_error_msg, enable_label, tax_config_id, spec_table_headers + show_on_mall_error_msg, enable_label, tax_config_id, spec_table_headers,group_category_id images, video, notice, group_snap, spec_info, select_spec @@ -933,4 +934,48 @@ #{item} + + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 44b1a0d..2d03903 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -391,15 +391,17 @@ + select + + + from tb_purchase_notice + where id = #{id} + + - - select * - from sys_dict - where type = 'hot' - - - - - - \ No newline at end of file diff --git a/src/main/resources/mapper/SysDictMapper.xml b/src/main/resources/mapper/SysDictMapper.xml index f1d271e..a83fcee 100644 --- a/src/main/resources/mapper/SysDictMapper.xml +++ b/src/main/resources/mapper/SysDictMapper.xml @@ -1,117 +1,48 @@ - - - - - - - - - - - dict_id, name, description, create_by, update_by, create_time, update_time - - - - delete from sys_dict - where dict_id = #{dictId,jdbcType=BIGINT} - - - insert into sys_dict (dict_id, name, description, - create_by, update_by, create_time, - update_time) - values (#{dictId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, - #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, - #{updateTime,jdbcType=TIMESTAMP}) - - - insert into sys_dict - - - dict_id, - - - name, - - - description, - - - create_by, - - - update_by, - - - create_time, - - - update_time, - - - - - #{dictId,jdbcType=BIGINT}, - - - #{name,jdbcType=VARCHAR}, - - - #{description,jdbcType=VARCHAR}, - - - #{createBy,jdbcType=VARCHAR}, - - - #{updateBy,jdbcType=VARCHAR}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - #{updateTime,jdbcType=TIMESTAMP}, - - - - - update sys_dict - - - name = #{name,jdbcType=VARCHAR}, - - - description = #{description,jdbcType=VARCHAR}, - - - create_by = #{createBy,jdbcType=VARCHAR}, - - - update_by = #{updateBy,jdbcType=VARCHAR}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - update_time = #{updateTime,jdbcType=TIMESTAMP}, - - - where dict_id = #{dictId,jdbcType=BIGINT} - - - update sys_dict - set name = #{name,jdbcType=VARCHAR}, - description = #{description,jdbcType=VARCHAR}, - create_by = #{createBy,jdbcType=VARCHAR}, - update_by = #{updateBy,jdbcType=VARCHAR}, - create_time = #{createTime,jdbcType=TIMESTAMP}, - update_time = #{updateTime,jdbcType=TIMESTAMP} - where dict_id = #{dictId,jdbcType=BIGINT} - + + + + + + + + + dict_id + , dict_name , name, value, is_child + + + dict_id + , dict_name , name, value + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbGroupOrderCouponMapper.xml b/src/main/resources/mapper/TbGroupOrderCouponMapper.xml new file mode 100644 index 0000000..cd8a5c6 --- /dev/null +++ b/src/main/resources/mapper/TbGroupOrderCouponMapper.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + id + , order_id, coupon_no, is_refund, refund_amount, refund_reason, refund_desc + + + + + + + + + + + + + + + + insert into tb_group_order_coupon(order_id, coupon_no, is_refund, refund_amount, refund_reason, refund_desc) + values (#{orderId}, #{couponNo}, #{isRefund}, #{refundAmount}, #{refundReason}, #{refundDesc}) + + + + insert into tb_group_order_coupon(order_id, coupon_no, is_refund, refund_amount, refund_reason, refund_desc) + values + + (#{entity.orderId}, #{entity.couponNo}, #{entity.isRefund}, #{entity.refundAmount}, #{entity.refundReason}, + #{entity.refundDesc}) + + + + + + update tb_group_order_coupon + + + order_id = #{orderId}, + + + coupon_no = #{couponNo}, + + + is_refund = #{isRefund}, + + + refund_amount = #{refundAmount}, + + + refund_reason = #{refundReason}, + + + refund_desc = #{refundDesc}, + + + where id = #{id} + + + + + delete + from tb_group_order_coupon + where id = #{id} + + + + diff --git a/src/main/resources/mapper/TbGroupOrderInfoMapper.xml b/src/main/resources/mapper/TbGroupOrderInfoMapper.xml index cb4c794..3574fe0 100644 --- a/src/main/resources/mapper/TbGroupOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbGroupOrderInfoMapper.xml @@ -5,18 +5,20 @@ + - - - + + + + @@ -24,18 +26,20 @@ + + id - , order_no, shop_id, user_id, pro_id, pro_name,pro_img, coupon_no, coupon_url, exp_date, order_type, order_amount, save_amount, pay_amount, number, status, remark, phone, pay_time, refund_able, create_time, update_time, pay_order_no, trade_day, source + , order_no, merchant_id, shop_id, user_id, pro_id, pro_img, pro_name, exp_date, order_type, pay_type, order_amount, save_amount, pay_amount, refund_amount, refund_number, number, status, remark, phone, pay_time, refund_able, create_time, verifier, update_time, pay_order_no, trade_day, source id - , order_no, pro_name,pro_img,coupon_url,order_amount, pay_amount, number, status + , order_no, pro_name,pro_img,order_amount, pay_amount, number, status + + - - insert into tb_group_order_info(order_no, shop_id, user_id, pro_id, pro_name, pro_img, coupon_no, coupon_url, - exp_date, order_type, order_amount, save_amount, pay_amount, number, status, + insert into tb_group_order_info(order_no, merchant_id, shop_id, user_id, pro_id, pro_name, pro_img, + exp_date, order_type, pay_type, order_amount, save_amount, pay_amount, number, + refund_number, status, remark, phone, pay_time, refund_able, create_time, update_time, pay_order_no, trade_day, source) - values (#{orderNo}, #{shopId}, #{userId}, #{proId}, #{proName}, #{proImg}, #{couponNo}, #{couponUrl}, - #{expDate}, #{orderType}, #{orderAmount}, #{saveAmount}, #{payAmount}, #{number}, #{status}, #{remark}, + values (#{orderNo}, #{merchantId}, #{shopId}, #{userId}, #{proId}, #{proName}, #{proImg}, + #{expDate}, #{orderType}, #{payType}, #{orderAmount}, #{saveAmount}, #{payAmount}, #{number}, + #{refundNumber}, #{status}, #{remark}, #{phone}, #{payTime}, #{refundAble}, #{createTime}, #{updateTime}, #{payOrderNo}, #{tradeDay}, #{source}) - insert into tb_group_order_info(order_no, shop_id, user_id, pro_id, pro_name, pro_img, coupon_no, coupon_url, - exp_date, order_type, order_amount, save_amount, pay_amount, number, status, remark, phone, pay_time, + insert into tb_group_order_info(order_no,merchant_id, shop_id, user_id, pro_id, pro_name, pro_img, + exp_date, order_type, pay_type, order_amount, save_amount, pay_amount, number, status, remark, phone, pay_time, refund_able, create_time, update_time, pay_order_no, trade_day, source) values - (#{entity.orderNo}, #{entity.shopId}, #{entity.userId}, #{entity.proId}, #{entity.proName},#{entity.proImg} - #{entity.couponNo}, #{entity.couponUrl}, #{entity.expDate}, #{entity.orderType}, - #{entity.orderAmount}, #{entity.saveAmount}, #{entity.payAmount}, #{entity.number}, #{entity.status}, + (#{entity.orderNo},#{entity.merchantId} #{entity.shopId}, #{entity.userId}, #{entity.proId}, + #{entity.proName},#{entity.proImg}, + #{entity.expDate}, #{entity.orderType}, + #{entity.payType}, #{entity.orderAmount}, #{entity.saveAmount}, #{entity.payAmount}, #{entity.number}, + #{entity.status}, #{entity.remark}, #{entity.phone}, #{entity.payTime}, #{entity.refundAble}, #{entity.createTime}, #{entity.updateTime}, #{entity.payOrderNo}, #{entity.tradeDay}, #{entity.source}) @@ -100,6 +115,9 @@ order_no = #{orderNo}, + + merchant_id = #{merchantId}, + shop_id = #{shopId}, @@ -115,18 +133,15 @@ pro_img = #{proImg}, - - coupon_no = #{couponNo}, - - - coupon_url = #{couponUrl}, - exp_date = #{expDate}, order_type = #{orderType}, + + pay_type = #{payType}, + order_amount = #{orderAmount}, @@ -172,13 +187,5 @@ where id = #{id} - - - - delete - from tb_group_order_info - where id = #{id} - - diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index a3f9a9c..ea03dba 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -551,7 +551,6 @@ order by a.id desc - Limit #{page}, #{size} select - id, name, type,font_color,back_color, cover_img, share_img, video, video_cover_img, jump_type, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort + id, name,value, type,font_color,back_color, cover_img, share_img, video, video_cover_img, jump_type, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort from tb_platform_dict where id = #{id} @@ -33,17 +34,18 @@ + + diff --git a/src/main/resources/mapper/TbProductGroupMapper.xml b/src/main/resources/mapper/TbProductGroupMapper.xml index bc1758d..a9bb7b2 100644 --- a/src/main/resources/mapper/TbProductGroupMapper.xml +++ b/src/main/resources/mapper/TbProductGroupMapper.xml @@ -222,4 +222,16 @@ order by g.sort asc + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index d405e1d..428ef66 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -74,7 +74,7 @@ id, category_id, spec_id, source_path, brand_id, merchant_id, shop_id, name, short_title, - type, pack_fee, low_price, low_member_price, unit_id, unit_snap, cover_img, share_img, + type, pack_fee, low_price, low_member_price, unit_id, unit_snap, cover_img, share_img, images, video_cover_img, sort, limit_number, product_score, status, fail_msg, is_recommend, is_hot, is_new, is_on_sale, is_show, type_enum, is_distribute, is_del, is_stock, is_pause_sale, is_free_freight, freight_id, strategy_type, strategy_id, is_vip, is_delete, @@ -882,6 +882,11 @@ spec_table_headers = #{specTableHeaders,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} + + update tb_product + set real_sales_number = real_sales_number + #{number,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + + \ No newline at end of file diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 2d03903..67d4e15 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -396,7 +396,7 @@ pro.cover_img AS image, sku.origin_price AS originPrice, sku.sale_price AS salePrice, - MAX( sku.real_sales_number ) AS realSalesNumber + pro.real_sales_number AS realSalesNumber FROM tb_product pro LEFT JOIN tb_product_sku sku ON pro.id = sku.product_id @@ -415,7 +415,7 @@ pro.cover_img AS image, sku.origin_price AS originPrice, sku.sale_price AS salePrice, - MAX( sku.real_sales_number ) AS realSalesNumber + pro.real_sales_number AS realSalesNumber FROM tb_product pro LEFT JOIN tb_product_sku sku ON pro.id = sku.product_id diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index 41185f0..9ed5468 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -29,6 +29,8 @@ + + @@ -56,7 +58,7 @@ , account, shop_code, sub_title, merchant_id, shop_name, chain_name, back_img, front_img, contact_name, phone, logo, is_deposit, is_supply, cover_img, share_img, detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, - industry, industry_name, business_time, post_time, post_amount_line, on_sale, settle_type, + industry, industry_name, business_start_day,business_end_day,business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq @@ -72,6 +74,13 @@ where id = #{id,jdbcType=INTEGER} + + diff --git a/src/main/resources/mapper/TbShopTableMapper.xml b/src/main/resources/mapper/TbShopTableMapper.xml index c7b6d68..cb4308d 100644 --- a/src/main/resources/mapper/TbShopTableMapper.xml +++ b/src/main/resources/mapper/TbShopTableMapper.xml @@ -35,6 +35,15 @@ from tb_shop_table where qrcode = #{qrcode} + + + \ No newline at end of file From 34e06b6b3fe1564068570f25301aa63066e362e3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 15 May 2024 14:53:06 +0800 Subject: [PATCH 033/134] =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20=E5=88=B0=E5=BA=97=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../cashierservice/auth/LoginFilter.java | 2 +- .../controller/CommonController.java | 13 ++-- .../cashierservice/entity/vo/ProductVo.java | 1 + .../cashierservice/service/FileService.java | 66 +++++++++++++++++++ .../cashierservice/service/OrderService.java | 2 +- .../cashierservice/util/ValidateCodeUtil.java | 8 --- src/main/resources/application.yml | 6 +- 8 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/FileService.java diff --git a/pom.xml b/pom.xml index 8c901e2..4493382 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,11 @@ fastjson 1.2.9 + + com.aliyun.oss + aliyun-sdk-oss + 3.15.1 + org.projectlombok lombok diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index ad3a5e7..3c1e7a4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -42,7 +42,7 @@ public class LoginFilter implements Filter { "cashierService/location/**",//高德 获取行政区域 "cashierService/home/homePageUp",//首页上半 "cashierService/home",//首页 - + "cashierService/common/**",//通用接口 "cashierService/distirict/**",//首页其它接口 "cashierService/login/**",//登录部分接口不校验 "cashierService/notify/**",//登录部分接口不校验 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 036b95d..6f6617a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller; import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.service.FileService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.LocationUtils; @@ -12,15 +13,12 @@ import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.gson.*; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import java.io.IOException; -import java.math.BigDecimal; import java.util.List; import java.util.concurrent.TimeUnit; @@ -39,6 +37,8 @@ public class CommonController { private RedisUtils redisUtils; @Resource private TbPlatformDictMapper platformDictMapper; + @Resource + private FileService fileService; /** * 一分钟 */ @@ -100,4 +100,9 @@ public class CommonController { JsonNode jsonNode = mapper.readTree(gpsInfo); return Result.success(CodeEnum.SUCCESS, jsonNode); } + + @RequestMapping("common/upload") + public Result upload(MultipartFile file) throws Exception { + return new Result(CodeEnum.SUCCESS, fileService.uploadFile(file)); + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java index ce1bbb8..0d6ee0b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java @@ -25,6 +25,7 @@ public class ProductVo { private Integer id; private String name; // 商品名称 private BigDecimal lowPrice; // 售价 + private String groupNum; // 数量 private String unitName; // 单位 /** * 商品标签 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/FileService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/FileService.java new file mode 100644 index 0000000..0d079ae --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/FileService.java @@ -0,0 +1,66 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.common.auth.CredentialsProvider; +import com.aliyun.oss.common.auth.DefaultCredentialProvider; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.PostConstruct; +import java.util.UUID; + +@Service +@Slf4j +public class FileService { + + @Value("${aliyun.keyid}") + private String accessKeyId; + @Value("${aliyun.keysecret}") + private String accessKeySecret; + @Value("${aliyun.oss.endpoint}") + private String endpoint; + @Value("${aliyun.oss.bucketname}") + private String bucketName; + + // 创建阿里云登录凭证 + public CredentialsProvider credentialsProvider; + + @PostConstruct + public void init() { + credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret); + } + + + public String uploadFile(MultipartFile file) throws Exception { + String suffix = FilenameUtils.getExtension(file.getResource().getFilename()); + String path = getPath("upload", suffix); + OSS client = new OSSClientBuilder().build(endpoint, credentialsProvider); + try { + client.putObject(bucketName, path, file.getInputStream()); + client.shutdown(); + } catch (Exception e) { + throw new Exception("上传异常"); + } + + return "https://" + bucketName + "." + endpoint + "/" + path; + } + + public String getPath(String prefix, String suffix) { + //生成uuid + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + //文件路径 + String path = DateUtils.getDays() + "/" + uuid; + + if (StringUtils.isNotBlank(prefix)) { + path = prefix + "/" + path; + } + + return path + "." + suffix; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 63cbc81..f4eeaa5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -229,7 +229,7 @@ public class OrderService { // date.setTotalNumber(number); // } // } - return Result.success(CodeEnum.ENCRYPT, tbOrderInfos); + return Result.success(CodeEnum.ENCRYPT, new PageInfo<>(tbOrderInfos)); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/ValidateCodeUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/ValidateCodeUtil.java index 75189f0..d1b2527 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/ValidateCodeUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/ValidateCodeUtil.java @@ -1,8 +1,5 @@ package com.chaozhanggui.system.cashierservice.util; -import cn.hutool.core.date.DateUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.aliyun.dysmsapi20170525.Client; import com.aliyun.teaopenapi.models.Config; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -10,11 +7,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.awt.image.BufferedImage; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 337ac0e..98cbeb9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -50,4 +50,8 @@ logging: #阿里云相关配置 aliyun: keyid: LTAI5tPdEfYSZcqHbjCrtPRD - keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy \ No newline at end of file + keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy + oss: + bucketname: cashier-oss + endpoint: oss-cn-beijing.aliyuncs.com + From 264867cd11bcd35a8415fffb7fc2c60eba8dc105 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 15 May 2024 14:55:10 +0800 Subject: [PATCH 034/134] =?UTF-8?q?pom=E7=89=88=E6=9C=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4493382..9252fdc 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ com.alibaba fastjson - 1.2.9 + 1.2.83 com.aliyun.oss From 5f88c35dc7abf5aa4e1279013046687795ac6220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 15 May 2024 15:16:17 +0800 Subject: [PATCH 035/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/PayService.java | 855 +++++++----------- .../thirdpay/constants/SignTypeEnum.java | 16 + .../thirdpay/req/MainScanReq.java | 41 + .../thirdpay/req/OrderRefundReq.java | 32 + .../thirdpay/req/OrderReturnQueryReq.java | 18 + .../thirdpay/req/OrderStatusQueryReq.java | 18 + .../thirdpay/req/PublicParam.java | 33 + .../thirdpay/req/WxScanPayReq.java | 49 + .../thirdpay/resp/MainScanResp.java | 47 + .../thirdpay/resp/OderReturnQueyResp.java | 36 + .../thirdpay/resp/OrderReturnResp.java | 33 + .../thirdpay/resp/OrderStatusQueryResp.java | 49 + .../thirdpay/resp/PublicResp.java | 22 + .../thirdpay/resp/WxScanPayResp.java | 51 ++ .../thirdpay/service/ThirdPayService.java | 300 ++++++ src/main/resources/application-hph.yml | 2 + src/main/resources/application.yml | 9 +- 17 files changed, 1091 insertions(+), 520 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 8814ca1..13a5191 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -17,6 +17,10 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.WxScanPayResp; +import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; import com.chaozhanggui.system.cashierservice.util.BeanUtil; import com.chaozhanggui.system.cashierservice.util.MD5Util; import com.chaozhanggui.system.cashierservice.util.N; @@ -101,47 +105,66 @@ public class PayService { @Autowired TbShopUserFlowMapper tbShopUserFlowMapper; - @Resource - private TbGroupOrderInfoMapper tbGroupOrderInfoMapper; + + @Value("${thirdPay.payType}") + private String thirdPayType; + + + @Value("${thirdPay.url}") + private String thirdUrl; + + + + @Value("${thirdPay.callBack}") + private String callBack; + + + @Autowired - private TbProductMapper tbProductMapper; - @Resource - private GroupOrderCouponService orderCouponService; + ThirdPayService thirdPayService; + @Transactional(rollbackFor = Exception.class) - public Result payOrder(String openId, String orderId,String payType, String ip) throws Exception { - TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); + public Result payOrder(String openId,String orderId,String ip) throws Exception { + TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); - if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus())) { + if(!"unpaid".equals(orderInfo.getStatus())&&!"paying".equals(orderInfo.getStatus())){ return Result.fail("订单状态异常,不允许支付"); } - if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) { + if(ObjectUtil.isNull(orderInfo.getMerchantId())||ObjectUtil.isEmpty(orderInfo.getMerchantId())){ return Result.fail("没有对应的商户"); } - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); + List cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"create"); + if(ObjectUtil.isEmpty(cashierCarts)||ObjectUtil.isNull(cashierCarts)){ + return Result.fail("购物车信息不存在"); + } - if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { + StringBuffer body=new StringBuffer(); + for (TbCashierCart cashierCart : cashierCarts) { + body.append(cashierCart.getName()); + } + + + + TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); + + if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ return Result.fail("支付通道不存在"); } - TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId); - if (ObjectUtil.isEmpty(payment) || payment == null) { - payment = new TbOrderPayment(); + TbOrderPayment payment=tbOrderPaymentMapper.selectByOrderId(orderId); + if(ObjectUtil.isEmpty(payment)||payment==null){ + payment=new TbOrderPayment(); payment.setPayTypeId("ysk"); payment.setAmount(orderInfo.getOrderAmount()); payment.setPaidAmount(orderInfo.getPayAmount()); payment.setHasRefundAmount(BigDecimal.ZERO); - if (payType.equals("wechatPay")) { - payment.setPayName("微信支付"); - payment.setPayType("wechatPay"); - } else if (payType.equals("aliPay")) { - payment.setPayName("支付宝支付"); - payment.setPayType("aliPay"); - } + payment.setPayName("微信支付"); + payment.setPayType("wechatPay"); payment.setReceived(payment.getAmount()); payment.setChangeFee(BigDecimal.ZERO); payment.setMemberId(orderInfo.getMemberId()); @@ -149,435 +172,280 @@ public class PayService { payment.setOrderId(orderInfo.getId().toString()); payment.setCreatedAt(System.currentTimeMillis()); tbOrderPaymentMapper.insert(payment); - } else { - if (payType.equals("wechatPay")) { - payment.setPayName("微信支付"); - payment.setPayType("wechatPay"); - } else if (payType.equals("aliPay")) { - payment.setPayName("支付宝支付"); - payment.setPayType("aliPay"); - } + }else { payment.setUpdatedAt(System.currentTimeMillis()); tbOrderPaymentMapper.updateByPrimaryKey(payment); } - PayReq req = new PayReq(); - req.setAppId(thirdApply.getAppId()); - req.setTimestamp(System.currentTimeMillis()); - req.setIp(ip); - req.setMercOrderNo(orderInfo.getOrderNo()); - req.setNotifyUrl(callBackurl); - req.setPayAmt(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString()); - if (payType.equals("wechatPay")) { + if("ysk".equals(thirdPayType)){ + PayReq req=new PayReq(); + + req.setAppId(thirdApply.getAppId()); + req.setTimestamp(System.currentTimeMillis()); + req.setIp(ip); + req.setMercOrderNo(orderInfo.getOrderNo()); + req.setNotifyUrl(callBackurl); + req.setPayAmt(payment.getAmount().setScale(2,BigDecimal.ROUND_DOWN).toPlainString()); req.setPayType("03"); - req.setPayWay("WXZF");//WXZF ZFBZF UNIONPAY - } else if (payType.equals("aliPay")) { - req.setPayWay("ZFBZF"); - } - req.setSubject("扫码点餐"); - req.setUserId(openId); - - Map map = BeanUtil.transBeanMap(req); - req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); - - ResponseEntity response = restTemplate.postForEntity(url.concat("trans/pay"), req, String.class); - if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - if (object.get("code").equals("0")) { - payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString()); - payment.setUpdatedAt(System.currentTimeMillis()); - tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); - orderInfo.setStatus("paying"); - orderInfo.setPayOrderNo(payment.getTradeNumber()); + req.setPayWay("WXZF"); + req.setSubject("扫码点餐"); + req.setUserId(openId); - tbOrderInfoMapper.updateByPrimaryKey(orderInfo); - String key = RedisCst.TABLE_CART.concat(orderInfo.getTableId()).concat("-").concat(orderInfo.getShopId()); - //清除缓存购物车数据 - redisUtil.deleteByKey(key); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", ""); - jsonObject1.put("data", new JSONArray()); - jsonObject1.put("amount", 0); - AppWebSocketServer.AppSendInfo(jsonObject1, key, false); - tbCashierCartMapper.updateStatusByOrderId(orderId.toString(), "final"); - return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); - } else { - return Result.fail(object.getString("msg")); - } - } + Map map= BeanUtil.transBeanMap(req); + req.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); - return Result.fail("失败"); - } - - @Transactional(rollbackFor = Exception.class) - public Result groupOrderPay(String orderId, String payType, String userId, String ip) { - TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.queryById(Integer.valueOf(orderId)); - - if (!"unpaid".equals(orderInfo.getStatus())) { - return Result.fail("订单状态异常,不允许支付"); - } - - TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(orderInfo.getShopId().toString()); - if (tbMerchantAccount == null) { - throw new MsgException("生成订单错误"); - } - - if (ObjectUtil.isNull(tbMerchantAccount.getMerchantId()) || ObjectUtil.isEmpty(tbMerchantAccount.getMerchantId())) { - return Result.fail("没有对应的商户"); - } - - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantAccount.getMerchantId())); - - if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { - return Result.fail("支付通道不存在"); - } - - TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId); - if (ObjectUtil.isEmpty(payment) || payment == null) { - payment = new TbOrderPayment(); - payment.setPayTypeId("ysk"); - payment.setAmount(orderInfo.getOrderAmount()); - payment.setPaidAmount(orderInfo.getPayAmount()); - payment.setHasRefundAmount(BigDecimal.ZERO); - if (payType.equals("wechatPay")) { - payment.setPayName("微信支付"); - payment.setPayType("wechatPay"); - } else if (payType.equals("aliPay")) { - payment.setPayName("支付宝支付"); - payment.setPayType("aliPay"); - } - payment.setReceived(payment.getAmount()); - payment.setChangeFee(BigDecimal.ZERO); -// payment.setMemberId(orderInfo.getMemberId());//会员Id - payment.setShopId(orderInfo.getShopId().toString()); - payment.setOrderId(orderInfo.getId().toString()); - payment.setCreatedAt(System.currentTimeMillis()); - tbOrderPaymentMapper.insert(payment); - } else { - if (payType.equals("wechatPay")) { - payment.setPayName("微信支付"); - payment.setPayType("wechatPay"); - } else if (payType.equals("aliPay")) { - payment.setPayName("支付宝支付"); - payment.setPayType("aliPay"); - } - payment.setUpdatedAt(System.currentTimeMillis()); - tbOrderPaymentMapper.updateByPrimaryKey(payment); - } - - PayReq req = new PayReq(); - - req.setAppId(thirdApply.getAppId()); - req.setTimestamp(System.currentTimeMillis()); - req.setIp(ip); - req.setMercOrderNo(orderInfo.getOrderNo()); - req.setNotifyUrl(callBackGroupurl); - req.setPayAmt(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString()); - if (payType.equals("wechatPay")) { - req.setPayType("03"); - req.setPayWay("WXZF");//WXZF ZFBZF UNIONPAY - } else if (payType.equals("aliPay")) { - req.setPayWay("ZFBZF"); - } - req.setSubject("零点八零:团购卷"); - req.setUserId(userId); + ResponseEntity response= restTemplate.postForEntity(url.concat("trans/pay"),req,String.class); + if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){ + JSONObject object=JSONObject.parseObject(response.getBody()); + if(object.get("code").equals("0")){ + payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString()); + payment.setUpdatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); + orderInfo.setStatus("paying"); + orderInfo.setPayOrderNo(payment.getTradeNumber()); - Map map = BeanUtil.transBeanMap(req); - req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); - - ResponseEntity response = restTemplate.postForEntity(url.concat("trans/pay"), req, String.class); - if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - log.info("团购卷支付响应:{}",object); - if (object.get("code").equals("0")) { - payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString()); - payment.setUpdatedAt(System.currentTimeMillis()); - tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); - orderInfo.setPayType(payType); - orderInfo.setPayOrderNo(payment.getTradeNumber()); - tbGroupOrderInfoMapper.update(orderInfo); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", ""); - jsonObject1.put("data", new JSONArray()); - jsonObject1.put("amount", 0); - tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); - return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); - } else { - return Result.fail(object.getString("msg")); - } - } - - return Result.fail("失败"); - } - - @Transactional(rollbackFor = Exception.class) - public Result returnOrder(ReturnGroupOrderDto param) { - TbGroupOrderInfo groupOrderInfo = tbGroupOrderInfoMapper.queryById(param.getOrderId()); - List tbGroupOrderCoupons = orderCouponService.queryNoRefundByOrderId(param.getOrderId()); - if (param.getNum() > tbGroupOrderCoupons.size()) { - return Result.fail("可退数量不足"); - } - for (int i = 0; i < param.getNum(); i++) { - TbGroupOrderCoupon coupon = tbGroupOrderCoupons.get(i); - coupon.setIsRefund(1); - coupon.setRefundAmount(param.getRefundAmount()); - coupon.setRefundDesc(param.getRefundDesc()); - coupon.setRefundReason(param.getRefundReason()); - orderCouponService.update(coupon); - } - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(groupOrderInfo.getMerchantId()); - MsgException.checkNull(thirdApply, "支付参数配置错误"); - ReturnOrderReq req = new ReturnOrderReq(); - req.setAppId(thirdApply.getAppId()); - req.setTimestamp(System.currentTimeMillis()); - req.setOrderNumber(groupOrderInfo.getPayOrderNo()); - req.setAmount(param.getRefundAmount().toString()); - req.setMercRefundNo(groupOrderInfo.getOrderNo()); - req.setRefundReason("团购卷:退货"); - req.setPayPassword(thirdApply.getPayPassword()); - Map map = BeanUtil.transBean2Map(req); - req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); - log.info("groupOrderReturn req:{}", JSONUtil.toJsonStr(req)); - ResponseEntity response = restTemplate.postForEntity(url.concat("merchantOrder/returnOrder"), req, String.class); - log.info("groupOrderReturn:{}", response.getBody()); - if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - if (!object.get("code").equals("0")) { - MsgException.check(true, "退款渠道调用失败"); - } - } - groupOrderInfo.setRefundNumber(groupOrderInfo.getRefundNumber() + param.getNum()); - groupOrderInfo.setRefundAmount(groupOrderInfo.getRefundAmount().add(param.getRefundAmount())); - if (groupOrderInfo.getNumber() == groupOrderInfo.getRefundNumber()) { - groupOrderInfo.setRefundAble(0); - groupOrderInfo.setStatus("refund"); - } - tbGroupOrderInfoMapper.update(groupOrderInfo); - return Result.success(CodeEnum.SUCCESS); - } - - @Transactional(rollbackFor = Exception.class) - public Result accountPay(String orderId, String userId, String shopId, String pwd) { - if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(pwd)) { - return Result.fail("参数错误"); - } - - TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); - if (ObjectUtil.isEmpty(orderInfo)) { - return Result.fail("订单信息不存在"); - } - - - if (!"unpaid".equals(orderInfo.getStatus())) { - return Result.fail("订单状态异常"); - } - - - int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "deposit"); - if (count < 1) { - return Result.fail("当前店铺未开通储值卡支付"); - } - - TbShopUser user = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); - - if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { - return Result.fail("此用户非会员用户"); - } - - - if ("1".equals(user.getIsPwd())) { - return Result.fail("会员支付密码为初始化密码"); - } - - if (!MD5Util.encrypt(pwd).equals(user.getPwd())) { - return Result.fail("会员支付密码错误"); - } - - if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { - return Result.fail("会员卡余额不足"); - } - - user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); - user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount())); - user.setConsumeNumber(user.getConsumeNumber() + 1); - user.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKeySelective(user); - - - TbShopUserFlow flow = new TbShopUserFlow(); - flow.setShopUserId(Integer.valueOf(user.getId())); - flow.setBizCode("accountPay"); - flow.setBizName("会员储值卡支付"); - flow.setAmount(orderInfo.getOrderAmount()); - flow.setBalance(user.getAmount()); - flow.setCreateTime(new Date()); - tbShopUserFlowMapper.insert(flow); - - - orderInfo.setPayAmount(orderInfo.getOrderAmount()); - orderInfo.setMemberId(userId); - orderInfo.setPayType("deposit"); - orderInfo.setStatus("closed"); - orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo())); - tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); - - - int cartCount = tbCashierCartMapper.updateStatusByOrderId(orderId.toString(), "final"); - - log.info("更新购物车:{}", cartCount); - - //更新子单状态 - tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed"); - - //修改主单状态 - orderInfo.setStatus("closed"); - orderInfo.setPayType("deposit"); - orderInfo.setPayOrderNo(user.getDynamicCode()); - orderInfo.setPayAmount(orderInfo.getOrderAmount()); - tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); - - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("token", 0); - jsonObject.put("type", "wxcreate"); - jsonObject.put("orderId", orderInfo.getId().toString()); - - producer.putOrderCollect(jsonObject.toJSONString()); - - producer.printMechine(orderInfo.getId() + ""); - - return Result.success(CodeEnum.SUCCESS); - } - - - @Transactional(rollbackFor = Exception.class) - public Result modifyOrderStatus(Integer orderId) throws IOException { - TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); - if (ObjectUtil.isEmpty(orderInfo)) { - return Result.fail("订单信息不存在"); - } - - if ("paying".equals(orderInfo.getStatus())) { - TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString()); - if (ObjectUtil.isNotEmpty(payment) && ObjectUtil.isNotEmpty(payment.getTradeNumber())) { - - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); - - if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { - return Result.fail("支付通道不存在"); + tbOrderInfoMapper.updateByPrimaryKey(orderInfo); + String key= RedisCst.TABLE_CART.concat(orderInfo.getTableId()).concat("-").concat(orderInfo.getShopId()); + //清除缓存购物车数据 + redisUtil.deleteByKey(key); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", ""); + jsonObject1.put("data", new JSONArray()); + jsonObject1.put("amount", 0); + AppWebSocketServer.AppSendInfo(jsonObject1,key, false); + tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); + return Result.success(CodeEnum.SUCCESS,object.getJSONObject("data")); + }else { + return Result.fail(object.getString("msg")); } - TradeQueryReq req = new TradeQueryReq(); - req.setAppId(thirdApply.getAppId()); - req.setTimestamp(System.currentTimeMillis()); - req.setOrderNumber(payment.getTradeNumber()); - Map map = BeanUtil.transBeanMap(req); + } + }else { + String reqbody=""; - req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + if(body.length()>15){ + reqbody=body.substring(0,6).concat("....").concat(body.substring(body.length()-6,body.length())).toString(); + }else { + reqbody=body.toString(); + } - ResponseEntity response = restTemplate.postForEntity(url.concat("merchantOrder/tradeQuery"), req, String.class); - if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - - if (object.get("code").equals("0")) { - JSONObject data = object.getJSONObject("data"); - String status = data.getString("status"); - String cartStatus = ""; - switch (status) { - case "0": //交易失败 - break; - case "1": //交易成功 - - //修改数据库中购物车数据 - int cartCount = tbCashierCartMapper.updateStatusByOrderId(orderId.toString(), "final"); - - log.info("更新购物车:{}", cartCount); - - //更新子单状态 - tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed"); - - //修改主单状态 - orderInfo.setStatus("closed"); - orderInfo.setPayType("wx_lite"); - orderInfo.setPayOrderNo(payment.getTradeNumber()); - orderInfo.setPayAmount(orderInfo.getOrderAmount()); - tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"wx212769170d2c6b2a","wx212769170d2c6b2a",openId,ip,orderInfo.getOrderNo(),"S2405103298",callBack,null,thirdApply.getAppToken()); + if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ + if("000000".equals(publicResp.getCode())){ + WxScanPayResp wxScanPayResp= publicResp.getObjData(); + if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + payment.setTradeNumber(wxScanPayResp.getPayOrderId()); + payment.setUpdatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); + orderInfo.setStatus("paying"); + orderInfo.setPayOrderNo(payment.getTradeNumber()); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("token", 0); - jsonObject.put("type", "wxcreate"); - jsonObject.put("orderId", orderInfo.getId().toString()); - - producer.putOrderCollect(jsonObject.toJSONString()); - - - log.info("发送打印数据"); - producer.printMechine(orderInfo.getId() + ""); - log.info("发送赠送购物券"); - JSONObject coupons = new JSONObject(); - coupons.put("type", "buy"); - coupons.put("orderId", orderId); - producer.printCoupons(coupons.toJSONString()); - return Result.success(CodeEnum.SUCCESS, orderId); - case "2": //退款成功 - cartStatus = "refund"; - orderInfo.setStatus("refund"); - break; - case "3": //退款失败 - break; - case "4": //退款中 - cartStatus = "refunding"; - orderInfo.setStatus("refunding"); - break; - } - - tbCashierCartMapper.updateStatusByOrderId(orderId.toString(), cartStatus); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + tbOrderInfoMapper.updateByPrimaryKey(orderInfo); + String key= RedisCst.TABLE_CART.concat(orderInfo.getTableId()).concat("-").concat(orderInfo.getShopId()); + //清除缓存购物车数据 + redisUtil.deleteByKey(key); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", ""); + jsonObject1.put("data", new JSONArray()); + jsonObject1.put("amount", 0); + AppWebSocketServer.AppSendInfo(jsonObject1,key, false); + tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); + return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); + }else{ + return Result.fail(publicResp.getMsg()); } } } } - return Result.success(CodeEnum.SUCCESS, orderId); + + + + return Result.fail("失败"); } + @Transactional(rollbackFor = Exception.class) - public Result memberIn(String openId, String userId, String amount, String shopId, String ip) { - if (ObjectUtil.isEmpty(openId) || ObjectUtil.isEmpty(userId)) { + public Result modifyOrderStatus(Integer orderId) throws IOException { + TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); + if(ObjectUtil.isEmpty(orderInfo)){ + return Result.fail("订单信息不存在"); + } + + if("paying".equals(orderInfo.getStatus())){ + TbOrderPayment payment= tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString()); + if(ObjectUtil.isNotEmpty(payment)&&ObjectUtil.isNotEmpty(payment.getTradeNumber())){ + + TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); + + if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ + return Result.fail("支付通道不存在"); + } + + + + if("ysk".equals(thirdPayType)){ + TradeQueryReq req=new TradeQueryReq(); + req.setAppId(thirdApply.getAppId()); + req.setTimestamp(System.currentTimeMillis()); + req.setOrderNumber(payment.getTradeNumber()); + Map map= BeanUtil.transBeanMap(req); + + req.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); + + ResponseEntity response= restTemplate.postForEntity(url.concat("merchantOrder/tradeQuery"),req,String.class); + if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){ + JSONObject object=JSONObject.parseObject(response.getBody()); + + if(object.get("code").equals("0")){ + JSONObject data=object.getJSONObject("data"); + String status=data.getString("status"); + String cartStatus=""; + switch (status){ + case "0": //交易失败 + break; + case "1": //交易成功 + + //修改数据库中购物车数据 + int cartCount= tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); + + log.info("更新购物车:{}",cartCount); + + //更新子单状态 + tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId),"closed"); + + //修改主单状态 + orderInfo.setStatus("closed"); + orderInfo.setPayType("wx_lite"); + orderInfo.setPayOrderNo(payment.getTradeNumber()); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + + + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderInfo.getId().toString()); + + producer.putOrderCollect(jsonObject.toJSONString()); + + + + log.info("发送打印数据"); + producer.printMechine(orderInfo.getId() + ""); + + return Result.success(CodeEnum.SUCCESS,orderId); + case "2": //退款成功 + cartStatus="refund"; + orderInfo.setStatus("refund"); + break; + case "3": //退款失败 + break; + case "4": //退款中 + cartStatus="refunding"; + orderInfo.setStatus("refunding"); + break; + } + + tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),cartStatus); + orderInfo.setUpdatedAt(System.currentTimeMillis()); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + } + } + }else { + PublicResp publicResp=thirdPayService.queryOrder(thirdUrl,thirdApply.getAppId(),orderInfo.getOrderNo(),null,thirdApply.getAppToken()); + if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ + if("000000".equals(publicResp.getCode())){ + String cartStatus=""; + switch (publicResp.getObjData().getState()){ + case "TRADE_SUCCESS": + //修改数据库中购物车数据 + int cartCount= tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); + + log.info("更新购物车:{}",cartCount); + + //更新子单状态 + tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId),"closed"); + + //修改主单状态 + orderInfo.setStatus("closed"); + orderInfo.setPayType("wx_lite"); + orderInfo.setPayOrderNo(payment.getTradeNumber()); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + + + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderInfo.getId().toString()); + + producer.putOrderCollect(jsonObject.toJSONString()); + + + + log.info("发送打印数据"); + producer.printMechine(orderInfo.getId() + ""); + + return Result.success(CodeEnum.SUCCESS,orderId); + case "REFUND_ING": + cartStatus="refunding"; + orderInfo.setStatus("refunding"); + break; + } + } + } + } + + } + } + return Result.success(CodeEnum.SUCCESS,orderId); + } + + + + + @Transactional(rollbackFor = Exception.class) + public Result memberIn(String openId,String userId,String amount,String shopId,String ip){ + if(ObjectUtil.isEmpty(openId)||ObjectUtil.isEmpty(userId)){ return Result.fail("用户信息允许为空"); } - TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); - if (ObjectUtil.isEmpty(tbShopUser)) { + TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userId,shopId); + if(ObjectUtil.isEmpty(tbShopUser)){ return Result.fail("对应的用户信息不存在"); } + if(ObjectUtil.isEmpty(tbShopUser.getIsVip())||!"1".equals(tbShopUser.getIsVip().toString())){ + return Result.fail("非会员用户不允许充值"); + } - TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); - if (ObjectUtil.isEmpty(shopInfo)) { + + TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); + if(ObjectUtil.isEmpty(shopInfo)){ return Result.fail("对应的店铺信息不存在"); } - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); - if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { + + TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); + if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ return Result.fail("支付通道不存在"); } - BigDecimal payAmount = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal payAmount= new BigDecimal(amount).setScale(2,BigDecimal.ROUND_DOWN); - TbMemberIn memberIn = new TbMemberIn(); + TbMemberIn memberIn=new TbMemberIn(); memberIn.setAmount(payAmount); memberIn.setUserId(Integer.valueOf(tbShopUser.getUserId())); - memberIn.setCode(tbShopUser.getDynamicCode()); + memberIn.setCode(tbShopUser.getCode()); memberIn.setShopId(shopInfo.getId()); memberIn.setStatus("7"); memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId())); @@ -585,7 +453,8 @@ public class PayService { tbMemberInMapper.insert(memberIn); - PayReq req = new PayReq(); + + PayReq req=new PayReq(); req.setAppId(thirdApply.getAppId()); req.setTimestamp(System.currentTimeMillis()); @@ -599,51 +468,26 @@ public class PayService { req.setUserId(openId); - Map map = BeanUtil.transBeanMap(req); - req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + Map map= BeanUtil.transBeanMap(req); + req.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); - ResponseEntity response = restTemplate.postForEntity(url.concat("trans/pay"), req, String.class); - if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - if (object.get("code").equals("0")) { + ResponseEntity response= restTemplate.postForEntity(url.concat("trans/pay"),req,String.class); + if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){ + JSONObject object=JSONObject.parseObject(response.getBody()); + if(object.get("code").equals("0")){ memberIn.setOrderNo(object.getJSONObject("data").get("orderNumber").toString()); memberIn.setUpdateTime(new Date()); tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); - } else { + return Result.success(CodeEnum.SUCCESS,object.getJSONObject("data")); + }else { return Result.fail(object.getString("msg")); } } return Result.fail("失败"); } - @Transactional(rollbackFor = Exception.class) - public String callBackGroupPay(String payOrderNO) { - TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.selectByPayOrderNo(payOrderNO); - if (ObjectUtil.isEmpty(orderInfo)) { - return "订单信息不存在"; - } - if ("unpaid".equals(orderInfo.getStatus())) { - for (int i = 0; i < orderInfo.getNumber(); i++) { - TbGroupOrderCoupon groupOrderCoupon = new TbGroupOrderCoupon(); - groupOrderCoupon.setOrderId(orderInfo.getId()); - groupOrderCoupon.setCouponNo(genCouponNumber()); - groupOrderCoupon.setIsRefund(0); - groupOrderCouponService.insert(groupOrderCoupon); - } - orderInfo.setExpDate(getNextMonDate()); - //修改主单状态 - orderInfo.setStatus("unused"); - orderInfo.setPayAmount(orderInfo.getOrderAmount()); - tbGroupOrderInfoMapper.update(orderInfo); - return "SUCCESS"; - }else { - log.error("支付回调异常,订单状态为{}",orderInfo); - } - return null; - } @Transactional(rollbackFor = Exception.class) public String callBackPay(String payOrderNO) { @@ -668,10 +512,10 @@ public class PayService { tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("token", 0); - jsonObject.put("type", "wxcreate"); - jsonObject.put("orderId", orderInfo.getId().toString()); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderInfo.getId().toString()); producer.putOrderCollect(jsonObject.toJSONString()); @@ -686,10 +530,10 @@ public class PayService { @Transactional(rollbackFor = Exception.class) - public String minsuccess(String payOrderNO, String tradeNo) { + public String minsuccess(String payOrderNO,String tradeNo){ - TbMemberIn memberIn = tbMemberInMapper.selectByOrderNo(payOrderNO); - if (ObjectUtil.isEmpty(memberIn)) { + TbMemberIn memberIn= tbMemberInMapper.selectByOrderNo(payOrderNO); + if(ObjectUtil.isEmpty(memberIn)){ return "充值记录不存在"; } @@ -698,18 +542,21 @@ public class PayService { memberIn.setUpdateTime(new Date()); tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(memberIn.getUserId().toString(), memberIn.getShopId().toString()); - if (ObjectUtil.isEmpty(tbShopUser)) { + TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(memberIn.getUserId().toString(),memberIn.getShopId().toString()); + if(ObjectUtil.isEmpty(tbShopUser)){ return "用户信息不存在"; } + if(!"1".equals(tbShopUser.getIsVip().toString())){ + tbShopUser.setIsVip(Byte.parseByte("1")); + } + //修改客户资金 - tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setAmount(tbShopUser.getAmount().add(memberIn.getAmount())); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); - TbShopUserFlow flow = new TbShopUserFlow(); + TbShopUserFlow flow=new TbShopUserFlow(); flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); flow.setBizCode("scanMemberIn"); flow.setBizName("会员扫码充值"); @@ -725,76 +572,52 @@ public class PayService { // // } - /** - * 生成长度为12的随机串 - * - * @return - */ - public static String genCouponNumber() { - Random random = new Random(); - long min = 10000000000L; - long max = 19999999999L; - // 生成介于min和max之间的随机整数 - long randomNumber = min + ((long) (random.nextDouble() * (max - min))); - // 将随机整数转换为字符串,并在前面补0,直到长度为12位 - return String.format("%012d", randomNumber); - } - /** - * 获取一个月后的时间 - * - * @return - */ - public Date getNextMonDate() { - // 获取当前日期和时间 - LocalDateTime currentDateTime = LocalDateTime.now(); - // 计算一个月后的日期和时间 - LocalDateTime nextMonthDateTime = currentDateTime.plusMonths(1); - return java.sql.Timestamp.valueOf(nextMonthDateTime); - } + public static void main(String[] args){ + + RestTemplate restTemplate1= new RestTemplate(); + JSONObject param=new JSONObject(); + + String priv="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIqNqTqhN8zE7eFZnwKcyBTENce2wdAtl/gaDHNuNVgg33dS27Jx0fKl9QSHXyzyxbAdG8F94niYbRBstrMymFRjuO72jH+rIH62Ym1k7l8JSLVK2dKHXt8lHDaQGUP10q0EEocnDQ9cL93oBNG1ttsV6vOAu1TPvRK9TGihRAe1AgMBAAECgYBmI8KCl0DkcrSOsRvYuC2DqZWf8el1B3eFjeZp3e/zVOCIPYv6Q5ArWg6DVSxjnWEA0KSagqvGjU+xkQMqnXzPcPMhsIS+1wyR/pP+pwiatO2ioHaQpEqHg9eXhxrgA477/xuKVw9zl5GNqaIgd++2NDXnqLh0Y6OR73f0OB5eDQJBAPihEm+UWLOam/Q/k2+k4Lm2dvxJTBur1fslBiJpgMhgcz/PlwRwpL7aPD0AuPv0NqLouuoTiKpq9icnUv12tgsCQQCOqTANw0IErCHUNdinjXewmG3ui1j9XgM41rSn5ZeTrPL4GhZc2zbS/pZT4PBKUL6NLGkfPHmw4rOmNL/Xc5E/AkBqAwQBX5eSvVHSC2mqKPtJNGv3lqlFAzfyJg8/jQzEY5vAkZsq4Xzdg+A7gptdkvvY6rMIK9wSDhl3CGVyfbORAkA1N+g1OiHmnFACWhP4bU25EyPvWQxZeDi7e1zpRTzGWj5JT3IIMb7B9zcdE0yQbI6pG2gbvvOmiOt7lTH7raEBAkBas2gugvR3f0aGqQcqMpyM627pyRppQ2h58/7KBylP3oR2BReqMUcXeiJ8TuBXzbRXpeVQ0DWOva5CWZJmBMdz"; + + PayReq req=new PayReq(); + + req.setAppId("M8002023120892f1e4"); + req.setTimestamp(System.currentTimeMillis()); + req.setIp("127.0.0.1"); + req.setMercOrderNo(System.currentTimeMillis()+""); + req.setNotifyUrl("https"); + req.setPayAmt("0.01"); + req.setPayType("03"); + req.setPayWay("WXZF"); + req.setSubject("ddd"); + req.setUserId("or1l864NBOoJZhC5x_yeziZ26j6c"); + + Map map= BeanUtil.transBeanMap(req); + + req.setSign(MD5Util.encrypt(map,priv,true)); -// public static void main(String[] args) { -// -// RestTemplate restTemplate1 = new RestTemplate(); -// JSONObject param = new JSONObject(); -// -// String priv = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIqNqTqhN8zE7eFZnwKcyBTENce2wdAtl/gaDHNuNVgg33dS27Jx0fKl9QSHXyzyxbAdG8F94niYbRBstrMymFRjuO72jH+rIH62Ym1k7l8JSLVK2dKHXt8lHDaQGUP10q0EEocnDQ9cL93oBNG1ttsV6vOAu1TPvRK9TGihRAe1AgMBAAECgYBmI8KCl0DkcrSOsRvYuC2DqZWf8el1B3eFjeZp3e/zVOCIPYv6Q5ArWg6DVSxjnWEA0KSagqvGjU+xkQMqnXzPcPMhsIS+1wyR/pP+pwiatO2ioHaQpEqHg9eXhxrgA477/xuKVw9zl5GNqaIgd++2NDXnqLh0Y6OR73f0OB5eDQJBAPihEm+UWLOam/Q/k2+k4Lm2dvxJTBur1fslBiJpgMhgcz/PlwRwpL7aPD0AuPv0NqLouuoTiKpq9icnUv12tgsCQQCOqTANw0IErCHUNdinjXewmG3ui1j9XgM41rSn5ZeTrPL4GhZc2zbS/pZT4PBKUL6NLGkfPHmw4rOmNL/Xc5E/AkBqAwQBX5eSvVHSC2mqKPtJNGv3lqlFAzfyJg8/jQzEY5vAkZsq4Xzdg+A7gptdkvvY6rMIK9wSDhl3CGVyfbORAkA1N+g1OiHmnFACWhP4bU25EyPvWQxZeDi7e1zpRTzGWj5JT3IIMb7B9zcdE0yQbI6pG2gbvvOmiOt7lTH7raEBAkBas2gugvR3f0aGqQcqMpyM627pyRppQ2h58/7KBylP3oR2BReqMUcXeiJ8TuBXzbRXpeVQ0DWOva5CWZJmBMdz"; -// -// PayReq req = new PayReq(); -// -// req.setAppId("M8002023120892f1e4"); + ResponseEntity response= restTemplate1.postForEntity("https://gatewaytestapi.sxczgkj.cn/gate-service/trans/pay",req,String.class); + + + +// TradeQueryReq req=new TradeQueryReq(); +// req.setAppId("M800202305094c170c"); // req.setTimestamp(System.currentTimeMillis()); -// req.setIp("127.0.0.1"); -// req.setMercOrderNo(System.currentTimeMillis() + ""); -// req.setNotifyUrl("https"); -// req.setPayAmt("0.01"); -// req.setPayType("03"); -// req.setPayWay("WXZF"); -// req.setSubject("ddd"); -// req.setUserId("or1l864NBOoJZhC5x_yeziZ26j6c"); +// req.setOrderNumber("SXF_W_MERC_20240205182102491"); +// Map map= BeanUtil.transBeanMap(req); // -// Map map = BeanUtil.transBeanMap(req); +// req.setSign(MD5Util.encrypt(map,priv,true)); // -// req.setSign(MD5Util.encrypt(map, priv, true)); +// ResponseEntity response= restTemplate1.postForEntity("https://gateway.api.sxczgkj.cn/gate-service/merchantOrder/tradeQuery",req,String.class); // // -// ResponseEntity response = restTemplate1.postForEntity("https://gatewaytestapi.sxczgkj.cn/gate-service/trans/pay", req, String.class); -// -// -//// TradeQueryReq req=new TradeQueryReq(); -//// req.setAppId("M800202305094c170c"); -//// req.setTimestamp(System.currentTimeMillis()); -//// req.setOrderNumber("SXF_W_MERC_20240205182102491"); -//// Map map= BeanUtil.transBeanMap(req); -//// -//// req.setSign(MD5Util.encrypt(map,priv,true)); -//// -//// ResponseEntity response= restTemplate1.postForEntity("https://gateway.api.sxczgkj.cn/gate-service/merchantOrder/tradeQuery",req,String.class); -//// -//// -// System.out.println(">>>>>>>>>>>>>>>" + response.getBody()); -// } + System.out.println(">>>>>>>>>>>>>>>"+response.getBody()); + } + + + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java new file mode 100644 index 0000000..142bfdf --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java @@ -0,0 +1,16 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.constants; + +public enum SignTypeEnum { + + MD5("MD5"),RSA2("RSA2"); + + private final String value; + + SignTypeEnum(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java new file mode 100644 index 0000000..502d535 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java @@ -0,0 +1,41 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class MainScanReq implements Serializable { + + private String subject; + + private String body; + + private Long amount; + + private String subAppid; + + private String currency; + + private String authCode; + + private String mchOrderNo; + + private String storeId; + + private String notifyUrl; + + public MainScanReq(String subject, String body, Long amount, String subAppid, String currency, String authCode, String mchOrderNo, String storeId, String notifyUrl) { + this.subject = subject; + this.body = body; + this.amount = amount; + this.subAppid = subAppid; + this.currency = currency; + this.authCode = authCode; + this.mchOrderNo = mchOrderNo; + this.storeId = storeId; + this.notifyUrl = notifyUrl; + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java new file mode 100644 index 0000000..9bdbbb8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class OrderRefundReq implements Serializable { + + private String mchRefundNo; + + private String payOrderId; + + private String mchOrderNo; + + private String refundReason; + + private Long refundAmount; + + private String notifyUrl; + + private String extParam; + + public OrderRefundReq(String mchRefundNo, String payOrderId, String mchOrderNo, String refundReason, Long refundAmount, String notifyUrl, String extParam) { + this.mchRefundNo = mchRefundNo; + this.payOrderId = payOrderId; + this.mchOrderNo = mchOrderNo; + this.refundReason = refundReason; + this.refundAmount = refundAmount; + this.notifyUrl = notifyUrl; + this.extParam = extParam; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java new file mode 100644 index 0000000..d39dba3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class OrderReturnQueryReq implements Serializable { + + private String mchRefundNo; + + private String refundOrderId; + + public OrderReturnQueryReq(String mchRefundNo, String refundOrderId) { + this.mchRefundNo = mchRefundNo; + this.refundOrderId = refundOrderId; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java new file mode 100644 index 0000000..c47a593 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class OrderStatusQueryReq implements Serializable { + + private String payOrderId; + + private String mchOrderNo; + + public OrderStatusQueryReq(String payOrderId, String mchOrderNo) { + this.payOrderId = payOrderId; + this.mchOrderNo = mchOrderNo; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java new file mode 100644 index 0000000..855ceac --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java @@ -0,0 +1,33 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class PublicParam implements Serializable { + + private String appId; + + private String sign; + + private String signType; + + private String bizData; + + private String reqTime; + + private String version; + + private String reqId; + + public PublicParam(String appId, String sign, String signType, String bizData, String reqTime, String version, String reqId) { + this.appId = appId; + this.sign = sign; + this.signType = signType; + this.bizData = bizData; + this.reqTime = reqTime; + this.version = version; + this.reqId = reqId; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java new file mode 100644 index 0000000..0e6eab3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java @@ -0,0 +1,49 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxScanPayReq implements Serializable { + + private String subject; + + private String body; + + private Long amount; + + private String currency; + + private String payType; + + + private String subAppid; + + private String userId; + + private String clientIp; + + private String mchOrderNo; + + private String storeId; + + private String notifyUrl; + + private String returnUrl; + + public WxScanPayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) { + this.subject = subject; + this.body = body; + this.amount = amount; + this.currency = currency; + this.payType = payType; + this.subAppid = subAppid; + this.userId = userId; + this.clientIp = clientIp; + this.mchOrderNo = mchOrderNo; + this.storeId = storeId; + this.notifyUrl = notifyUrl; + this.returnUrl = returnUrl; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java new file mode 100644 index 0000000..46a1636 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java @@ -0,0 +1,47 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class MainScanResp implements Serializable { + + private Long amount; + + private String mchOrderNo; + + private String payOrderId; + + private String mercNo; + + private String channelSendNo; + + private String channelTradeNo; + + private String state; + + private String payType; + + private String ifCode; + + private String extParam; + + private String note; + + private String tradeFee; + + private String storeId; + + private String subject; + + private String drType; + + private Long refundAmt; + + private Integer refundState; + + private Long cashFee; + + private String settlementType; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java new file mode 100644 index 0000000..b481b15 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java @@ -0,0 +1,36 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class OderReturnQueyResp implements Serializable { + + + private String mchRefundNo; + + private String refundOrderId; + + private String state; + + private String oriPayOrderId; + + private String mercNo; + + private Long oriAmount; + + private Long refundAmt; + + private String refundReason; + + private String ifCode; + + private String note; + + private String refundTime; + + private String extParam; + + private String payType; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java new file mode 100644 index 0000000..1a930f8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java @@ -0,0 +1,33 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class OrderReturnResp implements Serializable { + + private String mchRefundNo; + + private String refundOrderId; + + private String state; + + private String oriPayOrderId; + + private String mercNo; + + private Long oriAmount; + + private Long refundAmt; + + private String refundReason; + + private String ifCode; + + private String refundTime; + + private String extParam; + + private String payType; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java new file mode 100644 index 0000000..0afc145 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java @@ -0,0 +1,49 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class OrderStatusQueryResp implements Serializable { + + private Long amount; + + private String channelSendNo; + + private String ifCode; + + private String mercNo; + + private String mchOrderNo; + + private String payOrderId; + + private String payType; + + private String channelTradeNo; + + private String state; + + private String refundAmt; + + private String refundState; + + private String drType; + + private String extParam; + + private String payTime; + + private String subject; + + private String tradeFee; + + private String cashFee; + + private String storeId; + + private String userId; + + private String settlementType; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java new file mode 100644 index 0000000..d911c21 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class PublicResp implements Serializable { + + private String code; + + private String msg; + + private String sign; + + private String bizData; + + private T objData; + + private String signType; + + private String timestamp; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java new file mode 100644 index 0000000..af8b012 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java @@ -0,0 +1,51 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxScanPayResp implements Serializable { + + private Long amount; + + private String mchOrderNo; + + private String payOrderId; + + private String mercNo; + + private String channelSendNo; + + private String channelTradeNo; + + private String state; + + private String payType; + + private String ifCode; + + private String extParam; + + private String payInfo; + + private String liteInfo; + + private String note; + + private String tradeFee; + + private String storeId; + + private String subject; + + private String drType; + + private String refundAmt; + + private String refundState; + + private String cashFee; + + private String settlementType; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java new file mode 100644 index 0000000..2c0f05b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java @@ -0,0 +1,300 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.service; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.chaozhanggui.system.cashierservice.thirdpay.constants.SignTypeEnum; +import com.chaozhanggui.system.cashierservice.thirdpay.req.*; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.*; +import com.chaozhanggui.system.cashierservice.util.DateUtils; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; +import com.chaozhanggui.system.cashierservice.util.MD5Util; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedHashMap; + +@Service +@Slf4j +public class ThirdPayService { + + private static String micropay="/api/open/payment/micropay"; + + private static String ltpay="/api/open/payment/ltpay"; + + private static String trade="/api/open/query/trade"; + + /** + * 被扫接口 + * @param url + * @param appId + * @param subject + * @param body + * @param amount + * @param subAppId + * @param authCode + * @param orderNo + * @param storeId + * @param notifyUrl + * @param key + * @return + */ + public PublicResp mainScan(String url,String appId, String subject, String body, Long amount, String subAppId, String authCode, String orderNo, String storeId, String notifyUrl, + String key + ) { + + MainScanReq mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl); + PublicParam param = new PublicParam(appId, "", SignTypeEnum.MD5.getValue(), null, DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + + + try { + String str = JSONUtil.toJSONString(sortFields(mainScanReq)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(micropay)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),MainScanResp.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + + + /** + * 主扫接口(小程序) + * @param url + * @param appId + * @param subject + * @param body + * @param amount + * @param payType + * @param subAppId + * @param userId + * @param clinetIp + * @param orderNo + * @param storeId + * @param notifyUrl + * @param returnUrl + * @param key + * @return + */ + + public PublicResp scanpay(String url,String appId, String subject, String body, Long amount,String payType, String subAppId, String userId, + + String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl, + String key){ + WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,notifyUrl,returnUrl); + PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + + + try { + String str = JSONUtil.toJSONString(sortFields(scanPayReq)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(ltpay)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),WxScanPayResp.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + /** + * 查询订单状态 + * @param url + * @param appId + * @param payOrderId + * @param mchOrderNo + * @param key + * @return + */ + public PublicResp queryOrder(String url,String appId, String payOrderId,String mchOrderNo,String key){ + OrderStatusQueryReq req=new OrderStatusQueryReq(payOrderId,mchOrderNo); + PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + try { + String str = JSONUtil.toJSONString(sortFields(req)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderStatusQueryResp.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + + /** + * 退款 + * @param url + * @param appId + * @param mchRefundNo + * @param payOrderId + * @param mchOrderNo + * @param refundReason + * @param refundAmount + * @param notifyUrl + * @param extParam + * @param key + * @return + */ + public PublicResp returnOrder(String url,String appId, String mchRefundNo, String payOrderId, String mchOrderNo, String refundReason, Long refundAmount, String notifyUrl, String extParam,String key){ + OrderRefundReq req=new OrderRefundReq(mchRefundNo, payOrderId, mchOrderNo, refundReason, refundAmount, notifyUrl, extParam); + PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + try { + String str = JSONUtil.toJSONString(sortFields(req)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderReturnResp.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + + /** + * 查询退款订单 + * @param url + * @param appId + * @param mchRefundNo + * @param refundOrderId + * @param key + * @return + */ + public PublicResp returnOrderQuery(String url,String appId,String mchRefundNo, String refundOrderId,String key){ + OrderReturnQueryReq req=new OrderReturnQueryReq(mchRefundNo,refundOrderId); + PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + try { + String str = JSONUtil.toJSONString(sortFields(req)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderReturnQueryReq.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + + + + + + public static String sortFieldsAndPrint(Object obj) throws IllegalAccessException { + StringBuffer sb = new StringBuffer(); + Class clazz = obj.getClass(); + Field[] fields = clazz.getDeclaredFields(); + + // 按字段名称排序 + Arrays.sort(fields, Comparator.comparing(Field::getName)); + + for (Field field : fields) { + // 可能需要设置访问权限 + field.setAccessible(true); + if ("sign".equals(field.getName())) { + continue; + } + Object value = field.get(obj); + + + StringBuffer param = new StringBuffer(); + param.append(field.getName()); + param.append("="); + if (value instanceof String) { + param.append(value); + + } else if (value instanceof Integer) { + param.append(value); + } else if (value instanceof Long) { + param.append(value); + } + + param.append("&"); + sb.append(param); + } + return sb.toString(); + } + + + public static LinkedHashMap sortFields(Object obj) throws IllegalAccessException { + + LinkedHashMap map = new LinkedHashMap<>(); + Class clazz = obj.getClass(); + Field[] fields = clazz.getDeclaredFields(); + + // 按字段名称排序 + Arrays.sort(fields, Comparator.comparing(Field::getName)); + + for (Field field : fields) { + // 可能需要设置访问权限 + field.setAccessible(true); + Object value = field.get(obj); + if(value==null){ + continue; + } + + map.put(field.getName(), value); + } + return map; + } + + + + + public static void main(String[] args) { +// mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI"); + } +} diff --git a/src/main/resources/application-hph.yml b/src/main/resources/application-hph.yml index b90ae93..b05f49b 100644 --- a/src/main/resources/application-hph.yml +++ b/src/main/resources/application-hph.yml @@ -1,3 +1,5 @@ +server: + port: 9888 spring: datasource: url: jdbc:mysql://rm-bp1b572nblln4jho2po.mysql.rds.aliyuncs.com/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 98cbeb9..c2956be 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: -# port: 9889 + port: 9889 servlet: context-path: /cashierService/ wx: @@ -51,7 +51,8 @@ logging: aliyun: keyid: LTAI5tPdEfYSZcqHbjCrtPRD keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy - oss: - bucketname: cashier-oss - endpoint: oss-cn-beijing.aliyuncs.com +thirdPay: + payType: fushangtong + callBack: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay + url: https://paymentapi.sxczgkj.cn From fb86b296cb06f576b987067a238a4240edf9a1b0 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 15 May 2024 16:50:39 +0800 Subject: [PATCH 036/134] =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20=E5=9B=A2=E8=B4=AD=E5=8D=B7=E6=94=AF?= =?UTF-8?q?=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PayController.java | 33 ++- .../cashierservice/service/PayService.java | 247 +++++++++++++++++- src/main/resources/application.yml | 3 + 3 files changed, 268 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index f5b80f3..8049271 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -37,12 +37,26 @@ public class PayController { * @return */ @RequestMapping("orderPay") + public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map map) { + if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("orderId")||ObjectUtil.isEmpty(map.get("orderId"))){ + return Result.fail("订单号不允许为空"); + } + + try { + return payService.payOrder(openId,map.get("orderId").toString(), IpUtil.getIpAddr(request)); + } catch (Exception e) { + e.printStackTrace(); + } + return Result.fail("支付失败"); + } + + @RequestMapping("groupOrderPay") public Result pay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { return Result.fail("订单号不允许为空"); } String orderId = map.get("orderId").toString(); - String orderType = map.get("orderType").toString(); +// String orderType = map.get("orderType").toString(); String payType = map.get("payType").toString(); String userId=""; if(environment.equals("wx")){ @@ -50,25 +64,18 @@ public class PayController { }else { userId = TokenUtil.parseParamFromToken(token).getString("userId"); } - log.info("订单支付 orderId:{},orderType:{},payType={},userId:{}",orderId,orderType,payType,userId); + log.info("订单支付 orderId:{},payType={},userId:{}",orderId,payType,userId); try { - if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){ - return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request)); - }else { - return payService.payOrder(userId, orderId, payType, IpUtil.getIpAddr(request)); - } +// if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){ +// return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request)); +// } + return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request)); } catch (Exception e) { e.printStackTrace(); } return Result.fail("支付失败"); } - @RequestMapping("returnGpOrder") - public Result returnOrder(@RequestBody ReturnGroupOrderDto param){ - return payService.returnOrder(param); - } - - // // public Result memberAccountPay(@RequestHeader("openId") String openId, // @RequestParam("orderId") String orderId, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 13a5191..62c5fc7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -118,11 +118,15 @@ public class PayService { @Value("${thirdPay.callBack}") private String callBack; - - @Autowired ThirdPayService thirdPayService; + @Resource + private TbGroupOrderInfoMapper tbGroupOrderInfoMapper; + @Autowired + private TbProductMapper tbProductMapper; + @Resource + private GroupOrderCouponService orderCouponService; @Transactional(rollbackFor = Exception.class) @@ -269,7 +273,191 @@ public class PayService { return Result.fail("失败"); } + @Transactional(rollbackFor = Exception.class) + public Result groupOrderPay(String orderId, String payType, String userId, String ip) { + TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.queryById(Integer.valueOf(orderId)); + if (!"unpaid".equals(orderInfo.getStatus())) { + return Result.fail("订单状态异常,不允许支付"); + } + + TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(orderInfo.getShopId().toString()); + if (tbMerchantAccount == null) { + throw new MsgException("生成订单错误"); + } + + if (ObjectUtil.isNull(tbMerchantAccount.getMerchantId()) || ObjectUtil.isEmpty(tbMerchantAccount.getMerchantId())) { + return Result.fail("没有对应的商户"); + } + + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantAccount.getMerchantId())); + + if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { + return Result.fail("支付通道不存在"); + } + StringBuffer body=new StringBuffer(); + body.append(orderInfo.getProName()); + TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId); + if (ObjectUtil.isEmpty(payment) || payment == null) { + payment = new TbOrderPayment(); + payment.setPayTypeId("ysk"); + payment.setAmount(orderInfo.getOrderAmount()); + payment.setPaidAmount(orderInfo.getPayAmount()); + payment.setHasRefundAmount(BigDecimal.ZERO); + if (payType.equals("wechatPay")) { + payment.setPayName("微信支付"); + payment.setPayType("wechatPay"); + } else if (payType.equals("aliPay")) { + payment.setPayName("支付宝支付"); + payment.setPayType("aliPay"); + } + payment.setReceived(payment.getAmount()); + payment.setChangeFee(BigDecimal.ZERO); +// payment.setMemberId(orderInfo.getMemberId());//会员Id + payment.setShopId(orderInfo.getShopId().toString()); + payment.setOrderId(orderInfo.getId().toString()); + payment.setCreatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.insert(payment); + } else { + if (payType.equals("wechatPay")) { + payment.setPayName("微信支付"); + payment.setPayType("wechatPay"); + } else if (payType.equals("aliPay")) { + payment.setPayName("支付宝支付"); + payment.setPayType("aliPay"); + } + payment.setUpdatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.updateByPrimaryKey(payment); + } + if("ysk".equals(thirdPayType)){ + PayReq req = new PayReq(); + + req.setAppId(thirdApply.getAppId()); + req.setTimestamp(System.currentTimeMillis()); + req.setIp(ip); + req.setMercOrderNo(orderInfo.getOrderNo()); + req.setNotifyUrl(callBackGroupurl); + req.setPayAmt(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString()); + if (payType.equals("wechatPay")) { + req.setPayType("03"); + req.setPayWay("WXZF");//WXZF ZFBZF UNIONPAY + } else if (payType.equals("aliPay")) { + req.setPayWay("ZFBZF"); + } + req.setSubject("零点八零:团购卷"); + req.setUserId(userId); + + + Map map = BeanUtil.transBeanMap(req); + req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + + ResponseEntity response = restTemplate.postForEntity(url.concat("trans/pay"), req, String.class); + + + if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { + JSONObject object = JSONObject.parseObject(response.getBody()); + log.info("团购卷支付响应:{}",object); + if (object.get("code").equals("0")) { + payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString()); + payment.setUpdatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); + orderInfo.setPayType(payType); + orderInfo.setPayOrderNo(payment.getTradeNumber()); + tbGroupOrderInfoMapper.update(orderInfo); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", ""); + jsonObject1.put("data", new JSONArray()); + jsonObject1.put("amount", 0); + tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); + return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); + } else { + return Result.fail(object.getString("msg")); + } + } + }else { + String reqbody=""; + + if(body.length()>15){ + reqbody=body.substring(0,6).concat("....").concat(body.substring(body.length()-6,body.length())).toString(); + }else { + reqbody=body.toString(); + } + + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"wx212769170d2c6b2a","wx212769170d2c6b2a",userId,ip,orderInfo.getOrderNo(),"S2405103298",callBack,null,thirdApply.getAppToken()); + if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ + if("000000".equals(publicResp.getCode())){ + WxScanPayResp wxScanPayResp= publicResp.getObjData(); + if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + payment.setTradeNumber(wxScanPayResp.getPayOrderId()); + payment.setUpdatedAt(System.currentTimeMillis()); + tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); + orderInfo.setPayType(payType); + orderInfo.setPayOrderNo(payment.getTradeNumber()); + tbGroupOrderInfoMapper.update(orderInfo); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", ""); + jsonObject1.put("data", new JSONArray()); + jsonObject1.put("amount", 0); + tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); + return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); + }else{ + return Result.fail(publicResp.getMsg()); + } + } + } + } + return Result.fail("失败"); + } + + @Transactional(rollbackFor = Exception.class) + public Result returnOrder(ReturnGroupOrderDto param) { + TbGroupOrderInfo groupOrderInfo = tbGroupOrderInfoMapper.queryById(param.getOrderId()); + List tbGroupOrderCoupons = orderCouponService.queryNoRefundByOrderId(param.getOrderId()); + if (param.getNum() > tbGroupOrderCoupons.size()) { + return Result.fail("可退数量不足"); + } + for (int i = 0; i < param.getNum(); i++) { + TbGroupOrderCoupon coupon = tbGroupOrderCoupons.get(i); + coupon.setIsRefund(1); + coupon.setRefundAmount(param.getRefundAmount()); + coupon.setRefundDesc(param.getRefundDesc()); + coupon.setRefundReason(param.getRefundReason()); + orderCouponService.update(coupon); + } + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(groupOrderInfo.getMerchantId()); + MsgException.checkNull(thirdApply, "支付参数配置错误"); + ReturnOrderReq req = new ReturnOrderReq(); + req.setAppId(thirdApply.getAppId()); + req.setTimestamp(System.currentTimeMillis()); + req.setOrderNumber(groupOrderInfo.getPayOrderNo()); + req.setAmount(param.getRefundAmount().toString()); + req.setMercRefundNo(groupOrderInfo.getOrderNo()); + req.setRefundReason("团购卷:退货"); + req.setPayPassword(thirdApply.getPayPassword()); + Map map = BeanUtil.transBean2Map(req); + req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + log.info("groupOrderReturn req:{}", JSONUtil.toJsonStr(req)); + ResponseEntity response = restTemplate.postForEntity(url.concat("merchantOrder/returnOrder"), req, String.class); + log.info("groupOrderReturn:{}", response.getBody()); + if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { + JSONObject object = JSONObject.parseObject(response.getBody()); + if (!object.get("code").equals("0")) { + MsgException.check(true, "退款渠道调用失败"); + } + } + groupOrderInfo.setRefundNumber(groupOrderInfo.getRefundNumber() + param.getNum()); + groupOrderInfo.setRefundAmount(groupOrderInfo.getRefundAmount().add(param.getRefundAmount())); + if (groupOrderInfo.getNumber() == groupOrderInfo.getRefundNumber()) { + groupOrderInfo.setRefundAble(0); + groupOrderInfo.setStatus("refund"); + } + tbGroupOrderInfoMapper.update(groupOrderInfo); + return Result.success(CodeEnum.SUCCESS); + } @Transactional(rollbackFor = Exception.class) public Result modifyOrderStatus(Integer orderId) throws IOException { @@ -528,6 +716,61 @@ public class PayService { return null; } + @Transactional(rollbackFor = Exception.class) + public String callBackGroupPay(String payOrderNO) { + TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.selectByPayOrderNo(payOrderNO); + if (ObjectUtil.isEmpty(orderInfo)) { + return "订单信息不存在"; + } + + if ("unpaid".equals(orderInfo.getStatus())) { + for (int i = 0; i < orderInfo.getNumber(); i++) { + TbGroupOrderCoupon groupOrderCoupon = new TbGroupOrderCoupon(); + groupOrderCoupon.setOrderId(orderInfo.getId()); + groupOrderCoupon.setCouponNo(genCouponNumber()); + groupOrderCoupon.setIsRefund(0); + groupOrderCouponService.insert(groupOrderCoupon); + } + orderInfo.setExpDate(getNextMonDate()); + //修改主单状态 + orderInfo.setStatus("unused"); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + tbGroupOrderInfoMapper.update(orderInfo); + return "SUCCESS"; + }else { + log.error("支付回调异常,订单状态为{}",orderInfo); + } + return null; + } + + /** + * 生成长度为12的随机串 + * + * @return + */ + public static String genCouponNumber() { + Random random = new Random(); + long min = 10000000000L; + long max = 19999999999L; + // 生成介于min和max之间的随机整数 + long randomNumber = min + ((long) (random.nextDouble() * (max - min))); + // 将随机整数转换为字符串,并在前面补0,直到长度为12位 + return String.format("%012d", randomNumber); + } + + /** + * 获取一个月后的时间 + * + * @return + */ + public Date getNextMonDate() { + // 获取当前日期和时间 + LocalDateTime currentDateTime = LocalDateTime.now(); + // 计算一个月后的日期和时间 + LocalDateTime nextMonthDateTime = currentDateTime.plusMonths(1); + return java.sql.Timestamp.valueOf(nextMonthDateTime); + } + @Transactional(rollbackFor = Exception.class) public String minsuccess(String payOrderNO,String tradeNo){ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c2956be..8a8c34d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -51,6 +51,9 @@ logging: aliyun: keyid: LTAI5tPdEfYSZcqHbjCrtPRD keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy + oss: + bucketname: cashier-oss + endpoint: oss-cn-beijing.aliyuncs.com thirdPay: payType: fushangtong From c6257d75f220526cceee1e2be48a78e0df77bf89 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 15 May 2024 17:06:37 +0800 Subject: [PATCH 037/134] =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E5=8D=B7=E6=94=AF?= =?UTF-8?q?=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/PayController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 8049271..58f7005 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -51,7 +51,7 @@ public class PayController { } @RequestMapping("groupOrderPay") - public Result pay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map map) { + public Result groupOrderPay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { return Result.fail("订单号不允许为空"); } From 314d79ac2cf3ced580fea1477ec5c82089f4c9a4 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 10:52:16 +0800 Subject: [PATCH 038/134] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83red?= =?UTF-8?q?is=20=E6=9B=B4=E6=8D=A2=E5=88=B00=E5=BA=93=20=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=BB=8F=E7=BA=AC=E5=BA=A6=E8=8E=B7=E5=8F=96=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CommonController.java | 18 ++++-- .../cashierservice/entity/vo/BannerVO.java | 2 - .../cashierservice/entity/vo/DicDetailVO.java | 59 ------------------- .../cashierservice/entity/vo/DistrictVO.java | 19 ------ .../cashierservice/entity/vo/DistrictVo.java | 18 ++++++ .../cashierservice/entity/vo/OrderVo.java | 1 - .../cashierservice/entity/vo/carouselVO.java | 16 ----- .../cashierservice/rabbit/CartConsumer.java | 12 ---- .../cashierservice/service/CartService.java | 8 --- .../service/HomePageService.java | 2 +- .../cashierservice/util/LocationUtils.java | 24 +++++++- src/main/resources/application-dev.yml | 2 +- src/main/resources/application-dev2.yml | 2 +- src/main/resources/application-hph.yml | 2 +- src/main/resources/application-test.yml | 2 +- 15 files changed, 58 insertions(+), 129 deletions(-) delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 6f6617a..ed3e5c8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -1,7 +1,9 @@ package com.chaozhanggui.system.cashierservice.controller; +import com.alibaba.fastjson.TypeReference; import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; +import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.service.FileService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; @@ -83,16 +85,22 @@ public class CommonController { */ @GetMapping("location/district") public Result createOrder(String keywords) throws JsonProcessingException { - String district = LocationUtils.district(keywords); + String districtJson = LocationUtils.district(keywords); ObjectMapper mapper = new ObjectMapper(); // 将 JSON 字符串解析为 JsonNode 对象 - JsonNode jsonNode = mapper.readTree(district); + JsonNode jsonNode = mapper.readTree(districtJson); JsonNode districts = jsonNode.get("districts"); - - - return Result.success(CodeEnum.SUCCESS, districts); + String text = districts.toString(); + List cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class)); + return Result.success(CodeEnum.SUCCESS, cityInfoList); } + @GetMapping("location/geocode") + public Result geocode(String location){ + return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(location)); + } + + @GetMapping("location/getGPSByIp") public Result getGPSByIp(String ip) throws JsonProcessingException { String gpsInfo = LocationUtils.getGPSByIp(ip); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java index b98784c..c9e82da 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java @@ -1,7 +1,5 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; - import java.util.List; /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java deleted file mode 100644 index aa84863..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -import com.chaozhanggui.system.cashierservice.entity.SysDictDetail; - -import java.util.List; - -/** - * @author lyf - */ -public class DicDetailVO { - private String name; - private String dictName; - - private String description; - - private List detail; - - private Boolean isChild; - - public String getDictName() { - return dictName; - } - - public void setDictName(String dictName) { - this.dictName = dictName; - } - - public Boolean getIsChild() { - return isChild; - } - - public void setIsChild(Boolean isChild) { - this.isChild = isChild; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List getDetail() { - return detail; - } - - public void setDetail(List detail) { - this.detail = detail; - } -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java deleted file mode 100644 index aff7937..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -/** - * @author lyf - */ -public class DistrictVO { - /** - * 图片 - */ - private String icon; - /** - * 菜单名 - */ - private String name; - /** - * 跳转地址 - */ - private String relUrl; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java new file mode 100644 index 0000000..bfda3ac --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.util.List; + +/** + * 行政区域返回vo + */ +@Data +public class DistrictVo { + private Object citycode; + private Object adcode; + private Object name; + private Object center; + private Object level; + private List districts; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java index b179b01..2126631 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java @@ -1,6 +1,5 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.TbCashierCart; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import lombok.Data; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java deleted file mode 100644 index d7cffc7..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -/** - * 轮播图 - * @author lyf - */ -public class carouselVO { - /** - * 封面图 - */ - private String coverImg; - /** - * 跳转地址 - */ - private String relUrl; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index de871ca..6a01041 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -3,18 +3,10 @@ package com.chaozhanggui.system.cashierservice.rabbit; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.chaozhanggui.system.cashierservice.dao.*; -import com.chaozhanggui.system.cashierservice.entity.*; -import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.service.CartService; -import com.chaozhanggui.system.cashierservice.sign.Result; -import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; -import com.chaozhanggui.system.cashierservice.util.JSONUtil; -import com.chaozhanggui.system.cashierservice.util.RedisUtils; -import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.amqp.rabbit.annotation.RabbitHandler; @@ -23,10 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.*; - @Slf4j @Component //@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 110d980..dd404c1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -5,27 +5,19 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; -import com.chaozhanggui.system.cashierservice.entity.dto.ProductCartDto; -import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; -import com.chaozhanggui.system.cashierservice.sign.CodeEnum; -import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; -import com.chaozhanggui.system.cashierservice.socket.WebSocketServer; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.N; -import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 846cd42..6959f87 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -95,7 +95,7 @@ public class HomePageService { /** * 商品列表 */ - public Result proList(HomeDto homeDto) throws ExecutionException, InterruptedException { + public Result proList(HomeDto homeDto) { PageInfo products = productService.products(homeDto); return Result.success(CodeEnum.SUCCESS, products); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index dca81d6..c733b2c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -1,6 +1,10 @@ package com.chaozhanggui.system.cashierservice.util; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; import java.math.RoundingMode; @@ -27,6 +31,22 @@ public class LocationUtils { return s; } + /** + * 通过经纬度获取信息 + */ + public static JsonNode geocode(String location) { + RestTemplate restTemplate = new RestTemplate(); + String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location="+location, String.class); + ObjectMapper objectMapper = new ObjectMapper(); + // 将 JSON 字符串解析为 JsonNode 对象 + try { + JsonNode jsonNode = objectMapper.readTree(s).get("regeocode"); + return jsonNode; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + /** * 行政区域查询 * @param keywords @@ -37,7 +57,7 @@ public class LocationUtils { //超掌柜生活-用户端 param.put("key", "7a7f2e4790ea222660a027352ee3af39"); param.put("keywords", keywords); - param.put("subdistrict", "2"); + param.put("subdistrict", "1"); param.put("extensions", "base"); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param); return s; @@ -80,7 +100,7 @@ public class LocationUtils { * 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); */ public static Map returnLLSquarePoint(double longitude, double latitude, String distanceInKm) { - BigDecimal distanceKm = new BigDecimal(10); + BigDecimal distanceKm = new BigDecimal(20); if (StringUtils.isNotBlank(distanceInKm)) { distanceKm = new BigDecimal(distanceInKm); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f05640a..98135c4 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -16,7 +16,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml index 32b0c0f..b2b5fb8 100644 --- a/src/main/resources/application-dev2.yml +++ b/src/main/resources/application-dev2.yml @@ -13,7 +13,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-hph.yml b/src/main/resources/application-hph.yml index b05f49b..4eb52e5 100644 --- a/src/main/resources/application-hph.yml +++ b/src/main/resources/application-hph.yml @@ -15,7 +15,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 568a2b7..e7f2d81 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -13,7 +13,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) From f8b2a3a7d4de34d33881bb39213489c61db74fc7 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 11:12:27 +0800 Subject: [PATCH 039/134] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A1=8C=E6=94=BF?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=9F=8E?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/CommonController.java | 3 +++ .../system/cashierservice/entity/vo/DistrictVo.java | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index ed3e5c8..02dc95b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -92,6 +92,9 @@ public class CommonController { JsonNode districts = jsonNode.get("districts"); String text = districts.toString(); List cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class)); + DistrictVo allCity=new DistrictVo(); + allCity.setName("全城"); + cityInfoList.add(0,allCity); return Result.success(CodeEnum.SUCCESS, cityInfoList); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java index bfda3ac..186eef5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java @@ -9,10 +9,10 @@ import java.util.List; */ @Data public class DistrictVo { - private Object citycode; - private Object adcode; - private Object name; - private Object center; - private Object level; + private String citycode; + private String adcode; + private String name; + private String center; + private String level; private List districts; } From 796ca0c55160298593656a2f6094cce3b653b59e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 14:15:06 +0800 Subject: [PATCH 040/134] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=BB=8F=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6=E8=8E=B7=E5=8F=96=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/auth/LoginFilter.java | 9 ++------- .../cashierservice/controller/CommonController.java | 4 ++-- .../system/cashierservice/interceptor/CustomFilter.java | 3 --- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 3c1e7a4..50ed2c2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -45,11 +45,11 @@ public class LoginFilter implements Filter { "cashierService/common/**",//通用接口 "cashierService/distirict/**",//首页其它接口 "cashierService/login/**",//登录部分接口不校验 - "cashierService/notify/**",//登录部分接口不校验 "cashierService/product/queryShopIdByTableCode", "cashierService/product/queryProduct", "cashierService/product/productInfo", - "notify/**"//登录部分接口不校验 + "cashierService/notify/**",//登录部分接口不校验 + "notify/**"//回调部分接口不校验 ); @Autowired @@ -80,11 +80,6 @@ public class LoginFilter implements Filter { //environment 环境标识 wx app 后续environment不可为空 String environment = request.getHeader("environment"); -// //token校验目前只对app生效 -// if (StringUtils.isBlank(environment) || !environment.equals("app")) { -// chain.doFilter(req, resp); -// return; -// } // 判断用户TOKEN是否存在 String token = request.getHeader("token"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 02dc95b..4ffbe64 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -99,8 +99,8 @@ public class CommonController { } @GetMapping("location/geocode") - public Result geocode(String location){ - return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(location)); + public Result geocode(@RequestParam String lat, @RequestParam String lng){ + return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(lng+","+lat)); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java index 2745c1e..b79a877 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/CustomFilter.java @@ -1,10 +1,7 @@ package com.chaozhanggui.system.cashierservice.interceptor; -import ch.qos.logback.classic.turbo.TurboFilter; -import com.chaozhanggui.system.cashierservice.exception.MsgException; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; - import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; From f23e31adefbc21d428a7a770c66c5d21fe610496 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 14:27:49 +0800 Subject: [PATCH 041/134] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=BB=8F=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6=E8=8E=B7=E5=8F=96=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/CommonController.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 4ffbe64..eaa73c4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -92,15 +92,19 @@ public class CommonController { JsonNode districts = jsonNode.get("districts"); String text = districts.toString(); List cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class)); - DistrictVo allCity=new DistrictVo(); + DistrictVo allCity = new DistrictVo(); allCity.setName("全城"); - cityInfoList.add(0,allCity); + cityInfoList.add(0, allCity); return Result.success(CodeEnum.SUCCESS, cityInfoList); } @GetMapping("location/geocode") - public Result geocode(@RequestParam String lat, @RequestParam String lng){ - return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(lng+","+lat)); + public Result geocode(@RequestParam String lat, @RequestParam String lng) { + String address="108.939645,34.343207"; + if (StringUtils.isBlank(lat) || StringUtils.isBlank(lng)) { + address=lng + "," + lat; + } + return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(lng + "," + lat)); } From 63921852e92b9a452f1cc8147227fbd82f466c7e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 15:07:11 +0800 Subject: [PATCH 042/134] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=20no=20=20null=20=E7=BB=8F=E7=BA=AC=E5=BA=A6=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/CommonController.java | 4 ++-- .../system/cashierservice/service/ProductService.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index eaa73c4..eaf0c2b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -101,10 +101,10 @@ public class CommonController { @GetMapping("location/geocode") public Result geocode(@RequestParam String lat, @RequestParam String lng) { String address="108.939645,34.343207"; - if (StringUtils.isBlank(lat) || StringUtils.isBlank(lng)) { + if (!StringUtils.isBlank(lat) && !StringUtils.isBlank(lng)) { address=lng + "," + lat; } - return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(lng + "," + lat)); + return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(address)); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 74eb42c..d31e44b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -179,7 +179,7 @@ public class ProductService { homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat()); } if (CollectionUtils.isEmpty(shopGroupInfoVos)) { - return new PageInfo(); + return new PageInfo(shopGroupInfoVos); } List productIds = shopGroupInfoVos.stream().map(ShopGroupInfoVo::getProId).collect(Collectors.toList()); List stringList = productIds.stream() From 200b75e04db9ba1364f7efbe537ec87867d3e483 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 16 May 2024 16:41:13 +0800 Subject: [PATCH 043/134] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8C=BA=E5=9F=9F=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbShopInfo.java | 3 +++ .../entity/vo/ProductInfoVo.java | 3 +++ .../service/GroupOrderInfoService.java | 4 ++-- .../service/HomeDistrictService.java | 8 ++++---- .../service/ProductService.java | 11 ++++++---- .../cashierservice/util/LocationUtils.java | 20 ++++++++++++++----- .../resources/mapper/TbShopInfoMapper.xml | 5 ++++- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java index acd1778..003e451 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java @@ -106,6 +106,9 @@ public class TbShopInfo implements Serializable { * 商户标签 */ private String tag; + private String provinces; + private String cities; + private String districts; private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java index 97b5e97..efcfe7e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java @@ -70,6 +70,9 @@ public class ProductInfoVo { * 距离 */ private String distances = "100"; + private String lat; + private String lng; + private String districts; /** * 地址 */ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/GroupOrderInfoService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/GroupOrderInfoService.java index 03362d9..7183778 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/GroupOrderInfoService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/GroupOrderInfoService.java @@ -78,10 +78,10 @@ public class GroupOrderInfoService { TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(groupOrder.getShopId()); result.setShopName(shopInfo.getShopName()); - BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( + String distance = LocationUtils.getDistanceString( Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat())); - result.setDistances(distance.toString()); + result.setDistances(distance); result.setAddress(shopInfo.getAddress()); result.setShopPhone(shopInfo.getPhone()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java index 3f2afd7..db7e26a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomeDistrictService.java @@ -109,10 +109,10 @@ public class HomeDistrictService { param.getAddress(), param.getLng(), param.getLat(),null);//西安市 for (SubShopVo subShopVo : subShopVos) {//距离计算 if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) { - BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( + String distance = LocationUtils.getDistanceString( Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()), Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat())); - subShopVo.setDistances(distance.toString()); + subShopVo.setDistances(distance); } } return Result.success(CodeEnum.SUCCESS, new PageInfo(subShopVos)); @@ -133,10 +133,10 @@ public class HomeDistrictService { for (SubShopVo subShopVo : subShopVos) {//距离计算 subShopVo.setBusinessTime(subShopVo.getBusinessStartDay()+"至"+subShopVo.getBusinessEndDay()+" "+subShopVo.getBusinessTime()); if (StringUtils.isNotBlank(subShopVo.getLat()) && StringUtils.isNotBlank(subShopVo.getLng())) { - BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( + String distance = LocationUtils.getDistanceString( Double.parseDouble(param.getLng()), Double.parseDouble(param.getLat()), Double.parseDouble(subShopVo.getLng()), Double.parseDouble(subShopVo.getLat())); - subShopVo.setDistances(distance.toString()); + subShopVo.setDistances(distance); } } return Result.success(CodeEnum.SUCCESS, subShopVos); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index d31e44b..4458dc6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -204,10 +204,10 @@ public class ProductService { homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class)); } if (StringUtils.isNotBlank(o.getLat()) && StringUtils.isNotBlank(o.getLng())) { - BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( + String distance = LocationUtils.getDistanceString( Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), Double.parseDouble(o.getLng()), Double.parseDouble(o.getLat())); - homeVO.setDistances(distance.toString()); + homeVO.setDistances(distance); } homeVO.setProductName(o.getProName()); homeVO.setImage(o.getProImg()); @@ -297,12 +297,15 @@ public class ProductService { productInfo.setShopNum(i); } productInfo.setPhone(tbShopInfo.getPhone()); + productInfo.setLat(tbShopInfo.getLat()); + productInfo.setLng(tbShopInfo.getLng()); productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "至" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime()); - BigDecimal distance = LocationUtils.getDistanceFrom2LngLat( + String distance = LocationUtils.getDistanceString( Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(tbShopInfo.getLng()), Double.parseDouble(tbShopInfo.getLat())); - productInfo.setDistances(distance.toString());//距离 + productInfo.setDistances(distance);//距离 productInfo.setAddress(tbShopInfo.getAddress()); + productInfo.setDistricts(tbShopInfo.getDistricts()); List productVos = JSONUtil.parseListTNewList(tbProduct.getGroupSnap(), ProductVo.class); for (ProductVo productVo : productVos) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index c733b2c..65565ad 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -17,6 +17,7 @@ import static java.lang.Math.sin; public class LocationUtils { /** * 通过Ip获取定位信息 + * * @param ip * @return */ @@ -24,7 +25,7 @@ public class LocationUtils { Map param = new HashMap<>(); //超掌柜生活-用户端 param.put("key", "7a7f2e4790ea222660a027352ee3af39"); - if(StringUtils.isNotBlank(ip)){ + if (StringUtils.isNotBlank(ip)) { param.put("ip", ip); } String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/ip", param); @@ -36,7 +37,7 @@ public class LocationUtils { */ public static JsonNode geocode(String location) { RestTemplate restTemplate = new RestTemplate(); - String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location="+location, String.class); + String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location=" + location, String.class); ObjectMapper objectMapper = new ObjectMapper(); // 将 JSON 字符串解析为 JsonNode 对象 try { @@ -49,6 +50,7 @@ public class LocationUtils { /** * 行政区域查询 + * * @param keywords * @return */ @@ -83,12 +85,21 @@ public class LocationUtils { double a = radLat1 - radLat2; double b = radLng1 - radLng2; - double dis= 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137; + double dis = 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137; BigDecimal bigDecimalValue = new BigDecimal(dis); bigDecimalValue = bigDecimalValue.setScale(3, RoundingMode.DOWN); return bigDecimalValue; } + public static String getDistanceString(double lng1, double lat1, double lng2, double lat2) { + BigDecimal distance = getDistanceFrom2LngLat(lng1, lat1, lng2, lat2); + if (distance.compareTo(BigDecimal.ONE) < 0) { + return distance.multiply(new BigDecimal(1000)) + "m"; + } else { + return distance + "km"; + } + } + /** * @param longitude 经度 108 * @param latitude 纬度 34 @@ -128,14 +139,13 @@ public class LocationUtils { } - - /** * 将角度转化为弧度 */ public static double radians(double d) { return d * Math.PI / 180.0; } + //1KM public static void main(String[] args) { Map stringMap = returnLLSquarePoint(108.975418, 34.280890, "5"); diff --git a/src/main/resources/mapper/TbShopInfoMapper.xml b/src/main/resources/mapper/TbShopInfoMapper.xml index 9ed5468..ff6c738 100644 --- a/src/main/resources/mapper/TbShopInfoMapper.xml +++ b/src/main/resources/mapper/TbShopInfoMapper.xml @@ -48,6 +48,9 @@ + + + @@ -60,7 +63,7 @@ detail, lat, lng, mch_id, register_type, is_wx_ma_independent, address, city, type, industry, industry_name, business_start_day,business_end_day,business_time, post_time, post_amount_line, on_sale, settle_type, settle_time, enter_at, expire_at, status, average, order_wait_pay_minute, support_device_number, - distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq + distribute_level, created_at, updated_at, proxy_id, shop_qrcode, tag,is_open_yhq,provinces,cities,districts view From 879f4307bd8a9ef0871fbcb429fb01c302a3d678 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 May 2024 09:25:45 +0800 Subject: [PATCH 044/134] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=95=86=E5=AE=B6=E7=BB=8F=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E5=8F=8A=E6=89=80=E5=B1=9E=E5=9C=B0=E5=8C=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/entity/vo/HomeVO.java | 8 ++++++++ .../system/cashierservice/entity/vo/ShopGroupInfoVo.java | 1 + .../system/cashierservice/service/ProductService.java | 1 + src/main/resources/mapper/TbProductMapper.xml | 2 ++ 4 files changed, 12 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index 033cfcb..d770df2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -59,6 +59,7 @@ public class HomeVO { * 距离 */ private String distances ="100"; + private String districts; private Integer id; /** @@ -122,6 +123,13 @@ public class HomeVO { this.shopName = shopName; } + public String getDistricts() { + return districts; + } + + public void setDistricts(String districts) { + this.districts = districts; + } public String getProductName() { return productName; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopGroupInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopGroupInfoVo.java index aa13629..3adef0a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopGroupInfoVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopGroupInfoVo.java @@ -29,6 +29,7 @@ public class ShopGroupInfoVo { private Integer number; private String address; + private String districts; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 4458dc6..744c032 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -194,6 +194,7 @@ public class ProductService { homeVO.setId(o.getProId()); homeVO.setShopName(o.getShopName()); homeVO.setShopImage(o.getShopImg()); + homeVO.setDistricts(o.getDistricts()); if (StringUtils.isBlank(o.getShopTag())) { homeVO.setShopTag(new ArrayList<>()); } else { diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 428ef66..b275b2c 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -949,6 +949,7 @@ info.tag AS shopTag, info.lat AS lat, info.lng AS lng, + info.districts as districts, pro.id AS proId, pro.`name` AS proName, pro.cover_img AS proImg, @@ -992,6 +993,7 @@ info.tag AS shopTag, info.lat AS lat, info.lng AS lng, + info.districts as districts, pro.id AS proId, pro.`name` AS proName, pro.cover_img AS proImg, From 31d3a65c0054afbbedfe893e761aba05ccfa2207 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 May 2024 09:56:14 +0800 Subject: [PATCH 045/134] =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E4=B8=BAm=20=E4=B8=8D=E4=BF=9D=E7=95=99=E5=B0=8F=E6=95=B0=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=BAKm=20=E4=BF=9D=E7=95=99=E4=B8=80?= =?UTF-8?q?=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/util/LocationUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index 65565ad..265f2bb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -87,14 +87,14 @@ public class LocationUtils { double dis = 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137; BigDecimal bigDecimalValue = new BigDecimal(dis); - bigDecimalValue = bigDecimalValue.setScale(3, RoundingMode.DOWN); + bigDecimalValue = bigDecimalValue.setScale(1, RoundingMode.DOWN); return bigDecimalValue; } public static String getDistanceString(double lng1, double lat1, double lng2, double lat2) { BigDecimal distance = getDistanceFrom2LngLat(lng1, lat1, lng2, lat2); if (distance.compareTo(BigDecimal.ONE) < 0) { - return distance.multiply(new BigDecimal(1000)) + "m"; + return distance.multiply(new BigDecimal(1000)).setScale(0, RoundingMode.DOWN) + "m"; } else { return distance + "km"; } From 6a2efde318fa6b4a23bf5dad6ec99c8d1a66a21d Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Fri, 17 May 2024 10:02:39 +0800 Subject: [PATCH 046/134] =?UTF-8?q?=E6=88=91=E5=BE=97=E5=85=8D=E5=8D=95?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 6 ++++++ .../cashierservice/dao/TbOrderInfoMapper.java | 1 + .../system/cashierservice/entity/TbOrderInfo.java | 3 ++- .../cashierservice/service/OrderService.java | 15 +++++++++++++++ src/main/resources/mapper/TbOrderInfoMapper.xml | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index c47df9f..3025813 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -76,6 +76,12 @@ public class OrderController { private Result findWiningUser(){ return orderService.findWiningUser(); } + @GetMapping("/mineWinner") + private Result mineWinner(@RequestHeader String token,@RequestParam Integer userId, + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, + @RequestParam(value = "size", required = false, defaultValue = "1") Integer size){ + return orderService.mineWinner(userId,page,size); + } @GetMapping("/getYhqPara") private Result getYhqPara(){ return orderService.getYhqPara(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java index 3419c7c..20d3776 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbOrderInfoMapper.java @@ -33,4 +33,5 @@ public interface TbOrderInfoMapper { List selectByTradeDay(@Param("day") String day,@Param("minPrice") BigDecimal minPrice,@Param("maxPrice") BigDecimal maxPrice); + List selectWinnerByUserId(@Param("userId")Integer userId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index 4ca654d..f64eebd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -99,7 +99,8 @@ public class TbOrderInfo implements Serializable { private String isUseCoupon; private Integer totalNumber; private List detailList; - + private String winnnerNo; + private String isWinner; private static final long serialVersionUID = 1L; public TbOrderInfo(){ super(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index f4eeaa5..f0b89d0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.RedisUtils; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -383,4 +384,18 @@ public class OrderService { modityDouble(conponsId); } } + + public Result mineWinner(Integer userId, Integer page, Integer size) { + PageHelper.startPage(page, size); + List list = orderInfoMapper.selectWinnerByUserId(userId); + for (TbOrderInfo tbOrderInfo:list){ + if (StringUtils.isNotEmpty(tbOrderInfo.getWinnnerNo())){ + tbOrderInfo.setIsWinner("true"); + }else { + tbOrderInfo.setIsWinner("false"); + } + } + PageInfo pageInfo = new PageInfo(list); + return Result.success(CodeEnum.SUCCESS, pageInfo); + } } diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index ea03dba..bbbbdbc 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -560,4 +560,9 @@ select tio1.* from tb_order_info tio1 where not EXISTS (SELECT 1 FROM `tb_order_info` toi2 where toi2.order_type = 'return' and toi2.source = tio1.id) and tio1.trade_day = #{day} and status = 'closed' and tio1.pay_amount >= #{minPrice} and tio1.pay_amount < #{maxPrice} and tio1.order_type = 'miniapp' + \ No newline at end of file From 77d9a9ef25e204171b865d15a8daa6be111c6e9f Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 May 2024 10:11:00 +0800 Subject: [PATCH 047/134] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ProductService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 744c032..2162aad 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -275,16 +275,23 @@ public class ProductService { //价格组装 for (TbProductSku tbProductSku : productSku.get()) { - //原价 + //售价 if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO) == 0) { - productInfo.setOriginPrice(BigDecimal.ZERO); - productInfo.setDiscount(BigDecimal.ZERO); + if(tbProductSku.getOriginPrice().compareTo(BigDecimal.ZERO) == 0){ + productInfo.setOriginPrice(BigDecimal.ZERO); + productInfo.setDiscount(BigDecimal.ZERO); + productInfo.setSalePrice(BigDecimal.ZERO); + }else { + productInfo.setOriginPrice(tbProductSku.getOriginPrice()); + productInfo.setDiscount(BigDecimal.ZERO); + productInfo.setSalePrice(tbProductSku.getOriginPrice()); + } } else { - productInfo.setOriginPrice(tbProductSku.getSalePrice()); + productInfo.setOriginPrice(tbProductSku.getOriginPrice()); productInfo.setDiscount(BigDecimalUtils.getDiscount(tbProductSku.getOriginPrice(), tbProductSku.getSalePrice())); + //现价 + productInfo.setSalePrice(tbProductSku.getSalePrice()); } - //现价 - productInfo.setSalePrice(new BigDecimal(tbProductSku.getSalePrice().toString())); } //销量 productInfo.setRealSalesNumber(new BigDecimal(tbProduct.getRealSalesNumber())); From d09299d5840248166399f13640cc205a59f33ffe Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Fri, 17 May 2024 14:09:13 +0800 Subject: [PATCH 048/134] =?UTF-8?q?=E6=88=91=E5=BE=97=E5=85=8D=E5=8D=95?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/OrderService.java | 4 ++++ src/main/resources/mapper/TbOrderInfoMapper.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index f0b89d0..36881b7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -25,6 +25,7 @@ import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Objects; @@ -396,6 +397,9 @@ public class OrderService { } } PageInfo pageInfo = new PageInfo(list); + if (page > pageInfo.getPages()) { + pageInfo.setList(Collections.emptyList()); + } return Result.success(CodeEnum.SUCCESS, pageInfo); } } diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index bbbbdbc..1a0f845 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -563,6 +563,6 @@ \ No newline at end of file From 8ce08d18a3f3adf7177be48692916dc6f525d90e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 May 2024 14:25:58 +0800 Subject: [PATCH 049/134] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E4=B8=8A=E6=96=B0=20?= =?UTF-8?q?=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/HomePageService.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 6959f87..6202fc0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -65,15 +65,6 @@ public class HomePageService { * 销量榜 */ List homeVOs = productSkuMapper.selectSale(); - for (HomeVO o : homeVOs) { - BigDecimal originPrice = o.getOriginPrice(); - if (originPrice.compareTo(BigDecimal.ZERO) != 0) { - o.setDiscount(BigDecimalUtils.getDiscount(o.getOriginPrice(),o.getSalePrice())); - } else { - o.setDiscount(null); - } - } - HotRankingVO hotRankingVO = new HotRankingVO(); hotRankingVO.setHotList(homeVOs); homeUpVO.setSalesList(hotRankingVO); @@ -81,6 +72,14 @@ public class HomePageService { *每日榜 */ List homeVODay = productSkuMapper.selectDay(); + for (HomeVO o : homeVODay) { + BigDecimal originPrice = o.getOriginPrice(); + if (originPrice.compareTo(BigDecimal.ZERO) != 0) { + o.setDiscount(BigDecimalUtils.getDiscount(o.getOriginPrice(),o.getSalePrice())); + } else { + o.setDiscount(null); + } + } TodayRankingVO todayRankingVO = new TodayRankingVO(); todayRankingVO.setTodayList(homeVODay); homeUpVO.setTodayList(todayRankingVO); From 1da6507162bca299acae0120b03203c76d63aa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 17 May 2024 16:59:25 +0800 Subject: [PATCH 050/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/TbMerchantThirdApply.java | 23 ++++++ .../cashierservice/service/PayService.java | 82 ++++++++++++------- .../system/cashierservice/util/DateUtils.java | 8 ++ .../mapper/TbMerchantThirdApplyMapper.xml | 4 +- 4 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantThirdApply.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantThirdApply.java index b3c7922..8e9901e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantThirdApply.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbMerchantThirdApply.java @@ -21,6 +21,13 @@ public class TbMerchantThirdApply implements Serializable { private String appToken; + private String smallAppid; + + private String storeId; + + + + private static final long serialVersionUID = 1L; public Integer getId() { @@ -94,4 +101,20 @@ public class TbMerchantThirdApply implements Serializable { public void setAppToken(String appToken) { this.appToken = appToken == null ? null : appToken.trim(); } + + public String getSmallAppid() { + return smallAppid; + } + + public void setSmallAppid(String smallAppid) { + this.smallAppid = smallAppid; + } + + public String getStoreId() { + return storeId; + } + + public void setStoreId(String storeId) { + this.storeId = storeId; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 62c5fc7..0feff17 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -21,10 +21,7 @@ import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; import com.chaozhanggui.system.cashierservice.thirdpay.resp.WxScanPayResp; import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; -import com.chaozhanggui.system.cashierservice.util.BeanUtil; -import com.chaozhanggui.system.cashierservice.util.MD5Util; -import com.chaozhanggui.system.cashierservice.util.N; -import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; +import com.chaozhanggui.system.cashierservice.util.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -236,7 +233,7 @@ public class PayService { reqbody=body.toString(); } - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"wx212769170d2c6b2a","wx212769170d2c6b2a",openId,ip,orderInfo.getOrderNo(),"S2405103298",callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,orderInfo.getOrderNo(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); @@ -385,7 +382,7 @@ public class PayService { reqbody=body.toString(); } - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"wx212769170d2c6b2a","wx212769170d2c6b2a",userId,ip,orderInfo.getOrderNo(),"S2405103298",callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip,orderInfo.getOrderNo(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); @@ -430,6 +427,7 @@ public class PayService { } TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(groupOrderInfo.getMerchantId()); MsgException.checkNull(thirdApply, "支付参数配置错误"); + ReturnOrderReq req = new ReturnOrderReq(); req.setAppId(thirdApply.getAppId()); req.setTimestamp(System.currentTimeMillis()); @@ -547,7 +545,7 @@ public class PayService { } } }else { - PublicResp publicResp=thirdPayService.queryOrder(thirdUrl,thirdApply.getAppId(),orderInfo.getOrderNo(),null,thirdApply.getAppToken()); + PublicResp publicResp=thirdPayService.queryOrder(thirdUrl,thirdApply.getAppId(),payment.getTradeNumber(),null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ String cartStatus=""; @@ -641,37 +639,59 @@ public class PayService { tbMemberInMapper.insert(memberIn); + if("ysk".equals(thirdPayType)){ + PayReq req=new PayReq(); - PayReq req=new PayReq(); - - req.setAppId(thirdApply.getAppId()); - req.setTimestamp(System.currentTimeMillis()); - req.setIp(ip); - req.setMercOrderNo(SnowFlakeUtil.generateOrderNo()); - req.setNotifyUrl(callBackIn); - req.setPayAmt(amount); - req.setPayType("03"); - req.setPayWay("WXZF"); - req.setSubject("充值"); - req.setUserId(openId); + req.setAppId(thirdApply.getAppId()); + req.setTimestamp(System.currentTimeMillis()); + req.setIp(ip); + req.setMercOrderNo(SnowFlakeUtil.generateOrderNo()); + req.setNotifyUrl(callBackIn); + req.setPayAmt(amount); + req.setPayType("03"); + req.setPayWay("WXZF"); + req.setSubject("充值"); + req.setUserId(openId); - Map map= BeanUtil.transBeanMap(req); - req.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); + Map map= BeanUtil.transBeanMap(req); + req.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); - ResponseEntity response= restTemplate.postForEntity(url.concat("trans/pay"),req,String.class); - if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){ - JSONObject object=JSONObject.parseObject(response.getBody()); - if(object.get("code").equals("0")){ - memberIn.setOrderNo(object.getJSONObject("data").get("orderNumber").toString()); - memberIn.setUpdateTime(new Date()); - tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + ResponseEntity response= restTemplate.postForEntity(url.concat("trans/pay"),req,String.class); + if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())){ + JSONObject object=JSONObject.parseObject(response.getBody()); + if(object.get("code").equals("0")){ + memberIn.setOrderNo(object.getJSONObject("data").get("orderNumber").toString()); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - return Result.success(CodeEnum.SUCCESS,object.getJSONObject("data")); - }else { - return Result.fail(object.getString("msg")); + return Result.success(CodeEnum.SUCCESS,object.getJSONObject("data")); + }else { + return Result.fail(object.getString("msg")); + } + } + }else { + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip, DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); + if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ + if("000000".equals(publicResp.getCode())){ + WxScanPayResp wxScanPayResp= publicResp.getObjData(); + if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + + memberIn.setOrderNo(wxScanPayResp.getPayOrderId()); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + + return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); + + + }else{ + return Result.fail(publicResp.getMsg()); + } + } } } + + return Result.fail("失败"); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java index c8d783f..809d0ff 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -25,6 +25,8 @@ public class DateUtils { private final static SimpleDateFormat sdfTimeSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss"); + private final static SimpleDateFormat sdfTimesSS = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + private final static SimpleDateFormat sdfday = new SimpleDateFormat("MM-dd HH:mm"); @@ -77,6 +79,12 @@ public class DateUtils { } + + public static String getsdfTimesSS(){ + return sdfTimesSS.format(new Date()); + } + + public static String getNextSdfTimes(Date date){ return sdfTimes.format(date); } diff --git a/src/main/resources/mapper/TbMerchantThirdApplyMapper.xml b/src/main/resources/mapper/TbMerchantThirdApplyMapper.xml index d9782c3..619e306 100644 --- a/src/main/resources/mapper/TbMerchantThirdApplyMapper.xml +++ b/src/main/resources/mapper/TbMerchantThirdApplyMapper.xml @@ -10,12 +10,14 @@ + + - id, type, app_id, status, pay_password, applyment_state, created_at, updated_at + id, type, app_id, status, pay_password, applyment_state, created_at, updated_at,small_appid,store_id app_token From 5e1c3676fa81a8a1790e2fd204730d3b7ed12596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 17 May 2024 17:48:18 +0800 Subject: [PATCH 051/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 0feff17..ba8b8de 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -233,7 +233,7 @@ public class PayService { reqbody=body.toString(); } - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,orderInfo.getOrderNo(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); From 3f1839aaab143d543dc6c723c1267ce29827a379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 10:40:44 +0800 Subject: [PATCH 052/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/NotifyController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index a6f3a98..3dbb336 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -46,6 +46,16 @@ public class NotifyController { return null; } + @RequestMapping("fstmemberInCallBack") + public String fstmemberInCallBack(HttpServletRequest request){ + Map map= getParameterMap(request); + log.info("fstmemberInCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); + + + return null; + + } + @RequestMapping("notifyCallBack") public String notifyCallBack(HttpServletRequest request){ From 1aea7ba5bae4a9e89196447368495fc34dc4c62f Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Mon, 20 May 2024 15:21:57 +0800 Subject: [PATCH 053/134] =?UTF-8?q?=E6=88=91=E5=BE=97=E5=85=8D=E5=8D=95?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 1 + .../controller/LoginContoller.java | 20 ++++++++++++++++++- .../controller/OrderController.java | 4 ++++ .../cashierservice/entity/TbWiningUser.java | 2 +- .../cashierservice/rabbit/CartConsumer.java | 1 + .../cashierservice/service/CartService.java | 10 +++------- .../service/IntegralService.java | 7 ++++++- .../cashierservice/service/OrderService.java | 10 +++++++++- .../cashierservice/service/UserService.java | 2 +- .../socket/AppWebSocketServer.java | 6 ++++-- .../resources/mapper/TbUserInfoMapper.xml | 1 - 11 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 50ed2c2..c30176a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -42,6 +42,7 @@ public class LoginFilter implements Filter { "cashierService/location/**",//高德 获取行政区域 "cashierService/home/homePageUp",//首页上半 "cashierService/home",//首页 + "cashierService/order/testMessage",//首页 "cashierService/common/**",//通用接口 "cashierService/distirict/**",//首页其它接口 "cashierService/login/**",//登录部分接口不校验 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index d3606b5..1444142 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -271,7 +271,25 @@ public class LoginContoller { } } - + @PostMapping(value = "modityPass") + public Result modityPass(@RequestHeader String token,@RequestBody UserPassDto passVo){ + String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + String newPass = MD5Utils.MD5Encode(passVo.getNewPass(), "utf-8"); + if (ObjectUtil.isNull(passVo.getCode())) { + String oldPass = MD5Utils.MD5Encode(passVo.getOldPass(), "utf-8"); + return loginService.upPass(userId,oldPass, newPass); + } else { + boolean tf = loginService.validate(passVo.getCode(), passVo.getPhone()); + if (tf) { + TbUserInfo userInfo=new TbUserInfo(); + userInfo.setId(Integer.valueOf(userId)); + userInfo.setPassword(newPass); + return loginService.upUserInfo(userInfo); + } else { + return Result.fail("验证码输入有误"); + } + } + } /** * 用户注册 * phone 手机号 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 3025813..57a86d2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -94,4 +94,8 @@ public class OrderController { private Result yhqDouble(@RequestParam Integer conponsId){ return orderService.yhqDouble(conponsId); } + @GetMapping("/kc") + private Result kc(){ + return orderService.kc(); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java index 6fdc83b..3855259 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbWiningUser.java @@ -45,7 +45,7 @@ public class TbWiningUser implements Serializable { this.orderAmount = orderAmount; this.isUser = isUser; this.tradeDay = tradeDay; - this.isRefund = "false"; + this.isRefund = "true"; this.refundAmount = BigDecimal.ZERO; this.refundPayType = "WX"; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index 6a01041..08a4fea 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -33,6 +33,7 @@ public class CartConsumer { JSONObject jsonObject = JSON.parseObject(message); String tableId = jsonObject.getString("tableId"); String shopId = jsonObject.getString("shopId"); + log.info("推送信息"+jsonObject.toJSONString()); if (jsonObject.getString("type").equals("addcart") ) { if (!jsonObject.containsKey("num")) { throw new MsgException("商品数量错误"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index dd404c1..d16335f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -196,8 +196,7 @@ public class CartService { } @Transactional(rollbackFor = Exception.class) - public void createOrder(JSONObject jsonObject) throws IOException { - try { + public void createOrder(JSONObject jsonObject) throws Exception { String shopId = jsonObject.getString("shopId"); JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); List ids = new ArrayList<>(); @@ -212,13 +211,13 @@ public class CartService { Integer orderId = 0; TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); if (tbMerchantAccount == null) { - throw new MsgException("生成订单错误"); + MsgException.throwException("生成订单错误"); } String userId = jsonObject.getString("userId"); TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); if (tbUserInfo == null) { - throw new MsgException("生成订单失败"); + MsgException.throwException("生成订单失败"); } for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); @@ -408,9 +407,6 @@ public class CartService { jsonObject12.put("data", new JSONArray()); AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); - } catch (Exception e) { - e.getMessage(); - } } private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java index b9e520e..3d948da 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/IntegralService.java @@ -28,7 +28,7 @@ public class IntegralService { @Autowired private TbOrderInfoMapper orderInfoMapper; @Autowired - private TbCashierCartMapper cashierCartMapper; + private TbUserInfoMapper userInfoMapper; @Autowired private TbProductMapper productMapper; @Autowired @@ -65,6 +65,11 @@ public class IntegralService { integralFlow.setType("TRADEADD"); integralFlow.setUserId(userCoupons.getUserId()); integralFlowMapper.insert(integralFlow); + TbUserInfo userInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userCoupons.getUserId())); + if (Objects.nonNull(userInfo)){ + userInfo.setTotalScore(userInfo.getTotalScore() + integralFlow.getNum().intValue()); + userInfoMapper.updateByPrimaryKeySelective(userInfo); + } }else { Integer orderId = jsonObject.getInteger("orderId"); TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 36881b7..c1e1477 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -242,7 +242,7 @@ public class OrderService { List list = productSkuMapper.selectAll(); for (TbProductSku productSku : list) { // productSku.setStockNumber(200.00); - redisUtil.saveMessage("PRODUCT:" + productSku.getShopId() + ":" + productSku.getId(), productSku.getStockNumber().intValue() + ""); + redisUtil.saveMessage("PRODUCT:" + productSku.getShopId() + ":" + productSku.getId(), "10000"); } } @@ -402,4 +402,12 @@ public class OrderService { } return Result.success(CodeEnum.SUCCESS, pageInfo); } + + public Result kc() { + List list = productSkuMapper.selectAll(); + for (TbProductSku productSku:list){ + redisUtil.saveMessage(RedisCst.PRODUCT + productSku.getShopId() + ":" +productSku.getId(),"10000"); + } + return Result.success(CodeEnum.SUCCESS); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index f722e9e..acc7811 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -107,7 +107,7 @@ public class UserService { tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue()); } } else if (type.equals("add")) { - tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue()); + tbShopUser.setTotalScore(tbShopUser.getTotalScore() + num.intValue()); } if (flag) { TbReleaseFlow releaseFlow = new TbReleaseFlow(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index eac5be3..b436b5f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -90,6 +90,7 @@ public class AppWebSocketServer { this.tableId = tableId; this.shopId = shopId; this.userId = userId; + log.info("链接桌码:"+tableId); try { TbShopTable shopTable = shopTableMapper.selectQRcode(tableId); if (Objects.isNull(shopTable)) { @@ -185,7 +186,7 @@ public class AppWebSocketServer { @OnMessage public void onMessage(String message, Session session) { - System.out.println(message); + log.info("接收消息:"+message); //可以群发消息 //消息保存到数据库、redis if (StringUtils.isNotBlank(message) && !message.equals("undefined")) { @@ -198,7 +199,8 @@ public class AppWebSocketServer { //追加发送人(防止串改) jsonObject.put("tableId", this.tableId); jsonObject.put("shopId", this.shopId); - + log.info("tableId:"+this.tableId); + log.info("shopId:"+this.shopId); //这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象 // ChangeHandler changeHandler = new ChangeHandler(); // CreateOrderHandler createOrderHandler = new CreateOrderHandler(); diff --git a/src/main/resources/mapper/TbUserInfoMapper.xml b/src/main/resources/mapper/TbUserInfoMapper.xml index adca258..7b650b3 100644 --- a/src/main/resources/mapper/TbUserInfoMapper.xml +++ b/src/main/resources/mapper/TbUserInfoMapper.xml @@ -590,5 +590,4 @@ - \ No newline at end of file From 1c3908a9ce0f3db94d5f3f4cd6ef2ff750ed4f4b Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 20 May 2024 15:29:02 +0800 Subject: [PATCH 054/134] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=9B=E5=BA=97?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=AE=B0=E5=BD=95=20=E5=9B=A2=E8=B4=AD?= =?UTF-8?q?=E5=8D=B7=E5=8D=B7=E7=A0=81=E6=8E=92=E5=BA=8F=20=E5=9B=A2?= =?UTF-8?q?=E8=B4=AD=E5=8D=B7=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GroupOrderInfoController.java | 2 +- .../controller/ProductController.java | 15 +++++-- .../cashierservice/service/PayService.java | 39 ++++++++++++++----- .../service/ProductService.java | 30 ++++++++++++-- .../mapper/TbGroupOrderCouponMapper.xml | 3 +- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java index e70e5f5..caccae2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java @@ -47,7 +47,7 @@ public class GroupOrderInfoController { */ @RequestMapping("getCoupon") public Result queryCouponById(Integer id) { - return Result.success(CodeEnum.SUCCESS,orderCouponService.queryByOrderId(id)); + return Result.success(CodeEnum.SUCCESS,orderCouponService.queryNoRefundByOrderId(id)); } /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index c241d63..d6ede94 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -2,8 +2,10 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.service.ProductService; import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.TokenUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -23,16 +25,21 @@ public class ProductController { /** * 通过桌码获取shopId + * * @param code * @return shopid */ @RequestMapping("queryShopIdByTableCode") - public Result queryShopIdByTableCode(@RequestParam("code") String code) { - return productService.queryShopIdByTableCode(code); + public Result queryShopIdByTableCode(@RequestHeader String token, @RequestParam("code") String code) { + JSONObject jsonObject = TokenUtil.parseParamFromToken(token); + String userId = jsonObject.getString("userId"); + String openId = jsonObject.getString("openId"); + return productService.queryShopIdByTableCode(userId, openId, code); } /** * 通过code和分组Id + * * @param map * @return */ @@ -66,7 +73,7 @@ public class ProductController { @RequestParam String lat, @RequestParam String lng, @RequestHeader String environment) throws Exception { - return productService.productInfo(productId,lat,lng,environment); + return productService.productInfo(productId, lat, lng, environment); } /** @@ -76,6 +83,6 @@ public class ProductController { public Result orderConfirm( @RequestParam Integer productId, @RequestHeader String environment) throws Exception { - return productService.orderConfirm(productId,environment); + return productService.orderConfirm(productId, environment); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index ba8b8de..6263cf1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -22,6 +22,8 @@ import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; import com.chaozhanggui.system.cashierservice.thirdpay.resp.WxScanPayResp; import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; import com.chaozhanggui.system.cashierservice.util.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -271,7 +273,7 @@ public class PayService { } @Transactional(rollbackFor = Exception.class) - public Result groupOrderPay(String orderId, String payType, String userId, String ip) { + public Result groupOrderPay(String orderId, String payType, String userId, String ip) throws JsonProcessingException { TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.queryById(Integer.valueOf(orderId)); if (!"unpaid".equals(orderInfo.getStatus())) { @@ -370,7 +372,7 @@ public class PayService { tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); } else { - return Result.fail(object.getString("msg")); + return Result.fail("支付失败"); } } }else { @@ -381,12 +383,28 @@ public class PayService { }else { reqbody=body.toString(); } - - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip,orderInfo.getOrderNo(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay( + thirdUrl, + thirdApply.getAppId(), + reqbody, + reqbody, + payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(), + "WECHAT", + thirdApply.getSmallAppid(), + userId, + ip, +// orderInfo.getOrderNo(), + DateUtils.getsdfTimesSS(), + thirdApply.getStoreId(), + callBackGroupurl, + null, + thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); - if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + log.info("团购订单下单结果2:{}",wxScanPayResp); +// if("TRADE_SUCCESS".equals(wxScanPayResp.getState())||"TRADE_AWAIT".equals(wxScanPayResp.getState())){ + if("TRADE_AWAIT".equals(wxScanPayResp.getState())){ payment.setTradeNumber(wxScanPayResp.getPayOrderId()); payment.setUpdatedAt(System.currentTimeMillis()); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); @@ -400,10 +418,13 @@ public class PayService { jsonObject1.put("data", new JSONArray()); jsonObject1.put("amount", 0); tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); - return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); - }else{ - return Result.fail(publicResp.getMsg()); + ObjectMapper mapper = new ObjectMapper(); + return Result.success(CodeEnum.SUCCESS,mapper.readTree(wxScanPayResp.getPayInfo())); + } else{ + return Result.fail(wxScanPayResp.getNote()); } + }else { + return Result.fail(publicResp.getMsg()); } } } @@ -411,7 +432,7 @@ public class PayService { } @Transactional(rollbackFor = Exception.class) - public Result returnOrder(ReturnGroupOrderDto param) { + public Result returngroupOrder(ReturnGroupOrderDto param) { TbGroupOrderInfo groupOrderInfo = tbGroupOrderInfoMapper.queryById(param.getOrderId()); List tbGroupOrderCoupons = orderCouponService.queryNoRefundByOrderId(param.getOrderId()); if (param.getNum() > tbGroupOrderCoupons.size()) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 2162aad..55f09fe 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -62,11 +62,35 @@ public class ProductService { @Autowired TbProductSkuMapper tbProductSkuMapper; - public Result queryShopIdByTableCode(String code) { + @Autowired + private TbShopUserMapper tbShopUserMapper; + + public Result queryShopIdByTableCode(String userId,String openId,String code) { String shopId = tbShopTableMapper.queryShopIdByTableCode(code); if (StringUtils.isBlank(shopId)) { return Result.fail("台桌信息不存在"); } + + TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); + if (ObjectUtil.isEmpty(tbShopUser)) { + tbShopUser = new TbShopUser(); + tbShopUser.setAmount(BigDecimal.ZERO); + tbShopUser.setCreditAmount(BigDecimal.ZERO); + tbShopUser.setConsumeAmount(BigDecimal.ZERO); + tbShopUser.setConsumeNumber(0); + tbShopUser.setLevelConsume(BigDecimal.ZERO); + tbShopUser.setStatus(Byte.parseByte("1")); + tbShopUser.setShopId(shopId); + tbShopUser.setUserId(userId); + tbShopUser.setMiniOpenId(openId); + tbShopUser.setIsPwd("1"); + tbShopUser.setCreatedAt(System.currentTimeMillis()); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.insert(tbShopUser); + } else { + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } return Result.success(CodeEnum.SUCCESS, shopId); } @@ -277,11 +301,11 @@ public class ProductService { for (TbProductSku tbProductSku : productSku.get()) { //售价 if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO) == 0) { - if(tbProductSku.getOriginPrice().compareTo(BigDecimal.ZERO) == 0){ + if (tbProductSku.getOriginPrice().compareTo(BigDecimal.ZERO) == 0) { productInfo.setOriginPrice(BigDecimal.ZERO); productInfo.setDiscount(BigDecimal.ZERO); productInfo.setSalePrice(BigDecimal.ZERO); - }else { + } else { productInfo.setOriginPrice(tbProductSku.getOriginPrice()); productInfo.setDiscount(BigDecimal.ZERO); productInfo.setSalePrice(tbProductSku.getOriginPrice()); diff --git a/src/main/resources/mapper/TbGroupOrderCouponMapper.xml b/src/main/resources/mapper/TbGroupOrderCouponMapper.xml index cd8a5c6..fd5c455 100644 --- a/src/main/resources/mapper/TbGroupOrderCouponMapper.xml +++ b/src/main/resources/mapper/TbGroupOrderCouponMapper.xml @@ -32,6 +32,7 @@ from tb_group_order_coupon where order_id = #{orderId} + order by is_refund From 7c5433b2cc6fdd13e6a3e45f90520d2516195f85 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 20 May 2024 15:50:36 +0800 Subject: [PATCH 055/134] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E5=8D=B7=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 98135c4..f98e837 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -55,7 +55,7 @@ mybatis: ysk: url: https://gatewaytestapi.sxczgkj.cn/gate-service/ callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack - callBackGroupurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBackGroup + callBackGroupurl: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 server: From 7cabb2a109c1489bd2a3963c2e76a30018390462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 15:57:50 +0800 Subject: [PATCH 056/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/dao/TbActivateMapper.java | 26 ++++ .../cashierservice/entity/TbActivate.java | 78 +++++++++++ .../cashierservice/service/PayService.java | 103 ++++++++++++++- .../service/ProductService.java | 3 +- .../thirdpay/service/ThirdPayService.java | 2 +- src/main/resources/application.yml | 2 +- .../generator-mapper/generatorConfig.xml | 8 +- .../resources/mapper/TbActivateMapper.xml | 121 ++++++++++++++++++ 8 files changed, 334 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java create mode 100644 src/main/resources/mapper/TbActivateMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java new file mode 100644 index 0000000..2b8505e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java @@ -0,0 +1,26 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbActivate; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; + +@Component +@Mapper +public interface TbActivateMapper { + int deleteByPrimaryKey(Integer id); + + int insert(TbActivate record); + + int insertSelective(TbActivate record); + + TbActivate selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(TbActivate record); + + int updateByPrimaryKey(TbActivate record); + + TbActivate selectByAmount(@Param("shopId") String shopId,@Param("amount") BigDecimal amount); +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java new file mode 100644 index 0000000..c223bfc --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java @@ -0,0 +1,78 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; + +public class TbActivate implements Serializable { + private Integer id; + + private Integer shopId; + + private Integer minNum; + + private Integer maxNum; + + private BigDecimal handselNum; + + private String handselType; + + private String isDel; + + private static final long serialVersionUID = 1L; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getShopId() { + return shopId; + } + + public void setShopId(Integer shopId) { + this.shopId = shopId; + } + + public Integer getMinNum() { + return minNum; + } + + public void setMinNum(Integer minNum) { + this.minNum = minNum; + } + + public Integer getMaxNum() { + return maxNum; + } + + public void setMaxNum(Integer maxNum) { + this.maxNum = maxNum; + } + + public BigDecimal getHandselNum() { + return handselNum; + } + + public void setHandselNum(BigDecimal handselNum) { + this.handselNum = handselNum; + } + + public String getHandselType() { + return handselType; + } + + public void setHandselType(String handselType) { + this.handselType = handselType == null ? null : handselType.trim(); + } + + public String getIsDel() { + return isDel; + } + + public void setIsDel(String isDel) { + this.isDel = isDel == null ? null : isDel.trim(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 6263cf1..653ddc4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -120,6 +120,8 @@ public class PayService { @Autowired ThirdPayService thirdPayService; + + @Resource private TbGroupOrderInfoMapper tbGroupOrderInfoMapper; @Autowired @@ -127,6 +129,9 @@ public class PayService { @Resource private GroupOrderCouponService orderCouponService; + @Autowired + TbActivateMapper tbActivateMapper; + @Transactional(rollbackFor = Exception.class) public Result payOrder(String openId,String orderId,String ip) throws Exception { @@ -630,8 +635,9 @@ public class PayService { return Result.fail("对应的用户信息不存在"); } - if(ObjectUtil.isEmpty(tbShopUser.getIsVip())||!"1".equals(tbShopUser.getIsVip().toString())){ - return Result.fail("非会员用户不允许充值"); + + if("0".equals(tbShopUser.getIsPwd())){ + return Result.fail("用户支付密码未设置"); } @@ -848,10 +854,103 @@ public class PayService { flow.setBalance(tbShopUser.getAmount()); flow.setCreateTime(new Date()); tbShopUserFlowMapper.insert(flow); + TbActivate activate= tbActivateMapper.selectByAmount(tbShopUser.getShopId(),memberIn.getAmount()); + if(ObjectUtil.isNotEmpty(activate)&&ObjectUtil.isNotNull(activate)){ + BigDecimal amount=BigDecimal.ZERO; + switch (activate.getHandselType()){ + case "GD": + amount=activate.getHandselNum(); + break; + case "RATIO": + amount=memberIn.getAmount().multiply(activate.getHandselNum()); + break; + } + + + tbShopUser.setAmount(tbShopUser.getAmount().add(amount)); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); + + flow=new TbShopUserFlow(); + flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); + flow.setBizCode("scanMemberAwardIn"); + flow.setBizName("会员充值奖励"); + flow.setAmount(amount); + flow.setBalance(tbShopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + } return "success"; } + + public String fstMemberInSuccess(String payOrderNO,String tradeNo){ + TbMemberIn memberIn= tbMemberInMapper.selectByOrderNo(payOrderNO); + if(ObjectUtil.isEmpty(memberIn)){ + return "充值记录不存在"; + } + + memberIn.setTradeNo(tradeNo); + memberIn.setStatus("0"); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + + TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(memberIn.getUserId().toString(),memberIn.getShopId().toString()); + if(ObjectUtil.isEmpty(tbShopUser)){ + return "用户信息不存在"; + } + + if(!"1".equals(tbShopUser.getIsVip().toString())){ + tbShopUser.setIsVip(Byte.parseByte("1")); + } + + //修改客户资金 + tbShopUser.setAmount(tbShopUser.getAmount().add(memberIn.getAmount())); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); + + TbShopUserFlow flow=new TbShopUserFlow(); + flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); + flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setAmount(memberIn.getAmount()); + flow.setBalance(tbShopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + TbActivate activate= tbActivateMapper.selectByAmount(tbShopUser.getShopId(),memberIn.getAmount()); + if(ObjectUtil.isNotEmpty(activate)&&ObjectUtil.isNotNull(activate)){ + BigDecimal amount=BigDecimal.ZERO; + switch (activate.getHandselType()){ + case "GD": + amount=activate.getHandselNum(); + break; + case "RATIO": + amount=memberIn.getAmount().multiply(activate.getHandselNum()); + break; + } + + + tbShopUser.setAmount(tbShopUser.getAmount().add(amount)); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); + + flow=new TbShopUserFlow(); + flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); + flow.setBizCode("scanMemberAwardIn"); + flow.setBizName("会员充值奖励"); + flow.setAmount(amount); + flow.setBalance(tbShopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + } + return "SUCCESS"; + } + + // public Result returnOrder(){ // // } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 55f09fe..54cbf19 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -83,7 +83,8 @@ public class ProductService { tbShopUser.setShopId(shopId); tbShopUser.setUserId(userId); tbShopUser.setMiniOpenId(openId); - tbShopUser.setIsPwd("1"); + tbShopUser.setPwd(MD5Util.encrypt("123456")); + tbShopUser.setIsPwd("0"); tbShopUser.setCreatedAt(System.currentTimeMillis()); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.insert(tbShopUser); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java index 2c0f05b..65b0d48 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java @@ -295,6 +295,6 @@ public class ThirdPayService { public static void main(String[] args) { -// mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI"); + new ThirdPayService().mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "132933158610062686", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://cashierclient.sxczgkj.cn/cashierService/notify/fstmemberInCallBack", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI"); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8a8c34d..5ebc9df 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -57,5 +57,5 @@ aliyun: thirdPay: payType: fushangtong - callBack: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay + callBack: https://cashierclient.sxczgkj.cn/${server.servlet.context-path}/notify/fstmemberInCallBack url: https://paymentapi.sxczgkj.cn diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index c908550..87787f8 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -6,7 +6,7 @@ - + @@ -19,8 +19,8 @@ - + @@ -52,7 +52,7 @@ -
diff --git a/src/main/resources/mapper/TbActivateMapper.xml b/src/main/resources/mapper/TbActivateMapper.xml new file mode 100644 index 0000000..0f29dcc --- /dev/null +++ b/src/main/resources/mapper/TbActivateMapper.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + id, shop_id, min_num, max_num, handsel_num, handsel_type, is_del + + + + delete from tb_activate + where id = #{id,jdbcType=INTEGER} + + + insert into tb_activate (id, shop_id, min_num, + max_num, handsel_num, handsel_type, + is_del) + values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{minNum,jdbcType=INTEGER}, + #{maxNum,jdbcType=INTEGER}, #{handselNum,jdbcType=DECIMAL}, #{handselType,jdbcType=VARCHAR}, + #{isDel,jdbcType=VARCHAR}) + + + insert into tb_activate + + + id, + + + shop_id, + + + min_num, + + + max_num, + + + handsel_num, + + + handsel_type, + + + is_del, + + + + + #{id,jdbcType=INTEGER}, + + + #{shopId,jdbcType=INTEGER}, + + + #{minNum,jdbcType=INTEGER}, + + + #{maxNum,jdbcType=INTEGER}, + + + #{handselNum,jdbcType=DECIMAL}, + + + #{handselType,jdbcType=VARCHAR}, + + + #{isDel,jdbcType=VARCHAR}, + + + + + update tb_activate + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + min_num = #{minNum,jdbcType=INTEGER}, + + + max_num = #{maxNum,jdbcType=INTEGER}, + + + handsel_num = #{handselNum,jdbcType=DECIMAL}, + + + handsel_type = #{handselType,jdbcType=VARCHAR}, + + + is_del = #{isDel,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_activate + set shop_id = #{shopId,jdbcType=INTEGER}, + min_num = #{minNum,jdbcType=INTEGER}, + max_num = #{maxNum,jdbcType=INTEGER}, + handsel_num = #{handselNum,jdbcType=DECIMAL}, + handsel_type = #{handselType,jdbcType=VARCHAR}, + is_del = #{isDel,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + + + \ No newline at end of file From 6991cbaa00ae943982db3a83279ddc52c8ec45ed Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 20 May 2024 16:15:03 +0800 Subject: [PATCH 057/134] =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E5=8D=B7=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotifyController.java | 47 ++++++++++++------- .../cashierservice/service/PayService.java | 2 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index 3dbb336..ee05bf0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -6,6 +6,7 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.chaozhanggui.system.cashierservice.interceptor.RequestWrapper; import com.chaozhanggui.system.cashierservice.service.PayService; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; @@ -14,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.HashMap; import java.util.Map; import java.util.Random; @@ -24,32 +27,30 @@ import java.util.Random; public class NotifyController { - - @Autowired PayService payService; @RequestMapping("memberInCallBack") - public String memberInCallBack(HttpServletRequest request){ + public String memberInCallBack(HttpServletRequest request) { - Map map= getParameterMap(request); - log.info("回调返回信息:{}",JSONUtil.toJsonStr(map)); - if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"200".equals(map.get("code")+"")){ - JSONObject object=JSONUtil.parseObj(map.get("data")); - if(ObjectUtil.isNotEmpty(object)&&object.containsKey("status")&&"1".equals(object.getStr("status"))){ - String orderNo=object.getStr("orderNumber"); - String channelTradeNo=object.getStr("channelTradeNo"); - return payService.minsuccess(orderNo,channelTradeNo); + Map map = getParameterMap(request); + log.info("回调返回信息:{}", JSONUtil.toJsonStr(map)); + if (ObjectUtil.isNotEmpty(map) && map.containsKey("code") && "200".equals(map.get("code") + "")) { + JSONObject object = JSONUtil.parseObj(map.get("data")); + if (ObjectUtil.isNotEmpty(object) && object.containsKey("status") && "1".equals(object.getStr("status"))) { + String orderNo = object.getStr("orderNumber"); + String channelTradeNo = object.getStr("channelTradeNo"); + return payService.minsuccess(orderNo, channelTradeNo); } } return null; } @RequestMapping("fstmemberInCallBack") - public String fstmemberInCallBack(HttpServletRequest request){ - Map map= getParameterMap(request); - log.info("fstmemberInCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); + public String fstmemberInCallBack(HttpServletRequest request) { + Map map = getParameterMap(request); + log.info("fstmemberInCallBack回调返回信息:{}", JSONUtil.toJsonStr(map)); return null; @@ -72,8 +73,8 @@ public class NotifyController { return null; } - @RequestMapping("notifyCallBackGroup") - public String notifyCallBackGroup(HttpServletRequest request){ + @RequestMapping("notifyCallBackGroupYsk") + public String notifyCallBackGroupYsk(HttpServletRequest request){ Map map= getParameterMap(request); log.info("团购卷回调返回信息:{}",JSONUtil.toJsonStr(map)); if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"200".equals(map.get("code")+"")){ @@ -83,10 +84,22 @@ public class NotifyController { return payService.callBackGroupPay(orderNo); } } - return null; } + @RequestMapping("notifyCallBackGroup") + public String notifyCallBackGroup(HttpServletRequest request) { + Map map = getParameterMap(request); + log.info("团购卷回调返回信息:{}", JSONUtil.toJsonStr(map)); + if (ObjectUtil.isNotEmpty(map) && map.containsKey("code") && "000000".equals(map.get("code") + "")) { + JSONObject object = JSONUtil.parseObj(map.get("bizData")); + if (ObjectUtil.isNotEmpty(object) && object.containsKey("state") && "TRADE_SUCCESS".equals(object.getStr("state"))) { + String orderNo = object.getStr("payOrderId"); + return payService.callBackGroupPay(orderNo); + } + } + return null; + } private Map getParameterMap(HttpServletRequest request) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 653ddc4..b499e3f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -340,7 +340,7 @@ public class PayService { req.setTimestamp(System.currentTimeMillis()); req.setIp(ip); req.setMercOrderNo(orderInfo.getOrderNo()); - req.setNotifyUrl(callBackGroupurl); + req.setNotifyUrl(callBackGroupurl+"Ysk"); req.setPayAmt(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString()); if (payType.equals("wechatPay")) { req.setPayType("03"); From 30ee2b1b8671252afac833781b38145f87a656d7 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 20 May 2024 16:24:43 +0800 Subject: [PATCH 058/134] =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E5=8D=B7=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=20=E6=94=AF=E4=BB=98=E6=97=B6=E9=97=B4=E5=9B=9E?= =?UTF-8?q?=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/NotifyController.java | 7 +++++-- .../system/cashierservice/service/PayService.java | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index ee05bf0..eb208cd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -6,6 +6,7 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.chaozhanggui.system.cashierservice.interceptor.RequestWrapper; import com.chaozhanggui.system.cashierservice.service.PayService; +import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Random; @@ -81,7 +83,8 @@ public class NotifyController { JSONObject object=JSONUtil.parseObj(map.get("data")); if(ObjectUtil.isNotEmpty(object)&&object.containsKey("status")&&"1".equals(object.getStr("status"))){ String orderNo=object.getStr("orderNumber"); - return payService.callBackGroupPay(orderNo); + String payTime = object.getStr("payTime"); + return payService.callBackGroupPay(orderNo,payTime); } } return null; @@ -95,7 +98,7 @@ public class NotifyController { JSONObject object = JSONUtil.parseObj(map.get("bizData")); if (ObjectUtil.isNotEmpty(object) && object.containsKey("state") && "TRADE_SUCCESS".equals(object.getStr("state"))) { String orderNo = object.getStr("payOrderId"); - return payService.callBackGroupPay(orderNo); + return payService.callBackGroupPay(orderNo, DateUtils.getTime(new Date())); } } return null; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index b499e3f..e87725d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -764,7 +764,7 @@ public class PayService { } @Transactional(rollbackFor = Exception.class) - public String callBackGroupPay(String payOrderNO) { + public String callBackGroupPay(String payOrderNO,String payTime) { TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.selectByPayOrderNo(payOrderNO); if (ObjectUtil.isEmpty(orderInfo)) { return "订单信息不存在"; @@ -782,6 +782,7 @@ public class PayService { //修改主单状态 orderInfo.setStatus("unused"); orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfo.setPayTime(DateUtils.fomatDateTime(payTime)); tbGroupOrderInfoMapper.update(orderInfo); return "SUCCESS"; }else { From 2c154394049a72bab72620a73070c0aa42391b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 16:28:54 +0800 Subject: [PATCH 059/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 28 +++++++++ .../controller/NotifyController.java | 31 ++++++++- .../cashierservice/service/LoginService.java | 63 +++++++++++++++++++ .../cashierservice/service/PayService.java | 41 ++++++++++++ 4 files changed, 162 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 1444142..c8d56bd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -359,4 +359,32 @@ public class LoginContoller { } + /** + * 重置资金密码 + * @param token + * @param map + * @return + */ + @RequestMapping("resetPwd") + public Result resetPwd(@RequestHeader String token,@RequestBody Map map){ + + String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + return loginService.resetPwd(userId,map); + + } + + + /** + * 修改密码 + * @param token + * @param map + * @return + */ + @RequestMapping("mpdifyPwd") + public Result mpdifyPwd(@RequestHeader String token,@RequestBody Map map){ + String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + return loginService.modifyPwd(userId,map); + } + + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index 3dbb336..c785ae2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -50,7 +50,16 @@ public class NotifyController { public String fstmemberInCallBack(HttpServletRequest request){ Map map= getParameterMap(request); log.info("fstmemberInCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); - + if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"000000".equals(map.get("code")+"")){ + Map object=(Map)map.get("bizData"); + if(ObjectUtil.isNotEmpty(object)&&object.containsKey("state")){ + if("TRADE_SUCCESS".equals(object.get("state").toString())){ + String orderNo=map.get("mchOrderNo").toString(); + String tradeNo=map.get("payOrderId").toString(); + return payService.fstMemberInSuccess(orderNo,tradeNo); + } + } + } return null; @@ -72,6 +81,26 @@ public class NotifyController { return null; } + + @RequestMapping("notifyfstCallBack") + public String notifyfstCallBack(HttpServletRequest request){ + + Map map= getParameterMap(request); + log.info("notifyfstCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); + if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"000000".equals(map.get("code")+"")){ + Map object=(Map)map.get("bizData"); + if(ObjectUtil.isNotEmpty(object)&&object.containsKey("state")){ + if("TRADE_SUCCESS".equals(object.get("state").toString())){ + String orderNo=map.get("mchOrderNo").toString(); + String tradeNo=map.get("payOrderId").toString(); + return payService.callBackPayFST(tradeNo); + } + } + } + + return null; + } + @RequestMapping("notifyCallBackGroup") public String notifyCallBackGroup(HttpServletRequest request){ Map map= getParameterMap(request); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index c3b811d..0bb2fa4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -272,6 +272,69 @@ public class LoginService { return Result.success(CodeEnum.SUCCESS); } + + public Result resetPwd(String userId,Map map){ + if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") + ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("code") + ||ObjectUtil.isEmpty(map.get("code"))|| + !map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) + ){ + return Result.fail("参数错误"); + } + + TbUserInfo userInfo=tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + boolean flag= validate(map.get("code").toString(), userInfo.getPhone()); + if(!flag){ + return Result.fail("验证码错误"); + } + + + TbShopUser user=tbShopUserMapper.selectByUserIdAndShopId(userId,map.get("shopId").toString()); + if(ObjectUtil.isEmpty(user)||ObjectUtil.isNull(user)){ + return Result.fail("店铺用户信息不存在"); + } + + + user.setIsPwd("1"); + user.setPwd(MD5Utils.md5(map.get("pwd").toString())); + user.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(user); + + return Result.success(CodeEnum.SUCCESS); + + } + + + + public Result modifyPwd(String userId,Map map){ + if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") + ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("oldpwd") + ||ObjectUtil.isEmpty(map.get("oldpwd"))|| + !map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) + ){ + return Result.fail("参数错误"); + } + + TbShopUser user=tbShopUserMapper.selectByUserIdAndShopId(userId,map.get("shopId").toString()); + if(ObjectUtil.isEmpty(user)||ObjectUtil.isNull(user)){ + return Result.fail("店铺用户信息不存在"); + } + + if(!user.getPwd().equals(MD5Utils.md5(map.get("oldpwd").toString()))){ + return Result.fail("用户旧密码错误"); + } + + + user.setIsPwd("1"); + user.setPwd(MD5Utils.md5(map.get("pwd").toString())); + user.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(user); + + return Result.success(CodeEnum.SUCCESS); + + } + + public static void main(String[] args) { for (int i = 0; i < 10; i++) { System.out.println(RandomUtil.randomNumbers(10)); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 653ddc4..b00d2c4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -763,6 +763,47 @@ public class PayService { return null; } + + + @Transactional(rollbackFor = Exception.class) + public String callBackPayFST(String payOrderNO) { + TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPayOrderNo(payOrderNO); + if (ObjectUtil.isEmpty(orderInfo)) { + return "订单信息不存在"; + } + + if ("paying".equals(orderInfo.getStatus())) { + int cartCount = tbCashierCartMapper.updateStatusByOrderId(orderInfo.getId().toString(), "final"); + + log.info("更新购物车:{}", cartCount); + + //更新子单状态 + tbOrderDetailMapper.updateStatusByOrderIdAndStatus(orderInfo.getId(), "closed"); + + //修改主单状态 + orderInfo.setStatus("closed"); + orderInfo.setPayType("wx_lite"); + orderInfo.setPayOrderNo(payOrderNO); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + + + JSONObject jsonObject=new JSONObject(); + jsonObject.put("token",0); + jsonObject.put("type","wxcreate"); + jsonObject.put("orderId",orderInfo.getId().toString()); + + producer.putOrderCollect(jsonObject.toJSONString()); + + log.info("发送打印数据"); + producer.printMechine(orderInfo.getId() + ""); + + return "SUCCESS"; + + } + return null; + } + @Transactional(rollbackFor = Exception.class) public String callBackGroupPay(String payOrderNO) { TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.selectByPayOrderNo(payOrderNO); From a2eb106a0a155d2f0341e0d4ba37f9edb22b400d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 16:32:28 +0800 Subject: [PATCH 060/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=89=88?= =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/NotifyController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index 1f29634..1a026fd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -6,6 +6,7 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.chaozhanggui.system.cashierservice.interceptor.RequestWrapper; import com.chaozhanggui.system.cashierservice.service.PayService; +import com.chaozhanggui.system.cashierservice.util.DateUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import java.util.Date; import java.util.Map; import java.util.Random; From bd452d9ce42ef1ee4169d6ae1a09f6aaf1ef3505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 17:10:45 +0800 Subject: [PATCH 061/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PayController.java | 22 +++++ .../cashierservice/service/PayService.java | 85 +++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 58f7005..1c29eb1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -50,6 +50,28 @@ public class PayController { return Result.fail("支付失败"); } + + + + /** + * 储值卡支付 + * @param token + * @param loginName + * @param clientType + * @param orderId + * @param memberId + * @return + */ + @GetMapping("accountPay") + public Result accountPay(@RequestHeader("token") String token, + @RequestHeader("loginName") String loginName, + @RequestHeader("clientType") String clientType, + @RequestParam("orderId") String orderId, + @RequestParam("memberId") String memberId + ){ + return payService.accountPay(orderId,memberId,token); + } + @RequestMapping("groupOrderPay") public Result groupOrderPay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index ee5e796..43ff9f5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -277,6 +277,91 @@ public class PayService { return Result.fail("失败"); } + + + + + + + + @Transactional(rollbackFor = Exception.class) + public Result accountPay(String orderId, String memberId, String token) { + if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberId)) { + return Result.fail("参数错误"); + } + + TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); + if (ObjectUtil.isEmpty(orderInfo)) { + return Result.fail("订单信息不存在"); + } + + + if (!"unpaid".equals(orderInfo.getStatus())) { + return Result.fail("订单出状态异常"); + } + + + int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "deposit"); + if (count < 1) { + return Result.fail("店铺未开通此支付方式"); + } + + + TbShopUser user = tbShopUserMapper.selectByPrimaryKey(memberId); + if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { + return Result.fail("用户非会员"); + } + + if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { + return Result.fail("会员卡余额不足"); + } + + user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); + user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount())); + user.setConsumeNumber(user.getConsumeNumber() + 1); + user.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(user); + + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(Integer.valueOf(user.getId())); + flow.setBizCode("accountPay"); + flow.setBizName("会员储值卡支付"); + flow.setAmount(orderInfo.getOrderAmount()); + flow.setBalance(user.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfo.setMemberId(memberId); + orderInfo.setPayType("deposit"); + orderInfo.setStatus("closed"); + orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo())); + tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); + //更新购物车状态 + int cartCount = tbCashierCartMapper.updateStatusByOrderId(orderId, "final"); + + + tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed"); + + tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed"); + + log.info("更新购物车:{}", cartCount); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("token", token); + jsonObject.put("type", "create"); + jsonObject.put("orderId", orderId); + + producer.putOrderCollect(jsonObject.toJSONString()); + + producer.printMechine(orderId); + + return Result.success(CodeEnum.SUCCESS); + } + + @Transactional(rollbackFor = Exception.class) public Result groupOrderPay(String orderId, String payType, String userId, String ip) throws JsonProcessingException { TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.queryById(Integer.valueOf(orderId)); From 41605869e3e854868be774f33e945e320a2570b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 17:31:29 +0800 Subject: [PATCH 062/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 43ff9f5..9033c49 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -244,7 +244,7 @@ public class PayService { if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); - if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + if("TRADE_AWAIT".equals(wxScanPayResp.getState())){ payment.setTradeNumber(wxScanPayResp.getPayOrderId()); payment.setUpdatedAt(System.currentTimeMillis()); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); From 509137b200a82cdc19e7d75d6166bd78bfd14fb1 Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Mon, 20 May 2024 17:43:09 +0800 Subject: [PATCH 063/134] =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 2 +- src/main/resources/application.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 9033c49..3aacb09 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -146,7 +146,7 @@ public class PayService { } - List cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"create"); + List cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"closed"); if(ObjectUtil.isEmpty(cashierCarts)||ObjectUtil.isNull(cashierCarts)){ return Result.fail("购物车信息不存在"); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5ebc9df..94f3399 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -57,5 +57,5 @@ aliyun: thirdPay: payType: fushangtong - callBack: https://cashierclient.sxczgkj.cn/${server.servlet.context-path}/notify/fstmemberInCallBack + callBack: https://cashierclient.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack url: https://paymentapi.sxczgkj.cn From c92fbfc5544b499c1f8f209280f3f51606f20534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Mon, 20 May 2024 18:03:41 +0800 Subject: [PATCH 064/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 2 +- src/main/resources/mapper/TbCashierCartMapper.xml | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 3aacb09..1fb2a11 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -146,7 +146,7 @@ public class PayService { } - List cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"closed"); + List cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,null); if(ObjectUtil.isEmpty(cashierCarts)||ObjectUtil.isNull(cashierCarts)){ return Result.fail("购物车信息不存在"); } diff --git a/src/main/resources/mapper/TbCashierCartMapper.xml b/src/main/resources/mapper/TbCashierCartMapper.xml index 0f141c1..202975b 100644 --- a/src/main/resources/mapper/TbCashierCartMapper.xml +++ b/src/main/resources/mapper/TbCashierCartMapper.xml @@ -372,6 +372,11 @@ \ No newline at end of file From 4140d4c8b8199db3e3799a13a3a118dbb80ff86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Tue, 21 May 2024 10:36:02 +0800 Subject: [PATCH 065/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/auth/LoginFilter.java | 3 ++- .../system/cashierservice/controller/LoginContoller.java | 1 + .../system/cashierservice/service/OnlineUserService.java | 1 + .../chaozhanggui/system/cashierservice/service/PayService.java | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index c30176a..98c611d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -50,7 +50,8 @@ public class LoginFilter implements Filter { "cashierService/product/queryProduct", "cashierService/product/productInfo", "cashierService/notify/**",//登录部分接口不校验 - "notify/**"//回调部分接口不校验 + "notify/**", + "cashierService/table/**"//回调部分接口不校验 ); @Autowired diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index c8d56bd..fe52ccf 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -204,6 +204,7 @@ public class LoginContoller { //生成token String token = StringUtil.genRandomNum(6) + StringUtil.getBillno() + StringUtil.genRandomNum(6); + //存入redis OnlineUserDto jwtUserDto = onlineUserService.save(merchantAccount.getName(), merchantAccount.getAccount(), Integer.valueOf(merchantAccount.getShopId()), token, merchantAccount.getStatus()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OnlineUserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OnlineUserService.java index d9300d0..85eec9c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OnlineUserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OnlineUserService.java @@ -4,6 +4,7 @@ package com.chaozhanggui.system.cashierservice.service; import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto; import com.chaozhanggui.system.cashierservice.entity.dto.SecurityProperties; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.util.TokenUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 1fb2a11..fad9112 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -264,7 +264,8 @@ public class PayService { jsonObject1.put("amount", 0); AppWebSocketServer.AppSendInfo(jsonObject1,key, false); tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); - return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); + ObjectMapper mapper = new ObjectMapper(); + return Result.success(CodeEnum.SUCCESS,mapper.readTree(wxScanPayResp.getPayInfo())); }else{ return Result.fail(publicResp.getMsg()); } From 0101c47cb8286f831f43d337bae4c07c9c7ed0a2 Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Tue, 21 May 2024 10:37:32 +0800 Subject: [PATCH 066/134] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/entity/TbUserCoupons.java | 1 + .../system/cashierservice/service/OrderService.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java index 18f065c..6f59527 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java @@ -16,6 +16,7 @@ public class TbUserCoupons implements Serializable { private BigDecimal couponsPrice; private BigDecimal couponsAmount; + private TbOrderInfo orderInfo; private String status; private String isDouble; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index c1e1477..bad942b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -353,6 +353,10 @@ public class OrderService { public Result getYhqDouble(Integer orderId) { TbUserCoupons userCoupons = userCouponsMapper.selectByOrderId(orderId); + if (Objects.nonNull(userCoupons)){ + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + userCoupons.setOrderInfo(orderInfo); + } return Result.success(CodeEnum.SUCCESS,userCoupons); } @Transactional(rollbackFor = Exception.class) From 2c8800a0b513255ff3bbf309b4913472d48a543a Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 21 May 2024 11:02:03 +0800 Subject: [PATCH 067/134] =?UTF-8?q?=E9=80=9A=E8=BF=87=E6=A1=8C=E7=A0=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BA=97=E9=93=BAid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/chaozhanggui/system/cashierservice/auth/LoginFilter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 98c611d..9feb93c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -46,7 +46,6 @@ public class LoginFilter implements Filter { "cashierService/common/**",//通用接口 "cashierService/distirict/**",//首页其它接口 "cashierService/login/**",//登录部分接口不校验 - "cashierService/product/queryShopIdByTableCode", "cashierService/product/queryProduct", "cashierService/product/productInfo", "cashierService/notify/**",//登录部分接口不校验 From 83bffb6c84e203a3ee5b98279f478bc76f18f9eb Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 21 May 2024 11:59:50 +0800 Subject: [PATCH 068/134] =?UTF-8?q?=E5=9B=A2=E8=B4=AD=E5=8D=B7=E6=94=AF?= =?UTF-8?q?=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/PayController.java | 1 + .../system/cashierservice/service/PayService.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 1c29eb1..088d704 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -86,6 +86,7 @@ public class PayController { }else { userId = TokenUtil.parseParamFromToken(token).getString("userId"); } + //订单支付 orderId:62,payType=wechatPay,userId:or1l860rwM-rU_j9KrgMOwued log.info("订单支付 orderId:{},payType={},userId:{}",orderId,payType,userId); try { // if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index fad9112..6117d86 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -376,11 +376,11 @@ public class PayService { throw new MsgException("生成订单错误"); } - if (ObjectUtil.isNull(tbMerchantAccount.getMerchantId()) || ObjectUtil.isEmpty(tbMerchantAccount.getMerchantId())) { + if (ObjectUtil.isNull(tbMerchantAccount)) { return Result.fail("没有对应的商户"); } - TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantAccount.getMerchantId())); + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantAccount.getId())); if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { return Result.fail("支付通道不存在"); From cdde32af81f388b36beaa92a1f33ea0936edb577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Tue, 21 May 2024 12:00:15 +0800 Subject: [PATCH 069/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/PayController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 1c29eb1..81019c1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -56,16 +56,12 @@ public class PayController { /** * 储值卡支付 * @param token - * @param loginName - * @param clientType * @param orderId * @param memberId * @return */ @GetMapping("accountPay") public Result accountPay(@RequestHeader("token") String token, - @RequestHeader("loginName") String loginName, - @RequestHeader("clientType") String clientType, @RequestParam("orderId") String orderId, @RequestParam("memberId") String memberId ){ From 03c6f7c0dad22550fe999f3b7fbeb7da01e5e17f Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Tue, 21 May 2024 15:58:43 +0800 Subject: [PATCH 070/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8D=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=A2=9E=E5=8A=A0=E5=BE=85=E6=94=AF=E4=BB=98=E4=B8=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index fad9112..1fd83f4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -297,7 +297,7 @@ public class PayService { } - if (!"unpaid".equals(orderInfo.getStatus())) { + if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus()) ) { return Result.fail("订单出状态异常"); } From d118c922d3aee0a125686b3641fe1ccabedb3c3a Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Tue, 21 May 2024 17:38:55 +0800 Subject: [PATCH 071/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8D=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=A2=9E=E5=8A=A0=E5=BE=85=E6=94=AF=E4=BB=98=E4=B8=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 9 ++++++--- .../chaozhanggui/system/cashierservice/sign/Result.java | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 41f8522..5068589 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -310,11 +310,11 @@ public class PayService { TbShopUser user = tbShopUserMapper.selectByPrimaryKey(memberId); if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { - return Result.fail("用户非会员"); + return Result.failCode("会员卡余额不足","1"); } if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { - return Result.fail("会员卡余额不足"); + return Result.failCode("会员卡余额不足","2"); } user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); @@ -883,7 +883,10 @@ public class PayService { log.info("发送打印数据"); producer.printMechine(orderInfo.getId() + ""); - + JSONObject coupons = new JSONObject(); + coupons.put("type","buy"); + coupons.put("orderId",orderInfo.getId().toString()); + producer.printCoupons(coupons.toJSONString()); return "SUCCESS"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java index a47ee5a..9c9f7ff 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java @@ -144,6 +144,15 @@ public class Result { dto.setIcon(CodeEnum.FAIL.getIcon()); return dto; } + public static Result failCode(String msg,String data) { + Result dto = new Result(); + dto.setMsg(msg); + dto.setEncrypt(false); + dto.setCode("1"); + dto.setData(data); + dto.setIcon(CodeEnum.FAIL.getIcon()); + return dto; + } public static Result failure(IError error) { Result dto = new Result(); dto.setMsg(error.getErrorMessage()); From 92e9dee23643f10e74af960bfa5a43f8371710e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 22 May 2024 09:40:40 +0800 Subject: [PATCH 072/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotifyController.java | 15 +++++++++------ .../cashierservice/controller/PayController.java | 4 ++++ .../system/cashierservice/service/PayService.java | 15 +++++++++++---- src/main/resources/application-dev.yml | 2 +- src/main/resources/application.yml | 3 ++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index 1a026fd..96f5749 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -53,11 +53,13 @@ public class NotifyController { Map map= getParameterMap(request); log.info("fstmemberInCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"000000".equals(map.get("code")+"")){ - Map object=(Map)map.get("bizData"); +// Map object=(Map)map.get("bizData"); + + JSONObject object=JSONUtil.parseObj(map.get("bizData").toString()); if(ObjectUtil.isNotEmpty(object)&&object.containsKey("state")){ if("TRADE_SUCCESS".equals(object.get("state").toString())){ - String orderNo=map.get("mchOrderNo").toString(); - String tradeNo=map.get("payOrderId").toString(); + String orderNo=object.get("mchOrderNo").toString(); + String tradeNo=object.get("payOrderId").toString(); return payService.fstMemberInSuccess(orderNo,tradeNo); } } @@ -90,11 +92,12 @@ public class NotifyController { Map map= getParameterMap(request); log.info("notifyfstCallBack回调返回信息:{}",JSONUtil.toJsonStr(map)); if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"000000".equals(map.get("code")+"")){ - Map object=(Map)map.get("bizData"); + + JSONObject object=JSONUtil.parseObj(map.get("bizData").toString()); if(ObjectUtil.isNotEmpty(object)&&object.containsKey("state")){ if("TRADE_SUCCESS".equals(object.get("state").toString())){ - String orderNo=map.get("mchOrderNo").toString(); - String tradeNo=map.get("payOrderId").toString(); + String orderNo=object.get("mchOrderNo").toString(); + String tradeNo=object.get("payOrderId").toString(); return payService.callBackPayFST(tradeNo); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index c010e68..932f421 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -127,6 +127,10 @@ public class PayController { } +// public Result getActive(@RequestHeader("token") String token,@RequestParam("shopId") String shopId,@RequestParam("page") int page,@RequestParam("pageSize") int pageSize){ +// +// } + /** * 充值 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 6117d86..661c06e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -114,8 +114,11 @@ public class PayService { - @Value("${thirdPay.callBack}") - private String callBack; + @Value("${thirdPay.callInBack}") + private String callInBack; + + @Value("${thirdPay.callFSTBack}") + private String callFSTBack; @Autowired ThirdPayService thirdPayService; @@ -240,7 +243,7 @@ public class PayService { reqbody=body.toString(); } - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callFSTBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); @@ -784,7 +787,7 @@ public class PayService { } } }else { - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip, DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callBack,null,thirdApply.getAppToken()); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip, DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); @@ -918,6 +921,10 @@ public class PayService { return null; } + + + + /** * 生成长度为12的随机串 * diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f98e837..38086ab 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -59,7 +59,7 @@ ysk: callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 server: - port: 9888 + port: 9889 prod: dev1 queue: cart_queue_putdev1 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 94f3399..f520886 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -57,5 +57,6 @@ aliyun: thirdPay: payType: fushangtong - callBack: https://cashierclient.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack + callInBack: https://wxcashiertest.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack + callFSTBack: https://wxcashiertest.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack url: https://paymentapi.sxczgkj.cn From 1b4866c4dc44e0f83b20879e145b230326e54810 Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Wed, 22 May 2024 11:42:37 +0800 Subject: [PATCH 073/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=8D=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=A2=9E=E5=8A=A0=E5=BE=85=E6=94=AF=E4=BB=98=E4=B8=AD?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/UserContoller.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 8dbdfd3..43a9a24 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -74,6 +74,11 @@ public class UserContoller { jsonObject.put("data",object); return jsonObject; } + @GetMapping("/shopUserInfo") + public Result shopUserInfo(@RequestParam("userId") String userId ,@RequestParam("shopId") String shopId ) throws Exception { + TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(userId,shopId); + return Result.success(CodeEnum.SUCCESS,shopUser); + } @PostMapping("/modityIntegral") public JSONObject modityIntegral(@RequestHeader String token,@RequestBody IntegralVo integralVo ) throws Exception { JSONObject jsonObject = TokenUtil.parseParamFromToken(token); From 000bf44a6378d1265ba987c01e91c21186b97826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 22 May 2024 11:43:02 +0800 Subject: [PATCH 074/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 29 +++++++++---------- .../controller/PayController.java | 12 ++++++-- .../cashierservice/dao/TbActivateMapper.java | 3 ++ .../cashierservice/service/PayService.java | 10 +++++++ .../resources/mapper/TbActivateMapper.xml | 4 +++ 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index fe52ccf..aed4f14 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -217,21 +217,20 @@ public class LoginContoller { } -// /** -// * 获取会员码 -// * -// * @param openId -// * @param token -// * @param id -// * @return -// */ -// @GetMapping("createCardNo") -// public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id, -// -// @RequestParam("shopId") String shopId -// ) { -// return loginService.createCardNo(id, openId,shopId); -// } + /** + * 获取会员码 + * + * @param openId + * @param token + * @param id + * @return + */ + @GetMapping("createCardNo") + public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id, + @RequestParam("shopId") String shopId + ) { + return loginService.createCardNo(id, openId,shopId); + } @GetMapping("/userInfo") public Result userInfo(@RequestParam("userId") Integer userId) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 932f421..a7ce8a0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -127,9 +127,15 @@ public class PayController { } -// public Result getActive(@RequestHeader("token") String token,@RequestParam("shopId") String shopId,@RequestParam("page") int page,@RequestParam("pageSize") int pageSize){ -// -// } + @RequestMapping("getActive") + public Result getActive( + @RequestHeader("token") String token, + @RequestParam("shopId") String shopId, + @RequestParam("page") int page, + @RequestParam("pageSize") int pageSize){ + return payService.getActivate(shopId,page,pageSize); + + } /** * 充值 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java index 2b8505e..2a458b2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; import java.math.BigDecimal; +import java.util.List; @Component @Mapper @@ -23,4 +24,6 @@ public interface TbActivateMapper { int updateByPrimaryKey(TbActivate record); TbActivate selectByAmount(@Param("shopId") String shopId,@Param("amount") BigDecimal amount); + + List selectByShpopId(String shopId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index c328d4f..bcb9d7c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -24,6 +24,8 @@ import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; import com.chaozhanggui.system.cashierservice.util.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -925,6 +927,14 @@ public class PayService { } + public Result getActivate(String shopId,int page ,int pageSize){ + PageHelper.startPage(page, pageSize); + List list=tbActivateMapper.selectByShpopId(shopId); + PageInfo pageInfo=new PageInfo(list); + return Result.success(CodeEnum.SUCCESS,pageInfo); + } + + diff --git a/src/main/resources/mapper/TbActivateMapper.xml b/src/main/resources/mapper/TbActivateMapper.xml index 0f29dcc..821aa29 100644 --- a/src/main/resources/mapper/TbActivateMapper.xml +++ b/src/main/resources/mapper/TbActivateMapper.xml @@ -118,4 +118,8 @@ + + \ No newline at end of file From 75b451cdda1e65b93c3d69d6caffaa2a6280bd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 22 May 2024 18:09:01 +0800 Subject: [PATCH 075/134] =?UTF-8?q?=E6=9C=AA=E7=9F=A5=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 3 +- .../controller/PayController.java | 56 +++++++++++-------- .../dao/TbMerchantAccountMapper.java | 4 ++ .../cashierservice/dao/TbShopUserMapper.java | 5 +- .../cashierservice/entity/TbShopUser.java | 18 ------ .../cashierservice/entity/TbUserInfo.java | 25 +++++++++ .../cashierservice/service/LoginService.java | 38 ++++++------- .../cashierservice/service/PayService.java | 38 ++++++++++--- .../service/ProductService.java | 2 - .../thirdpay/service/ThirdPayService.java | 1 - .../resources/mapper/TbActivateMapper.xml | 2 +- .../resources/mapper/TbShopUserMapper.xml | 23 +++++++- 12 files changed, 135 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 9feb93c..2acce14 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -50,7 +50,8 @@ public class LoginFilter implements Filter { "cashierService/product/productInfo", "cashierService/notify/**",//登录部分接口不校验 "notify/**", - "cashierService/table/**"//回调部分接口不校验 + "cashierService/table/**",//回调部分接口不校验 + "cashierService/pay/**" ); @Autowired diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index a7ce8a0..5074ca9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -1,20 +1,17 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; -import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; -import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.IpUtil; import com.chaozhanggui.system.cashierservice.util.TokenUtil; +import com.fasterxml.jackson.core.JsonProcessingException; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; -import java.util.List; import java.util.Map; @CrossOrigin(origins = "*") @@ -31,19 +28,18 @@ public class PayController { /** * 支付 * - * @param request - * payType wechatPay:微信支付;aliPay:支付宝支付; + * @param request payType wechatPay:微信支付;aliPay:支付宝支付; * @param map * @return */ @RequestMapping("orderPay") - public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map map) { - if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("orderId")||ObjectUtil.isEmpty(map.get("orderId"))){ + public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map map) { + if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { return Result.fail("订单号不允许为空"); } try { - return payService.payOrder(openId,map.get("orderId").toString(), IpUtil.getIpAddr(request)); + return payService.payOrder(openId, map.get("orderId"), IpUtil.getIpAddr(request)); } catch (Exception e) { e.printStackTrace(); } @@ -51,10 +47,9 @@ public class PayController { } - - /** * 储值卡支付 + * * @param token * @param orderId * @param memberId @@ -64,26 +59,26 @@ public class PayController { public Result accountPay(@RequestHeader("token") String token, @RequestParam("orderId") String orderId, @RequestParam("memberId") String memberId - ){ - return payService.accountPay(orderId,memberId,token); + ) { + return payService.accountPay(orderId, memberId, token); } @RequestMapping("groupOrderPay") - public Result groupOrderPay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map map) { + public Result groupOrderPay(HttpServletRequest request, @RequestHeader String environment, @RequestHeader String token, @RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { return Result.fail("订单号不允许为空"); } - String orderId = map.get("orderId").toString(); + String orderId = map.get("orderId"); // String orderType = map.get("orderType").toString(); - String payType = map.get("payType").toString(); - String userId=""; - if(environment.equals("wx")){ + String payType = map.get("payType"); + String userId = ""; + if (environment.equals("wx")) { userId = TokenUtil.parseParamFromToken(token).getString("openId"); - }else { + } else { userId = TokenUtil.parseParamFromToken(token).getString("userId"); } //订单支付 orderId:62,payType=wechatPay,userId:or1l860rwM-rU_j9KrgMOwued - log.info("订单支付 orderId:{},payType={},userId:{}",orderId,payType,userId); + log.info("订单支付 orderId:{},payType={},userId:{}", orderId, payType, userId); try { // if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){ // return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request)); @@ -132,8 +127,8 @@ public class PayController { @RequestHeader("token") String token, @RequestParam("shopId") String shopId, @RequestParam("page") int page, - @RequestParam("pageSize") int pageSize){ - return payService.getActivate(shopId,page,pageSize); + @RequestParam("pageSize") int pageSize) { + return payService.getActivate(shopId, page, pageSize); } @@ -149,7 +144,22 @@ public class PayController { public Result memeberIn(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestHeader("id") String id, @RequestBody Map map ) { - return payService.memberIn(openId, id, map.get("amount").toString(), map.get("shopId").toString(), IpUtil.getIpAddr(request)); + try { + return payService.memberIn(openId, id, map.get("amount").toString(), map.get("shopId").toString(), IpUtil.getIpAddr(request)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + + @RequestMapping("getShopByMember") + public Result getShopByMember(@RequestHeader("token") String token, + @RequestParam("page") int page, + @RequestParam("pageSize") int pageSize, + @RequestParam("userId") String userId, + @RequestParam("shopId") String shopId + ) { + return payService.getShopByMember(userId,shopId,page,pageSize); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantAccountMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantAccountMapper.java index e067028..b0d4ee6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantAccountMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantAccountMapper.java @@ -1,7 +1,11 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Component; +@Component +@Mapper public interface TbMerchantAccountMapper { TbMerchantAccount selectByAccount(String account); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java index 37b597e..d1a23f9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java @@ -6,6 +6,9 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + @Component @Mapper public interface TbShopUserMapper { @@ -25,7 +28,7 @@ public interface TbShopUserMapper { TbShopUser selectByUserIdAndShopId(@Param("userId") String userId,@Param("shopId") String shopId); - TbShopUser selectByUserId(@Param("userId") String userId); + List> selectByUserId(@Param("userId") String userId,@Param("shopId") String shopId); TbShopUser selectByOpenId(@Param("openId") String openId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java index f447e2d..1c58321 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java @@ -45,9 +45,6 @@ public class TbShopUser implements Serializable { private String dynamicCode; - private String isPwd; - - private String pwd; private Byte isAttention; @@ -229,21 +226,6 @@ public class TbShopUser implements Serializable { this.dynamicCode = dynamicCode; } - public String getIsPwd() { - return isPwd; - } - - public void setIsPwd(String isPwd) { - this.isPwd = isPwd; - } - - public String getPwd() { - return pwd; - } - - public void setPwd(String pwd) { - this.pwd = pwd; - } public Byte getIsAttention() { return isAttention; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserInfo.java index ed8f27d..bf905f9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserInfo.java @@ -99,6 +99,15 @@ public class TbUserInfo implements Serializable { private String phone=""; + + private String isPwd; + + private String pwd; + + + + + public String getPhone() { return phone; } @@ -484,4 +493,20 @@ public class TbUserInfo implements Serializable { public void setPassword(String password) { this.password = password; } + + public String getIsPwd() { + return isPwd; + } + + public void setIsPwd(String isPwd) { + this.isPwd = isPwd; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 0bb2fa4..3c14fd4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -77,6 +77,8 @@ public class LoginService { userInfo.setSourcePath("WECHAT-APP"); userInfo.setIsAttentionMp(Byte.parseByte("0")); userInfo.setSearchWord("||微信用户"); + userInfo.setIsPwd("0"); + userInfo.setPwd(MD5Utils.md5("123456")); userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); @@ -276,8 +278,7 @@ public class LoginService { public Result resetPwd(String userId,Map map){ if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("code") - ||ObjectUtil.isEmpty(map.get("code"))|| - !map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) + ||ObjectUtil.isEmpty(map.get("code")) ){ return Result.fail("参数错误"); } @@ -289,16 +290,10 @@ public class LoginService { } - TbShopUser user=tbShopUserMapper.selectByUserIdAndShopId(userId,map.get("shopId").toString()); - if(ObjectUtil.isEmpty(user)||ObjectUtil.isNull(user)){ - return Result.fail("店铺用户信息不存在"); - } - - - user.setIsPwd("1"); - user.setPwd(MD5Utils.md5(map.get("pwd").toString())); - user.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(user); + userInfo.setIsPwd("1"); + userInfo.setPwd(MD5Utils.md5(map.get("pwd").toString())); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKey(userInfo); return Result.success(CodeEnum.SUCCESS); @@ -309,26 +304,25 @@ public class LoginService { public Result modifyPwd(String userId,Map map){ if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("oldpwd") - ||ObjectUtil.isEmpty(map.get("oldpwd"))|| - !map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) + ||ObjectUtil.isEmpty(map.get("oldpwd")) ){ return Result.fail("参数错误"); } - TbShopUser user=tbShopUserMapper.selectByUserIdAndShopId(userId,map.get("shopId").toString()); - if(ObjectUtil.isEmpty(user)||ObjectUtil.isNull(user)){ - return Result.fail("店铺用户信息不存在"); + TbUserInfo userInfo=tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + if(ObjectUtil.isEmpty(userInfo)||ObjectUtil.isNull(userInfo)){ + return Result.fail("用户基本信息不存在"); } - if(!user.getPwd().equals(MD5Utils.md5(map.get("oldpwd").toString()))){ + if(!userInfo.getPwd().equals(MD5Utils.md5(map.get("oldpwd").toString()))){ return Result.fail("用户旧密码错误"); } - user.setIsPwd("1"); - user.setPwd(MD5Utils.md5(map.get("pwd").toString())); - user.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(user); + userInfo.setIsPwd("1"); + userInfo.setPwd(MD5Utils.md5(map.get("pwd").toString())); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKey(userInfo); return Result.success(CodeEnum.SUCCESS); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index bcb9d7c..50e200f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -125,6 +125,9 @@ public class PayService { @Autowired ThirdPayService thirdPayService; + @Autowired + TbUserInfoMapper tbUserInfoMapper; + @Resource @@ -715,11 +718,15 @@ public class PayService { @Transactional(rollbackFor = Exception.class) - public Result memberIn(String openId,String userId,String amount,String shopId,String ip){ + public Result memberIn(String openId,String userId,String amount,String shopId,String ip) throws JsonProcessingException { if(ObjectUtil.isEmpty(openId)||ObjectUtil.isEmpty(userId)){ return Result.fail("用户信息允许为空"); } + TbUserInfo userInfo= tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + if(ObjectUtil.isEmpty(userInfo)){ + return Result.fail("用户基本信息不存在"); + } TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userId,shopId); if(ObjectUtil.isEmpty(tbShopUser)){ @@ -727,7 +734,7 @@ public class PayService { } - if("0".equals(tbShopUser.getIsPwd())){ + if("0".equals(userInfo.getIsPwd())){ return Result.fail("用户支付密码未设置"); } @@ -789,18 +796,19 @@ public class PayService { } } }else { - PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),userId,ip, DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken()); + String orderNo=DateUtils.getsdfTimesSS(); + PublicResp publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip, orderNo,thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken()); if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ if("000000".equals(publicResp.getCode())){ WxScanPayResp wxScanPayResp= publicResp.getObjData(); - if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){ + if("TRADE_AWAIT".equals(wxScanPayResp.getState())){ - memberIn.setOrderNo(wxScanPayResp.getPayOrderId()); + memberIn.setOrderNo(orderNo); + memberIn.setTradeNo(wxScanPayResp.getPayOrderId()); memberIn.setUpdateTime(new Date()); tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - - return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo()); - + ObjectMapper mapper = new ObjectMapper(); + return Result.success(CodeEnum.SUCCESS,mapper.readTree(wxScanPayResp.getPayInfo())); }else{ return Result.fail(publicResp.getMsg()); @@ -936,6 +944,15 @@ public class PayService { + public Result getShopByMember(String userId,String shopId,int page,int pageSize){ + PageHelper.startPage(page, pageSize); + List> list= tbShopUserMapper.selectByUserId(userId,shopId); + PageInfo pageInfo=new PageInfo(list); + return Result.success(CodeEnum.SUCCESS,pageInfo); + } + + + /** @@ -1040,6 +1057,10 @@ public class PayService { return "充值记录不存在"; } + if(!"7".equals(memberIn.getStatus())){ + return "订单已处理"; + } + memberIn.setTradeNo(tradeNo); memberIn.setStatus("0"); memberIn.setUpdateTime(new Date()); @@ -1051,6 +1072,7 @@ public class PayService { } if(!"1".equals(tbShopUser.getIsVip().toString())){ + tbShopUser.setCode(DateUtils.getsdfTimesSS()); tbShopUser.setIsVip(Byte.parseByte("1")); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 54cbf19..18b51f9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -83,8 +83,6 @@ public class ProductService { tbShopUser.setShopId(shopId); tbShopUser.setUserId(userId); tbShopUser.setMiniOpenId(openId); - tbShopUser.setPwd(MD5Util.encrypt("123456")); - tbShopUser.setIsPwd("0"); tbShopUser.setCreatedAt(System.currentTimeMillis()); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.insert(tbShopUser); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java index 65b0d48..4b1f928 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java @@ -94,7 +94,6 @@ public class ThirdPayService { */ public PublicResp scanpay(String url,String appId, String subject, String body, Long amount,String payType, String subAppId, String userId, - String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl, String key){ WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,notifyUrl,returnUrl); diff --git a/src/main/resources/mapper/TbActivateMapper.xml b/src/main/resources/mapper/TbActivateMapper.xml index 821aa29..50d204a 100644 --- a/src/main/resources/mapper/TbActivateMapper.xml +++ b/src/main/resources/mapper/TbActivateMapper.xml @@ -116,7 +116,7 @@ - + + \ No newline at end of file From 7c5e40cd38dc8a64bd5c056d421c23545d461dce Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Thu, 23 May 2024 09:27:18 +0800 Subject: [PATCH 076/134] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/UserContoller.java | 7 +++++++ .../cashierservice/dao/TbSystemCouponsMapper.java | 3 +++ .../system/cashierservice/dao/TbUserCouponsMapper.java | 3 +++ .../system/cashierservice/service/UserService.java | 10 ++++++++++ src/main/resources/mapper/TbSystemCouponsMapper.xml | 3 +++ src/main/resources/mapper/TbUserCouponsMapper.xml | 5 ++++- 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 43a9a24..24af319 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -79,6 +80,12 @@ public class UserContoller { TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(userId,shopId); return Result.success(CodeEnum.SUCCESS,shopUser); } + + @GetMapping("/userCoupon") + public Result userCoupon(@RequestParam("userId") String userId ,@RequestParam("shopId") BigDecimal orderNum ) throws Exception { + int num = userService.userCoupon(userId,orderNum); + return Result.success(CodeEnum.SUCCESS,num); + } @PostMapping("/modityIntegral") public JSONObject modityIntegral(@RequestHeader String token,@RequestBody IntegralVo integralVo ) throws Exception { JSONObject jsonObject = TokenUtil.parseParamFromToken(token); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java index f4bfecf..c66ed50 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbSystemCouponsMapper.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbSystemCoupons; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; public interface TbSystemCouponsMapper { @@ -19,4 +20,6 @@ public interface TbSystemCouponsMapper { int updateByPrimaryKey(TbSystemCoupons record); List selectAll(@Param("type") String type); + + int selectByAmount(@Param("orderNum") BigDecimal orderNum); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java index 6ea8997..9f5c926 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.List; @Component @@ -25,4 +26,6 @@ public interface TbUserCouponsMapper { List selectByUserId(@Param("userId") String userId,@Param("status") String status); TbUserCoupons selectByOrderId(@Param("orderId") Integer orderId); + + int selectByUserIdAndAmount(@Param("userId") String userId, @Param("orderNum") BigDecimal orderNum); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index acc7811..c39c22d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -36,6 +36,10 @@ public class UserService { @Autowired private TbUserInfoMapper userInfoMapper; @Autowired + private TbUserCouponsMapper userCouponsMapper; + @Autowired + private TbSystemCouponsMapper systemCouponsMapper; + @Autowired RedisUtils redisUtils; public JSONObject modityIntegral(IntegralVo integralVo, String userSign) { @@ -218,4 +222,10 @@ public class UserService { result.put("data", pageInfo); return result; } + + public int userCoupon(String userId, BigDecimal orderNum) { + int userNum = userCouponsMapper.selectByUserIdAndAmount(userId,orderNum); + int sysNum = systemCouponsMapper.selectByAmount(orderNum); + return userNum+sysNum; + } } diff --git a/src/main/resources/mapper/TbSystemCouponsMapper.xml b/src/main/resources/mapper/TbSystemCouponsMapper.xml index 2185fbf..115e91f 100644 --- a/src/main/resources/mapper/TbSystemCouponsMapper.xml +++ b/src/main/resources/mapper/TbSystemCouponsMapper.xml @@ -24,6 +24,9 @@ + delete from tb_system_coupons where id = #{id,jdbcType=INTEGER} diff --git a/src/main/resources/mapper/TbUserCouponsMapper.xml b/src/main/resources/mapper/TbUserCouponsMapper.xml index 3c5c1c0..02c9600 100644 --- a/src/main/resources/mapper/TbUserCouponsMapper.xml +++ b/src/main/resources/mapper/TbUserCouponsMapper.xml @@ -30,7 +30,10 @@ - + + delete from tb_user_coupons where id = #{id,jdbcType=INTEGER} From 30871466965b7cfd66843048edc9f6327dbbe28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 23 May 2024 09:57:35 +0800 Subject: [PATCH 077/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/PayController.java | 5 +++-- .../system/cashierservice/service/PayService.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 5074ca9..4d0f7fb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -58,9 +58,10 @@ public class PayController { @GetMapping("accountPay") public Result accountPay(@RequestHeader("token") String token, @RequestParam("orderId") String orderId, - @RequestParam("memberId") String memberId + @RequestParam("memberId") String memberId, + @RequestParam("pwd") String pwd ) { - return payService.accountPay(orderId, memberId, token); + return payService.accountPay(orderId, memberId, token,pwd); } @RequestMapping("groupOrderPay") diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 50e200f..97ce1c4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -294,7 +294,7 @@ public class PayService { @Transactional(rollbackFor = Exception.class) - public Result accountPay(String orderId, String memberId, String token) { + public Result accountPay(String orderId, String memberId, String token,String pwd) { if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberId)) { return Result.fail("参数错误"); } @@ -305,6 +305,19 @@ public class PayService { } + TbUserInfo userInfo= tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserId())); + if(ObjectUtil.isEmpty(userInfo)){ + return Result.fail("未获取到用户信息"); + } + + + + + if(!userInfo.getPwd().equals(MD5Utils.md5(pwd))){ + return Result.fail("支付密码错误"); + } + + if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus()) ) { return Result.fail("订单出状态异常"); } From 1a3f19ff5c50718c864ad9964adada68fd69a773 Mon Sep 17 00:00:00 2001 From: wangguocheng Date: Thu, 23 May 2024 10:36:59 +0800 Subject: [PATCH 078/134] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/UserContoller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 24af319..98aa3a7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -82,7 +82,7 @@ public class UserContoller { } @GetMapping("/userCoupon") - public Result userCoupon(@RequestParam("userId") String userId ,@RequestParam("shopId") BigDecimal orderNum ) throws Exception { + public Result userCoupon(@RequestParam("userId") String userId ,@RequestParam("orderNum") BigDecimal orderNum ) throws Exception { int num = userService.userCoupon(userId,orderNum); return Result.success(CodeEnum.SUCCESS,num); } From b35da0ed1b16b191366a193973025e8627d81a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 23 May 2024 10:57:51 +0800 Subject: [PATCH 079/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mapper/TbUserInfoMapper.xml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/resources/mapper/TbUserInfoMapper.xml b/src/main/resources/mapper/TbUserInfoMapper.xml index 7b650b3..af915a2 100644 --- a/src/main/resources/mapper/TbUserInfoMapper.xml +++ b/src/main/resources/mapper/TbUserInfoMapper.xml @@ -48,6 +48,8 @@ + + id, amount, charge_amount, line_of_credit, consume_amount, consume_number, total_score, @@ -56,7 +58,7 @@ parent_id, parent_level, parent_type, project_id, merchant_id, is_resource, is_online, is_vip, vip_effect_at, tips, source_path, is_sales_person, is_attention_mp, city, search_word, last_log_in_at, last_leave_at, created_at, updated_at, bind_parent_at, - grand_parent_id,password + grand_parent_id,password,is_pwd,pwd select From 160a37f32443486a988f71d256261fde69590311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 29 May 2024 16:00:56 +0800 Subject: [PATCH 088/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 6e9883c..ec61c9d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -270,6 +270,7 @@ public class PayService { jsonObject1.put("type", ""); jsonObject1.put("data", new JSONArray()); jsonObject1.put("amount", 0); + AppWebSocketServer.AppSendInfo(jsonObject1,key, false); tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); ObjectMapper mapper = new ObjectMapper(); @@ -373,7 +374,7 @@ public class PayService { JSONObject jsonObject = new JSONObject(); jsonObject.put("token", token); - jsonObject.put("type", "create"); + jsonObject.put("type", "wxcreate"); jsonObject.put("orderId", orderId); producer.putOrderCollect(jsonObject.toJSONString()); From a59377e20d2a61a9eb19487a21818872cf28a704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 30 May 2024 09:17:04 +0800 Subject: [PATCH 089/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index ec61c9d..0024091 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -1060,6 +1060,13 @@ public class PayService { flow.setCreateTime(new Date()); tbShopUserFlowMapper.insert(flow); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("shopId", memberIn.getShopId()); + jsonObject.put("type", "wxMemberIn"); + jsonObject.put("amount",memberIn.getAmount()); + producer.putOrderCollect(jsonObject.toJSONString()); + } return "success"; } @@ -1130,8 +1137,14 @@ public class PayService { flow.setBalance(tbShopUser.getAmount()); flow.setCreateTime(new Date()); tbShopUserFlowMapper.insert(flow); - } + + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("shopId", memberIn.getShopId()); + jsonObject.put("type", "wxMemberIn"); + jsonObject.put("amount",memberIn.getAmount()); + producer.putOrderCollect(jsonObject.toJSONString()); return "SUCCESS"; } From fc962e62b73e104db95168351daf42bd540f66c3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 30 May 2024 09:21:35 +0800 Subject: [PATCH 090/134] =?UTF-8?q?web=20socket=20=E6=94=AF=E4=BB=98=20?= =?UTF-8?q?=E4=BC=9A=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/config/OtherHandler.java | 2 +- .../controller/PayController.java | 7 + .../controller/UserContoller.java | 11 +- .../cashierservice/dao/TbShopUserMapper.java | 1 + .../cashierservice/service/CartService.java | 64 ++++---- .../cashierservice/service/LoginService.java | 99 ++++++++---- .../cashierservice/service/PayService.java | 133 ++++++++-------- .../service/ProductService.java | 12 +- .../system/cashierservice/sign/CodeEnum.java | 2 +- .../system/cashierservice/sign/Result.java | 12 ++ .../socket/AppWebSocketServer.java | 145 +++++++++--------- .../system/cashierservice/util/TokenUtil.java | 9 -- src/main/resources/application.yml | 5 +- .../resources/mapper/TbShopUserFlowMapper.xml | 4 + .../resources/mapper/TbShopUserMapper.xml | 9 ++ 15 files changed, 308 insertions(+), 207 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java index 8fd78ee..44ecf80 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/OtherHandler.java @@ -21,7 +21,7 @@ public class OtherHandler extends Handler{ //传送给对应tableId用户的websocket if (StringUtils.isNotBlank(webSocke.getTableId()) && webSocketMap.containsKey(webSocke.getTableId())) { - AppSendInfo("1", webSocke.getTableId(),false); + AppSendInfo("1", webSocke.getTableId(),"",false); } else { System.out.println("请求的tableId:" + webSocke.getTableId() + "不在该服务器上"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index a5311ca..2fb2b0c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -160,5 +160,12 @@ public class PayController { return payService.getShopByMember(userId,shopId,page,pageSize); } + @RequestMapping("queryMemberAccount") + public Result queryMemberAccount(@RequestParam("memberId") String memberId, + @RequestParam(value = "page", defaultValue = "1") int page, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize + ) { + return payService.queryMemberAccount(memberId, page, pageSize); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 51108fd..df6fd58 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper; @@ -79,9 +80,17 @@ public class UserContoller { public Result shopUserInfo(@RequestParam("userId") String userId ,@RequestHeader("openId") String openId,@RequestParam("shopId") String shopId ) throws Exception { TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(userId,shopId); if (ObjectUtil.isEmpty(shopUser)) { + TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); shopUser = new TbShopUser(); + shopUser.setName(tbUserInfo.getNickName()); + shopUser.setSex(tbUserInfo.getSex()); + shopUser.setBirthDay(tbUserInfo.getBirthDay()); + shopUser.setLevel(Byte.parseByte("1")); + String code= RandomUtil.randomNumbers(6); + shopUser.setCode(code); + shopUser.setTelephone(tbUserInfo.getTelephone()); shopUser.setAmount(BigDecimal.ZERO); - shopUser.setIsVip(Byte.parseByte("0")); + shopUser.setIsVip(Byte.parseByte("1")); shopUser.setCreditAmount(BigDecimal.ZERO); shopUser.setConsumeAmount(BigDecimal.ZERO); shopUser.setConsumeNumber(0); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java index d1a23f9..44b1ab8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java @@ -19,6 +19,7 @@ public interface TbShopUserMapper { int insertSelective(TbShopUser record); TbShopUser selectByPrimaryKey(String id); + List selectByPhone(String phone); int updateByPrimaryKeySelective(TbShopUser record); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index d16335f..83b9c04 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -55,10 +55,9 @@ public class CartService { // @Transactional(rollbackFor = Exception.class) public void createCart(JSONObject jsonObject) throws Exception { try { - - String tableId = jsonObject.getString("tableId"); String shopId = jsonObject.getString("shopId"); + String key=tableId+"-"+shopId; JSONArray jsonArray = new JSONArray(); BigDecimal amount = BigDecimal.ZERO; boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId")); @@ -67,7 +66,7 @@ public class CartService { jsonObject1.put("status", "fail"); jsonObject1.put("msg", "该商品库存已售罄"); jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1, key,jsonObject.getString("userId"), true); throw new MsgException("该商品库存已售罄"); } if (jsonObject.getInteger("num") > 0) { @@ -77,7 +76,7 @@ public class CartService { jsonObject1.put("status", "fail"); jsonObject1.put("msg", "该商品库存已售罄"); jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); throw new MsgException("该商品库存已售罄"); } } else { @@ -143,7 +142,7 @@ public class CartService { jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", jsonArray); jsonObject1.put("amount", amount); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId), false); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } catch (Exception e) { e.getMessage(); } @@ -151,12 +150,13 @@ public class CartService { private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception { TbProduct product = productMapper.selectById(Integer.valueOf(productId)); + String key=tableId+"-"+shopId; if (Objects.isNull(product)) { JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); jsonObject1.put("msg", "该商品不存在"); jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, userId.toString(), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); throw new MsgException("该商品不存在"); } TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); @@ -165,7 +165,7 @@ public class CartService { jsonObject1.put("status", "fail"); jsonObject1.put("msg", "该商品规格不存在"); jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, userId.toString(), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); throw new MsgException("该商品规格不存在"); } TbCashierCart cashierCart = new TbCashierCart(); @@ -196,8 +196,11 @@ public class CartService { } @Transactional(rollbackFor = Exception.class) - public void createOrder(JSONObject jsonObject) throws Exception { + public void createOrder(JSONObject jsonObject) { + try { String shopId = jsonObject.getString("shopId"); + String tableId = jsonObject.getString("tableId"); + String key=tableId+"-"+shopId; JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); List ids = new ArrayList<>(); BigDecimal totalAmount = BigDecimal.ZERO; @@ -263,7 +266,7 @@ public class CartService { String isBuyYhq = "false"; String isuseYhq = "false"; if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { - couponId =jsonObject.getString("couponsId"); + couponId = jsonObject.getString("couponsId"); //1:购买优惠券,0:自己持有优惠券 Integer couponsId = jsonObject.getInteger("couponsId"); if (jsonObject.getString("isBuyYhq").equals("1")) { @@ -275,7 +278,7 @@ public class CartService { jsonObject1.put("msg", "优惠券已售空"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -286,7 +289,7 @@ public class CartService { jsonObject1.put("msg", "订单金额小于优惠价金额"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -314,7 +317,7 @@ public class CartService { jsonObject1.put("msg", "优惠券已使用"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -325,7 +328,7 @@ public class CartService { jsonObject1.put("msg", "订单金额小于优惠价金额"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -347,7 +350,7 @@ public class CartService { jsonObject1.put("msg", "订单正在支付中,请稍后再试"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -398,7 +401,7 @@ public class CartService { jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", orderInfo); redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); JSONObject jsonObject12 = new JSONObject(); jsonObject12.put("status", "success"); jsonObject12.put("msg", "成功"); @@ -406,7 +409,10 @@ public class CartService { jsonObject12.put("amount", BigDecimal.ZERO); jsonObject12.put("data", new JSONArray()); - AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); + AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); + } catch (Exception e) { + e.printStackTrace(); + } } private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, @@ -468,13 +474,15 @@ public class CartService { jsonObject1.put("type", "clearCart"); jsonObject1.put("amount", BigDecimal.ZERO); jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId), false); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } @Transactional(rollbackFor = Exception.class) public void pendingOrder(JSONObject jsonObject) throws IOException { try { String shopId = jsonObject.getString("shopId"); + String tableId = jsonObject.getString("tableId"); + String key=tableId+"-"+shopId; JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); List ids = new ArrayList<>(); BigDecimal totalAmount = BigDecimal.ZERO; @@ -540,7 +548,7 @@ public class CartService { String isBuyYhq = "false"; String isuseYhq = "false"; if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { - couponId =jsonObject.getString("couponsId"); + couponId = jsonObject.getString("couponsId"); //1:购买优惠券,0:自己持有优惠券 Integer couponsId = jsonObject.getInteger("couponsId"); if (jsonObject.getString("isBuyYhq").equals("1")) { @@ -552,7 +560,7 @@ public class CartService { jsonObject1.put("msg", "优惠券已售空"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -563,7 +571,7 @@ public class CartService { jsonObject1.put("msg", "订单金额小于优惠价金额"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -591,7 +599,7 @@ public class CartService { jsonObject1.put("msg", "优惠券已使用"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -602,7 +610,7 @@ public class CartService { jsonObject1.put("msg", "订单金额小于优惠价金额"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -624,7 +632,7 @@ public class CartService { jsonObject1.put("msg", "订单正在支付中,请稍后再试"); jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", ""); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); log.info("消息推送"); return; } @@ -675,8 +683,8 @@ public class CartService { jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", orderInfo); redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()),JSONObject.toJSONString(orderInfo),24*60*60); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true); + redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()), JSONObject.toJSONString(orderInfo), 24 * 60 * 60); + AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); JSONObject jsonObject12 = new JSONObject(); jsonObject12.put("status", "success"); jsonObject12.put("msg", "成功"); @@ -684,7 +692,7 @@ public class CartService { jsonObject12.put("amount", BigDecimal.ZERO); jsonObject12.put("data", new JSONArray()); - AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false); + AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } catch (Exception e) { e.getMessage(); } @@ -697,7 +705,7 @@ public class CartService { for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); } JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "success"); @@ -705,6 +713,6 @@ public class CartService { jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", array); jsonObject1.put("amount", amount); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId), false); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 95948e5..9587fb4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -9,6 +9,7 @@ import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.MD5Utils; import com.chaozhanggui.system.cashierservice.util.TokenUtil; import lombok.extern.slf4j.Slf4j; @@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; @@ -65,9 +67,9 @@ public class LoginService { userInfo.setConsumeAmount(BigDecimal.ZERO); userInfo.setTotalScore(0); userInfo.setLockScore(0); - userInfo.setHeadImg(ObjectUtil.isNotNull(headImage) ? headImage : ""); + userInfo.setHeadImg("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240411/a2be5869bfa24d72a4782f695cc53ed1.png"); userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户"); - userInfo.setTelephone(ObjectUtil.isNotNull(telephone) ? telephone : ""); + userInfo.setTelephone(telephone); userInfo.setMiniAppOpenId(openId); userInfo.setStatus(Byte.parseByte("1")); userInfo.setParentType("PERSON"); @@ -82,13 +84,39 @@ public class LoginService { userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); + List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); + if(CollectionUtils.isEmpty(tbShopUsers)){ + for (TbShopUser tbShopUser : tbShopUsers) { + userInfo.setNickName(tbShopUser.getName()); + userInfo.setSex(tbShopUser.getSex()); + userInfo.setBirthDay(tbShopUser.getBirthDay()); + tbShopUser.setLevel(Byte.parseByte("1")); + String dynamicCode = RandomUtil.randomNumbers(8); + tbShopUser.setCode(dynamicCode); + tbShopUser.setUserId(userInfo.getId() + ""); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } + } tbUserInfoMapper.insert(userInfo); - } else { + } + else { userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); userInfo.setMiniAppOpenId(openId); userInfo.setUpdatedAt(System.currentTimeMillis()); tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); } + }else { + String phone = userInfo.getTelephone(); + if (StringUtils.isBlank(phone) || !phone.equals(telephone)) { + userInfo.setTelephone(telephone); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + }else { + List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setTelephone(phone); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } + } } //生成token 信息 String token = TokenUtil.generateToken(userInfo.getId(), userInfo.getMiniAppOpenId(), userInfo.getTelephone(), userInfo.getNickName()); @@ -105,7 +133,7 @@ public class LoginService { //展示描述 //图标 // map.put("", ); -// log.info("登录结果:"+ JSONUtil.toJSONString(map)); + log.info("登录结果:" + JSONUtil.toJSONString(map)); return Result.success(CodeEnum.SUCCESS, map); } catch (Exception e) { e.printStackTrace(); @@ -149,9 +177,19 @@ public class LoginService { if (StringUtils.isNotBlank(password)) { userInfo.setPassword(MD5Utils.MD5Encode(password, "UTF-8")); } + List tbShopUsers = tbShopUserMapper.selectByPhone(phone); + for (TbShopUser tbShopUser : tbShopUsers) { + userInfo.setNickName(tbShopUser.getName()); + userInfo.setSex(tbShopUser.getSex()); + userInfo.setBirthDay(tbShopUser.getBirthDay()); + tbShopUser.setLevel(Byte.parseByte("1")); + String code= RandomUtil.randomNumbers(6); + tbShopUser.setCode(code); + tbShopUser.setUserId(userInfo.getId() + ""); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } tbUserInfoMapper.insert(userInfo); - TbUserInfo appUser = tbUserInfoMapper.selectByPhone(phone); - return appUser; + return userInfo; } /** @@ -181,9 +219,9 @@ public class LoginService { return Result.fail("暂未设置密码,请使用验证码登录"); } userInfo = register(username, password, username); - }else { + } else { String searchWord = userInfo.getSearchWord(); - if(!searchWord.contains("移动端用户")){ + if (!searchWord.contains("移动端用户")) { userInfo.setSearchWord(userInfo.getSearchWord() + "||移动端用户"); userInfo.setUpdatedAt(System.currentTimeMillis()); tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); @@ -257,12 +295,12 @@ public class LoginService { return Result.success(CodeEnum.ENCRYPT, tbUserInfo); } - public Result upPass(String userId,String oldPass,String newPass) { + public Result upPass(String userId, String oldPass, String newPass) { TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - if(!tbUserInfo.getPassword().equals(oldPass)){ + if (!tbUserInfo.getPassword().equals(oldPass)) { return Result.success(CodeEnum.FAIL_OLDPASS); } - if(tbUserInfo.getPassword().equals(newPass)){ + if (tbUserInfo.getPassword().equals(newPass)) { return Result.success(CodeEnum.FAIL_NEWPASS); } tbUserInfo.setPassword(newPass); @@ -275,19 +313,19 @@ public class LoginService { } - public Result resetPwd(String userId,Map map){ - if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") - ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("code") - ||ObjectUtil.isEmpty(map.get("code")) - ){ + public Result resetPwd(String userId, Map map) { + if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("pwd") + || ObjectUtil.isEmpty(map.get("pwd")) || !map.containsKey("code") + || ObjectUtil.isEmpty(map.get("code")) + ) { return Result.fail("参数错误"); } - TbUserInfo userInfo=tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - boolean flag= validate(map.get("code").toString(), userInfo.getTelephone()); - if(!flag){ - return Result.fail("验证码错误"); - } + TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + boolean flag = validate(map.get("code").toString(), userInfo.getTelephone()); + if (!flag) { + return Result.fail("验证码错误"); + } userInfo.setIsPwd("1"); @@ -295,26 +333,25 @@ public class LoginService { userInfo.setUpdatedAt(System.currentTimeMillis()); tbUserInfoMapper.updateByPrimaryKey(userInfo); - return Result.success(CodeEnum.SUCCESS); + return Result.success(CodeEnum.SUCCESS); } - - public Result modifyPwd(String userId,Map map){ - if(ObjectUtil.isNull(map)||ObjectUtil.isEmpty(map)||!map.containsKey("pwd") - ||ObjectUtil.isEmpty(map.get("pwd"))||!map.containsKey("oldpwd") - ||ObjectUtil.isEmpty(map.get("oldpwd")) - ){ + public Result modifyPwd(String userId, Map map) { + if (ObjectUtil.isNull(map) || ObjectUtil.isEmpty(map) || !map.containsKey("pwd") + || ObjectUtil.isEmpty(map.get("pwd")) || !map.containsKey("oldpwd") + || ObjectUtil.isEmpty(map.get("oldpwd")) + ) { return Result.fail("参数错误"); } - TbUserInfo userInfo=tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - if(ObjectUtil.isEmpty(userInfo)||ObjectUtil.isNull(userInfo)){ + TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + if (ObjectUtil.isEmpty(userInfo) || ObjectUtil.isNull(userInfo)) { return Result.fail("用户基本信息不存在"); } - if(!userInfo.getPwd().equals(MD5Utils.md5(map.get("oldpwd").toString()))){ + if (!userInfo.getPwd().equals(MD5Utils.md5(map.get("oldpwd").toString()))) { return Result.fail("用户旧密码错误"); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 0024091..fcf4063 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; @@ -232,7 +233,7 @@ public class PayService { jsonObject1.put("type", ""); jsonObject1.put("data", new JSONArray()); jsonObject1.put("amount", 0); - AppWebSocketServer.AppSendInfo(jsonObject1,key, false); + AppWebSocketServer.AppSendInfo(jsonObject1,key, "",false); tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); return Result.success(CodeEnum.SUCCESS,object.getJSONObject("data")); }else { @@ -271,7 +272,7 @@ public class PayService { jsonObject1.put("data", new JSONArray()); jsonObject1.put("amount", 0); - AppWebSocketServer.AppSendInfo(jsonObject1,key, false); + AppWebSocketServer.AppSendInfo(jsonObject1,key, "",false); tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final"); ObjectMapper mapper = new ObjectMapper(); return Result.success(CodeEnum.SUCCESS,mapper.readTree(wxScanPayResp.getPayInfo())); @@ -335,7 +336,7 @@ public class PayService { return Result.failCode("会员卡余额不足","1"); } - if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { + if (N.gt(orderInfo.getOrderAmount(), user.getAmount())) { return Result.failCode("会员卡余额不足","2"); } @@ -428,18 +429,26 @@ public class PayService { flow.setCreateTime(new Date()); tbShopUserFlowMapper.insert(flow); - orderInfo.setPayAmount(orderInfo.getOrderAmount()); - orderInfo.setPayType("deposit"); + for (int i = 0; i < orderInfo.getNumber(); i++) { + TbGroupOrderCoupon groupOrderCoupon = new TbGroupOrderCoupon(); + groupOrderCoupon.setOrderId(orderInfo.getId()); + groupOrderCoupon.setCouponNo(genCouponNumber()); + groupOrderCoupon.setIsRefund(0); + groupOrderCouponService.insert(groupOrderCoupon); + } + orderInfo.setExpDate(getNextMonDate()); + //修改主单状态 orderInfo.setStatus("unused"); + orderInfo.setPayAmount(orderInfo.getOrderAmount()); + orderInfo.setPayTime(new Date()); + orderInfo.setPayType("deposit"); + tbGroupOrderInfoMapper.update(orderInfo); orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo())); tbGroupOrderInfoMapper.update(orderInfo); -// JSONObject jsonObject = new JSONObject(); -// jsonObject.put("token", ""); -// jsonObject.put("type", "create"); -// jsonObject.put("orderId", orderId); -// -// producer.putOrderCollect(jsonObject.toJSONString()); - + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type", "groupCreate"); + jsonObject.put("orderId", orderId); + producer.putOrderCollect(jsonObject.toJSONString()); return Result.success(CodeEnum.SUCCESS); } else { @@ -480,7 +489,8 @@ public class PayService { payment.setOrderId(orderInfo.getOrderNo()); payment.setCreatedAt(System.currentTimeMillis()); tbOrderPaymentMapper.insert(payment); - } else { + } + else { if (payType.equals("wechatPay")) { payment.setPayName("微信支付"); payment.setPayType("wechatPay"); @@ -520,20 +530,14 @@ public class PayService { orderInfo.setPayType(payType); orderInfo.setPayOrderNo(payment.getTradeNumber()); tbGroupOrderInfoMapper.update(orderInfo); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", ""); - jsonObject1.put("data", new JSONArray()); - jsonObject1.put("amount", 0); tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); } else { return Result.fail("支付失败"); } } - }else { - log.info("支付金额为"); + } + else { String reqbody=""; if(body.length()>15){ @@ -568,12 +572,6 @@ public class PayService { orderInfo.setPayType(payType); orderInfo.setPayOrderNo(payment.getTradeNumber()); tbGroupOrderInfoMapper.update(orderInfo); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", ""); - jsonObject1.put("data", new JSONArray()); - jsonObject1.put("amount", 0); tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber()); ObjectMapper mapper = new ObjectMapper(); return Result.success(CodeEnum.SUCCESS,mapper.readTree(wxScanPayResp.getPayInfo())); @@ -966,6 +964,17 @@ public class PayService { return Result.success(CodeEnum.SUCCESS,pageInfo); } + public Result queryMemberAccount(String memberId,int page, int pageSize){ + if(StringUtils.isBlank(memberId)){ + return Result.fail("会员编号不许为空"); + } + PageHelper.startPage(page,pageSize); + List> list=tbShopUserFlowMapper.selectByMemberAccountFlow(memberId); + PageInfo pageInfo=new PageInfo(list); + return Result.success(CodeEnum.SUCCESS,pageInfo); + + } + @@ -1154,48 +1163,48 @@ public class PayService { // } - public static void main(String[] args){ - - RestTemplate restTemplate1= new RestTemplate(); - JSONObject param=new JSONObject(); - - String priv="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIqNqTqhN8zE7eFZnwKcyBTENce2wdAtl/gaDHNuNVgg33dS27Jx0fKl9QSHXyzyxbAdG8F94niYbRBstrMymFRjuO72jH+rIH62Ym1k7l8JSLVK2dKHXt8lHDaQGUP10q0EEocnDQ9cL93oBNG1ttsV6vOAu1TPvRK9TGihRAe1AgMBAAECgYBmI8KCl0DkcrSOsRvYuC2DqZWf8el1B3eFjeZp3e/zVOCIPYv6Q5ArWg6DVSxjnWEA0KSagqvGjU+xkQMqnXzPcPMhsIS+1wyR/pP+pwiatO2ioHaQpEqHg9eXhxrgA477/xuKVw9zl5GNqaIgd++2NDXnqLh0Y6OR73f0OB5eDQJBAPihEm+UWLOam/Q/k2+k4Lm2dvxJTBur1fslBiJpgMhgcz/PlwRwpL7aPD0AuPv0NqLouuoTiKpq9icnUv12tgsCQQCOqTANw0IErCHUNdinjXewmG3ui1j9XgM41rSn5ZeTrPL4GhZc2zbS/pZT4PBKUL6NLGkfPHmw4rOmNL/Xc5E/AkBqAwQBX5eSvVHSC2mqKPtJNGv3lqlFAzfyJg8/jQzEY5vAkZsq4Xzdg+A7gptdkvvY6rMIK9wSDhl3CGVyfbORAkA1N+g1OiHmnFACWhP4bU25EyPvWQxZeDi7e1zpRTzGWj5JT3IIMb7B9zcdE0yQbI6pG2gbvvOmiOt7lTH7raEBAkBas2gugvR3f0aGqQcqMpyM627pyRppQ2h58/7KBylP3oR2BReqMUcXeiJ8TuBXzbRXpeVQ0DWOva5CWZJmBMdz"; - - PayReq req=new PayReq(); - - req.setAppId("M8002023120892f1e4"); - req.setTimestamp(System.currentTimeMillis()); - req.setIp("127.0.0.1"); - req.setMercOrderNo(System.currentTimeMillis()+""); - req.setNotifyUrl("https"); - req.setPayAmt("0.01"); - req.setPayType("03"); - req.setPayWay("WXZF"); - req.setSubject("ddd"); - req.setUserId("or1l864NBOoJZhC5x_yeziZ26j6c"); - - Map map= BeanUtil.transBeanMap(req); - - req.setSign(MD5Util.encrypt(map,priv,true)); - - - ResponseEntity response= restTemplate1.postForEntity("https://gatewaytestapi.sxczgkj.cn/gate-service/trans/pay",req,String.class); - - - -// TradeQueryReq req=new TradeQueryReq(); -// req.setAppId("M800202305094c170c"); +// public static void main(String[] args){ +// +// RestTemplate restTemplate1= new RestTemplate(); +// JSONObject param=new JSONObject(); +// +// String priv="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIqNqTqhN8zE7eFZnwKcyBTENce2wdAtl/gaDHNuNVgg33dS27Jx0fKl9QSHXyzyxbAdG8F94niYbRBstrMymFRjuO72jH+rIH62Ym1k7l8JSLVK2dKHXt8lHDaQGUP10q0EEocnDQ9cL93oBNG1ttsV6vOAu1TPvRK9TGihRAe1AgMBAAECgYBmI8KCl0DkcrSOsRvYuC2DqZWf8el1B3eFjeZp3e/zVOCIPYv6Q5ArWg6DVSxjnWEA0KSagqvGjU+xkQMqnXzPcPMhsIS+1wyR/pP+pwiatO2ioHaQpEqHg9eXhxrgA477/xuKVw9zl5GNqaIgd++2NDXnqLh0Y6OR73f0OB5eDQJBAPihEm+UWLOam/Q/k2+k4Lm2dvxJTBur1fslBiJpgMhgcz/PlwRwpL7aPD0AuPv0NqLouuoTiKpq9icnUv12tgsCQQCOqTANw0IErCHUNdinjXewmG3ui1j9XgM41rSn5ZeTrPL4GhZc2zbS/pZT4PBKUL6NLGkfPHmw4rOmNL/Xc5E/AkBqAwQBX5eSvVHSC2mqKPtJNGv3lqlFAzfyJg8/jQzEY5vAkZsq4Xzdg+A7gptdkvvY6rMIK9wSDhl3CGVyfbORAkA1N+g1OiHmnFACWhP4bU25EyPvWQxZeDi7e1zpRTzGWj5JT3IIMb7B9zcdE0yQbI6pG2gbvvOmiOt7lTH7raEBAkBas2gugvR3f0aGqQcqMpyM627pyRppQ2h58/7KBylP3oR2BReqMUcXeiJ8TuBXzbRXpeVQ0DWOva5CWZJmBMdz"; +// +// PayReq req=new PayReq(); +// +// req.setAppId("M8002023120892f1e4"); // req.setTimestamp(System.currentTimeMillis()); -// req.setOrderNumber("SXF_W_MERC_20240205182102491"); +// req.setIp("127.0.0.1"); +// req.setMercOrderNo(System.currentTimeMillis()+""); +// req.setNotifyUrl("https"); +// req.setPayAmt("0.01"); +// req.setPayType("03"); +// req.setPayWay("WXZF"); +// req.setSubject("ddd"); +// req.setUserId("or1l864NBOoJZhC5x_yeziZ26j6c"); +// // Map map= BeanUtil.transBeanMap(req); // // req.setSign(MD5Util.encrypt(map,priv,true)); // -// ResponseEntity response= restTemplate1.postForEntity("https://gateway.api.sxczgkj.cn/gate-service/merchantOrder/tradeQuery",req,String.class); +// +// ResponseEntity response= restTemplate1.postForEntity("https://gatewaytestapi.sxczgkj.cn/gate-service/trans/pay",req,String.class); // // - System.out.println(">>>>>>>>>>>>>>>"+response.getBody()); - } +// +//// TradeQueryReq req=new TradeQueryReq(); +//// req.setAppId("M800202305094c170c"); +//// req.setTimestamp(System.currentTimeMillis()); +//// req.setOrderNumber("SXF_W_MERC_20240205182102491"); +//// Map map= BeanUtil.transBeanMap(req); +//// +//// req.setSign(MD5Util.encrypt(map,priv,true)); +//// +//// ResponseEntity response= restTemplate1.postForEntity("https://gateway.api.sxczgkj.cn/gate-service/merchantOrder/tradeQuery",req,String.class); +//// +//// +// System.out.println(">>>>>>>>>>>>>>>"+response.getBody()); +// } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 5f1d829..677a495 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.chaozhanggui.system.cashierservice.dao.*; @@ -64,6 +65,8 @@ public class ProductService { @Autowired private TbShopUserMapper tbShopUserMapper; + @Autowired + private TbUserInfoMapper tbUserInfoMapper; public Result queryShopIdByTableCode(String userId,String openId,String code) { String shopId = tbShopTableMapper.queryShopIdByTableCode(code); @@ -73,9 +76,16 @@ public class ProductService { TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); if (ObjectUtil.isEmpty(tbShopUser)) { + TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); tbShopUser = new TbShopUser(); + tbShopUser.setName(tbUserInfo.getNickName()); + tbShopUser.setSex(tbUserInfo.getSex()); + tbShopUser.setBirthDay(tbUserInfo.getBirthDay()); + tbShopUser.setLevel(Byte.parseByte("1")); + tbShopUser.setCode(RandomUtil.randomNumbers(6)); + tbShopUser.setTelephone(tbUserInfo.getTelephone()); tbShopUser.setAmount(BigDecimal.ZERO); - tbShopUser.setIsVip(Byte.parseByte("0")); + tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setCreditAmount(BigDecimal.ZERO); tbShopUser.setConsumeAmount(BigDecimal.ZERO); tbShopUser.setConsumeNumber(0); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/CodeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/CodeEnum.java index c9262d3..4cc4ff8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/CodeEnum.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/CodeEnum.java @@ -11,7 +11,7 @@ public enum CodeEnum { FAIL_OLDPASS("1",false,"修改失败,旧密码错误","fail"), FAIL_NEWPASS("1",false,"新密码不能与旧密码相同","fail"), TOKEN_EXEIST("-4",false,"token不能为空","fail"), - TOKEN_EXPIRED("-4",false,"账号已过期,请重新登陆","fail"), + TOKEN_EXPIRED("-4",false,"请先登陆","fail"), SIGN_FAIL("100013",false,"签名不正确","fail"), ORGAN_NO_EXEIST("100010",false,"机构代码不存在或状态异常,请联系服务商","fail"), diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java index 9c9f7ff..e571b5c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java @@ -53,6 +53,18 @@ public class Result { } +// public Result(String msg, Object data, String code, boolean encrypt, String icon) { +// this.msg = msg; +// this.code = code; +// this.encrypt = encrypt; +// this.icon = icon; +// if(encrypt){ +// this.data= DESUtil.encode(JSONUtil.toJsonStr(data)); +// }else{ +// this.data=data; +// } +// } + public Result(CodeEnum enums) { this.msg = enums.getMsg(); this.encrypt = enums.getEncrypt(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index b436b5f..d1e8e61 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -54,9 +54,9 @@ public class AppWebSocketServer { * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 */ //一个 AppWebSocketServer 就是一个用户,一个tableId下有一个 List 也就是多个用户 - private static ConcurrentHashMap> webSocketMap = new ConcurrentHashMap<>(); + private static HashMap> webSocketMap = new HashMap<>(); public static ConcurrentHashMap> userMap = new ConcurrentHashMap<>(); - private static ConcurrentHashMap userSocketMap = new ConcurrentHashMap<>(); +// private static ConcurrentHashMap userSocketMap = new ConcurrentHashMap<>(); //购物车的记录,用于第一次扫码的人同步购物车 private static ConcurrentHashMap> recordMap = new ConcurrentHashMap<>(); private static ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); @@ -86,12 +86,13 @@ public class AppWebSocketServer { */ @OnOpen public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) { + log.info("建立连接参数 tableId:{} shopId:{} userId:{}",tableId,shopId,userId); this.session = session; this.tableId = tableId; this.shopId = shopId; this.userId = userId; - log.info("链接桌码:"+tableId); try { + String key=tableId + "-" + shopId; TbShopTable shopTable = shopTableMapper.selectQRcode(tableId); if (Objects.isNull(shopTable)) { JSONObject jsonObject1 = new JSONObject(); @@ -103,27 +104,26 @@ public class AppWebSocketServer { sendMessage(jsonObject1); onClose(); } - if (webSocketMap.containsKey(tableId + "-" + shopId)) { - List serverList = webSocketMap.get(tableId + "-" + shopId); - serverList.add(this); + if (webSocketMap.containsKey(key)) { + ConcurrentHashMap userSocketMap = webSocketMap.get(key); + // 在放置新条目之前检查并清除同名userId的数据 + userSocketMap.put(userId,this); } else { - List serverList = new ArrayList<>(); - serverList.add(this); - webSocketMap.put(tableId + "-" + shopId, serverList); + ConcurrentHashMap userSocketMap=new ConcurrentHashMap<>(); + userSocketMap.put(userId,this); + webSocketMap.put(key,userSocketMap); } - if (userMap.containsKey(tableId + "-" + shopId)) { - Set userSet = userMap.get(tableId + "-" + shopId); + + if (userMap.containsKey(key)) { + Set userSet = userMap.get(key); userSet.add(userId); } else { Set userSet = new HashSet<>(); userSet.add(userId); - userMap.put(tableId + "-" + shopId,userSet); + userMap.put(key,userSet); } - - userSocketMap.put(userId, this); -// sessionMap.put(userId,session); - String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId)); + String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(key)); if (StringUtils.isEmpty(mes)) { JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "success"); @@ -138,7 +138,7 @@ public class AppWebSocketServer { jsonObject1.put("msg", "成功"); jsonObject1.put("type", "addCart"); BigDecimal amount = BigDecimal.ZERO; - JSONArray jsonArray = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(tableId + "-" + shopId))); + JSONArray jsonArray = JSON.parseArray(redisUtils.getMessage(RedisCst.TABLE_CART.concat(key))); for (int i = 0; i < jsonArray.size(); i++) { JSONObject object = jsonArray.getJSONObject(i); amount = amount.add(object.getBigDecimal("totalAmount")); @@ -157,14 +157,13 @@ public class AppWebSocketServer { * 连接关闭调用的方法 */ @OnClose - public void onClose() { - if (webSocketMap.containsKey(tableId + "-" + shopId)) { - List serverList = webSocketMap.get(tableId + "-" + shopId); - if (serverList.isEmpty()) { - webSocketMap.remove(tableId + "-" + shopId); - } - serverList.remove(this); - + public void onClose() throws IOException { + String key=tableId + "-" + shopId; + log.info("触发关闭操作 key为:{} userId为:{}",key,userId); + if (webSocketMap.containsKey(key)) { + ConcurrentHashMap userSocketMap = webSocketMap.get(key); + // 在放置新条目之前检查并清除同名userId的数据 + userSocketMap.remove(userId); } if (userMap.containsKey(tableId + "-" + shopId)){ Set userSet = userMap.get(tableId + "-" + shopId); @@ -174,10 +173,7 @@ public class AppWebSocketServer { userSet.remove(userId); } } - public static void onClosed(String user) throws IOException { - Session session1 = sessionMap.get(user); - session1.close(); - } + /** * 收到客户端消息后调用的方法 * @@ -246,9 +242,8 @@ public class AppWebSocketServer { * @param error */ @OnError - public void onError(Session session, Throwable error) { + public void onError(Session session, Throwable error) throws IOException { log.error("用户错误:" + this.tableId + ",原因:" + error.getMessage()); - error.printStackTrace(); } /** @@ -274,29 +269,35 @@ public class AppWebSocketServer { * 发送自定义消息 * * @param message 发送的信息 - * @param tableId 如果为null默认发送所有 + * @param tableId 如果为null默认发送所有 tableId-shopId(桌码-店铺ID) + * @param userId userFlag为 true时 必填 + * @param userFlag true 发送给指定用户 false 群发 * @throws IOException */ - public static void AppSendInfo(Object message, String tableId, boolean userFlag) throws IOException { + public static void AppSendInfo(Object message, String tableId,String userId, boolean userFlag) throws IOException { + log.info("发送消息 tableId:{} \n userFlag:{}\n message:{}",tableId,userFlag,JSONUtil.toJSONString(message)); if (userFlag) { - if (userSocketMap.containsKey(tableId)) { - AppWebSocketServer server = userSocketMap.get(tableId); - server.sendMessage(message); - } else { - log.error("请求的userId:" + tableId + "不在该服务器上"); + if (webSocketMap.containsKey(tableId)) { + ConcurrentHashMap userSocketMap = webSocketMap.get(tableId); + if(StringUtils.isNotBlank(userId)){ + userSocketMap.get(userId).sendMessage(message); + } + }else { + log.error("请求的tableId:"+tableId+" userId:" + userId + "不在该服务器上"); } } else { if (StringUtils.isEmpty(tableId)) { // 向所有用户发送信息 - for (List serverList : webSocketMap.values()) { - for (AppWebSocketServer server : serverList) { + for (ConcurrentHashMap value : webSocketMap.values()) { + for (AppWebSocketServer server : value.values()) { server.sendMessage(message); } } } else if (webSocketMap.containsKey(tableId)) { - // 发送给指定用户信息 - List serverList = webSocketMap.get(tableId); - for (AppWebSocketServer server : serverList) { + log.info("发送消息的webSocketMap:存在"); + // 对应桌码发送消息 + for (AppWebSocketServer server : webSocketMap.get(tableId).values()) { + log.info("发送消息的webSocketMap 次数:"); server.sendMessage(message); } } else { @@ -307,33 +308,33 @@ public class AppWebSocketServer { } - public static synchronized ConcurrentHashMap> getWebSocketMap() { - return AppWebSocketServer.webSocketMap; - } - - public static synchronized ConcurrentHashMap> getRecordMap() { - return AppWebSocketServer.recordMap; - } - private byte[] serialize(Object obj) { - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(obj); - return bos.toByteArray(); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - private Object deserialize(byte[] bytes) { - try { - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInputStream ois = new ObjectInputStream(bis); - return ois.readObject(); - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); - return null; - } - } +// public static synchronized ConcurrentHashMap> getWebSocketMap() { +// return AppWebSocketServer.webSocketMap; +// } +// +// public static synchronized ConcurrentHashMap> getRecordMap() { +// return AppWebSocketServer.recordMap; +// } +// private byte[] serialize(Object obj) { +// try { +// ByteArrayOutputStream bos = new ByteArrayOutputStream(); +// ObjectOutputStream oos = new ObjectOutputStream(bos); +// oos.writeObject(obj); +// return bos.toByteArray(); +// } catch (IOException e) { +// e.printStackTrace(); +// return null; +// } +// } +// +// private Object deserialize(byte[] bytes) { +// try { +// ByteArrayInputStream bis = new ByteArrayInputStream(bytes); +// ObjectInputStream ois = new ObjectInputStream(bis); +// return ois.readObject(); +// } catch (IOException | ClassNotFoundException e) { +// e.printStackTrace(); +// return null; +// } +// } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java index 86404fa..2450d3c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java @@ -29,10 +29,6 @@ public class TokenUtil { */ private static final String TOKEN_SECRET = "BBDFSDFHFGHSGSRTRESDFSDFS"; - private JwtBuilder jwtBuilder; - - public static final String AUTHORITIES_KEY = "user"; - /** * 初始化生成token的参数 * @param userId @@ -45,17 +41,12 @@ public class TokenUtil { if(ObjectUtil.isNotEmpty(openId)){ claims.put("openId",openId); } - if(ObjectUtil.isNotEmpty(phone)){ claims.put("phone",phone); } - if(ObjectUtil.isNotEmpty(userName)){ claims.put("userName",userName); } - - - return generateToken(claims); } public static String generateJfToken(String openId,String userSign) throws Exception { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f520886..618e53b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 9889 +# port: 9889 servlet: context-path: /cashierService/ wx: @@ -10,6 +10,9 @@ wx: custom: appId: wxd88fffa983758a30 secrete: a34a61adc0602118b49400baa8812454 +# 卓尔 +# appId: wx0dcea6001b0a8fb4 +# secrete: ba42423cce61f93f02519ff3030ceb1c # spring: profiles: diff --git a/src/main/resources/mapper/TbShopUserFlowMapper.xml b/src/main/resources/mapper/TbShopUserFlowMapper.xml index c395a1f..9c9e34a 100644 --- a/src/main/resources/mapper/TbShopUserFlowMapper.xml +++ b/src/main/resources/mapper/TbShopUserFlowMapper.xml @@ -122,6 +122,10 @@ FROM tb_shop_user_flow f LEFT JOIN tb_shop_user u ON f.shop_user_id = u.id + where 1=1 + + and u.id = #{memberId} + order by f.id desc \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index 859a01a..7658195 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -44,6 +44,13 @@ from tb_shop_user where id = #{id,jdbcType=VARCHAR} + + delete from tb_shop_user where id = #{id,jdbcType=VARCHAR} @@ -386,11 +393,13 @@ + + From 2e422ae6b1dc9b6b74e431767120d4b61ef5fd80 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 30 May 2024 13:44:39 +0800 Subject: [PATCH 096/134] =?UTF-8?q?=E8=A7=A3=E7=A0=81=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=83=85=E5=86=B5=E6=97=A5?= =?UTF-8?q?=E5=BF=97=20=E9=99=84=E8=BF=91=E4=B8=80=E5=8D=83=E7=B1=B3?= =?UTF-8?q?=E7=9A=84type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/LoginContoller.java | 7 ++++++- .../system/cashierservice/service/ProductService.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 2911e96..590149e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -127,8 +127,13 @@ public class LoginContoller { return Result.fail("签名校验失败"); } String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); + String phone = ""; log.info("登录传参:解码获取手机号{}",data); - String phone =JSONObject.parseObject(data).get("phoneNumber").toString(); + if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { + phone =JSONObject.parseObject(data).get("phoneNumber").toString(); + }else { + log.info("登录传参:获取手机号失败{}",data); + } String nickName = rawDataJson.getString("nickName"); String avatarUrl = rawDataJson.getString("avatarUrl"); try { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 34832c6..b168420 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -187,6 +187,7 @@ public class ProductService { homeDto.setSize(4); } if (homeDto.getType().equals("near")) { + homeDto.setType(""); homeDto.setDistanceInKm("1"); } PageHelper.startPage(homeDto.getPage(), homeDto.getSize()); From a50210ec524f5cdc19d86d0069fe2a6d987bd993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 30 May 2024 15:03:06 +0800 Subject: [PATCH 097/134] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=A4=B1=E6=95=88=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/CommonController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 0002982..3888625 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -43,7 +43,7 @@ public class CommonController { /** * 一分钟 */ - protected static final long ONE_MINUTE = 60; + protected static final long ONE_MINUTE = 1800; /** * 发送短信验证码 From 9a30a40cee06b5cb7f8df9c3d08d18b0220a4404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Thu, 30 May 2024 15:03:24 +0800 Subject: [PATCH 098/134] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E5=A4=B1=E6=95=88=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 618e53b..0d3801d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -60,6 +60,6 @@ aliyun: thirdPay: payType: fushangtong - callInBack: https://wxcashiertest.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack - callFSTBack: https://wxcashiertest.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack + callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack + callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack url: https://paymentapi.sxczgkj.cn From c403b691022a3f3808a70e26d98addef2d8adae0 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 30 May 2024 16:47:02 +0800 Subject: [PATCH 099/134] =?UTF-8?q?socket=E4=B8=BA=E7=A9=BA=E6=97=B6=20?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=20=E8=8E=B7=E5=8F=96=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 10 ++--- .../cashierservice/service/LoginService.java | 44 +++++++++++-------- .../socket/AppWebSocketServer.java | 10 +++-- src/main/resources/application-dev2.yml | 2 +- .../resources/mapper/TbProductSkuMapper.xml | 2 + 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 590149e..5112a7c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -110,7 +110,6 @@ public class LoginContoller { String encryptedData = map.get("encryptedData"); String ivStr = map.get("iv"); // String phone = map.get("phone"); - log.info("登录传参:入参:{}",JSONUtil.toJSONString(map)); // 用户非敏感信息:rawData // 签名:signature JSONObject rawDataJson = JSON.parseObject(rawData); @@ -128,10 +127,11 @@ public class LoginContoller { } String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); String phone = ""; - log.info("登录传参:解码获取手机号{}",data); - if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { - phone =JSONObject.parseObject(data).get("phoneNumber").toString(); - }else { + try{ + if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { + phone =JSONObject.parseObject(data).get("phoneNumber").toString(); + } + }catch (Exception e){ log.info("登录传参:获取手机号失败{}",data); } String nickName = rawDataJson.getString("nickName"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 0a39bce..9ccd7ce 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -57,7 +57,9 @@ public class LoginService { public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String ip) throws Exception { TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId); if (ObjectUtil.isNull(userInfo)) { - userInfo = tbUserInfoMapper.selectByPhone(telephone); + if(StringUtils.isNotBlank(telephone)){ + userInfo = tbUserInfoMapper.selectByPhone(telephone); + } if (ObjectUtil.isNull(userInfo)) { userInfo = new TbUserInfo(); userInfo.setAmount(BigDecimal.ZERO); @@ -84,17 +86,19 @@ public class LoginService { userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); - List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); - if(CollectionUtils.isEmpty(tbShopUsers)){ - for (TbShopUser tbShopUser : tbShopUsers) { - userInfo.setNickName(tbShopUser.getName()); - userInfo.setSex(tbShopUser.getSex()); - userInfo.setBirthDay(tbShopUser.getBirthDay()); - tbShopUser.setLevel(Byte.parseByte("1")); - String dynamicCode = RandomUtil.randomNumbers(8); - tbShopUser.setCode(dynamicCode); - tbShopUser.setUserId(userInfo.getId() + ""); - tbShopUserMapper.updateByPrimaryKey(tbShopUser); + if(StringUtils.isNotBlank(telephone)){ + List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); + if(CollectionUtils.isEmpty(tbShopUsers)){ + for (TbShopUser tbShopUser : tbShopUsers) { + userInfo.setNickName(tbShopUser.getName()); + userInfo.setSex(tbShopUser.getSex()); + userInfo.setBirthDay(tbShopUser.getBirthDay()); + tbShopUser.setLevel(Byte.parseByte("1")); + String dynamicCode = RandomUtil.randomNumbers(8); + tbShopUser.setCode(dynamicCode); + tbShopUser.setUserId(userInfo.getId() + ""); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } } } tbUserInfoMapper.insert(userInfo); @@ -108,13 +112,15 @@ public class LoginService { } else { String phone = userInfo.getTelephone(); - if (StringUtils.isBlank(phone) || !phone.equals(telephone)) { - userInfo.setTelephone(telephone); - tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); - List tbShopUsers = tbShopUserMapper.selectAllByUserId(userInfo.getId().toString()); - for (TbShopUser tbShopUser : tbShopUsers) { - tbShopUser.setTelephone(phone); - tbShopUserMapper.updateByPrimaryKey(tbShopUser); + if(StringUtils.isNotBlank(telephone)){ + if (StringUtils.isBlank(phone) || !phone.equals(telephone)) { + userInfo.setTelephone(telephone); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + List tbShopUsers = tbShopUserMapper.selectAllByUserId(userInfo.getId().toString()); + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setTelephone(phone); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } } } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index d1e8e61..4f84092 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -275,12 +275,16 @@ public class AppWebSocketServer { * @throws IOException */ public static void AppSendInfo(Object message, String tableId,String userId, boolean userFlag) throws IOException { - log.info("发送消息 tableId:{} \n userFlag:{}\n message:{}",tableId,userFlag,JSONUtil.toJSONString(message)); + log.info("发送消息 tableId:{} \n userId:{}\n userFlag:{}\n message:{}",tableId,userId,userFlag,JSONUtil.toJSONString(message)); if (userFlag) { if (webSocketMap.containsKey(tableId)) { ConcurrentHashMap userSocketMap = webSocketMap.get(tableId); - if(StringUtils.isNotBlank(userId)){ - userSocketMap.get(userId).sendMessage(message); + if(!userSocketMap.isEmpty()){ + if(StringUtils.isNotBlank(userId)){ + userSocketMap.get(userId).sendMessage(message); + } + }else { + log.error("请求的tableId:"+tableId+"用户连接为空"); } }else { log.error("请求的tableId:"+tableId+" userId:" + userId + "不在该服务器上"); diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml index b2b5fb8..3287e1e 100644 --- a/src/main/resources/application-dev2.yml +++ b/src/main/resources/application-dev2.yml @@ -52,7 +52,7 @@ mybatis: ysk: url: https://gatewaytestapi.sxczgkj.cn/gate-service/ callBackurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBack - callBackGroupurl: https://p40312246f.goho.co/cashierService/notify/notifyCallBackGroup + callBackGroupurl: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 server: diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 67d4e15..c928a35 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -402,6 +402,7 @@ LEFT JOIN tb_product_sku sku ON pro.id = sku.product_id WHERE pro.type_enum = 'group' + AND pro.is_combo = '1' GROUP BY sku.product_id ORDER BY @@ -421,6 +422,7 @@ LEFT JOIN tb_product_sku sku ON pro.id = sku.product_id WHERE pro.type_enum = 'group' + AND pro.is_combo = '1' GROUP BY sku.product_id ORDER BY From c81a2106d038823683c7270cd0cf0de45129b7c3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 31 May 2024 10:18:40 +0800 Subject: [PATCH 100/134] =?UTF-8?q?=E8=BF=9B=E5=BA=97=E5=8D=B3=E4=BC=9A?= =?UTF-8?q?=E5=91=98=20=E5=8F=96=E6=B6=88=20=E9=95=BF=E9=93=BE=E6=8E=A5=20?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserContoller.java | 2 +- .../cashierservice/rabbit/CartConsumer.java | 7 + .../cashierservice/service/CartService.java | 173 ++++++++++-------- .../cashierservice/service/LoginService.java | 12 -- .../service/ProductService.java | 2 +- 5 files changed, 104 insertions(+), 92 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index a24b675..929f7df 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -90,7 +90,7 @@ public class UserContoller { shopUser.setCode(dynamicCode); shopUser.setTelephone(tbUserInfo.getTelephone()); shopUser.setAmount(BigDecimal.ZERO); - shopUser.setIsVip(Byte.parseByte("1")); + shopUser.setIsVip(Byte.parseByte("0")); shopUser.setCreditAmount(BigDecimal.ZERO); shopUser.setConsumeAmount(BigDecimal.ZERO); shopUser.setConsumeNumber(0); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index 08a4fea..6aa17c7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -44,6 +44,13 @@ public class CartConsumer { } else if(jsonObject.getString("type").equals("createOrder")){ String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId)); if (StringUtils.isEmpty(cartDetail)){ + log.info("createOrder购物车为空"); +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("status", "success"); +// jsonObject1.put("msg", "订单已存在"); +// jsonObject1.put("type", jsonObject.getString("type")); +// jsonObject1.put("data", "{\"id\": \"-1\"}"); +// AppWebSocketServer.AppSendInfo(jsonObject1,tableId+"-"+shopId, jsonObject.getString("userId"), true); throw new MsgException("购物车为空无法下单"); } JSONArray array = JSON.parseArray(cartDetail); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 83b9c04..19cd361 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -53,7 +53,7 @@ public class CartService { private TbSystemCouponsMapper systemCouponsMapper; // @Transactional(rollbackFor = Exception.class) - public void createCart(JSONObject jsonObject) throws Exception { + public void createCart(JSONObject jsonObject) { try { String tableId = jsonObject.getString("tableId"); String shopId = jsonObject.getString("shopId"); @@ -144,55 +144,60 @@ public class CartService { jsonObject1.put("amount", amount); AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } catch (Exception e) { - e.getMessage(); + log.info("长链接错误 createCart{}",e.getMessage()); } } private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception { - TbProduct product = productMapper.selectById(Integer.valueOf(productId)); - String key=tableId+"-"+shopId; - if (Objects.isNull(product)) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品不存在"); - jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); - throw new MsgException("该商品不存在"); + try { + TbProduct product = productMapper.selectById(Integer.valueOf(productId)); + String key=tableId+"-"+shopId; + if (Objects.isNull(product)) { + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "该商品不存在"); + jsonObject1.put("data", new ArrayList<>()); + AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); + throw new MsgException("该商品不存在"); + } + TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); + if (Objects.isNull(productSku)) { + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "该商品规格不存在"); + jsonObject1.put("data", new ArrayList<>()); + AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); + throw new MsgException("该商品规格不存在"); + } + TbCashierCart cashierCart = new TbCashierCart(); + cashierCart.setProductId(productId); + cashierCart.setSkuId(skuId); + cashierCart.setNumber(num); + cashierCart.setCoverImg(product.getCoverImg()); + cashierCart.setName(product.getName()); + cashierCart.setCategoryId(product.getCategoryId()); + cashierCart.setShopId(shopId); + cashierCart.setUserId(userId); + cashierCart.setTableId(tableId); + cashierCart.setSkuName(productSku.getSpecSnap()); + cashierCart.setIsPack("false"); + cashierCart.setIsGift("false"); + cashierCart.setUserId(userId); + cashierCart.setStatus("create"); + cashierCart.setType((byte) 0); + cashierCart.setSalePrice(productSku.getSalePrice()); + cashierCart.setCreatedAt(Instant.now().toEpochMilli()); + cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); + cashierCart.setTotalNumber(num); + cashierCart.setPackFee(BigDecimal.ZERO); + cashierCart.setRefundNumber(0); + cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee()))); + cashierCartMapper.insert(cashierCart); + return cashierCart; + }catch (Exception e){ + log.info("长链接错误 addCart{}",e.getMessage()); + throw e; } - TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); - if (Objects.isNull(productSku)) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品规格不存在"); - jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true); - throw new MsgException("该商品规格不存在"); - } - TbCashierCart cashierCart = new TbCashierCart(); - cashierCart.setProductId(productId); - cashierCart.setSkuId(skuId); - cashierCart.setNumber(num); - cashierCart.setCoverImg(product.getCoverImg()); - cashierCart.setName(product.getName()); - cashierCart.setCategoryId(product.getCategoryId()); - cashierCart.setShopId(shopId); - cashierCart.setUserId(userId); - cashierCart.setTableId(tableId); - cashierCart.setSkuName(productSku.getSpecSnap()); - cashierCart.setIsPack("false"); - cashierCart.setIsGift("false"); - cashierCart.setUserId(userId); - cashierCart.setStatus("create"); - cashierCart.setType((byte) 0); - cashierCart.setSalePrice(productSku.getSalePrice()); - cashierCart.setCreatedAt(Instant.now().toEpochMilli()); - cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); - cashierCart.setTotalNumber(num); - cashierCart.setPackFee(BigDecimal.ZERO); - cashierCart.setRefundNumber(0); - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee()))); - cashierCartMapper.insert(cashierCart); - return cashierCart; } @Transactional(rollbackFor = Exception.class) @@ -411,6 +416,7 @@ public class CartService { jsonObject12.put("data", new JSONArray()); AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } catch (Exception e) { + log.info("长链接错误 addCart{}",e.getMessage()); e.printStackTrace(); } } @@ -453,28 +459,33 @@ public class CartService { return "WX" + date + randomNum; } - public void clearCart(JSONObject jsonObject) throws IOException { - String shopId = jsonObject.getString("shopId"); - if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) { - for (int i = 0; i < array.size(); i++) { - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(array.get(i).toString(), TbCashierCart.class); + public void clearCart(JSONObject jsonObject){ + try{ + String shopId = jsonObject.getString("shopId"); + if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { + JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); + if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) { + for (int i = 0; i < array.size(); i++) { + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(array.get(i).toString(), TbCashierCart.class); // String result = redisUtil.secAdd(RedisCst.PRODUCT+shopId+":"+jsonObject.getString("skuId"),cashierCart.getNumber().toString()); - productSkuMapper.updateAddStockById(jsonObject.getString("skuId"), cashierCart.getNumber()); + productSkuMapper.updateAddStockById(jsonObject.getString("skuId"), cashierCart.getNumber()); + } } } + cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed"); + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString()); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", "clearCart"); + jsonObject1.put("amount", BigDecimal.ZERO); + jsonObject1.put("data", new ArrayList<>()); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); + }catch (Exception e){ + log.info("长链接错误 clearCart{}",e.getMessage()); + e.printStackTrace(); } - cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed"); - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString()); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", "clearCart"); - jsonObject1.put("amount", BigDecimal.ZERO); - jsonObject1.put("data", new ArrayList<>()); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } @Transactional(rollbackFor = Exception.class) @@ -694,25 +705,31 @@ public class CartService { jsonObject12.put("data", new JSONArray()); AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } catch (Exception e) { - e.getMessage(); + log.info("长链接错误 pendingOrder{}",e.getMessage()); + e.printStackTrace(); } } - public void queryCart(JSONObject jsonObject) throws IOException { - String shopId = jsonObject.getString("shopId"); - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - BigDecimal amount = BigDecimal.ZERO; - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + public void queryCart(JSONObject jsonObject) { + try { + String shopId = jsonObject.getString("shopId"); + JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); + BigDecimal amount = BigDecimal.ZERO; + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("data", array); + jsonObject1.put("amount", amount); + AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); + }catch (Exception e){ + log.info("长链接错误 queryCart{}",e.getMessage()); + e.printStackTrace(); } - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", array); - jsonObject1.put("amount", amount); - AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 9ccd7ce..bc4a05e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -90,12 +90,6 @@ public class LoginService { List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); if(CollectionUtils.isEmpty(tbShopUsers)){ for (TbShopUser tbShopUser : tbShopUsers) { - userInfo.setNickName(tbShopUser.getName()); - userInfo.setSex(tbShopUser.getSex()); - userInfo.setBirthDay(tbShopUser.getBirthDay()); - tbShopUser.setLevel(Byte.parseByte("1")); - String dynamicCode = RandomUtil.randomNumbers(8); - tbShopUser.setCode(dynamicCode); tbShopUser.setUserId(userInfo.getId() + ""); tbShopUserMapper.updateByPrimaryKey(tbShopUser); } @@ -185,12 +179,6 @@ public class LoginService { } List tbShopUsers = tbShopUserMapper.selectByPhone(phone); for (TbShopUser tbShopUser : tbShopUsers) { - userInfo.setNickName(tbShopUser.getName()); - userInfo.setSex(tbShopUser.getSex()); - userInfo.setBirthDay(tbShopUser.getBirthDay()); - tbShopUser.setLevel(Byte.parseByte("1")); - String dynamicCode = RandomUtil.randomNumbers(8); - tbShopUser.setCode(dynamicCode); tbShopUser.setUserId(userInfo.getId() + ""); tbShopUserMapper.updateByPrimaryKey(tbShopUser); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index b168420..d850127 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -85,7 +85,7 @@ public class ProductService { tbShopUser.setCode(RandomUtil.randomNumbers(8)); tbShopUser.setTelephone(tbUserInfo.getTelephone()); tbShopUser.setAmount(BigDecimal.ZERO); - tbShopUser.setIsVip(Byte.parseByte("1")); + tbShopUser.setIsVip(Byte.parseByte("0")); tbShopUser.setCreditAmount(BigDecimal.ZERO); tbShopUser.setConsumeAmount(BigDecimal.ZERO); tbShopUser.setConsumeNumber(0); From 63a3c7c652938300b4812edb6458264c99c4d5f6 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 31 May 2024 10:34:50 +0800 Subject: [PATCH 101/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=85=85=E5=80=BC?= =?UTF-8?q?=E6=88=90=E5=8A=9F=20=E6=90=BA=E5=B8=A6=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chaozhanggui/system/cashierservice/service/PayService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 9df5b68..61f8b90 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -1103,6 +1103,9 @@ public class PayService { } if(!"1".equals(tbShopUser.getIsVip().toString())){ + TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(memberIn.getUserId()); + tbShopUser.setName(userInfo.getNickName()); + tbShopUser.setTelephone(userInfo.getTelephone()); tbShopUser.setCode(DateUtils.getsdfTimesSS()); tbShopUser.setIsVip(Byte.parseByte("1")); } From caa46364c226b1fe782d2f110ac28cad24b84b83 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 31 May 2024 11:37:03 +0800 Subject: [PATCH 102/134] =?UTF-8?q?session=E5=85=B3=E9=97=AD=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/controller/GroupOrderInfoController.java | 1 - .../system/cashierservice/socket/AppWebSocketServer.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java index caccae2..bf1d924 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/GroupOrderInfoController.java @@ -3,7 +3,6 @@ package com.chaozhanggui.system.cashierservice.controller; import com.chaozhanggui.system.cashierservice.entity.TbGroupOrderInfo; import com.chaozhanggui.system.cashierservice.entity.dto.CreateGroupOrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.GroupOrderDto; -import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto; import com.chaozhanggui.system.cashierservice.service.GroupOrderCouponService; import com.chaozhanggui.system.cashierservice.service.GroupOrderInfoService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index 4f84092..7babf63 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -172,6 +172,7 @@ public class AppWebSocketServer { } userSet.remove(userId); } + session.close(); } /** From 78c5f533a87920bf9bcb96b754a08e0eab50f0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 31 May 2024 11:40:31 +0800 Subject: [PATCH 103/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=A0=81=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/LoginService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index bc4a05e..9ad5330 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -272,7 +272,7 @@ public class LoginService { String dynamicCode = RandomUtil.randomNumbers(8); dynamicCode = StringUtils.rightPad(tbShopUser.getId(), 6, "0").concat(dynamicCode); - tbShopUser.setDynamicCode(dynamicCode); + tbShopUser.setDynamicCode("46".concat(dynamicCode)); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); From 543f840aaad3261dc72200baf5f889989123ae88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 31 May 2024 15:34:43 +0800 Subject: [PATCH 104/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/LoginService.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 9ad5330..52e9ba9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -116,6 +116,28 @@ public class LoginService { tbShopUserMapper.updateByPrimaryKey(tbShopUser); } } + + List tbShopUse= tbShopUserMapper.selectByPhone(telephone); + if(ObjectUtil.isNotNull(tbShopUse)){ + TbUserInfo finalUserInfo = userInfo; + tbShopUse.parallelStream().forEach(it->{ + if(ObjectUtil.isNull(it.getUserId())||ObjectUtil.isEmpty(it.getUserId())){ + it.setUserId(finalUserInfo.getId().toString()); + it.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(it); + } + }); + } + + + + + + + + + + } } //生成token 信息 From 6ecb41cbe9614e2effa92c25b93418da4b13608e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 31 May 2024 17:33:34 +0800 Subject: [PATCH 105/134] =?UTF-8?q?=E4=BC=9A=E5=91=98=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 1 + .../cashierservice/service/LoginService.java | 28 ++----------------- .../socket/AppWebSocketServer.java | 26 +++++++++++++---- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 2acce14..a9305dc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -47,6 +47,7 @@ public class LoginFilter implements Filter { "cashierService/distirict/**",//首页其它接口 "cashierService/login/**",//登录部分接口不校验 "cashierService/product/queryProduct", + "cashierService/product/queryProductSku", "cashierService/product/productInfo", "cashierService/notify/**",//登录部分接口不校验 "notify/**", diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 52e9ba9..7f78ca2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -86,16 +86,16 @@ public class LoginService { userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.insert(userInfo); if(StringUtils.isNotBlank(telephone)){ List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); - if(CollectionUtils.isEmpty(tbShopUsers)){ + if(!CollectionUtils.isEmpty(tbShopUsers)){ for (TbShopUser tbShopUser : tbShopUsers) { tbShopUser.setUserId(userInfo.getId() + ""); tbShopUserMapper.updateByPrimaryKey(tbShopUser); } } } - tbUserInfoMapper.insert(userInfo); } else { userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); @@ -116,28 +116,6 @@ public class LoginService { tbShopUserMapper.updateByPrimaryKey(tbShopUser); } } - - List tbShopUse= tbShopUserMapper.selectByPhone(telephone); - if(ObjectUtil.isNotNull(tbShopUse)){ - TbUserInfo finalUserInfo = userInfo; - tbShopUse.parallelStream().forEach(it->{ - if(ObjectUtil.isNull(it.getUserId())||ObjectUtil.isEmpty(it.getUserId())){ - it.setUserId(finalUserInfo.getId().toString()); - it.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(it); - } - }); - } - - - - - - - - - - } } //生成token 信息 @@ -299,7 +277,7 @@ public class LoginService { tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); - return Result.success(CodeEnum.SUCCESS, dynamicCode); + return Result.success(CodeEnum.SUCCESS, "46"+dynamicCode); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index 7babf63..1696c66 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -58,8 +58,8 @@ public class AppWebSocketServer { public static ConcurrentHashMap> userMap = new ConcurrentHashMap<>(); // private static ConcurrentHashMap userSocketMap = new ConcurrentHashMap<>(); //购物车的记录,用于第一次扫码的人同步购物车 - private static ConcurrentHashMap> recordMap = new ConcurrentHashMap<>(); - private static ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); +// private static ConcurrentHashMap> recordMap = new ConcurrentHashMap<>(); +// private static ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); /** * 与某个客户端的连接会话,需要通过它来给客户端发送数据 @@ -164,13 +164,14 @@ public class AppWebSocketServer { ConcurrentHashMap userSocketMap = webSocketMap.get(key); // 在放置新条目之前检查并清除同名userId的数据 userSocketMap.remove(userId); + log.info("存在的 {}用户数3为:{}",key,userSocketMap.size()); } if (userMap.containsKey(tableId + "-" + shopId)){ Set userSet = userMap.get(tableId + "-" + shopId); - if (userSet.isEmpty()){ - userMap.remove(tableId + "-" + shopId); - } userSet.remove(userId); +// if (userSet.isEmpty()){ +// userMap.remove(tableId + "-" + shopId); +// } } session.close(); } @@ -198,6 +199,19 @@ public class AppWebSocketServer { jsonObject.put("shopId", this.shopId); log.info("tableId:"+this.tableId); log.info("shopId:"+this.shopId); + if (userMap.containsKey(tableId + "-" + shopId)) { + Set userSet = userMap.get(tableId + "-" + shopId); + userSet.add(userId); + } + if (webSocketMap.containsKey(tableId+"-"+shopId)) { + ConcurrentHashMap userSocketMap = webSocketMap.get(tableId+"-"+shopId); + // 在放置新条目之前检查并清除同名userId的数据 + userSocketMap.put(userId,this); + } else { + ConcurrentHashMap userSocketMap=new ConcurrentHashMap<>(); + userSocketMap.put(userId,this); + webSocketMap.put(tableId+"-"+shopId,userSocketMap); + } //这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象 // ChangeHandler changeHandler = new ChangeHandler(); // CreateOrderHandler createOrderHandler = new CreateOrderHandler(); @@ -227,6 +241,8 @@ public class AppWebSocketServer { jsonObject1.put("data", new ArrayList<>()); jsonObject1.put("amount", num); sendMessage(jsonObject1); + }else if("close".equals(jsonObject.getString("type"))){ + onClose(); }else { rabbitProducer.putCart(jsonObject.toJSONString()); } From a375fb10a815f4329620d82e209c592ad25a2802 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 31 May 2024 17:39:39 +0800 Subject: [PATCH 106/134] =?UTF-8?q?sessoin=E5=85=B3=E9=97=AD=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/socket/AppWebSocketServer.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index 1696c66..2ad5ca7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -173,7 +173,6 @@ public class AppWebSocketServer { // userMap.remove(tableId + "-" + shopId); // } } - session.close(); } /** @@ -241,8 +240,6 @@ public class AppWebSocketServer { jsonObject1.put("data", new ArrayList<>()); jsonObject1.put("amount", num); sendMessage(jsonObject1); - }else if("close".equals(jsonObject.getString("type"))){ - onClose(); }else { rabbitProducer.putCart(jsonObject.toJSONString()); } From c85f82f385ec8158b1b864f02dfd0bad75989f67 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 1 Jun 2024 21:34:43 +0800 Subject: [PATCH 107/134] =?UTF-8?q?token=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 9 ++++ .../system/cashierservice/util/TokenUtil.java | 41 +++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index a9305dc..ab31241 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -122,6 +122,15 @@ public class LoginFilter implements Filter { response.getWriter().flush();//流里边的缓存刷出 return; } + JSONObject jsonObject1 = TokenUtil.parseParamFromToken(token); + if (jsonObject1.containsKey("status")){ + Result result = new Result(CodeEnum.TOKEN_EXPIRED); + String jsonString = JSONObject.toJSONString(result); + JSONObject jsonObject = JSONObject.parseObject(jsonString, JSONObject.class); + response.getWriter().print(jsonObject); + response.getWriter().flush();//流里边的缓存刷出 + return; + } chain.doFilter(req, resp); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java index 2450d3c..16f3bdc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java @@ -7,6 +7,7 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import lombok.extern.slf4j.Slf4j; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -18,6 +19,7 @@ import java.util.Map; * @author admin * @date 2020/8/6 13:04 */ +@Slf4j public class TokenUtil { /** @@ -51,8 +53,8 @@ public class TokenUtil { } public static String generateJfToken(String openId,String userSign) throws Exception { Map claims = new HashMap<>(1); - claims.put("openId",openId); - claims.put("userSign",userSign); + claims.put("openId",openId); + claims.put("userSign",userSign); @@ -66,7 +68,7 @@ public class TokenUtil { private static String generateToken(Map claims) throws Exception { return Jwts.builder() .setClaims(claims) - .setExpiration(new Date(System.currentTimeMillis()+EXPIRE_DATE)) +// .setExpiration(new Date(System.currentTimeMillis()+EXPIRE_DATE)) .setIssuedAt(new Date()) .signWith(SignatureAlgorithm.HS256,TOKEN_SECRET) .compact(); @@ -106,20 +108,27 @@ public class TokenUtil { * @return 用户Id */ public static JSONObject parseParamFromToken(final String token) { - Claims claims = Jwts.parser() - .setSigningKey(TOKEN_SECRET) - .parseClaimsJws(token) - .getBody(); - JSONObject jsonObject = (JSONObject) JSONObject.toJSON(claims); + JSONObject jsonObject=new JSONObject(); + try{ + Claims claims = Jwts.parser() + .setSigningKey(TOKEN_SECRET) + .parseClaimsJws(token) + .getBody(); + jsonObject = (JSONObject) JSONObject.toJSON(claims); + }catch (Exception e){ + jsonObject.put("status","-4"); + log.info("token解析失败{}",e.getMessage()); + e.printStackTrace(); + } return jsonObject; } - public static void main(String[] args){ - System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw")); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar cld = Calendar.getInstance(); - cld.setTime(new Date()); - cld.set(Calendar.DATE, cld.get(Calendar.DATE)-1); - System.out.println(sdf.format(cld.getTime())); - } +// public static void main(String[] args){ +// System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw")); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); +// Calendar cld = Calendar.getInstance(); +// cld.setTime(new Date()); +// cld.set(Calendar.DATE, cld.get(Calendar.DATE)-1); +// System.out.println(sdf.format(cld.getTime())); +// } } From fefb4c3a850032f782a3f48609022fbffd0a555e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 4 Jun 2024 11:59:58 +0800 Subject: [PATCH 108/134] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=97=AE=E9=A2=98=20token=E6=9C=89=E6=95=88=E6=9C=9F?= =?UTF-8?q?=20=E5=8F=8A=20=E7=BB=AD=E6=9C=9F=20=E8=AE=A2=E5=8D=95=E8=AF=A6?= =?UTF-8?q?=E6=83=85=20=E4=B8=BAnull=E7=9A=84=E6=83=85=E5=86=B5=20?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=A1=8C=E7=A0=81=E8=8E=B7=E5=8F=96shopid?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4=20=E9=A6=96=E9=A1=B5=20?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/Shell.java | 4 +- .../cashierservice/auth/LoginFilter.java | 26 +++++-- .../controller/CommonController.java | 70 +++++++++++++++++-- .../controller/OrderController.java | 5 +- .../controller/ProductController.java | 8 +-- .../dao/TbCashierCartMapper.java | 2 - .../entity/dto/HomeBaseDto.java | 26 ++++++- .../cashierservice/rabbit/CartConsumer.java | 4 +- .../system/cashierservice/redis/RedisCst.java | 1 + .../cashierservice/redis/RedisUtil.java | 51 +++++++++++++- .../cashierservice/service/CartService.java | 5 +- .../cashierservice/service/LoginService.java | 2 +- .../cashierservice/service/PayService.java | 17 +++-- .../service/ProductService.java | 55 ++++++++------- .../socket/AppWebSocketServer.java | 61 +++++++++++----- .../cashierservice/util/RedisUtils.java | 5 ++ .../system/cashierservice/util/TokenUtil.java | 13 ++-- src/main/resources/application-dev.yml | 5 +- src/main/resources/application-dev2.yml | 3 + src/main/resources/application-prod.yml | 3 + src/main/resources/application-prod2.yml | 3 + src/main/resources/application.yml | 4 +- .../resources/mapper/TbCashierCartMapper.xml | 28 ++------ src/main/resources/mapper/TbProductMapper.xml | 1 + 24 files changed, 289 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java b/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java index 08e4839..7e62b24 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/Shell.java @@ -14,6 +14,7 @@ import org.springframework.context.ApplicationContext; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.client.RestTemplate; @@ -26,11 +27,12 @@ import java.net.Socket; @EnableScheduling @EntityScan(basePackageClasses = {Shell.class}) @MapperScan(basePackageClasses ={Shell.class} ) -@ComponentScan(basePackageClasses ={Shell.class}) +//@ComponentScan(basePackageClasses ={Shell.class}) @EnableTransactionManagement @EnableAspectJAutoProxy(proxyTargetClass = true) @Slf4j @EnableWebSocket +@EnableAsync public class Shell { private static Logger logger = LoggerFactory.getLogger(Shell.class); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index ab31241..9b88dd8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -10,6 +10,7 @@ import com.chaozhanggui.system.cashierservice.util.TokenUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.servlet.*; @@ -36,7 +37,7 @@ public class LoginFilter implements Filter { // 忽略静态资源 "css/**", "js/**", - "cashierService/websocket/table/**",//websocket + "cashierService/websocket/table",//websocket "cashierService/phoneValidateCode",//验证码 "cashierService/tbPlatformDict",//获取菜单 "cashierService/location/**",//高德 获取行政区域 @@ -45,7 +46,10 @@ public class LoginFilter implements Filter { "cashierService/order/testMessage",//首页 "cashierService/common/**",//通用接口 "cashierService/distirict/**",//首页其它接口 - "cashierService/login/**",//登录部分接口不校验 + +// "cashierService/login/**",//登录部分接口不校验 + "cashierService/login/wx/**",//登录部分接口不校验 + "cashierService/login/app/login",//登录部分接口不校验 "cashierService/product/queryProduct", "cashierService/product/queryProductSku", "cashierService/product/productInfo", @@ -95,16 +99,18 @@ public class LoginFilter implements Filter { return; } String message = ""; + String tokenKey=""; if(environment.equals("app")){ //获取当前登录人的用户id - String loginName = TokenUtil.parseParamFromToken(token).getString("userId"); + String userId = TokenUtil.parseParamFromToken(token).getString("userId"); + tokenKey=RedisCst.ONLINE_APP_USER.concat(userId); //获取redis中的token - message = redisUtil.getMessage(RedisCst.ONLINE_APP_USER.concat(loginName)); }else if(environment.equals("wx")){ //获取当前登录人的用户id String openId = TokenUtil.parseParamFromToken(token).getString("openId"); - message = redisUtil.getMessage(RedisCst.ONLINE_USER.concat(openId)); + tokenKey=RedisCst.ONLINE_USER.concat(openId); } + message = redisUtil.getMessage(tokenKey); if (StringUtils.isBlank(message)) { Result result = new Result(CodeEnum.TOKEN_EXPIRED); String jsonString = JSONObject.toJSONString(result); @@ -131,9 +137,19 @@ public class LoginFilter implements Filter { response.getWriter().flush();//流里边的缓存刷出 return; } + checkRenewal(tokenKey); chain.doFilter(req, resp); } + @Async + public void checkRenewal(String tokenKey) { + // 判断是否续期token,计算token的过期时间 + long time = redisUtil.getRemainingTime(tokenKey); + if(time<60*60*24*10L){ + redisUtil.setKeyExpirationTime(tokenKey,60*60*24*30L); + } + } + /** * 判断url请求是否配置在urls列表中 */ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 3888625..eab2639 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -4,11 +4,12 @@ import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.redis.RedisCst; +import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.service.FileService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.LocationUtils; -import com.chaozhanggui.system.cashierservice.util.RedisUtils; import com.chaozhanggui.system.cashierservice.util.StringUtil; import com.chaozhanggui.system.cashierservice.util.ValidateCodeUtil; import com.fasterxml.jackson.core.JsonProcessingException; @@ -16,12 +17,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; -import java.util.concurrent.TimeUnit; /** * 通用接口 @@ -34,8 +36,9 @@ import java.util.concurrent.TimeUnit; public class CommonController { private final ValidateCodeUtil validateCodeUtil; - @Resource - private RedisUtils redisUtils; + + @Autowired + private RedisUtil redisUtil; @Resource private TbPlatformDictMapper platformDictMapper; @Resource @@ -52,15 +55,24 @@ public class CommonController { * @return */ @GetMapping("/phoneValidateCode") - public Result verifyPhoneIsExist(@RequestParam String phone) { + public Result phoneValidateCode(@RequestParam String phone) { if (StringUtils.isBlank(phone)) { return Result.fail("手机号不可为空!"); } + // 检查手机号格式是否正确 + if (!isValidPhoneNumber(phone)) { + return Result.fail("手机号格式不正确!"); + } + // 检查手机号请求次数是否超出限制 + Result isOk = isRequestLimit(phone); + if (!isOk.getCode().equals("0")) { + return isOk; + } String random = StringUtil.random(6); validateCodeUtil.requestValidateCodeAli(phone, random); //存入缓存 try { - redisUtils.set(phone, random, ONE_MINUTE, TimeUnit.SECONDS); + redisUtil.saveMessage(phone, random, 60L); } catch (Exception e) { throw new MsgException("验证码发送失败"); } @@ -119,4 +131,50 @@ public class CommonController { public Result upload(MultipartFile file) throws Exception { return new Result(CodeEnum.SUCCESS, fileService.uploadFile(file)); } + + // 检查手机号格式是否正确的方法 + private boolean isValidPhoneNumber(String phone) { + return phone.matches("^1[3-9]\\d{9}$"); + } + + // 检查手机号请求次数是否超出限制的方法 + public Result isRequestLimit(String phone) { + Object count = redisUtil.getMessage(RedisCst.PHONE_LIMIT + phone); + if (count != null && Integer.valueOf(count.toString()) >= 5) { + return Result.fail("请求次数超出限制!,请半小时后重试"); + } + long time = redisUtil.getRemainingTime(phone); + if (time > 0) { + return Result.fail("请" + time + "秒后重试"); + } + refreshPhoneLimit(phone,count != null); + return Result.success(CodeEnum.SUCCESS); + } + + // 从 Redis 中获取手机号码的请求次数的方法 + @Async + public void refreshPhoneLimit(String phone,boolean isExist) { + if (isExist) { + phoneRequestrinc(RedisCst.PHONE_LIMIT + phone); + } else { + phoneRequestset(RedisCst.PHONE_LIMIT + phone); + } + } + + /** + * 存储手机号和请求次数的对应关系 时间 半小时 + */ + public void phoneRequestset(String key) { + // 使用 Hash 结构存储手机号和请求次数的对应关系 时间 半小时 + redisUtil.saveMessage(key, "1", 60*30L); + } + + + /** + * 将手机号码的请求次数加1 + */ + public void phoneRequestrinc(String key) { + // 将手机号码的请求次数加1 + redisUtil.getIncrNum(key, "2"); + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index e39372d..5ba73f7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -38,7 +38,10 @@ public class OrderController { * @return */ @GetMapping ("/orderInfo") - private Result orderInfo(@RequestParam Integer orderId){ + private Result orderInfo(@RequestParam(required = false) Integer orderId){ + if (orderId==null) { + return Result.fail("请返回首页订单列表查看"); + } return orderService.orderInfo(orderId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index d6ede94..3602a64 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -30,10 +30,10 @@ public class ProductController { * @return shopid */ @RequestMapping("queryShopIdByTableCode") - public Result queryShopIdByTableCode(@RequestHeader String token, @RequestParam("code") String code) { - JSONObject jsonObject = TokenUtil.parseParamFromToken(token); - String userId = jsonObject.getString("userId"); - String openId = jsonObject.getString("openId"); + public Result queryShopIdByTableCode( + @RequestHeader("openId") String openId, + @RequestHeader("id") String userId, + @RequestParam("code") String code) { return productService.queryShopIdByTableCode(userId, openId, code); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java index 5df9578..e9ed13b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java @@ -20,8 +20,6 @@ public interface TbCashierCartMapper { int updateByPrimaryKeySelective(TbCashierCart record); - int updateByPrimaryKey(TbCashierCart record); - List selectALlByMasterId(@Param("masterId") String masterId, @Param("status") String status); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java index cca7cbf..143c537 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeBaseDto.java @@ -1,7 +1,7 @@ package com.chaozhanggui.system.cashierservice.entity.dto; import lombok.Data; - +import org.apache.commons.lang3.StringUtils; /** @@ -27,4 +27,28 @@ public class HomeBaseDto extends BasePageDto{ private String distanceInKm; private Integer isPage = 1; + + public void setLat(String lat) { + if (StringUtils.isBlank(lat) || lat.equals("undefined")) { + this.lat = "34.343207"; + }else { + this.lat = lat; + } + } + + public void setLng(String lng) { + if (StringUtils.isBlank(lng) || lng.equals("undefined")) { + this.lng = "108.939645"; + }else { + this.lng = lng; + } + } + + public void setAddress(String address) { + if (StringUtils.isBlank(address) || address.equals("undefined")) { + this.address = "西安市"; + }else { + this.address = address; + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index 6aa17c7..d0d0e61 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -30,6 +30,7 @@ public class CartConsumer { @RabbitListener(queues = {"${queue}"}) public void listener(String message) { try { + log.info("监听数据进入 "+message); JSONObject jsonObject = JSON.parseObject(message); String tableId = jsonObject.getString("tableId"); String shopId = jsonObject.getString("shopId"); @@ -70,7 +71,8 @@ public class CartConsumer { cartService.clearCart(jsonObject); } } catch (Exception e) { - e.getMessage(); + log.info("数据处理失败:{}",e.getMessage()); + e.printStackTrace(); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java index 6cd4e31..8d73098 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java @@ -10,6 +10,7 @@ public class RedisCst { //在线用户 public static final String ONLINE_USER = "ONLINE_USER:"; + public static final String PHONE_LIMIT = "PHONE_LIMIT:"; public static final String ONLINE_APP_USER = "ONLINE_APP_USER:"; public static final String LDBL_APP_VERSION = "LDBL_APP_VERSION:"; public static final String TABLE_CART = "TABLE:CART:"; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java index d45af0f..784732c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisUtil.java @@ -1,7 +1,5 @@ package com.chaozhanggui.system.cashierservice.redis; -import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -112,7 +110,7 @@ public class RedisUtil{ * @author wgc * @date 2018-12-19 19:49 */ - public Integer saveMessage(String key, String message, int expire) { + public Integer saveMessage(String key, String message, Long expire) { Jedis jedis = null; try { if (StringUtils.isEmpty(key)) { @@ -162,6 +160,53 @@ public class RedisUtil{ } return flag; } + + /** + * 通过key 获取数据的剩余存活时间 + */ + public long getRemainingTime(String key) { + Jedis jedis = null; + long remainingTime = -1; + try { + // 从jedis池中获取一个jedis实例 + jedis = pool.getResource(); + if (database != 0) { + jedis.select(database); + } + + // 获取键的剩余生存时间 + remainingTime = jedis.ttl(key); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + return remainingTime; + } + + public void setKeyExpirationTime(String key, long seconds) { + Jedis jedis = null; + try { + // 从jedis池中获取一个jedis实例 + jedis = pool.getResource(); + if (database != 0) { + jedis.select(database); + } + // 设置键的存活时间 + jedis.expire(key, seconds); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 释放对象池,即获取jedis实例使用后要将对象还回去 + if (jedis != null) { + jedis.close(); + } + } + } + /** * @param key * @param message diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 19cd361..d0910d1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -104,6 +104,7 @@ public class CartService { TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); if (cashierCart.getNumber() > 0) { cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + cashierCart.setUserId(jsonObject.getIntValue("userId")); if (StringUtils.isNotEmpty(cashierCart.getStatus())) { cashierCart.setStatus("create"); } @@ -150,6 +151,7 @@ public class CartService { private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception { try { + //productId 235 skuId 85 userId 78 num 1 tableId 55246240 shopId 10 TbProduct product = productMapper.selectById(Integer.valueOf(productId)); String key=tableId+"-"+shopId; if (Objects.isNull(product)) { @@ -182,7 +184,6 @@ public class CartService { cashierCart.setSkuName(productSku.getSpecSnap()); cashierCart.setIsPack("false"); cashierCart.setIsGift("false"); - cashierCart.setUserId(userId); cashierCart.setStatus("create"); cashierCart.setType((byte) 0); cashierCart.setSalePrice(productSku.getSalePrice()); @@ -694,7 +695,7 @@ public class CartService { jsonObject1.put("type", jsonObject.getString("type")); jsonObject1.put("data", orderInfo); redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()), JSONObject.toJSONString(orderInfo), 24 * 60 * 60); + redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()), JSONObject.toJSONString(orderInfo), 24 * 60 * 60L); AppWebSocketServer.AppSendInfo(jsonObject1,key, jsonObject.getString("userId"), true); JSONObject jsonObject12 = new JSONObject(); jsonObject12.put("status", "success"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 7f78ca2..d6d5a94 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -125,7 +125,7 @@ public class LoginService { try { map.put("token", token); map.put("userInfo", userInfo); - redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(openId), JSON.toJSONString(map)); + redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(openId), JSON.toJSONString(map),60*60*24*30L); //redis里 获取要关注的公众号信息 //userInfo 某字段存储关注公众号的标识 // userInfo.get diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 61f8b90..34ae139 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -312,9 +312,10 @@ public class PayService { return Result.fail("未获取到用户信息"); } - - - + if(StringUtils.isBlank(userInfo.getPwd())){ +// return Result.fail("支付密码未设置"); + return Result.success(CodeEnum.SUCCESS,"3"); + } if(!userInfo.getPwd().equals(MD5Utils.md5(pwd))){ return Result.fail("支付密码错误"); } @@ -332,12 +333,14 @@ public class PayService { TbShopUser user = tbShopUserMapper.selectByPrimaryKey(memberId); - if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { - return Result.failCode("会员卡余额不足","1"); + if (ObjectUtil.isEmpty(user) || user.getIsVip()==null || !"1".equals(user.getIsVip().toString())) { +// return Result.failCode("会员卡余额不足","1"); + return Result.success(CodeEnum.SUCCESS,"4"); } if (N.gt(orderInfo.getOrderAmount(), user.getAmount())) { - return Result.failCode("会员卡余额不足","2"); +// return Result.failCode("会员卡余额不足","2"); + return Result.success(CodeEnum.SUCCESS,"2"); } user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); @@ -382,7 +385,7 @@ public class PayService { producer.printMechine(orderId); - return Result.success(CodeEnum.SUCCESS); + return Result.success(CodeEnum.SUCCESS,"1"); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index d850127..ea1f497 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -75,31 +75,36 @@ public class ProductService { } TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); - if (ObjectUtil.isEmpty(tbShopUser)) { - TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - tbShopUser = new TbShopUser(); - tbShopUser.setName(tbUserInfo.getNickName()); - tbShopUser.setSex(tbUserInfo.getSex()); - tbShopUser.setBirthDay(tbUserInfo.getBirthDay()); - tbShopUser.setLevel(Byte.parseByte("1")); - tbShopUser.setCode(RandomUtil.randomNumbers(8)); - tbShopUser.setTelephone(tbUserInfo.getTelephone()); - tbShopUser.setAmount(BigDecimal.ZERO); - tbShopUser.setIsVip(Byte.parseByte("0")); - tbShopUser.setCreditAmount(BigDecimal.ZERO); - tbShopUser.setConsumeAmount(BigDecimal.ZERO); - tbShopUser.setConsumeNumber(0); - tbShopUser.setLevelConsume(BigDecimal.ZERO); - tbShopUser.setStatus(Byte.parseByte("1")); - tbShopUser.setShopId(shopId); - tbShopUser.setUserId(userId); - tbShopUser.setMiniOpenId(openId); - tbShopUser.setCreatedAt(System.currentTimeMillis()); - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.insert(tbShopUser); - } else { - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(tbShopUser); + try{ + if (ObjectUtil.isEmpty(tbShopUser)) { + TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + tbShopUser = new TbShopUser(); + tbShopUser.setName(tbUserInfo.getNickName()); + tbShopUser.setSex(tbUserInfo.getSex()); + tbShopUser.setBirthDay(tbUserInfo.getBirthDay()); + tbShopUser.setLevel(Byte.parseByte("1")); + tbShopUser.setCode(RandomUtil.randomNumbers(8)); + tbShopUser.setTelephone(tbUserInfo.getTelephone()); + tbShopUser.setAmount(BigDecimal.ZERO); + tbShopUser.setIsVip(Byte.parseByte("0")); + tbShopUser.setCreditAmount(BigDecimal.ZERO); + tbShopUser.setConsumeAmount(BigDecimal.ZERO); + tbShopUser.setConsumeNumber(0); + tbShopUser.setLevelConsume(BigDecimal.ZERO); + tbShopUser.setStatus(Byte.parseByte("1")); + tbShopUser.setShopId(shopId); + tbShopUser.setUserId(userId); + tbShopUser.setMiniOpenId(openId); + tbShopUser.setCreatedAt(System.currentTimeMillis()); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.insert(tbShopUser); + } else { + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } + }catch (Exception e){ + log.info("通过桌码获取shopId 进行用户绑定错误:{}",e.getMessage()); + e.printStackTrace(); } return Result.success(CodeEnum.SUCCESS, shopId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index 2ad5ca7..018e144 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -29,7 +29,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -@ServerEndpoint(value = "/websocket/table/{tableId}/{shopId}/{userId}", encoders = WebSocketCustomEncoding.class) +@ServerEndpoint(value = "/websocket/table", encoders = WebSocketCustomEncoding.class) @Component @Slf4j @Data @@ -56,10 +56,6 @@ public class AppWebSocketServer { //一个 AppWebSocketServer 就是一个用户,一个tableId下有一个 List 也就是多个用户 private static HashMap> webSocketMap = new HashMap<>(); public static ConcurrentHashMap> userMap = new ConcurrentHashMap<>(); -// private static ConcurrentHashMap userSocketMap = new ConcurrentHashMap<>(); - //购物车的记录,用于第一次扫码的人同步购物车 -// private static ConcurrentHashMap> recordMap = new ConcurrentHashMap<>(); -// private static ConcurrentHashMap sessionMap = new ConcurrentHashMap<>(); /** * 与某个客户端的连接会话,需要通过它来给客户端发送数据 @@ -85,9 +81,16 @@ public class AppWebSocketServer { * 连接建立成功调用的方法 */ @OnOpen - public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) { - log.info("建立连接参数 tableId:{} shopId:{} userId:{}",tableId,shopId,userId); + public void onOpen(Session session) { this.session = session; + log.info("建立连接开始"); +// public void onOpen(Session session, @PathParam("tableId") String tableId, @PathParam("shopId") String shopId, @PathParam("userId") String userId) { + Map queryParams = getParamMap(); + String tableId = queryParams.get("tableId"); + String shopId = queryParams.get("shopId"); + String userId = queryParams.get("userId"); + + log.info("建立连接参数 tableId:{} shopId:{} userId:{}",tableId,shopId,userId); this.tableId = tableId; this.shopId = shopId; this.userId = userId; @@ -115,13 +118,13 @@ public class AppWebSocketServer { webSocketMap.put(key,userSocketMap); } - if (userMap.containsKey(key)) { - Set userSet = userMap.get(key); + if (userMap.containsKey(tableId)) { + Set userSet = userMap.get(tableId); userSet.add(userId); } else { Set userSet = new HashSet<>(); userSet.add(userId); - userMap.put(key,userSet); + userMap.put(tableId,userSet); } String mes = redisUtils.getMessage(RedisCst.TABLE_CART.concat(key)); if (StringUtils.isEmpty(mes)) { @@ -166,8 +169,8 @@ public class AppWebSocketServer { userSocketMap.remove(userId); log.info("存在的 {}用户数3为:{}",key,userSocketMap.size()); } - if (userMap.containsKey(tableId + "-" + shopId)){ - Set userSet = userMap.get(tableId + "-" + shopId); + if (userMap.containsKey(tableId)){ + Set userSet = userMap.get(tableId); userSet.remove(userId); // if (userSet.isEmpty()){ // userMap.remove(tableId + "-" + shopId); @@ -182,8 +185,7 @@ public class AppWebSocketServer { */ @OnMessage public void onMessage(String message, Session session) { - - log.info("接收消息:"+message); + log.info("接收消息 tableId:{} shopId:{} userId:{} message:{}",this.tableId,this.shopId,this.userId,message); //可以群发消息 //消息保存到数据库、redis if (StringUtils.isNotBlank(message) && !message.equals("undefined")) { @@ -196,10 +198,10 @@ public class AppWebSocketServer { //追加发送人(防止串改) jsonObject.put("tableId", this.tableId); jsonObject.put("shopId", this.shopId); - log.info("tableId:"+this.tableId); - log.info("shopId:"+this.shopId); - if (userMap.containsKey(tableId + "-" + shopId)) { - Set userSet = userMap.get(tableId + "-" + shopId); +// log.info("tableId:"+this.tableId); +// log.info("shopId:"+this.shopId); + if (userMap.containsKey(tableId)) { + Set userSet = userMap.get(tableId); userSet.add(userId); } if (webSocketMap.containsKey(tableId+"-"+shopId)) { @@ -258,6 +260,7 @@ public class AppWebSocketServer { @OnError public void onError(Session session, Throwable error) throws IOException { log.error("用户错误:" + this.tableId + ",原因:" + error.getMessage()); +// error.printStackTrace(); } /** @@ -289,7 +292,7 @@ public class AppWebSocketServer { * @throws IOException */ public static void AppSendInfo(Object message, String tableId,String userId, boolean userFlag) throws IOException { - log.info("发送消息 tableId:{} \n userId:{}\n userFlag:{}\n message:{}",tableId,userId,userFlag,JSONUtil.toJSONString(message)); + log.info("发送消息 tableId:{} userId:{} userFlag:{} message:{}",tableId,userId,userFlag,JSONUtil.toJSONString(message)); if (userFlag) { if (webSocketMap.containsKey(tableId)) { ConcurrentHashMap userSocketMap = webSocketMap.get(tableId); @@ -325,6 +328,26 @@ public class AppWebSocketServer { } + public Map getParamMap(){ + // 获取连接建立时传递的参数 + Map> queryParams = session.getRequestParameterMap(); + // 创建新的Map来存储转换后的参数 + Map parameterMap = new HashMap<>(); + + // 遍历原始参数Map的键值对 + for (Map.Entry> entry : queryParams.entrySet()) { + String key = entry.getKey(); + List values = entry.getValue(); + + // 如果值列表不为空,则将第一个值作为键的值存储在新的Map中 + if (!values.isEmpty()) { + String value = values.get(0); + parameterMap.put(key, value); + } + } + return parameterMap; + } + // public static synchronized ConcurrentHashMap> getWebSocketMap() { // return AppWebSocketServer.webSocketMap; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java index 21a5920..5d71683 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java @@ -286,6 +286,11 @@ public class RedisUtils { return false; } } + + public Long strincrement(String key, long delta) { + return stringRedisTemplate.opsForValue().increment(key, delta); + } + /** * 普通缓存放入并设置时间 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java index 16f3bdc..26cc779 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java @@ -1,16 +1,12 @@ package com.chaozhanggui.system.cashierservice.util; -import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import io.jsonwebtoken.Claims; -import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import lombok.extern.slf4j.Slf4j; -import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -25,7 +21,7 @@ public class TokenUtil { /** * 设置过期时间 */ - public static final long EXPIRE_DATE=24*60*60*1000*365; + public static final long EXPIRE_DATE=24L*60*60*1000*365; /** * token秘钥 */ @@ -65,10 +61,10 @@ public class TokenUtil { * @param claims * @return String */ - private static String generateToken(Map claims) throws Exception { + private static String generateToken(Map claims) { return Jwts.builder() .setClaims(claims) -// .setExpiration(new Date(System.currentTimeMillis()+EXPIRE_DATE)) + .setExpiration(new Date(System.currentTimeMillis()+EXPIRE_DATE)) .setIssuedAt(new Date()) .signWith(SignatureAlgorithm.HS256,TOKEN_SECRET) .compact(); @@ -117,12 +113,13 @@ public class TokenUtil { jsonObject = (JSONObject) JSONObject.toJSON(claims); }catch (Exception e){ jsonObject.put("status","-4"); + jsonObject.put("message","token解析失败了"); log.info("token解析失败{}",e.getMessage()); e.printStackTrace(); } return jsonObject; } -// public static void main(String[] args){ +// public static void main(String[] args) throws Exception { // System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw")); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // Calendar cld = Calendar.getInstance(); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 38086ab..9d7ee4d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -58,8 +58,11 @@ ysk: callBackGroupurl: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 +thirdPay: + callInBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/fstmemberInCallBack + callFSTBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyfstCallBack server: - port: 9889 + port: 9888 prod: dev1 queue: cart_queue_putdev1 diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml index 3287e1e..73b6469 100644 --- a/src/main/resources/application-dev2.yml +++ b/src/main/resources/application-dev2.yml @@ -55,6 +55,9 @@ ysk: callBackGroupurl: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://p40312246f.goho.co/cashierService/notify/memberInCallBack default: 18710449883 +thirdPay: + callInBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/fstmemberInCallBack + callFSTBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyfstCallBack server: port: 9889 prod: devyhq diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index f6eccf5..5ac4ba2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -57,6 +57,9 @@ ysk: callBackGroupurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +thirdPay: + callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack + callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack prod: prod1 queue: cart_queue_putprod1 diff --git a/src/main/resources/application-prod2.yml b/src/main/resources/application-prod2.yml index 27b9d53..7c8aa90 100644 --- a/src/main/resources/application-prod2.yml +++ b/src/main/resources/application-prod2.yml @@ -57,6 +57,9 @@ ysk: callBackGroupurl: https://cashier.sxczgkj.cn/cashierService/notify/notifyCallBackGroup callBackIn: https://cashier.sxczgkj.cn/cashierService/notify/memberInCallBack default: 19191703856 +thirdPay: + callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack + callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack prod: prod2 queue: cart_queue_putprod2 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0d3801d..edc4599 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,6 +10,8 @@ wx: custom: appId: wxd88fffa983758a30 secrete: a34a61adc0602118b49400baa8812454 +# appId: wxc2bb94c0ddda1032 +# secrete: 5fe6b30f688ae461561250ed3e3db35b # 卓尔 # appId: wx0dcea6001b0a8fb4 # secrete: ba42423cce61f93f02519ff3030ceb1c @@ -60,6 +62,4 @@ aliyun: thirdPay: payType: fushangtong - callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack - callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack url: https://paymentapi.sxczgkj.cn diff --git a/src/main/resources/mapper/TbCashierCartMapper.xml b/src/main/resources/mapper/TbCashierCartMapper.xml index 202975b..ae726ec 100644 --- a/src/main/resources/mapper/TbCashierCartMapper.xml +++ b/src/main/resources/mapper/TbCashierCartMapper.xml @@ -310,6 +310,9 @@ updated_at = #{updatedAt,jdbcType=BIGINT}, + + user_id=#{userId,jdbcType=INTEGER}, + pending_at = #{pendingAt,jdbcType=BIGINT}, @@ -322,30 +325,7 @@ where id = #{id,jdbcType=INTEGER} - - update tb_cashier_cart - set master_id = #{masterId,jdbcType=VARCHAR}, - order_id = #{orderId,jdbcType=VARCHAR}, - ref_order_id = #{refOrderId,jdbcType=VARCHAR}, - total_amount = #{totalAmount,jdbcType=DECIMAL}, - product_id = #{productId,jdbcType=VARCHAR}, - cover_img = #{coverImg,jdbcType=VARCHAR}, - is_sku = #{isSku,jdbcType=TINYINT}, - sku_id = #{skuId,jdbcType=VARCHAR}, - name = #{name,jdbcType=VARCHAR}, - sale_price = #{salePrice,jdbcType=DECIMAL}, - number = #{number,jdbcType=REAL}, - total_number = #{totalNumber,jdbcType=REAL}, - refund_number = #{refundNumber,jdbcType=REAL}, - category_id = #{categoryId,jdbcType=VARCHAR}, - status = #{status,jdbcType=VARCHAR}, - type = #{type,jdbcType=TINYINT}, - merchant_id = #{merchantId,jdbcType=VARCHAR}, - shop_id = #{shopId,jdbcType=VARCHAR}, - created_at = #{createdAt,jdbcType=BIGINT}, - updated_at = #{updatedAt,jdbcType=BIGINT} - where id = #{id,jdbcType=INTEGER} - + update tb_cashier_cart set status = #{status} where id = #{id} diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 9c2c15f..61aa81b 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -924,6 +924,7 @@ AND t.product_id = #{productId} AND t.`status` = 'create' AND t.table_id = #{code} + AND user_id IN #{item} From b7ce764bdb3e9f67029cec1d61b5d52f112b8708 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 5 Jun 2024 09:25:53 +0800 Subject: [PATCH 109/134] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/auth/LoginFilter.java | 3 +++ .../cashierservice/service/LoginService.java | 13 +++++++++--- .../socket/AppWebSocketServer.java | 20 +++++++++++++------ .../system/cashierservice/util/TokenUtil.java | 2 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 9b88dd8..da85e9b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -108,6 +108,9 @@ public class LoginFilter implements Filter { }else if(environment.equals("wx")){ //获取当前登录人的用户id String openId = TokenUtil.parseParamFromToken(token).getString("openId"); + if(StringUtils.isBlank(openId)){ + openId = TokenUtil.parseParamFromToken(token).getString("userId"); + } tokenKey=RedisCst.ONLINE_USER.concat(openId); } message = redisUtil.getMessage(tokenKey); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index d6d5a94..556438a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -98,7 +98,9 @@ public class LoginService { } } else { - userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); + if(!userInfo.getSearchWord().contains("微信用户")){ + userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); + } userInfo.setMiniAppOpenId(openId); userInfo.setUpdatedAt(System.currentTimeMillis()); tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); @@ -232,7 +234,7 @@ public class LoginService { //生成token 信息 String token = null; try { - token = TokenUtil.generateToken(userInfo.getId(), null, userInfo.getTelephone(), userInfo.getNickName()); + token = TokenUtil.generateToken(userInfo.getId(), userInfo.getMiniAppOpenId(), userInfo.getTelephone(), userInfo.getNickName()); } catch (Exception e) { throw new RuntimeException(e); } @@ -240,7 +242,12 @@ public class LoginService { try { map.put("token", token); map.put("userInfo", userInfo); - redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map)); + if(StringUtils.isNotBlank(userInfo.getMiniAppOpenId())){ + redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map),60*60*24*30L); + }else { + redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L); + } +// redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L); return Result.success(CodeEnum.SUCCESS, map); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java index 018e144..43a1beb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/socket/AppWebSocketServer.java @@ -90,7 +90,7 @@ public class AppWebSocketServer { String shopId = queryParams.get("shopId"); String userId = queryParams.get("userId"); - log.info("建立连接参数 tableId:{} shopId:{} userId:{}",tableId,shopId,userId); + log.info("建立连接参数 tableId:{} shopId:{} userId:{} sessionId:{}",tableId,shopId,userId,session.getId()); this.tableId = tableId; this.shopId = shopId; this.userId = userId; @@ -162,7 +162,7 @@ public class AppWebSocketServer { @OnClose public void onClose() throws IOException { String key=tableId + "-" + shopId; - log.info("触发关闭操作 key为:{} userId为:{}",key,userId); + log.info("触发关闭操作 key为:{} userId为:{} sessionId:{}",key,userId,session.getId()); if (webSocketMap.containsKey(key)) { ConcurrentHashMap userSocketMap = webSocketMap.get(key); // 在放置新条目之前检查并清除同名userId的数据 @@ -176,6 +176,7 @@ public class AppWebSocketServer { // userMap.remove(tableId + "-" + shopId); // } } + session.close(); } /** @@ -185,7 +186,7 @@ public class AppWebSocketServer { */ @OnMessage public void onMessage(String message, Session session) { - log.info("接收消息 tableId:{} shopId:{} userId:{} message:{}",this.tableId,this.shopId,this.userId,message); + log.info("接收消息 tableId:{} shopId:{} userId:{} message:{} sessionId:{}",this.tableId,this.shopId,this.userId,message,session.getId()); //可以群发消息 //消息保存到数据库、redis if (StringUtils.isNotBlank(message) && !message.equals("undefined")) { @@ -207,11 +208,17 @@ public class AppWebSocketServer { if (webSocketMap.containsKey(tableId+"-"+shopId)) { ConcurrentHashMap userSocketMap = webSocketMap.get(tableId+"-"+shopId); // 在放置新条目之前检查并清除同名userId的数据 - userSocketMap.put(userId,this); + if(userSocketMap.get(userId)!=null && userSocketMap.get(userId).session!=null){ + this.session=userSocketMap.get(userId).session; + userSocketMap.put(userId,this); + } } else { ConcurrentHashMap userSocketMap=new ConcurrentHashMap<>(); - userSocketMap.put(userId,this); - webSocketMap.put(tableId+"-"+shopId,userSocketMap); + if(userSocketMap.get(userId)!=null && userSocketMap.get(userId).session!=null){ + this.session=userSocketMap.get(userId).session; + userSocketMap.put(userId,this); + webSocketMap.put(tableId+"-"+shopId,userSocketMap); + } } //这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象 // ChangeHandler changeHandler = new ChangeHandler(); @@ -270,6 +277,7 @@ public class AppWebSocketServer { //加入线程锁 synchronized (session) { try { + log.info("发送消息 session:{}",session.getId()); //同步发送信息 this.session.getBasicRemote().sendObject(message); } catch (Exception e) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java index 26cc779..96444b2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java @@ -114,7 +114,7 @@ public class TokenUtil { }catch (Exception e){ jsonObject.put("status","-4"); jsonObject.put("message","token解析失败了"); - log.info("token解析失败{}",e.getMessage()); + log.info("token解析失败token为:{} message:{}",token,e.getMessage()); e.printStackTrace(); } return jsonObject; From 4aa5bd33b16425826f15e58206bba9f0e7e200db Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 5 Jun 2024 09:31:05 +0800 Subject: [PATCH 110/134] =?UTF-8?q?shopId=E4=B8=BA=E7=A9=BA=E6=97=B6=20?= =?UTF-8?q?=E4=BD=99=E9=A2=9D=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserContoller.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 929f7df..23dea72 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -29,6 +29,7 @@ import com.chaozhanggui.system.cashierservice.util.TokenUtil; import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -78,30 +79,35 @@ public class UserContoller { // } @GetMapping("/shopUserInfo") public Result shopUserInfo(@RequestParam("userId") String userId ,@RequestHeader("openId") String openId,@RequestParam("shopId") String shopId ) throws Exception { - TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(userId,shopId); - if (ObjectUtil.isEmpty(shopUser)) { - TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - shopUser = new TbShopUser(); - shopUser.setName(tbUserInfo.getNickName()); - shopUser.setSex(tbUserInfo.getSex()); - shopUser.setBirthDay(tbUserInfo.getBirthDay()); - shopUser.setLevel(Byte.parseByte("1")); - String dynamicCode = RandomUtil.randomNumbers(8); - shopUser.setCode(dynamicCode); - shopUser.setTelephone(tbUserInfo.getTelephone()); + TbShopUser shopUser=new TbShopUser(); + if (StringUtils.isNotBlank(shopId)) { + shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId); + if (ObjectUtil.isEmpty(shopUser)) { + TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + shopUser = new TbShopUser(); + shopUser.setName(tbUserInfo.getNickName()); + shopUser.setSex(tbUserInfo.getSex()); + shopUser.setBirthDay(tbUserInfo.getBirthDay()); + shopUser.setLevel(Byte.parseByte("1")); + String dynamicCode = RandomUtil.randomNumbers(8); + shopUser.setCode(dynamicCode); + shopUser.setTelephone(tbUserInfo.getTelephone()); + shopUser.setAmount(BigDecimal.ZERO); + shopUser.setIsVip(Byte.parseByte("0")); + shopUser.setCreditAmount(BigDecimal.ZERO); + shopUser.setConsumeAmount(BigDecimal.ZERO); + shopUser.setConsumeNumber(0); + shopUser.setLevelConsume(BigDecimal.ZERO); + shopUser.setStatus(Byte.parseByte("1")); + shopUser.setShopId(shopId); + shopUser.setUserId(userId); + shopUser.setMiniOpenId(openId); + shopUser.setCreatedAt(System.currentTimeMillis()); + shopUser.setUpdatedAt(System.currentTimeMillis()); + shopUserMapper.insert(shopUser); + } + }else { shopUser.setAmount(BigDecimal.ZERO); - shopUser.setIsVip(Byte.parseByte("0")); - shopUser.setCreditAmount(BigDecimal.ZERO); - shopUser.setConsumeAmount(BigDecimal.ZERO); - shopUser.setConsumeNumber(0); - shopUser.setLevelConsume(BigDecimal.ZERO); - shopUser.setStatus(Byte.parseByte("1")); - shopUser.setShopId(shopId); - shopUser.setUserId(userId); - shopUser.setMiniOpenId(openId); - shopUser.setCreatedAt(System.currentTimeMillis()); - shopUser.setUpdatedAt(System.currentTimeMillis()); - shopUserMapper.insert(shopUser); } return Result.success(CodeEnum.SUCCESS,shopUser); } From 759467c38371a0b047864311debb00e226f39fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 5 Jun 2024 09:34:23 +0800 Subject: [PATCH 111/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mapper/TbProductMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 61aa81b..45e9b7d 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -891,7 +891,7 @@ @@ -46,6 +46,11 @@ from tb_cashier_cart where id = #{id,jdbcType=INTEGER} + select * from tb_cashier_cart where order_id=#{orderId} diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 45e9b7d..ac7801c 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -891,7 +891,7 @@ + + From ada1dafe86c7c3a36e4b62e59c91537c2b99af4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 14:24:14 +0800 Subject: [PATCH 116/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/LimitSubmit.java | 22 ++ .../controller/PayController.java | 3 + .../exception/DefaultExceptionAdvice.java | 13 + .../interceptor/LimitSubmitAspect.java | 186 +++++++++ .../cashierservice/util/RedisUtils.java | 366 ++++-------------- 5 files changed, 305 insertions(+), 285 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java new file mode 100644 index 0000000..2a367fa --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.annotation; + +import java.lang.annotation.*; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LimitSubmit { + String key() ; + /** + * 默认 10s + */ + int limit() default 30; + + /** + * 请求完成后 是否一直等待 + * true则等待 + * @return + */ + boolean needAllWait() default true; +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index 2fb2b0c..fa090d4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; +import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.IpUtil; @@ -33,6 +34,7 @@ public class PayController { * @return */ @RequestMapping("orderPay") + @LimitSubmit(key = "orderPay:%s") public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) { return Result.fail("订单号不允许为空"); @@ -139,6 +141,7 @@ public class PayController { * @return */ @RequestMapping("memeberIn") + @LimitSubmit(key = "memeberIn:%s") public Result memeberIn(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestHeader("id") String id, @RequestBody Map map ) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index 083db51..549edcd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -152,4 +152,17 @@ public class DefaultExceptionAdvice { return new ResponseEntity<>(response, HttpStatus.OK); } + /** + * 使用ExceptionHandler注解声明处理TestException异常 + * + */ + @ResponseBody + @ExceptionHandler(MsgException.class) + public Result exception(MsgException e) { + // 控制台打印异常 + e.printStackTrace(); + // 返回错误格式信息 + return Result.fail(e.getMessage()); + } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java new file mode 100644 index 0000000..406ca17 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java @@ -0,0 +1,186 @@ +package com.chaozhanggui.system.cashierservice.interceptor; + +import cn.hutool.core.util.ObjectUtil; +import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.util.RedisUtils; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.*; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.LocalVariableTableParameterNameDiscoverer; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; + +@Component +@Aspect +@Slf4j +public class LimitSubmitAspect { + //封装了redis操作各种方法 + @Autowired + private RedisUtils redisUtil; + + @Pointcut("@annotation(com.chaozhanggui.system.cashierservice.annotation.LimitSubmit)") + private void pay() { + } + + @Pointcut("@annotation(com.chaozhanggui.system.cashierservice.annotation.LimitSubmit)") + private void pay1() { + } + + @Around("pay()") + public Object handleSubmit(ProceedingJoinPoint joinPoint) throws Throwable { + + Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + + String orderId= request.getParameter("orderId"); + if(ObjectUtil.isEmpty(orderId)||ObjectUtil.isNull(orderId)){ + orderId=request.getParameter("authCode"); + } + + + if(ObjectUtil.isEmpty(orderId)||ObjectUtil.isNull(orderId)){ + orderId=request.getParameter("id"); + } + + + //获取注解信息 + LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class); + boolean needAllWait = limitSubmit.needAllWait(); + String redisKey = limitSubmit.key(); + + + int submitTimeLimiter = limitSubmit.limit(); + String key = getRedisKey(joinPoint, redisKey, orderId); + Object result = redisUtil.get(key); + log.info("开始锁定资源信息" + key); + + if (result != null) { + log.info("锁定的值是" + result.toString()); + throw new MsgException("正在处理中, 请勿重复操作"); + } + boolean setResult = redisUtil.setIfAbsent(key, String.valueOf(System.currentTimeMillis()), submitTimeLimiter); + if (!setResult) { + throw new MsgException("1正在处理中, 请勿重复操作"); + } + + + try { + Object proceed = joinPoint.proceed(); + return proceed; + } catch (Throwable e) { + log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'", joinPoint.getSignature().getDeclaringTypeName(), + joinPoint.getSignature().getName(), e.getCause() != null ? e.getCause() : "NULL", e.getMessage(), e); + throw e; + } finally { + if (!needAllWait) { + redisUtil.del(redisKey); + log.info("删除后的结果: " + redisUtil.get(redisKey)); + } + } + } + + + @AfterReturning("pay1()") + public void AfterReturning(JoinPoint joinPoint) { + Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); + LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class); + String redisKey = limitSubmit.key(); + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + + String orderId= request.getParameter("orderId"); + + String key = getRedisKey1(joinPoint, redisKey, orderId); + log.info("正常释放了锁资源" + key); + // 延时 1s 释放 + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { +// redisUtil.del(key); + log.info("删除后的结果: " + redisUtil.get(redisKey)); + } + } + + @AfterThrowing(pointcut = "pay1()", throwing = "ex") + public void AfterThrowing(JoinPoint joinPoint, Throwable ex) { + + if (!(ex instanceof MsgException)) { + // 抛出的如果不是重复性提交的异常, 则释放锁资源 + + Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); + LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class); + String redisKey = limitSubmit.key(); + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + + String orderId= request.getParameter("orderId"); + + String key = getRedisKey1(joinPoint, redisKey, orderId); + log.info("发生异常释放了锁资源" + key); + // 延时 1s 释放 + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + redisUtil.del(key); + log.info("删除后的结果: " + redisUtil.get(redisKey)); + } + } + } + + /** + * 支持多参数,从请求参数进行处理 + */ + private String getRedisKey(ProceedingJoinPoint joinPoint, String key, String orderId) { + if (key.contains("%s") && orderId != null) { + key = String.format(key, orderId); + } + Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); + + LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); + String[] parameterNames = discoverer.getParameterNames(method); + if (parameterNames != null) { + for (int i = 0; i < parameterNames.length; i++) { + String item = parameterNames[i]; + if (key.contains("#" + item)) { + key = key.replace("#" + item, joinPoint.getArgs()[i].toString()); + } + } + } + return key.toString(); + } + + private String getRedisKey1(JoinPoint joinPoint, String key, String orderId) { + if (key.contains("%s") && orderId != null) { + key = String.format(key, orderId); + } + Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); + + LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); + String[] parameterNames = discoverer.getParameterNames(method); + if (parameterNames != null) { + for (int i = 0; i < parameterNames.length; i++) { + String item = parameterNames[i]; + if (key.contains("#" + item)) { + key = key.replace("#" + item, joinPoint.getArgs()[i].toString()); + } + } + } + return key.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java index 5d71683..91de6c3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java @@ -1,163 +1,51 @@ package com.chaozhanggui.system.cashierservice.util; -/* - * Copyright 2019-2020 Zheng Jie - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.core.*; -import org.springframework.data.redis.core.script.DefaultRedisScript; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; -import org.springframework.data.redis.serializer.RedisSerializer; -import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.TimeUnit; -/** - * @author / - */ @Component -@SuppressWarnings({"unchecked", "all"}) public class RedisUtils { - private static final Logger log = LoggerFactory.getLogger(RedisUtils.class); - @Resource - private RedisTemplate redisTemplate; - @Value("${jwt.online-key}") - private String onlineKey; + + @Autowired + private RedisTemplate redisTemplate; + /** * 指定缓存失效时间 * * @param key 键 * @param time 时间(秒) + * @return */ public boolean expire(String key, long time) { try { if (time > 0) { redisTemplate.expire(key, time, TimeUnit.SECONDS); } + return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } - return true; } /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - * @param timeUnit 单位 - */ - public boolean expire(String key, long time, TimeUnit timeUnit) { - try { - if (time > 0) { - redisTemplate.expire(key, time, timeUnit); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - return true; - } - - /** - * 根据 key 获取过期时间 + * 根据key 获取过期时间 * * @param key 键 不能为null * @return 时间(秒) 返回0代表为永久有效 */ - public long getExpire(Object key) { + public long getExpire(String key) { return redisTemplate.getExpire(key, TimeUnit.SECONDS); } - /** - * 查找匹配key - * - * @param pattern key - * @return / - */ - public List scan(String pattern) { - ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); - RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(); - while (cursor.hasNext()) { - result.add(new String(cursor.next())); - } - try { - RedisConnectionUtils.releaseConnection(rc, factory); - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return result; - } - - /** - * 分页查询 key - * - * @param patternKey key - * @param page 页码 - * @param size 每页数目 - * @return / - */ - public List findKeysForPage(String patternKey, int page, int size) { - ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); - RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); - RedisConnection rc = Objects.requireNonNull(factory).getConnection(); - Cursor cursor = rc.scan(options); - List result = new ArrayList<>(size); - int tmpIndex = 0; - int fromIndex = page * size; - int toIndex = page * size + size; - while (cursor.hasNext()) { - if (tmpIndex >= fromIndex && tmpIndex < toIndex) { - result.add(new String(cursor.next())); - tmpIndex++; - continue; - } - // 获取到满足条件的数据后,就可以退出了 - if (tmpIndex >= toIndex) { - break; - } - tmpIndex++; - cursor.next(); - } - try { - RedisConnectionUtils.releaseConnection(rc, factory); - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return result; - } - /** * 判断key是否存在 * @@ -168,7 +56,7 @@ public class RedisUtils { try { return redisTemplate.hasKey(key); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -178,23 +66,13 @@ public class RedisUtils { * * @param key 可以传一个值 或多个 */ - public void del(String... keys) { - if (keys != null && keys.length > 0) { - if (keys.length == 1) { - boolean result = redisTemplate.delete(keys[0]); - log.debug("--------------------------------------------"); - log.debug(new StringBuilder("删除缓存:").append(keys[0]).append(",结果:").append(result).toString()); - log.debug("--------------------------------------------"); + @SuppressWarnings("unchecked") + public void del(String... key) { + if (key != null && key.length > 0) { + if (key.length == 1) { + redisTemplate.delete(key[0]); } else { - Set keySet = new HashSet<>(); - for (String key : keys) { - keySet.addAll(redisTemplate.keys(key)); - } - long count = redisTemplate.delete(keySet); - log.debug("--------------------------------------------"); - log.debug("成功删除缓存:" + keySet.toString()); - log.debug("缓存删除数量:" + count + "个"); - log.debug("--------------------------------------------"); + redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); } } } @@ -211,19 +89,6 @@ public class RedisUtils { return key == null ? null : redisTemplate.opsForValue().get(key); } - /** - * 批量获取 - * - * @param keys - * @return - */ - public List multiGet(List keys) { - List list = redisTemplate.opsForValue().multiGet(Sets.newHashSet(keys)); - List resultList = Lists.newArrayList(); - Optional.ofNullable(list).ifPresent(e-> list.forEach(ele-> Optional.ofNullable(ele).ifPresent(resultList::add))); - return resultList; - } - /** * 普通缓存放入 * @@ -236,9 +101,10 @@ public class RedisUtils { redisTemplate.opsForValue().set(key, value); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } + } /** @@ -258,60 +124,37 @@ public class RedisUtils { } return true; } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - @Resource - private StringRedisTemplate stringRedisTemplate; - /** - * 普通缓存放入并设置时间(重写) - * - * @param key 键 - * @param value 值 - * @param time 时间 - * @param timeUnit 类型 - * @return true成功 false 失败 - */ - public boolean setextend(String key, Object value, long time) { - try { - if (time > 0) { - stringRedisTemplate.opsForValue().set(key, value.toString(), time); - } else { - set(key, value); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } - public Long strincrement(String key, long delta) { - return stringRedisTemplate.opsForValue().increment(key, delta); + /** + * 递增 + * + * @param key 键 + * @param by 要增加几(大于0) + * @return + */ + public long incr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递增因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, delta); } /** - * 普通缓存放入并设置时间 + * 递减 * - * @param key 键 - * @param value 值 - * @param time 时间 - * @param timeUnit 类型 - * @return true成功 false 失败 + * @param key 键 + * @param by 要减少几(小于0) + * @return */ - public boolean set(String key, String value, long time, TimeUnit timeUnit) { - try { - if (time > 0) { - stringRedisTemplate.opsForValue().set(key, value, time, timeUnit); - } else { - set(key, value); - } - return true; - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; + public long decr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递减因子必须大于0"); } + return redisTemplate.opsForValue().increment(key, -delta); } // ================================Map================================= @@ -335,7 +178,6 @@ public class RedisUtils { */ public Map hmget(String key) { return redisTemplate.opsForHash().entries(key); - } /** @@ -350,7 +192,7 @@ public class RedisUtils { redisTemplate.opsForHash().putAll(key, map); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -371,7 +213,7 @@ public class RedisUtils { } return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -389,7 +231,7 @@ public class RedisUtils { redisTemplate.opsForHash().put(key, item, value); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -411,7 +253,7 @@ public class RedisUtils { } return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -473,7 +315,7 @@ public class RedisUtils { try { return redisTemplate.opsForSet().members(key); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return null; } } @@ -489,7 +331,7 @@ public class RedisUtils { try { return redisTemplate.opsForSet().isMember(key, value); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -505,7 +347,7 @@ public class RedisUtils { try { return redisTemplate.opsForSet().add(key, values); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } @@ -526,7 +368,7 @@ public class RedisUtils { } return count; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } @@ -541,7 +383,7 @@ public class RedisUtils { try { return redisTemplate.opsForSet().size(key); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } @@ -558,11 +400,10 @@ public class RedisUtils { Long count = redisTemplate.opsForSet().remove(key, values); return count; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } - // ===============================list================================= /** @@ -577,7 +418,7 @@ public class RedisUtils { try { return redisTemplate.opsForList().range(key, start, end); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return null; } } @@ -592,7 +433,7 @@ public class RedisUtils { try { return redisTemplate.opsForList().size(key); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } @@ -608,7 +449,7 @@ public class RedisUtils { try { return redisTemplate.opsForList().index(key, index); } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return null; } } @@ -618,6 +459,7 @@ public class RedisUtils { * * @param key 键 * @param value 值 + * @param time 时间(秒) * @return */ public boolean lSet(String key, Object value) { @@ -625,7 +467,7 @@ public class RedisUtils { redisTemplate.opsForList().rightPush(key, value); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -646,7 +488,7 @@ public class RedisUtils { } return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -656,6 +498,7 @@ public class RedisUtils { * * @param key 键 * @param value 值 + * @param time 时间(秒) * @return */ public boolean lSet(String key, List value) { @@ -663,7 +506,7 @@ public class RedisUtils { redisTemplate.opsForList().rightPushAll(key, value); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -684,7 +527,7 @@ public class RedisUtils { } return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -695,14 +538,14 @@ public class RedisUtils { * @param key 键 * @param index 索引 * @param value 值 - * @return / + * @return */ public boolean lUpdateIndex(String key, long index, Object value) { try { redisTemplate.opsForList().set(key, index, value); return true; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return false; } } @@ -717,74 +560,27 @@ public class RedisUtils { */ public long lRemove(String key, long count, Object value) { try { - return redisTemplate.opsForList().remove(key, count, value); + Long remove = redisTemplate.opsForList().remove(key, count, value); + return remove; } catch (Exception e) { - log.error(e.getMessage(), e); + e.printStackTrace(); return 0; } } /** - * @param prefix 前缀 - * @param ids id - */ - public void delByKeys(String prefix, Set ids) { - Set keys = new HashSet<>(); - for (Long id : ids) { - keys.addAll(redisTemplate.keys(new StringBuffer(prefix).append(id).toString())); + * @Description 上锁并设置过期时间 + * @Date 15:09 2023/7/7 + * @Param [key, value, time] + * @return boolean + **/ + public boolean setIfAbsent(String key, Object value, long time) { + try { + return redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS); + } catch (Exception e) { + e.printStackTrace(); + return false; } - long count = redisTemplate.delete(keys); - // 此处提示可自行删除 - log.debug("--------------------------------------------"); - log.debug("成功删除缓存:" + keys.toString()); - log.debug("缓存删除数量:" + count + "个"); - log.debug("--------------------------------------------"); - } - String secKillScript = "local userid=KEYS[1];\r\n" + - "local prodid=KEYS[2];\r\n" + - "local qtkey=prodid;\r\n" + - "local usernum=KEYS[3];\r\n" + - "local usersKey='sk:'..prodid..\":usr\";\r\n" + - "local num= redis.call(\"get\" ,qtkey);\r\n" + - "if tonumber(num) redisScript = new DefaultRedisScript<>(); - redisScript.setResultType(Long.class);//返回类型是Long - redisScript.setScriptText(secKillScript); - Object execute = redisTemplate.execute(redisScript, Arrays.asList(uid, key,num), prodid); - String reString = String.valueOf(execute); - return reString; - } - String secAddScript = "local prodid=KEYS[1];\r\n" + - "local usernum=KEYS[2];\r\n" + - "local num= redis.call(\"get\" ,prodid);\r\n" + - " redis.call(\"SET\",prodid,tonumber(usernum)+tonumber(num));\r\n" + - "return 1"; - public String secAdd(String key,String num) { - - DefaultRedisScript redisScript = new DefaultRedisScript<>(); - redisScript.setResultType(Long.class);//返回类型是Long - redisScript.setScriptText(secKillScript); - Object execute = redisTemplate.execute(redisScript, Arrays.asList(key,num)); - String reString = String.valueOf(execute); - return reString; - - } - public boolean lock(String key, long timeout, TimeUnit timeUnit) { - String value = UUID.randomUUID().toString(); - Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit); - return success != null && success; } - public void releaseLock(String key) { - redisTemplate.delete(key); - } -} +} \ No newline at end of file From f766e2508d286f0419b63f6ced1a758385b30619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 14:31:03 +0800 Subject: [PATCH 117/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/util/RedisUtils.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java index 91de6c3..21d2563 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/RedisUtils.java @@ -5,10 +5,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; @Component @@ -583,4 +580,15 @@ public class RedisUtils { } } + public boolean lock(String key, long timeout, TimeUnit timeUnit) { + String value = UUID.randomUUID().toString(); + Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit); + return success != null && success; + } + + + public void releaseLock(String key) { + redisTemplate.delete(key); + } + } \ No newline at end of file From b872a4a2cef2a265022eacadce22572fac2a2766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 14:36:02 +0800 Subject: [PATCH 118/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/redis/RedisConfig.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java index 33e8140..35934b2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisConfig.java @@ -4,12 +4,16 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; +import java.nio.charset.Charset; + /** * @ClassName RedisConfig * @Author Administrator @@ -80,4 +84,16 @@ public class RedisConfig { container.setConnectionFactory(connectionFactory); return container; } + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + RedisTemplate template = new RedisTemplate<>(); + // 设置Redis连接工厂 + template.setConnectionFactory(factory); + // 设置默认的Key序列化器为StringRedisSerializer + template.setDefaultSerializer(new StringRedisSerializer()); + // 设置Value序列化器为StringRedisSerializer,并指定字符集编码为UTF-8 + template.setValueSerializer(new StringRedisSerializer(Charset.forName("UTF-8"))); + return template; + } } From 39c67616fe3155834679e37b0ee2dcc3edc5997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 14:39:25 +0800 Subject: [PATCH 119/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/DefaultExceptionAdvice.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index 549edcd..0abb7d6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -152,17 +152,17 @@ public class DefaultExceptionAdvice { return new ResponseEntity<>(response, HttpStatus.OK); } - /** - * 使用ExceptionHandler注解声明处理TestException异常 - * - */ - @ResponseBody - @ExceptionHandler(MsgException.class) - public Result exception(MsgException e) { - // 控制台打印异常 - e.printStackTrace(); - // 返回错误格式信息 - return Result.fail(e.getMessage()); - } +// /** +// * 使用ExceptionHandler注解声明处理TestException异常 +// * +// */ +// @ResponseBody +// @ExceptionHandler(MsgException.class) +// public Result exception(MsgException e) { +// // 控制台打印异常 +// e.printStackTrace(); +// // 返回错误格式信息 +// return Result.fail(e.getMessage()); +// } } From f3de388e4969ba77e2f1444e20a3df51a45eebf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 14:50:25 +0800 Subject: [PATCH 120/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9msg=20=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/exception/DefaultExceptionAdvice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index 0abb7d6..b68db15 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -147,7 +147,7 @@ public class DefaultExceptionAdvice { @ExceptionHandler(MsgException.class) public ResponseEntity handleException(MsgException e) { LOGGER.error("业务异常", e); - Result response = Result.failure(DefaultError.BUSINESS_ERROR); + Result response = Result.fail(e.getMessage()); response.setMsg(e.getMessage()); return new ResponseEntity<>(response, HttpStatus.OK); } From 69b7ed77ec0ef96f61afcf2dfba133b1d081217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 14 Jun 2024 15:26:48 +0800 Subject: [PATCH 121/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9msg=20=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbShopUserFlowMapper.java | 5 +--- .../cashierservice/entity/TbShopUserFlow.java | 10 +++++++ .../cashierservice/service/PayService.java | 8 ++++++ .../generator-mapper/generatorConfig.xml | 4 ++- .../resources/mapper/TbShopUserFlowMapper.xml | 28 +++++++++++++------ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserFlowMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserFlowMapper.java index 7cf0c32..8beec03 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserFlowMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserFlowMapper.java @@ -1,14 +1,10 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbShopUserFlow; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; -@Component -@Mapper public interface TbShopUserFlowMapper { int deleteByPrimaryKey(Integer id); @@ -22,5 +18,6 @@ public interface TbShopUserFlowMapper { int updateByPrimaryKey(TbShopUserFlow record); + List> selectByMemberAccountFlow(String memberId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUserFlow.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUserFlow.java index d70e58c..730cd8f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUserFlow.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUserFlow.java @@ -19,6 +19,8 @@ public class TbShopUserFlow implements Serializable { private Date createTime; + private String type; + private static final long serialVersionUID = 1L; public Integer getId() { @@ -76,4 +78,12 @@ public class TbShopUserFlow implements Serializable { public void setCreateTime(Date createTime) { this.createTime = createTime; } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type == null ? null : type.trim(); + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index af29d61..caa0112 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -352,6 +352,7 @@ public class PayService { flow.setShopUserId(Integer.valueOf(user.getId())); flow.setBizCode("accountPay"); flow.setBizName("会员储值卡支付"); + flow.setType("-"); flow.setAmount(orderInfo.getOrderAmount()); flow.setBalance(user.getAmount()); flow.setCreateTime(new Date()); @@ -424,6 +425,7 @@ public class PayService { TbShopUserFlow flow = new TbShopUserFlow(); flow.setShopUserId(Integer.valueOf(user.getId())); flow.setBizCode("accountGroupPay"); + flow.setType("-"); flow.setBizName("会员储值卡支付团购卷"); flow.setAmount(orderInfo.getOrderAmount()); flow.setBalance(user.getAmount()); @@ -1039,7 +1041,9 @@ public class PayService { TbShopUserFlow flow=new TbShopUserFlow(); flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setType("+"); flow.setAmount(memberIn.getAmount()); flow.setBalance(tbShopUser.getAmount()); flow.setCreateTime(new Date()); @@ -1065,6 +1069,7 @@ public class PayService { flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); flow.setBizCode("scanMemberAwardIn"); flow.setBizName("会员充值奖励"); + flow.setType("+"); flow.setAmount(amount); flow.setBalance(tbShopUser.getAmount()); flow.setCreateTime(new Date()); @@ -1119,6 +1124,8 @@ public class PayService { TbShopUserFlow flow=new TbShopUserFlow(); flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); flow.setBizCode("scanMemberIn"); + flow.setType("+"); + flow.setBizName("线上充值"); flow.setAmount(memberIn.getAmount()); flow.setBalance(tbShopUser.getAmount()); @@ -1145,6 +1152,7 @@ public class PayService { flow=new TbShopUserFlow(); flow.setShopUserId(Integer.valueOf(tbShopUser.getId())); flow.setBizCode("scanMemberAwardIn"); + flow.setType("+"); flow.setBizName("充值活动奖励"); flow.setAmount(amount); flow.setBalance(tbShopUser.getAmount()); diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index 87787f8..a6c8bea 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -52,9 +52,11 @@ -
+ + \ No newline at end of file diff --git a/src/main/resources/mapper/TbShopUserFlowMapper.xml b/src/main/resources/mapper/TbShopUserFlowMapper.xml index 9c9e34a..9e02f10 100644 --- a/src/main/resources/mapper/TbShopUserFlowMapper.xml +++ b/src/main/resources/mapper/TbShopUserFlowMapper.xml @@ -9,9 +9,10 @@ + - id, shop_user_id, amount, balance, biz_code, biz_name, create_time + id, shop_user_id, amount, balance, biz_code, biz_name, create_time, type + SELECT - f.*, - u.`name` + f.*, + u.`name` FROM - tb_shop_user_flow f - LEFT JOIN tb_shop_user u ON f.shop_user_id = u.id + tb_shop_user_flow f + LEFT JOIN tb_shop_user u ON f.shop_user_id = u.id where 1=1 and u.id = #{memberId} From 4c5fabfffb9681c64f24e63db2ec537ce33acdcf Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 14 Jun 2024 16:33:02 +0800 Subject: [PATCH 122/134] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=80=92=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=20=E4=BC=9A=E5=91=98=E4=BD=99=E9=A2=9D=E6=98=8E?= =?UTF-8?q?=E7=BB=86=20=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/LimitSubmit.java | 2 +- .../controller/LoginContoller.java | 4 +-- .../cashierservice/dao/TbShopUserMapper.java | 3 +- .../cashierservice/entity/TbOrderInfo.java | 23 +++++++++++++++ .../cashierservice/entity/dto/HomeDto.java | 5 ++++ .../cashierservice/entity/vo/OrderVo.java | 2 ++ .../entity/vo/ShopUserListVo.java | 20 +++++++++++++ .../cashierservice/service/CartService1.java | 29 ++++++++++++++----- .../cashierservice/service/OrderService.java | 8 +++++ .../cashierservice/service/PayService.java | 15 ++++++++-- .../service/ProductService.java | 14 ++++++++- src/main/resources/mapper/TbProductMapper.xml | 3 ++ .../resources/mapper/TbProductSkuMapper.xml | 2 +- .../resources/mapper/TbShopUserMapper.xml | 4 +-- 14 files changed, 116 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopUserListVo.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java index 2a367fa..c54118e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/annotation/LimitSubmit.java @@ -11,7 +11,7 @@ public @interface LimitSubmit { /** * 默认 10s */ - int limit() default 30; + int limit() default 5; /** * 请求完成后 是否一直等待 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 5112a7c..5312839 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -125,14 +125,14 @@ public class LoginContoller { if (!signature.equals(signature2)) { return Result.fail("签名校验失败"); } - String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); String phone = ""; try{ + String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { phone =JSONObject.parseObject(data).get("phoneNumber").toString(); } }catch (Exception e){ - log.info("登录传参:获取手机号失败{}",data); + log.info("登录传参:获取手机号失败{}",e.getMessage()); } String nickName = rawDataJson.getString("nickName"); String avatarUrl = rawDataJson.getString("avatarUrl"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java index 12d538e..3c46087 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbParams; import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -31,7 +32,7 @@ public interface TbShopUserMapper { List selectAllByUserId(@Param("userId") String userId); - List> selectByUserId(@Param("userId") String userId,@Param("shopId") String shopId); + List selectByUserId(@Param("userId") String userId, @Param("shopId") String shopId); TbShopUser selectByOpenId(@Param("openId") String openId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index f64eebd..53c9715 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -101,6 +101,29 @@ public class TbOrderInfo implements Serializable { private List detailList; private String winnnerNo; private String isWinner; + + + //根据状态返回 需付款 已付款 未付款 已退 + private String description; + + public void setDescription() { + switch (status) { + case "closed": + this.description = "已付款"; + break; + case "refund": + this.description = "已退款"; + break; + case "paying": + case "unpaid": + this.description = "需付款"; + break; + default: + this.description = ""; + break; + } + } + private static final long serialVersionUID = 1L; public TbOrderInfo(){ super(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java index 354fdc7..ebd27a8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/HomeDto.java @@ -29,4 +29,9 @@ public class HomeDto extends HomeBaseDto { */ private Integer dateType = 1; + public void setOrderBy(Integer orderBy) { + if(orderBy!=null){ + this.orderBy = orderBy; + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java index 2126631..bfa60a1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java @@ -24,6 +24,8 @@ public class OrderVo { private String orderNo; private Long time; + private Long expiredMinutes = 0l; + private Long expiredSeconds = 0l; private BigDecimal payAmount; private String orderType; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopUserListVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopUserListVo.java new file mode 100644 index 0000000..39b4aaf --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ShopUserListVo.java @@ -0,0 +1,20 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class ShopUserListVo { + + private Long memberId; + private Long shopId; + private String shopName; + private String chainName; + private String logo; + private String detail; + private BigDecimal levelConsume; + private BigDecimal amount; + private String code; + private Integer isVip; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java index 8aede8a..11d7f0b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java @@ -106,7 +106,7 @@ public class CartService1 { String skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId")); TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId)); if (tbProduct.getIsStock() == 1) { - if (Integer.valueOf(skuNum) < 1) { + if (Integer.valueOf(skuNum) < 1 && jsonObject.getInteger("num") > 0) { JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); jsonObject1.put("msg", "该商品库存已售罄"); @@ -116,11 +116,6 @@ public class CartService1 { throw new MsgException("该商品库存已售罄"); } } - if (jsonObject.getInteger("num") > 0) { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); - } else { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); - } if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); @@ -130,6 +125,12 @@ public class CartService1 { jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + if (jsonObject.getInteger("num") > 0) { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); + } else { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); + } + productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); } } else { boolean flag = true; @@ -139,8 +140,15 @@ public class CartService1 { if (cashierCart.getSkuId().equals(jsonObject.getString("skuId"))) { cashierCart.setTotalNumber(cashierCart.getTotalNumber() + jsonObject.getInteger("num")); cashierCart.setNumber(cashierCart.getNumber() + jsonObject.getInteger("num")); + if (jsonObject.getInteger("num") > 0) { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); + } else { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); + } + productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); if (cashierCart.getNumber() > 0) { cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); cashierCartMapper.updateByPrimaryKeySelective(cashierCart); } else { cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); @@ -156,6 +164,12 @@ public class CartService1 { jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + if (jsonObject.getInteger("num") > 0) { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); + } else { + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); + } + productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); } } } else { @@ -164,9 +178,10 @@ public class CartService1 { jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); + productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); } } - productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString()); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "success"); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 5da256c..9641f92 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -195,6 +195,13 @@ public class OrderService { orderVo.setDetails(details); orderVo.setOrderNo(orderInfo.getOrderNo()); orderVo.setTime(orderInfo.getCreatedAt()); + if (orderInfo.getStatus().equals("paying") || orderInfo.getStatus().equals("unpaid")) { + Long totalSeconds = orderInfo.getCreatedAt() + 15 * 60 * 1000l - System.currentTimeMillis(); + if(totalSeconds>0){ + orderVo.setExpiredMinutes(totalSeconds/1000 / 60); + orderVo.setExpiredSeconds(totalSeconds/1000 % 60); + } + } orderVo.setPayAmount(orderInfo.getOrderAmount()); orderVo.setTableName(tbShopTable == null ? "" : tbShopTable.getName()); orderVo.setOrderType(orderInfo.getOrderType()); @@ -214,6 +221,7 @@ public class OrderService { List tbOrderInfos = orderInfoMapper.selectByUserId(userId, status); for (TbOrderInfo orderInfo : tbOrderInfos) { + orderInfo.setDescription(); List list = tbOrderDetailMapper.selectAllByOrderId(orderInfo.getId()); int num = 0; for (TbOrderDetail orderDetail : list) { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index caa0112..aa19e5b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; +import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.model.PayReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; @@ -147,6 +148,9 @@ public class PayService { if(!"unpaid".equals(orderInfo.getStatus())&&!"paying".equals(orderInfo.getStatus())){ return Result.fail("订单状态异常,不允许支付"); } + if (System.currentTimeMillis() - orderInfo.getCreatedAt() > 60 * 15 * 1000) { + return Result.fail("订单十五分钟内有效,当前已超时,请重新下单。"); + } if(ObjectUtil.isNull(orderInfo.getMerchantId())||ObjectUtil.isEmpty(orderInfo.getMerchantId())){ return Result.fail("没有对应的商户"); @@ -303,6 +307,9 @@ public class PayService { if (ObjectUtil.isEmpty(orderInfo)) { return Result.fail("订单信息不存在"); } + if (System.currentTimeMillis() - orderInfo.getCreatedAt() > 60 * 15 * 1000) { + return Result.fail("订单十五分钟内有效,当前已超时,请重新下单。"); + } TbUserInfo userInfo= tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserId())); @@ -320,7 +327,7 @@ public class PayService { if (!"unpaid".equals(orderInfo.getStatus()) && !"paying".equals(orderInfo.getStatus()) ) { - return Result.fail("订单出状态异常"); + return Result.fail("订单状态异常"); } @@ -717,6 +724,7 @@ public class PayService { log.info("发送打印数据"); producer.printMechine(orderInfo.getId() + ""); + redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString())); return Result.success(CodeEnum.SUCCESS,orderId); case "REFUND_ING": cartStatus="refunding"; @@ -871,7 +879,7 @@ public class PayService { log.info("发送打印数据"); producer.printMechine(orderInfo.getId() + ""); - + redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString())); return "SUCCESS"; } @@ -916,6 +924,7 @@ public class PayService { coupons.put("type","buy"); coupons.put("orderId",orderInfo.getId().toString()); producer.printCoupons(coupons.toJSONString()); + redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString())); return "SUCCESS"; } @@ -962,7 +971,7 @@ public class PayService { public Result getShopByMember(String userId,String shopId,int page,int pageSize){ PageHelper.startPage(page, pageSize); - List> list= tbShopUserMapper.selectByUserId(userId,shopId); + List list= tbShopUserMapper.selectByUserId(userId,shopId); PageInfo pageInfo=new PageInfo(list); return Result.success(CodeEnum.SUCCESS,pageInfo); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index dc90abf..6eab725 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -218,7 +218,12 @@ public class ProductService { if (CollectionUtils.isEmpty(shopGroupInfoVos)) { return new PageInfo(shopGroupInfoVos); } - List productIds = shopGroupInfoVos.stream().map(ShopGroupInfoVo::getProId).collect(Collectors.toList()); + List productIds = shopGroupInfoVos.stream() + .filter(Objects::nonNull) // 过滤掉 null 的 ShopGroupInfoVo 对象 + .map(ShopGroupInfoVo::getProId) + .filter(Objects::nonNull) // 过滤掉 null 的 ProId + .collect(Collectors.toList()); + List stringList = productIds.stream() .map(Object::toString) // 将 Integer 对象映射为 String 对象 .collect(Collectors.toList()); @@ -227,6 +232,9 @@ public class ProductService { //组装 List homeVOList = new ArrayList<>(); for (ShopGroupInfoVo o : shopGroupInfoVos) { + if (o.getProId() == null) { + continue; + } HomeVO homeVO = new HomeVO(); homeVO.setId(o.getProId()); homeVO.setShopName(o.getShopName()); @@ -291,6 +299,10 @@ public class ProductService { * @throws Exception */ public Result productInfo(Integer productId, String lat, String lng, String environment) throws Exception { + if (StringUtils.isBlank(lat) || lat.equals("undefined")) { + lat = "34.343207"; + lng = "108.939645"; + } CompletableFuture product = CompletableFuture.supplyAsync(() -> tbProductMapper.selectByPrimaryKey(productId)); CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index ac7801c..de28bdf 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -961,6 +961,7 @@ info.`status`='1' AND pro.is_combo = '1' + AND pro.type_enum = 'group' AND (info.cities = #{cities} or info.districts = #{cities}) AND pro.`name` LIKE concat('%',#{proName,jdbcType=VARCHAR},'%') @@ -1008,6 +1009,8 @@ LEFT JOIN tb_shop_info AS info ON info.id = `order`.shop_id info.`status`='1' + AND pro.is_combo = '1' + AND pro.type_enum = 'group' AND (info.cities = #{cities} or info.districts = #{cities}) AND pro.`name` LIKE concat('%',#{proName,jdbcType=VARCHAR},'%') diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 7181d60..c928a35 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -339,7 +339,7 @@ where id = #{id,jdbcType=INTEGER} - update tb_product_sku set stock_number = stock_number + #{num} where id = #{skuId} + update tb_product_sku set stock_number = stock_number - #{num} where id = #{skuId} update tb_product_sku set stock_number = stock_number + #{num} where id = #{skuId} diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index 72da852..0bdeb13 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -399,7 +399,7 @@ select * from tb_params where id = 1 - SELECT u.id as memberId, i.id as shopId, @@ -410,7 +410,7 @@ u.level_consume as levelConsume, u.amount, u.`code`, - u.is_vip + u.is_vip as isVip FROM tb_shop_user u left join tb_shop_info i on u.shop_id=i.id From 3d6bf6a0aeedb9480f0126b5d0beb44dd9a11d27 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 17 Jun 2024 17:51:04 +0800 Subject: [PATCH 123/134] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index aa19e5b..e08eb3b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -758,11 +758,6 @@ public class PayService { } - if("0".equals(userInfo.getIsPwd())){ - return Result.fail("用户支付密码未设置"); - } - - TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); if(ObjectUtil.isEmpty(shopInfo)){ return Result.fail("对应的店铺信息不存在"); From e2b22116a0473d813c61252684f676cfe8dbc64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Wed, 19 Jun 2024 09:55:00 +0800 Subject: [PATCH 124/134] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=96=E9=A4=90?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbOrderInfo.java | 1 + .../system/cashierservice/redis/RedisCst.java | 2 + .../cashierservice/service/CartService1.java | 39 +++++++++++++++++++ .../cashierservice/service/PayService.java | 6 +-- .../resources/mapper/TbOrderInfoMapper.xml | 16 ++++++-- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java index f64eebd..2706f70 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderInfo.java @@ -101,6 +101,7 @@ public class TbOrderInfo implements Serializable { private List detailList; private String winnnerNo; private String isWinner; + private String outNumber; private static final long serialVersionUID = 1L; public TbOrderInfo(){ super(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java index e58e403..8bf5631 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java @@ -20,4 +20,6 @@ public class RedisCst { public static final String INTEGRAL_COIN_KEY = "INTEGRAL:COIN:KEY"; public static final String COUPONS_COIN_KEY = "COUPONS:COIN:KEY"; + + public static final String OUT_NUMBER="ORDER:NUMBER:"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java index 8aede8a..8942b81 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java @@ -412,6 +412,25 @@ public class CartService1 { orderInfo.setIsBuyCoupon(isBuyYhq); orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setUserCouponAmount(couponAmount); + + JSONObject object=new JSONObject(); + String outNumber= redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); + Integer number=1; + if(Objects.isNull(outNumber)){ + object.put("outNumber",number); + object.put("times",DateUtils.getDay()); + }else { + object=JSONObject.parseObject(outNumber); + if(object.getString("times").equals(DateUtils.getDay())){ + number=object.getInteger("outNumber")+1; + object.put("outNumber",number); + }else { + object.put("outNumber",number); + object.put("times",DateUtils.getDay()); + } + } + orderInfo.setOutNumber(number+""); + redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")),object.toString()); orderInfoMapper.insert(orderInfo); orderId = orderInfo.getId(); } @@ -701,6 +720,26 @@ public class CartService1 { orderInfo.setIsBuyCoupon(isBuyYhq); orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setUserCouponAmount(couponAmount); + + JSONObject object=new JSONObject(); + String outNumber= redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); + Integer number=1; + if(Objects.isNull(outNumber)){ + object.put("outNumber",number); + object.put("times",DateUtils.getDay()); + }else { + object=JSONObject.parseObject(outNumber); + if(object.getString("times").equals(DateUtils.getDay())){ + number=object.getInteger("outNumber")+1; + object.put("outNumber",number); + }else { + object.put("outNumber",number); + object.put("times",DateUtils.getDay()); + } + } + orderInfo.setOutNumber(number+""); + redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")),object.toString()); + orderInfoMapper.insert(orderInfo); orderId = orderInfo.getId(); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index caa0112..0d11de7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -750,9 +750,9 @@ public class PayService { } - if("0".equals(userInfo.getIsPwd())){ - return Result.fail("用户支付密码未设置"); - } +// if("0".equals(userInfo.getIsPwd())){ +// return Result.fail("用户支付密码未设置"); +// } TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); diff --git a/src/main/resources/mapper/TbOrderInfoMapper.xml b/src/main/resources/mapper/TbOrderInfoMapper.xml index 754ecca..5ee9c7d 100644 --- a/src/main/resources/mapper/TbOrderInfoMapper.xml +++ b/src/main/resources/mapper/TbOrderInfoMapper.xml @@ -48,6 +48,7 @@ + id, order_no, settlement_amount, pack_fee, origin_amount, product_amount, amount, @@ -56,7 +57,7 @@ billing_id, merchant_id, shop_id, is_vip, member_id, user_id, product_score, deduct_score, user_coupon_id, user_coupon_amount, refund_able, paid_time, is_effect, is_group, updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`, - remark,master_id,`table_name`,is_buy_coupon,is_use_coupon + remark,master_id,`table_name`,is_buy_coupon,is_use_coupon,out_number select * from tb_shop_user where user_id=#{userId} and shop_id=#{shopId} From 94f769e091e0c4d490707251437e128a8e415c63 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 21 Jun 2024 11:17:29 +0800 Subject: [PATCH 129/134] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E6=97=B6=20=E4=BC=9A=E5=91=98=E5=85=B3=E7=B3=BB=20?= =?UTF-8?q?=E8=A7=A3=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../netty/PushToClientChannelHandlerAdapter.java | 4 ++++ .../system/cashierservice/service/HomePageService.java | 2 -- .../system/cashierservice/service/LoginService.java | 8 +------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/netty/PushToClientChannelHandlerAdapter.java b/src/main/java/com/chaozhanggui/system/cashierservice/netty/PushToClientChannelHandlerAdapter.java index d092661..ff709fc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/netty/PushToClientChannelHandlerAdapter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/netty/PushToClientChannelHandlerAdapter.java @@ -113,6 +113,10 @@ public class PushToClientChannelHandlerAdapter extends NettyChannelHandlerAdapte this.shopId=shopId; if (webSocketMap.containsKey(shopId)) { ConcurrentHashMap clientSocketMap = webSocketMap.get(shopId); + ChannelHandlerContext channelHandlerContext = clientSocketMap.get(clientId); + if (channelHandlerContext != null) { + channelHandlerContext.close(); + } clientSocketMap.put(clientId, ctx); } else { ConcurrentHashMap clientSocketMap = new ConcurrentHashMap<>(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 3b4f539..35b2e8c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -22,10 +22,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; -import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; /** * @author lyf diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index db6db01..9b6eba9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -116,16 +116,10 @@ public class LoginService { tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); List tbShopUsers = tbShopUserMapper.selectAllByUserId(userInfo.getId().toString()); for (TbShopUser tbShopUser : tbShopUsers) { - tbShopUser.setUserId(""); + tbShopUser.setUserId(null); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.upUserBYId(tbShopUser); } - List tbShopUsers1 = tbShopUserMapper.selectByPhone(telephone); - for (TbShopUser tbShopUser : tbShopUsers1) { - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUser.setUserId(userInfo.getId().toString()); - tbShopUserMapper.upUserBYId(tbShopUser); - } } } } From 4567c8ab4a29888783beb77a96777ac33615a777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Fri, 21 Jun 2024 13:56:43 +0800 Subject: [PATCH 130/134] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=B0=8F=E7=A5=A8?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/util/PrinterUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java index 1573255..1b00095 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java @@ -131,9 +131,9 @@ public class PrinterUtils { sb.append("余额:"+detailPO.getBalance()+"
"); sb.append("------------------------
"); - if(Objects.nonNull(detailPO.getOutNumber())){ - sb.append("".concat(detailPO.getOutNumber()).concat("
")); - } +// if(Objects.nonNull(detailPO.getOutNumber())){ +// sb.append("".concat(detailPO.getOutNumber()).concat("
")); +// } sb.append("打印时间:"+DateUtils.getTime(new Date())+"
"); From 941c33ea7a4604b3bc278188abc9079d34f4ed8f Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 22 Jun 2024 09:34:16 +0800 Subject: [PATCH 131/134] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/CartService1.java | 822 ------------------ .../cashierservice/service/LoginService.java | 101 ++- 2 files changed, 62 insertions(+), 861 deletions(-) delete mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java deleted file mode 100644 index f6fd341..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService1.java +++ /dev/null @@ -1,822 +0,0 @@ -package com.chaozhanggui.system.cashierservice.service; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.chaozhanggui.system.cashierservice.dao.*; -import com.chaozhanggui.system.cashierservice.entity.*; -import com.chaozhanggui.system.cashierservice.exception.MsgException; -import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter; -import com.chaozhanggui.system.cashierservice.redis.RedisCst; -import com.chaozhanggui.system.cashierservice.redis.RedisUtil; -import com.chaozhanggui.system.cashierservice.util.DateUtils; -import com.chaozhanggui.system.cashierservice.util.JSONUtil; -import com.chaozhanggui.system.cashierservice.util.N; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.CollectionUtils; - -import java.io.IOException; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.*; - -/** - * @author lyf - */ -@Service -@Slf4j -public class CartService1 { - - @Autowired - private RedisUtil redisUtil; - @Autowired - private TbOrderInfoMapper orderInfoMapper; - @Autowired - private TbCashierCartMapper cashierCartMapper; - @Autowired - private TbProductMapper productMapper; - @Autowired - private TbProductSkuMapper productSkuMapper; - @Autowired - private TbMerchantAccountMapper merchantAccountMapper; - @Autowired - private TbUserInfoMapper userInfoMapper; - @Autowired - private TbOrderDetailMapper orderDetailMapper; - @Autowired - private TbShopTableMapper shopTableMapper; - @Autowired - private TbUserCouponsMapper userCouponsMapper; - @Autowired - private TbSystemCouponsMapper systemCouponsMapper; - - public void initCart(JSONObject jsonObject) { - String tableId = jsonObject.getString("tableId"); - String shopId = jsonObject.getString("shopId"); - String key = tableId + "-" + shopId; - BigDecimal amount = BigDecimal.ZERO; - JSONArray array = new JSONArray(); - if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) { - array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - if (cashierCart.getNumber() > 0) { - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - } - } - } else { - List tbCashierCarts = cashierCartMapper.selectByShopIdAndTableId(shopId, tableId); - if (!CollectionUtils.isEmpty(tbCashierCarts)) { - for (TbCashierCart cashierCart : tbCashierCarts) { - array.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), array.toString()); - } - } - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", "addCart"); - jsonObject1.put("data", array); - jsonObject1.put("amount", amount); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - } - - // @Transactional(rollbackFor = Exception.class) - public void createCart(JSONObject jsonObject) { - try { - String tableId = jsonObject.getString("tableId"); - String shopId = jsonObject.getString("shopId"); - String productId = jsonObject.getString("productId"); - String key = tableId + "-" + shopId; - JSONArray jsonArray = new JSONArray(); - BigDecimal amount = BigDecimal.ZERO; - boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId")); - if (!exist) { - TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(jsonObject.getString("skuId"))); - Double stock = tbProductSkuWithBLOBs.getStockNumber(); - redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), Math.round(stock) + ""); - } - String skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId")); - TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId)); - if (tbProduct.getIsStock() == 1) { - if (Integer.valueOf(skuNum) < 1 && jsonObject.getInteger("num") > 0) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品库存已售罄"); - jsonObject1.put("data", new ArrayList<>()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.error("该商品库存已售罄 skuId:{}", jsonObject.getString("skuId")); - throw new MsgException("该商品库存已售罄"); - } - } - - if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) { - if (jsonObject.getInteger("num") > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), jsonObject.getString("skuId"), - jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - if (jsonObject.getInteger("num") > 0) { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); - } else { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); - } - productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); - } - } else { - boolean flag = true; - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - if (cashierCart.getSkuId().equals(jsonObject.getString("skuId"))) { - cashierCart.setTotalNumber(cashierCart.getTotalNumber() + jsonObject.getInteger("num")); - cashierCart.setNumber(cashierCart.getNumber() + jsonObject.getInteger("num")); - if (jsonObject.getInteger("num") > 0) { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); - } else { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); - } - productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); - if (cashierCart.getNumber() > 0) { - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - } else { - cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); - continue; - } - flag = false; - } - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - } - if (flag && jsonObject.getInteger("num") > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), jsonObject.getString("skuId"), - jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - if (jsonObject.getInteger("num") > 0) { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); - } else { - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "2"); - } - productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); - } - } - } else { - if (jsonObject.getInteger("num") > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), jsonObject.getString("skuId"), - jsonObject.getInteger("userId"), jsonObject.getInteger("num"), tableId, jsonObject.getString("shopId")); - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - redisUtil.getIncrNum(RedisCst.PRODUCT + shopId + ":" + jsonObject.getString("skuId"), "1"); - productSkuMapper.updateStockById(jsonObject.getString("skuId"), jsonObject.getInteger("num")); - } - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString()); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", jsonArray); - jsonObject1.put("amount", amount); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - } catch (Exception e) { - log.error("长链接错误 createCart{}", e.getMessage()); - } - } - - private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception { - try { - TbProduct product = productMapper.selectById(Integer.valueOf(productId)); - String key = tableId + "-" + shopId; - if (Objects.isNull(product)) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品不存在"); - jsonObject1.put("data", new ArrayList<>()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true); - log.error("购物车添加商品异常,该商品不存在:{}",productId); - throw new MsgException("该商品不存在"); - } - TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); - if (Objects.isNull(productSku)) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品规格不存在"); - jsonObject1.put("data", new ArrayList<>()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true); - log.error("购物车添加商品异常,该商品sku不存在:{}",productId); - throw new MsgException("该商品规格不存在"); - } - TbCashierCart cashierCart = new TbCashierCart(); - cashierCart.setProductId(productId); - cashierCart.setSkuId(skuId); - cashierCart.setNumber(num); - cashierCart.setCoverImg(product.getCoverImg()); - cashierCart.setName(product.getName()); - cashierCart.setCategoryId(product.getCategoryId()); - cashierCart.setShopId(shopId); - cashierCart.setUserId(userId); - cashierCart.setTableId(tableId); - cashierCart.setSkuName(productSku.getSpecSnap()); - cashierCart.setIsPack("false"); - cashierCart.setIsGift("false"); - cashierCart.setStatus("create"); - cashierCart.setType((byte) 0); - cashierCart.setSalePrice(productSku.getSalePrice()); - cashierCart.setCreatedAt(Instant.now().toEpochMilli()); - cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); - cashierCart.setTotalNumber(num); - cashierCart.setPackFee(BigDecimal.ZERO); - cashierCart.setRefundNumber(0); - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee()))); - cashierCartMapper.insert(cashierCart); - return cashierCart; - } catch (Exception e) { - log.error("长链接错误 addCart{}", e.getMessage()); - throw e; - } - } - - @Transactional(rollbackFor = Exception.class) - public void createOrder(JSONObject jsonObject) { - try { - String shopId = jsonObject.getString("shopId"); - String tableId = jsonObject.getString("tableId"); - String key = tableId + "-" + shopId; - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - List ids = new ArrayList<>(); - BigDecimal totalAmount = BigDecimal.ZERO; - BigDecimal packAMount = BigDecimal.ZERO; - BigDecimal originAmount = BigDecimal.ZERO; - BigDecimal saleAmount = BigDecimal.ZERO; - String couponId = ""; - BigDecimal couponAmount = BigDecimal.ZERO; - List orderDetails = new ArrayList<>(); - Integer orderId = 0; - TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); - if (tbMerchantAccount == null) { - MsgException.throwException("生成订单错误"); - } - - String userId = jsonObject.getString("userId"); - TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - if (tbUserInfo == null) { - MsgException.throwException("生成订单失败"); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId())); - totalAmount = totalAmount.add(cashierCart.getTotalAmount()); - packAMount = packAMount.add(cashierCart.getPackFee()); - originAmount = originAmount.add(cashierCart.getTotalAmount()); - if (Objects.nonNull(tbProduct)) { - saleAmount = saleAmount.add(tbProduct.getSalePrice()); - } - TbOrderDetail orderDetail = new TbOrderDetail(); - orderDetail.setCreateTime(new Date()); - orderDetail.setNum(cashierCart.getNumber()); - orderDetail.setPrice(cashierCart.getSalePrice()); - if (cashierCart.getIsPack().equals("true")) { - orderDetail.setPriceAmount(cashierCart.getTotalAmount().add(cashierCart.getPackFee())); - } else { - orderDetail.setPriceAmount(cashierCart.getTotalAmount()); - } - orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId())); - orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId())); - orderDetail.setProductSkuName(tbProduct.getSpecSnap()); - orderDetail.setProductName(cashierCart.getName()); - orderDetail.setShopId(jsonObject.getInteger("shopId")); - orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setProductImg(cashierCart.getCoverImg()); - orderDetail.setStatus("unpaid"); - if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { - orderId = Integer.valueOf(cashierCart.getOrderId()); - } - orderDetails.add(orderDetail); - if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { - orderId = Integer.valueOf(cashierCart.getOrderId()); - } - cashierCartMapper.updateStatusById(cashierCart.getId(), "final"); - } - //总金额 - TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId")); - //生成订单 - TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - String isBuyYhq = "false"; - String isuseYhq = "false"; - if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { - couponId = jsonObject.getString("couponsId"); - //1:购买优惠券,0:自己持有优惠券 - Integer couponsId = jsonObject.getInteger("couponsId"); - if (jsonObject.getString("isBuyYhq").equals("1")) { - TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已售空"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); - originAmount = originAmount.add(systemCoupons.getCouponsPrice()); - couponAmount = systemCoupons.getCouponsAmount(); - systemCoupons.setStatus("1"); - systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons); - TbUserCoupons userCoupons = new TbUserCoupons(); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum())); - userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount()); - userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice()); - userCoupons.setStatus("1"); - userCoupons.setUserId(userId); - userCoupons.setCreateTime(new Date()); - userCouponsMapper.insert(userCoupons); - couponId = userCoupons.getId() + ""; - couponAmount = userCoupons.getCouponsAmount(); - } else { - TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已使用"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); - userCoupons.setStatus("1"); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); - userCouponsMapper.updateByPrimaryKeySelective(userCoupons); - couponAmount = userCoupons.getCouponsAmount(); - } - isuseYhq = "true"; - - } - if (Objects.nonNull(orderInfo)) { - log.info("订单状态:" + orderInfo.getStatus()); - if (!"unpaid".equals(orderInfo.getStatus())) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单正在支付中,请稍后再试"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - - orderDetailMapper.deleteByOUrderId(orderId); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setUserCouponAmount(couponAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(originAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setFreightAmount(BigDecimal.ZERO); - orderInfo.setProductAmount(saleAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setIsUseCoupon(isuseYhq); - orderInfoMapper.updateByPrimaryKeySelective(orderInfo); - } else { - orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount); - orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); - orderInfo.setUserCouponId(couponId); - orderInfo.setOriginAmount(originAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setIsUseCoupon(isuseYhq); - orderInfo.setUserCouponAmount(couponAmount); - - JSONObject object=new JSONObject(); - String outNumber= redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); - Integer number=1; - if(Objects.isNull(outNumber)){ - object.put("outNumber",number); - object.put("times",DateUtils.getDay()); - }else { - object=JSONObject.parseObject(outNumber); - if(object.getString("times").equals(DateUtils.getDay())){ - number=object.getInteger("outNumber")+1; - object.put("outNumber",number); - }else { - object.put("outNumber",number); - object.put("times",DateUtils.getDay()); - } - } - orderInfo.setOutNumber(number+""); - redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")),object.toString()); - orderInfoMapper.insert(orderInfo); - orderId = orderInfo.getId(); - } - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - orderDetailMapper.insert(orderDetail); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setOrderId(orderId + ""); - cashierCart.setStatus("closed"); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - object.put("updatedAt", System.currentTimeMillis()); - object.put("orderId", orderId + ""); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); - orderInfo.setDetailList(orderDetails); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", orderInfo); - redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - JSONObject jsonObject12 = new JSONObject(); - jsonObject12.put("status", "success"); - jsonObject12.put("msg", "成功"); - jsonObject12.put("type", "order"); - jsonObject12.put("amount", BigDecimal.ZERO); - - jsonObject12.put("data", new JSONArray()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L); - } catch (Exception e) { - log.info("长链接错误 addCart{}", e.getMessage()); - e.printStackTrace(); - } - } - - private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, - TbShopTable shopTable, String merchantId, JSONObject jsonObject, BigDecimal originAmount) { - TbOrderInfo orderInfo = new TbOrderInfo(); - String orderNo = generateOrderNumber(); - orderInfo.setOrderNo(orderNo); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setPackFee(packAMount); - orderInfo.setOriginAmount(originAmount); - orderInfo.setProductAmount(originAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setPayAmount(BigDecimal.ZERO); - orderInfo.setRefundAmount(new BigDecimal("0.00")); - orderInfo.setTableId(jsonObject.getString("tableId")); - orderInfo.setSendType("table"); - orderInfo.setOrderType("miniapp"); - orderInfo.setTradeDay(DateUtils.getDay()); - orderInfo.setStatus("unpaid"); - orderInfo.setShopId(jsonObject.getString("shopId")); - orderInfo.setUserId(jsonObject.getString("userId")); - orderInfo.setCreatedAt(Instant.now().toEpochMilli()); - orderInfo.setSystemTime(Instant.now().toEpochMilli()); - orderInfo.setUpdatedAt(Instant.now().toEpochMilli()); - orderInfo.setIsAccepted((byte) 1); - if (Objects.nonNull(shopTable)) { - orderInfo.setTableName(shopTable.getName()); - } - orderInfo.setMerchantId(merchantId); - return orderInfo; - } - - public String generateOrderNumber() { - String date = DateUtils.getSdfTimes(); - Random random = new Random(); - int randomNum = random.nextInt(900) + 100; - return "WX" + date + randomNum; - } - - public void clearCart(JSONObject jsonObject) { - try { - String shopId = jsonObject.getString("shopId"); - if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) { - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) { - for (int i = 0; i < array.size(); i++) { - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(array.get(i).toString(), TbCashierCart.class); - redisUtil.secAdd(RedisCst.PRODUCT+shopId+":"+jsonObject.getString("skuId"),cashierCart.getNumber().toString()); - productSkuMapper.updateAddStockById(jsonObject.getString("skuId"), cashierCart.getNumber()); - - } - } - } - cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed"); - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString()); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", "clearCart"); - jsonObject1.put("amount", BigDecimal.ZERO); - jsonObject1.put("data", new ArrayList<>()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - } catch (Exception e) { - log.info("长链接错误 clearCart{}", e.getMessage()); - e.printStackTrace(); - } - } - - @Transactional(rollbackFor = Exception.class) - public void pendingOrder(JSONObject jsonObject) throws IOException { - try { - String shopId = jsonObject.getString("shopId"); - String tableId = jsonObject.getString("tableId"); - String key = tableId + "-" + shopId; - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - List ids = new ArrayList<>(); - BigDecimal totalAmount = BigDecimal.ZERO; - BigDecimal packAMount = BigDecimal.ZERO; - BigDecimal originAmount = BigDecimal.ZERO; - BigDecimal saleAmount = BigDecimal.ZERO; - String couponId = ""; - BigDecimal couponAmount = BigDecimal.ZERO; - Map skuMap = new HashMap<>(); - List orderDetails = new ArrayList<>(); - Integer orderId = 0; - TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); - if (tbMerchantAccount == null) { - throw new MsgException("生成订单错误"); - } - - String userId = jsonObject.getString("userId"); - TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); - if (tbUserInfo == null) { - throw new MsgException("生成订单失败"); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId())); - totalAmount = totalAmount.add(cashierCart.getTotalAmount()); - packAMount = packAMount.add(cashierCart.getPackFee()); - originAmount = originAmount.add(cashierCart.getTotalAmount()); - if (Objects.nonNull(tbProduct)) { - saleAmount = saleAmount.add(tbProduct.getSalePrice()); - } - skuMap.put(tbProduct.getId(), tbProduct); - TbOrderDetail orderDetail = new TbOrderDetail(); - orderDetail.setCreateTime(new Date()); - orderDetail.setNum(cashierCart.getNumber()); - orderDetail.setPrice(cashierCart.getSalePrice()); - if (cashierCart.getIsPack().equals("true")) { - orderDetail.setPriceAmount(cashierCart.getTotalAmount().add(cashierCart.getPackFee())); - } else { - orderDetail.setPriceAmount(cashierCart.getTotalAmount()); - } - orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId())); - orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId())); - orderDetail.setProductSkuName(tbProduct.getSpecSnap()); - orderDetail.setProductName(cashierCart.getName()); - orderDetail.setShopId(jsonObject.getInteger("shopId")); - orderDetail.setPackAmount(cashierCart.getPackFee()); - orderDetail.setProductImg(cashierCart.getCoverImg()); - orderDetail.setStatus("unpaid"); - if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { - orderId = Integer.valueOf(cashierCart.getOrderId()); - - } - orderDetails.add(orderDetail); - if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { - orderId = Integer.valueOf(cashierCart.getOrderId()); - } - } - //总金额 - TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId")); - //生成订单 - TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - String isBuyYhq = "false"; - String isuseYhq = "false"; - if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { - couponId = jsonObject.getString("couponsId"); - //1:购买优惠券,0:自己持有优惠券 - Integer couponsId = jsonObject.getInteger("couponsId"); - if (jsonObject.getString("isBuyYhq").equals("1")) { - TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已售空"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); - originAmount = originAmount.add(systemCoupons.getCouponsPrice()); - couponAmount = systemCoupons.getCouponsAmount(); - systemCoupons.setStatus("1"); - systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons); - TbUserCoupons userCoupons = new TbUserCoupons(); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum())); - userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount()); - userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice()); - userCoupons.setStatus("1"); - userCoupons.setUserId(userId); - userCoupons.setCreateTime(new Date()); - userCouponsMapper.insert(userCoupons); - couponId = userCoupons.getId() + ""; - couponAmount = userCoupons.getCouponsAmount(); - } else { - TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已使用"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); - userCoupons.setStatus("1"); - userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); - userCouponsMapper.updateByPrimaryKeySelective(userCoupons); - couponAmount = userCoupons.getCouponsAmount(); - } - isuseYhq = "true"; - - } - if (Objects.nonNull(orderInfo)) { - log.info("订单状态:" + orderInfo.getStatus()); - if (!"unpaid".equals(orderInfo.getStatus())) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单正在支付中,请稍后再试"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - - orderDetailMapper.deleteByOUrderId(orderId); - orderInfo.setUpdatedAt(System.currentTimeMillis()); - orderInfo.setSettlementAmount(totalAmount); - orderInfo.setUserCouponId(couponId); - orderInfo.setUserCouponAmount(couponAmount); - orderInfo.setAmount(totalAmount); - orderInfo.setOriginAmount(originAmount); - orderInfo.setOrderAmount(totalAmount.add(packAMount)); - orderInfo.setFreightAmount(BigDecimal.ZERO); - orderInfo.setProductAmount(saleAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setIsUseCoupon(isuseYhq); - orderInfoMapper.updateByPrimaryKeySelective(orderInfo); - } else { - orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount); - orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId())); - orderInfo.setUserCouponId(couponId); - orderInfo.setOriginAmount(originAmount); - orderInfo.setIsBuyCoupon(isBuyYhq); - orderInfo.setIsUseCoupon(isuseYhq); - orderInfo.setUserCouponAmount(couponAmount); - - JSONObject object=new JSONObject(); - String outNumber= redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); - Integer number=1; - if(Objects.isNull(outNumber)){ - object.put("outNumber",number); - object.put("times",DateUtils.getDay()); - }else { - object=JSONObject.parseObject(outNumber); - if(object.getString("times").equals(DateUtils.getDay())){ - number=object.getInteger("outNumber")+1; - object.put("outNumber",number); - }else { - object.put("outNumber",number); - object.put("times",DateUtils.getDay()); - } - } - orderInfo.setOutNumber(number+""); - redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")),object.toString()); - - orderInfoMapper.insert(orderInfo); - orderId = orderInfo.getId(); - } - for (TbOrderDetail orderDetail : orderDetails) { - orderDetail.setOrderId(orderId); - orderDetailMapper.insert(orderDetail); - } - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - cashierCart.setUpdatedAt(System.currentTimeMillis()); - cashierCart.setOrderId(orderId + ""); - cashierCart.setStatus("closed"); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - object.put("updatedAt", System.currentTimeMillis()); - object.put("orderId", orderId + ""); - } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString()); - orderInfo.setDetailList(orderDetails); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", orderInfo); - redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId)); - redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()), JSONObject.toJSONString(orderInfo), 24 * 60 * 60L); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - JSONObject jsonObject12 = new JSONObject(); - jsonObject12.put("status", "success"); - jsonObject12.put("msg", "成功"); - jsonObject12.put("type", "order"); - jsonObject12.put("amount", BigDecimal.ZERO); - - jsonObject12.put("data", new JSONArray()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - } catch (Exception e) { - log.info("长链接错误 pendingOrder{}", e.getMessage()); - e.printStackTrace(); - } - } - - public void queryCart(JSONObject jsonObject) { - try { - String shopId = jsonObject.getString("shopId"); - JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); - BigDecimal amount = BigDecimal.ZERO; - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - } - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "success"); - jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", array); - jsonObject1.put("amount", amount); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); - } catch (Exception e) { - log.info("长链接错误 queryCart{}", e.getMessage()); - e.printStackTrace(); - } - } - -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 9b6eba9..2d4a7ba 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -55,12 +55,69 @@ public class LoginService { @Transactional(rollbackFor = Exception.class) public Result wxCustomLogin(String openId, String headImage, String nickName, String telephone, String ip) throws Exception { - TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId); - if (ObjectUtil.isNull(userInfo)) { - if(StringUtils.isNotBlank(telephone)){ - userInfo = tbUserInfoMapper.selectByPhone(telephone); - } + TbUserInfo userInfo = new TbUserInfo(); + if(StringUtils.isNotBlank(telephone)){ + userInfo = tbUserInfoMapper.selectByPhone(telephone); if (ObjectUtil.isNull(userInfo)) { + userInfo = tbUserInfoMapper.selectByOpenId(openId); + if (ObjectUtil.isNull(userInfo)) { + userInfo = new TbUserInfo(); + userInfo.setAmount(BigDecimal.ZERO); + userInfo.setChargeAmount(BigDecimal.ZERO); + userInfo.setLineOfCredit(BigDecimal.ZERO); + userInfo.setConsumeNumber(0); + userInfo.setConsumeAmount(BigDecimal.ZERO); + userInfo.setTotalScore(0); + userInfo.setLockScore(0); + userInfo.setHeadImg("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240411/a2be5869bfa24d72a4782f695cc53ed1.png"); + userInfo.setNickName(ObjectUtil.isNotNull(nickName) ? nickName : "微信用户"); + userInfo.setTelephone(telephone); + userInfo.setMiniAppOpenId(openId); + userInfo.setStatus(Byte.parseByte("1")); + userInfo.setParentType("PERSON"); + userInfo.setIsResource(Byte.parseByte("0")); + userInfo.setIsOnline(Byte.parseByte("0")); + userInfo.setIsVip(Byte.parseByte("0")); + userInfo.setSourcePath("WECHAT-APP"); + userInfo.setIsAttentionMp(Byte.parseByte("0")); + userInfo.setSearchWord("||微信用户"); + userInfo.setIsPwd("0"); + userInfo.setPwd(MD5Utils.md5("123456")); + userInfo.setLastLogInAt(System.currentTimeMillis()); + userInfo.setCreatedAt(System.currentTimeMillis()); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.insert(userInfo); + List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); + if (!CollectionUtils.isEmpty(tbShopUsers)) { + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setUserId(userInfo.getId() + ""); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } + } + }else { + userInfo.setTelephone(telephone); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); + if (!CollectionUtils.isEmpty(tbShopUsers)) { + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setUserId(null); + tbShopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKey(tbShopUser); + } + } + } + }else { + if(!userInfo.getMiniAppOpenId().equals(openId)){ + userInfo.setMiniAppOpenId(openId); + userInfo.setUpdatedAt(System.currentTimeMillis()); + tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); + } + } + }else { + userInfo = tbUserInfoMapper.selectByOpenId(openId); + if(ObjectUtil.isNull(userInfo)){ userInfo = new TbUserInfo(); userInfo.setAmount(BigDecimal.ZERO); userInfo.setChargeAmount(BigDecimal.ZERO); @@ -87,40 +144,6 @@ public class LoginService { userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); tbUserInfoMapper.insert(userInfo); - if(StringUtils.isNotBlank(telephone)){ - List tbShopUsers = tbShopUserMapper.selectByPhone(telephone); - if(!CollectionUtils.isEmpty(tbShopUsers)){ - for (TbShopUser tbShopUser : tbShopUsers) { - tbShopUser.setUserId(userInfo.getId() + ""); - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKey(tbShopUser); - } - } - } - } - else { - if(!userInfo.getSearchWord().contains("微信用户")){ - userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户"); - } - userInfo.setMiniAppOpenId(openId); - userInfo.setUpdatedAt(System.currentTimeMillis()); - tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); - } - } - else { - String phone = userInfo.getTelephone(); - if(StringUtils.isNotBlank(telephone)){ - if (StringUtils.isBlank(phone) || !phone.equals(telephone)) { - userInfo.setTelephone(telephone); - userInfo.setUpdatedAt(System.currentTimeMillis()); - tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); - List tbShopUsers = tbShopUserMapper.selectAllByUserId(userInfo.getId().toString()); - for (TbShopUser tbShopUser : tbShopUsers) { - tbShopUser.setUserId(null); - tbShopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.upUserBYId(tbShopUser); - } - } } } //生成token 信息 From d86463155d41909661bd2304df19e6dd07b30597 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 22 Jun 2024 11:26:07 +0800 Subject: [PATCH 132/134] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 7 ++++-- .../entity/dto/AuthUserDto.java | 9 ++++++++ .../cashierservice/service/LoginService.java | 22 +++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index 5312839..247a8ce 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -320,18 +320,21 @@ public class LoginContoller { @PostMapping("/app/login") public Result applogin(@RequestBody AuthUserDto authUserDto) { boolean tf = false; + JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(authUserDto.getOpencode(), customAppId, customSecrete); + // 3.接收微信接口服务 获取返回的参数 + String openid = SessionKeyOpenId.getString("openid"); if (ObjectUtil.isNull(authUserDto.getCode())) { if (StringUtils.isBlank(authUserDto.getPassword())) { return Result.fail("请输入密码,或使用验证码登录"); } //验证密码 String mdPasswordString = MD5Utils.MD5Encode(authUserDto.getPassword(), "utf-8"); - return loginService.appLogin(authUserDto.getUsername(), mdPasswordString); + return loginService.appLogin(authUserDto.getUsername(),openid, mdPasswordString); } else { // tf = true; tf = loginService.validate(authUserDto.getCode(), authUserDto.getUsername()); if (tf) { - return loginService.appLogin(authUserDto.getUsername(), null); + return loginService.appLogin(authUserDto.getUsername(),openid, null); } else { return Result.fail("验证码输入有误"); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/AuthUserDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/AuthUserDto.java index c27ef49..e01c109 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/AuthUserDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/AuthUserDto.java @@ -13,6 +13,7 @@ public class AuthUserDto { private String password; private String code; + private String opencode; private String uuid = ""; @@ -47,4 +48,12 @@ public class AuthUserDto { public void setUuid(String uuid) { this.uuid = uuid; } + + public String getOpencode() { + return opencode; + } + + public void setOpencode(String opencode) { + this.opencode = opencode; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index 2d4a7ba..3773928 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -178,7 +178,7 @@ public class LoginService { * @param nickName * @return */ - public TbUserInfo register(String phone, String password, String nickName) { + public TbUserInfo register(String phone, String openId,String password, String nickName) { TbUserInfo userInfo = new TbUserInfo(); userInfo.setAmount(BigDecimal.ZERO); @@ -202,6 +202,9 @@ public class LoginService { userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setCreatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis()); + userInfo.setMiniAppOpenId(openId); + userInfo.setIsPwd("0"); + userInfo.setPwd(MD5Utils.md5("123456")); if (StringUtils.isNotBlank(password)) { userInfo.setPassword(MD5Utils.MD5Encode(password, "UTF-8")); } @@ -234,14 +237,19 @@ public class LoginService { } @Transactional(rollbackFor = Exception.class) - public Result appLogin(String username, String password) { + public Result appLogin(String username,String openId, String password) { TbUserInfo userInfo = tbUserInfoMapper.selectByPhone(username); if (ObjectUtil.isNull(userInfo)) { if (StringUtils.isNotBlank(password)) { return Result.fail("暂未设置密码,请使用验证码登录"); } - userInfo = register(username, password, username); + userInfo = register(username,openId, password, username); } else { + if (StringUtils.isNotBlank(userInfo.getMiniAppOpenId())) { + if (!userInfo.getMiniAppOpenId().equals(openId)) { + userInfo.setMiniAppOpenId(openId); + } + } String searchWord = userInfo.getSearchWord(); if (!searchWord.contains("移动端用户")) { userInfo.setSearchWord(userInfo.getSearchWord() + "||移动端用户"); @@ -268,10 +276,10 @@ public class LoginService { try { map.put("token", token); map.put("userInfo", userInfo); - if(StringUtils.isNotBlank(userInfo.getMiniAppOpenId())){ - redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map),60*60*24*30L); - }else { - redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L); + if (StringUtils.isNotBlank(userInfo.getMiniAppOpenId())) { + redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map), 60 * 60 * 24 * 30L); + } else { + redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map), 60 * 60 * 24 * 30L); } // redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L); return Result.success(CodeEnum.SUCCESS, map); From bdf9a2c89f51e57c9c4fdee2366a7bcc84cca783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Sat, 22 Jun 2024 13:42:29 +0800 Subject: [PATCH 133/134] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=B0=8F=E7=A5=A8?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/PayService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 567afdb..585aecc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -144,6 +144,11 @@ public class PayService { @Transactional(rollbackFor = Exception.class) public Result payOrder(String openId,String orderId,String ip) throws Exception { + + if(ObjectUtil.isEmpty(openId)||Objects.isNull(openId)){ + return Result.fail("付款用户[userId]参数不能为空"); + } + TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); if(!"unpaid".equals(orderInfo.getStatus())&&!"paying".equals(orderInfo.getStatus())){ @@ -836,8 +841,6 @@ public class PayService { } } } - - return Result.fail("失败"); } From 4c8cbe7c20cc109e7797ef9e784a6a14716bf26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E9=B9=8F=E8=BE=89?= <18322780655@163.com> Date: Tue, 25 Jun 2024 14:57:34 +0800 Subject: [PATCH 134/134] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/util/PrinterUtils.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java index 1b00095..7ab595a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/PrinterUtils.java @@ -89,6 +89,7 @@ public class PrinterUtils { sb.append(""+detailPO.getMerchantName()+"

"); sb.append(""+type+"【"+detailPO.getMasterId()+"】

"); + sb.append(""+detailPO.getOutNumber()+"

"); sb.append("订单号: "+detailPO.getOrderNo()+"
"); sb.append("交易时间: "+detailPO.getTradeDate()+"
"); sb.append("收银员: "+detailPO.getOperator()+"


"); @@ -96,7 +97,7 @@ public class PrinterUtils { char paddingCharacter = ' '; sb.append(""+String.format("%-15s","品名").replace(' ', paddingCharacter)+String.format("%-4s","数量").replace(' ', paddingCharacter)+String.format("%4s","小计").replace(' ', paddingCharacter)+"
"); for (OrderDetailPO.Detail detail : detailPO.getDetailList()) { - if(detail.getProductName().length()>4){ + if(detail.getProductName().length()>4&&detail.getProductName().length()<=10){ int count=getProducrName(detail.getProductName()); if(count<=0){ @@ -107,6 +108,11 @@ public class PrinterUtils { sb.append(""+String.format("%-"+length+"s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"
"); } + }else if(detail.getProductName().length()>10){ + + sb.append(""+detail.getProductName()+"
"); + sb.append(""+String.format("%20s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%11s",detail.getAmount()).replace(' ', paddingCharacter)+"
"); + }else { sb.append(""+String.format("%-15s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"
"); } @@ -131,9 +137,9 @@ public class PrinterUtils { sb.append("余额:"+detailPO.getBalance()+"
"); sb.append("------------------------
"); -// if(Objects.nonNull(detailPO.getOutNumber())){ -// sb.append("".concat(detailPO.getOutNumber()).concat("
")); -// } + if(Objects.nonNull(detailPO.getOutNumber())){ + sb.append("".concat(detailPO.getOutNumber()).concat("
")); + } sb.append("打印时间:"+DateUtils.getTime(new Date())+"
");