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