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..f15259c --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateMapper.java @@ -0,0 +1,27 @@ +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/DutyService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/DutyService.java index d2925f2..8b900d0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/DutyService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/DutyService.java @@ -56,40 +56,180 @@ public class DutyService { JSONObject jsonObject = JSON.parseObject(message); String token = jsonObject.getString("token"); String type = jsonObject.getString("type"); + boolean quick = jsonObject.containsKey("quick"); TbToken tbToken = tbTokenMapper.selectByToken(token); String day = DateUtils.getDay(); - if (type.equals("return") || type.equals("create")) { - if (Objects.isNull(tbToken)) { - throw new MsgException("当前用户不存在"); - } + if (quick) { + + Integer tokenId = tbToken.getId(); - Integer orderId = jsonObject.getInteger("orderId"); + String orderNo = jsonObject.getString("orderNo"); + BigDecimal amount = new BigDecimal(jsonObject.getString("amount")); + JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken()); Integer shopId = tokenJson.getInteger("shopId"); Integer userId = tokenJson.getInteger("staffId"); String loginName = tokenJson.getString("loginName"); - TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - if (Objects.isNull(orderInfo) && orderId > 0) { - throw new MsgException("订单不存在"); - } - List list = orderDetailMapper.selectAllByOrderId(orderId); TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId); -// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId); ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0"); + + if (Objects.isNull(shopUserDuty)) { + shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, amount, shopInfo.getShopName(), "0", + amount, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, ""); + shopUserDuty.setTokenId(tokenId); + shopUserDuty.setReturnAmount(BigDecimal.ZERO); + shopUserDuty.setTradeDay(DateUtils.getDay()); + shopUserDutyMapper.insert(shopUserDuty); + } + + } else { + + + if (type.equals("return") || type.equals("create")) { + if (Objects.isNull(tbToken)) { + throw new MsgException("当前用户不存在"); + } + Integer tokenId = tbToken.getId(); + Integer orderId = jsonObject.getInteger("orderId"); + JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken()); + Integer shopId = tokenJson.getInteger("shopId"); + Integer userId = tokenJson.getInteger("staffId"); + String loginName = tokenJson.getString("loginName"); + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + if (Objects.isNull(orderInfo) && orderId > 0) { + throw new MsgException("订单不存在"); + } + List list = orderDetailMapper.selectAllByOrderId(orderId); + TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId); +// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId); + ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0"); // ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndTrade(shopId, day); // ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(tokenId, day, orderInfo.getShopId()); - BigDecimal cashAmount = BigDecimal.ZERO; + BigDecimal cashAmount = BigDecimal.ZERO; - if (type.equals("create")) { + if (type.equals("create")) { + if (orderInfo.getPayType().equals("cash")) { + cashAmount = orderInfo.getPayAmount(); + } + if (Objects.isNull(shopUserDuty)) { + shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), shopInfo.getShopName(), "0", + orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, ""); + shopUserDuty.setTokenId(tokenId); + shopUserDuty.setReturnAmount(BigDecimal.ZERO); + shopUserDuty.setTradeDay(DateUtils.getDay()); + shopUserDutyMapper.insert(shopUserDuty); + List detaiList = new ArrayList<>(); + for (TbOrderDetail orderDetail : list) { + ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail(); + shopUserDutyDetail.setDutyId(shopUserDuty.getId()); + shopUserDutyDetail.setAmount(orderDetail.getPriceAmount()); + shopUserDutyDetail.setNum(orderDetail.getNum()); + shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId()); + shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName()); + shopUserDutyDetail.setProductId(orderDetail.getProductId()); + shopUserDutyDetail.setProductName(orderDetail.getProductName()); + detaiList.add(shopUserDutyDetail); +// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); + subInventory(shopId, orderDetail.getProductSkuId(), orderDetail.getNum()); + } + if (detaiList.size() > 0) { + shopUserDutyDetailMapper.batchInsert(detaiList); + } + } else { + shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount())); + shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount)); + shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount())); + shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1); + shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty); + List skuIds = new ArrayList<>(); + for (TbOrderDetail orderDetail : list) { + skuIds.add(orderDetail.getProductSkuId()); + } + List details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds); + + Map map = new HashMap<>(); + for (ShopUserDutyDetail shopUserDutyDetail : details) { + map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail); + } + List detaiList = new ArrayList<>(); + for (TbOrderDetail orderDetail : list) { + if (map.containsKey(orderDetail.getProductSkuId())) { + ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId()); + shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum()); + shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount()))); + shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail); + } else { + ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail(); + shopUserDutyDetail.setDutyId(shopUserDuty.getId()); + shopUserDutyDetail.setAmount(orderDetail.getPriceAmount()); + shopUserDutyDetail.setNum(orderDetail.getNum()); + shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId()); + shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName()); + shopUserDutyDetail.setProductId(orderDetail.getProductId()); + shopUserDutyDetail.setProductName(orderDetail.getProductName()); + detaiList.add(shopUserDutyDetail); + + } +// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); + subInventory(shopId, orderDetail.getProductSkuId(), orderDetail.getNum()); + } + if (detaiList.size() > 0) { + shopUserDutyDetailMapper.batchInsert(detaiList); + } + } + ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(), orderInfo.getPayType()); + if (Objects.nonNull(shopUserDutyPay)) { + shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount())); + shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay); + } else { + shopUserDutyPay = new ShopUserDutyPay(); + shopUserDutyPay.setDutyId(shopUserDuty.getId()); + shopUserDutyPay.setType(orderInfo.getPayType()); + shopUserDutyPay.setAmount(orderInfo.getOrderAmount()); + shopUserDutyPayMapper.insert(shopUserDutyPay); + } +// for (TbOrderDetail orderDetail : list){ +// +// } + } else if (type.equals("return")) { + BigDecimal amount = jsonObject.getBigDecimal("amount"); + if (Objects.isNull(shopUserDuty)) { + shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, BigDecimal.ZERO, loginName, "0", + BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, ""); + shopUserDuty.setReturnAmount(amount); + shopUserDuty.setTokenId(tokenId); + shopUserDuty.setTradeDay(DateUtils.getDay()); + shopUserDutyMapper.insert(shopUserDuty); + } else { + shopUserDuty.setReturnAmount(shopUserDuty.getReturnAmount().add(amount)); + shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty); + } + } + } else if (type.equals("wxcreate")) { + Integer orderId = jsonObject.getInteger("orderId"); + TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + if (Objects.isNull(orderInfo)) { + throw new MsgException("订单不存在"); + } + List list = orderDetailMapper.selectAllByOrderId(orderId); + BigDecimal cashAmount = BigDecimal.ZERO; if (orderInfo.getPayType().equals("cash")) { cashAmount = orderInfo.getPayAmount(); } + ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(Integer.valueOf(orderInfo.getShopId()), "0"); +// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndTrade(Integer.valueOf(orderInfo.getShopId()), day); +// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(0, day, orderInfo.getShopId()); + TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); if (Objects.isNull(shopUserDuty)) { - shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), shopInfo.getShopName(), "0", - orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, ""); - shopUserDuty.setTokenId(tokenId); - shopUserDuty.setReturnAmount(BigDecimal.ZERO); + shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0", + orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, ""); + shopUserDuty.setTokenId(0); + shopUserDuty.setType("wx"); + if (Objects.nonNull(shopInfo)) { + shopUserDuty.setUserName(shopInfo.getShopName()); + } shopUserDuty.setTradeDay(DateUtils.getDay()); + shopUserDuty.setReturnAmount(BigDecimal.ZERO); shopUserDutyMapper.insert(shopUserDuty); List detaiList = new ArrayList<>(); for (TbOrderDetail orderDetail : list) { @@ -102,8 +242,7 @@ public class DutyService { shopUserDutyDetail.setProductId(orderDetail.getProductId()); shopUserDutyDetail.setProductName(orderDetail.getProductName()); detaiList.add(shopUserDutyDetail); -// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); - subInventory(shopId,orderDetail.getProductSkuId(),orderDetail.getNum()); + productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); } if (detaiList.size() > 0) { shopUserDutyDetailMapper.batchInsert(detaiList); @@ -143,9 +282,9 @@ public class DutyService { detaiList.add(shopUserDutyDetail); } -// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); - subInventory(shopId,orderDetail.getProductSkuId(),orderDetail.getNum()); + productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); } + if (detaiList.size() > 0) { shopUserDutyDetailMapper.batchInsert(detaiList); } @@ -161,130 +300,19 @@ public class DutyService { shopUserDutyPay.setAmount(orderInfo.getOrderAmount()); shopUserDutyPayMapper.insert(shopUserDutyPay); } -// for (TbOrderDetail orderDetail : list){ -// -// } - } else if (type.equals("return")) { - BigDecimal amount = jsonObject.getBigDecimal("amount"); - if (Objects.isNull(shopUserDuty)) { - shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, BigDecimal.ZERO, loginName, "0", - BigDecimal.ZERO, shopId, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, ""); - shopUserDuty.setReturnAmount(amount); - shopUserDuty.setTokenId(tokenId); - shopUserDuty.setTradeDay(DateUtils.getDay()); - shopUserDutyMapper.insert(shopUserDuty); - } else { - shopUserDuty.setReturnAmount(shopUserDuty.getReturnAmount().add(amount)); - shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty); - } - } - } else if (type.equals("wxcreate")) { - Integer orderId = jsonObject.getInteger("orderId"); - TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); - if (Objects.isNull(orderInfo)) { - throw new MsgException("订单不存在"); - } - List list = orderDetailMapper.selectAllByOrderId(orderId); - BigDecimal cashAmount = BigDecimal.ZERO; - if (orderInfo.getPayType().equals("cash")) { - cashAmount = orderInfo.getPayAmount(); - } - ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(Integer.valueOf(orderInfo.getShopId()), "0"); -// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndTrade(Integer.valueOf(orderInfo.getShopId()), day); -// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(0, day, orderInfo.getShopId()); - TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId())); - if (Objects.isNull(shopUserDuty)) { - shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0", - orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, ""); - shopUserDuty.setTokenId(0); - shopUserDuty.setType("wx"); - if (Objects.nonNull(shopInfo)) { - shopUserDuty.setUserName(shopInfo.getShopName()); - } - shopUserDuty.setTradeDay(DateUtils.getDay()); - shopUserDuty.setReturnAmount(BigDecimal.ZERO); - shopUserDutyMapper.insert(shopUserDuty); - List detaiList = new ArrayList<>(); - for (TbOrderDetail orderDetail : list) { - ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail(); - shopUserDutyDetail.setDutyId(shopUserDuty.getId()); - shopUserDutyDetail.setAmount(orderDetail.getPriceAmount()); - shopUserDutyDetail.setNum(orderDetail.getNum()); - shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId()); - shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName()); - shopUserDutyDetail.setProductId(orderDetail.getProductId()); - shopUserDutyDetail.setProductName(orderDetail.getProductName()); - detaiList.add(shopUserDutyDetail); - productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); - } - if (detaiList.size() > 0) { - shopUserDutyDetailMapper.batchInsert(detaiList); - } } else { - shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount())); - shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount)); - shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount())); - shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1); - shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty); - List skuIds = new ArrayList<>(); - for (TbOrderDetail orderDetail : list) { - skuIds.add(orderDetail.getProductSkuId()); - } - List details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds); - - Map map = new HashMap<>(); - for (ShopUserDutyDetail shopUserDutyDetail : details) { - map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail); - } - List detaiList = new ArrayList<>(); - for (TbOrderDetail orderDetail : list) { - if (map.containsKey(orderDetail.getProductSkuId())) { - ShopUserDutyDetail shopUserDutyDetail = map.get(orderDetail.getProductSkuId()); - shopUserDutyDetail.setNum(shopUserDutyDetail.getNum() + orderDetail.getNum()); - shopUserDutyDetail.setAmount(shopUserDutyDetail.getAmount().add(orderDetail.getPriceAmount().add(orderDetail.getPackAmount()))); - shopUserDutyDetailMapper.updateByPrimaryKeySelective(shopUserDutyDetail); - } else { - ShopUserDutyDetail shopUserDutyDetail = new ShopUserDutyDetail(); - shopUserDutyDetail.setDutyId(shopUserDuty.getId()); - shopUserDutyDetail.setAmount(orderDetail.getPriceAmount()); - shopUserDutyDetail.setNum(orderDetail.getNum()); - shopUserDutyDetail.setSkuId(orderDetail.getProductSkuId()); - shopUserDutyDetail.setSkuName(orderDetail.getProductSkuName()); - shopUserDutyDetail.setProductId(orderDetail.getProductId()); - shopUserDutyDetail.setProductName(orderDetail.getProductName()); - detaiList.add(shopUserDutyDetail); - - } - productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); - } - - if (detaiList.size() > 0) { - shopUserDutyDetailMapper.batchInsert(detaiList); - } - } - ShopUserDutyPay shopUserDutyPay = shopUserDutyPayMapper.selectByDuctIdAndType(shopUserDuty.getId(), orderInfo.getPayType()); - if (Objects.nonNull(shopUserDutyPay)) { - shopUserDutyPay.setAmount(orderInfo.getOrderAmount().add(shopUserDutyPay.getAmount())); - shopUserDutyPayMapper.updateByPrimaryKeySelective(shopUserDutyPay); - } else { - shopUserDutyPay = new ShopUserDutyPay(); - shopUserDutyPay.setDutyId(shopUserDuty.getId()); - shopUserDutyPay.setType(orderInfo.getPayType()); - shopUserDutyPay.setAmount(orderInfo.getOrderAmount()); - shopUserDutyPayMapper.insert(shopUserDutyPay); - } - } else { - if (type.equals("close")) { - JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken()); - Integer shopId = tokenJson.getInteger("shopId"); - Integer staffId = tokenJson.getInteger("staffId"); - ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0"); - cloudPrinterService.handoverprintData(token, shopUserDuty.getId(), ""); + if (type.equals("close")) { + JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken()); + Integer shopId = tokenJson.getInteger("shopId"); + Integer staffId = tokenJson.getInteger("staffId"); + ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0"); + cloudPrinterService.handoverprintData(token, shopUserDuty.getId(), ""); // shopUserDutyMapper.updateStatusByTokenId(day, shopId, staffId); - shopUserDutyMapper.updateStatusById(shopUserDuty.getId(),staffId); + shopUserDutyMapper.updateStatusById(shopUserDuty.getId(), staffId); + } } } - } catch (Exception e) { + }catch (Exception e) { e.getMessage(); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java index 2b5300c..d69cd58 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MemberService.java @@ -9,12 +9,17 @@ import com.chaozhanggui.system.cashierservice.model.ScanPayReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.MainScanResp; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; +import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; import com.chaozhanggui.system.cashierservice.util.BeanUtil; +import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.MD5Util; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; -import org.apache.ibatis.annotations.Mapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; @@ -23,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import java.util.List; import java.util.Map; @@ -50,67 +56,67 @@ public class MemberService { @Autowired TbShopPayTypeMapper tbShopPayTypeMapper; - - - - @Value("${gateway.url}") - private String gateWayUrl; - - - + @Autowired + ThirdPayService thirdPayService; @Autowired RestTemplate restTemplate; + @Autowired + TbActivateMapper tbActivateMapper; + @Value("${gateway.url}") + private String gateWayUrl; + @Value("${thirdPay.payType}") + private String thirdPayType; + @Value("${thirdPay.url}") + private String url; + @Value("${thirdPay.callBack}") + private String callBack; + public Result queryMember(String shopId, String phone, int page, int pageSize) { - - - - public Result queryMember(String shopId,String phone,int page,int pageSize){ - - PageHelper.startPage(page,pageSize); - List tbShopUsers= tbShopUserMapper.selectByShopId(shopId,phone); - PageInfo pageInfo=new PageInfo(tbShopUsers); - return Result.success(CodeEnum.SUCCESS,pageInfo); + PageHelper.startPage(page, pageSize); + List tbShopUsers = tbShopUserMapper.selectByShopId(shopId, phone); + PageInfo pageInfo = new PageInfo(tbShopUsers); + return Result.success(CodeEnum.SUCCESS, pageInfo); } @Transactional(rollbackFor = Exception.class) - public Result createMember(Map map){ - if(ObjectUtil.isEmpty(map)||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) - || !map.containsKey("phone")||ObjectUtil.isEmpty(map.get("phone")) - ||!map.containsKey("nickName")||ObjectUtil.isEmpty(map.get("nickName")) - ||!map.containsKey("sex")||ObjectUtil.isEmpty(map.get("sex")) - ||!map.containsKey("level") ||ObjectUtil.isEmpty(map.get("level"))|| - !map.containsKey("birthDay")||ObjectUtil.isEmpty(map.get("birthDay")) - ){ + public Result createMember(Map map) { + if (ObjectUtil.isEmpty(map) || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId")) + || !map.containsKey("phone") || ObjectUtil.isEmpty(map.get("phone")) + || !map.containsKey("nickName") || ObjectUtil.isEmpty(map.get("nickName")) + || !map.containsKey("sex") || ObjectUtil.isEmpty(map.get("sex")) + || !map.containsKey("level") || ObjectUtil.isEmpty(map.get("level")) || + !map.containsKey("birthDay") || ObjectUtil.isEmpty(map.get("birthDay")) + ) { return Result.fail(CodeEnum.PARAM); } - String phone=map.get("phone")+""; + String phone = String.valueOf(map.get("phone")); - String shopId=map.get("shopId")+""; + String shopId = String.valueOf(map.get("shopId")); - List tbShopUsers= tbShopUserMapper.selectByShopId(shopId,phone); + List tbShopUsers = tbShopUserMapper.selectByShopId(shopId, phone); - if(ObjectUtil.isNotEmpty(tbShopUsers)&&tbShopUsers.get(0).getIsVip().toString().equals("1")){ + if (ObjectUtil.isNotEmpty(tbShopUsers) && tbShopUsers.get(0).getIsVip().toString().equals("1")) { return Result.fail(CodeEnum.MEMBERHAVED); } - if(ObjectUtil.isNotNull(tbShopUsers)&&ObjectUtil.isNotEmpty(tbShopUsers)){ - TbShopUser tbShopUser= tbShopUsers.get(0); - String code= RandomUtil.randomNumbers(6); + if (ObjectUtil.isNotNull(tbShopUsers) && ObjectUtil.isNotEmpty(tbShopUsers)) { + TbShopUser tbShopUser = tbShopUsers.get(0); + String code = DateUtils.getSsdfTimes(); tbShopUser.setCode(code); tbShopUser.setTelephone(phone); - tbShopUser.setBirthDay(map.get("birthDay")+""); - tbShopUser.setName(map.get("nickName")+""); - tbShopUser.setSex(Byte.parseByte(map.get("sex")+"")); - tbShopUser.setLevel(Byte.parseByte(map.get("level")+"")); + tbShopUser.setBirthDay(String.valueOf(map.get("birthDay"))); + tbShopUser.setName(String.valueOf(map.get("nickName"))); + tbShopUser.setSex(Byte.parseByte(String.valueOf(map.get("sex")))); + tbShopUser.setLevel(Byte.parseByte(String.valueOf(map.get("level")))); tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); return Result.success(CodeEnum.SUCCESS); } - TbShopUser tbShopUser=new TbShopUser(); + TbShopUser tbShopUser = new TbShopUser(); tbShopUser.setAmount(BigDecimal.ZERO); tbShopUser.setCreditAmount(BigDecimal.ZERO); tbShopUser.setConsumeAmount(BigDecimal.ZERO); @@ -119,11 +125,11 @@ public class MemberService { tbShopUser.setStatus(Byte.parseByte("1")); tbShopUser.setShopId(shopId); tbShopUser.setTelephone(phone); - tbShopUser.setBirthDay(map.get("birthDay")+""); - tbShopUser.setName(map.get("nickName")+""); - tbShopUser.setSex(Byte.parseByte(map.get("sex")+"")); - tbShopUser.setLevel(Byte.parseByte(map.get("level")+"")); - String code= RandomUtil.randomNumbers(6); + tbShopUser.setBirthDay(String.valueOf(map.get("birthDay"))); + tbShopUser.setName(String.valueOf(map.get("nickName"))); + tbShopUser.setSex(Byte.parseByte(String.valueOf(map.get("sex")))); + tbShopUser.setLevel(Byte.parseByte(String.valueOf(map.get("level")))); + String code = RandomUtil.randomNumbers(6); tbShopUser.setCode(code); tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setCreatedAt(System.currentTimeMillis()); @@ -132,53 +138,52 @@ public class MemberService { } - @Transactional(rollbackFor = Exception.class) - public Result memberScanPay(Map map){ - if(ObjectUtil.isEmpty(map)||map.size()<=0 - ||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) - ||!map.containsKey("memberId")||ObjectUtil.isEmpty(map.get("memberId")) - ||!map.containsKey("amount")||ObjectUtil.isEmpty(map.get("amount")) - ||!map.containsKey("authCode")||ObjectUtil.isEmpty(map.get("authCode")) - ){ + public Result memberScanPay(Map map) { + if (ObjectUtil.isEmpty(map) || map.size() <= 0 + || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId")) + || !map.containsKey("memberId") || ObjectUtil.isEmpty(map.get("memberId")) + || !map.containsKey("amount") || ObjectUtil.isEmpty(map.get("amount")) + || !map.containsKey("authCode") || ObjectUtil.isEmpty(map.get("authCode")) + ) { return Result.fail(CodeEnum.PARAM); } - String memberId=map.get("memberId")+""; + String memberId = String.valueOf(map.get("memberId")); - String shopId=map.get("shopId")+""; + String shopId = String.valueOf(map.get("shopId")); - TbShopInfo shopInfo=tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); - if(ObjectUtil.isEmpty(shopInfo)||shopInfo==null){ + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); + if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) { return Result.fail(CodeEnum.SHOPINFONOEXIST); } - TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); - if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){ + TbShopUser shopUser = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); + if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) { return Result.fail(CodeEnum.MEMBERNOEXIST); } - String authCode=map.get("authCode").toString(); - String qpay=null; + String authCode = map.get("authCode").toString(); + String qpay = null; String payTypeCode = authCode.substring(0, 1);// 判断收款码 - switch (payTypeCode){ + switch (payTypeCode) { case "1": - qpay="scanCode"; + qpay = "scanCode"; break; case "2": - qpay="scanCode"; + qpay = "scanCode"; break; } - int count= tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId,qpay); - if(count<1){ + int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId, qpay); + if (count < 1) { return Result.fail(CodeEnum.PAYTYPENOEXIST); } - BigDecimal amount= new BigDecimal(map.get("amount")+"").setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal amount = new BigDecimal(String.valueOf(map.get("amount"))).setScale(2, RoundingMode.DOWN); - TbMemberIn memberIn=new TbMemberIn(); + TbMemberIn memberIn = new TbMemberIn(); memberIn.setAmount(amount); memberIn.setUserId(shopUser.getId()); memberIn.setCode(shopUser.getCode()); @@ -187,165 +192,301 @@ public class MemberService { memberIn.setCreateTime(new Date()); tbMemberInMapper.insert(memberIn); + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); - TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); - - if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ + if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { return Result.fail(CodeEnum.NOCUSTOMER); } - ScanPayReq scanPayReq=new ScanPayReq(); - scanPayReq.setAppId(thirdApply.getAppId()); - scanPayReq.setTimestamp(System.currentTimeMillis()); - scanPayReq.setAuthCode(authCode); - scanPayReq.setNotifyUrl("http://cas"); - scanPayReq.setConsumeFee(amount.toPlainString()); + if ("ysk".equals(thirdPayType)) { + ScanPayReq scanPayReq = new ScanPayReq(); + scanPayReq.setAppId(thirdApply.getAppId()); + scanPayReq.setTimestamp(System.currentTimeMillis()); + scanPayReq.setAuthCode(authCode); + scanPayReq.setNotifyUrl("http://cas"); + scanPayReq.setConsumeFee(amount.toPlainString()); - Map reqMap= BeanUtil.transBean2Map(scanPayReq); - scanPayReq.setSign(MD5Util.encrypt(reqMap,thirdApply.getAppToken(),true)); + Map reqMap = BeanUtil.transBean2Map(scanPayReq); + scanPayReq.setSign(MD5Util.encrypt(reqMap, thirdApply.getAppToken(), true)); - ResponseEntity response= restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"),scanPayReq,String.class); - if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())) { - JSONObject object = JSONObject.parseObject(response.getBody()); - if(object.get("code").equals("0")){ - String orderNO=object.getJSONObject("data").get("orderNumber").toString(); + ResponseEntity response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class); + if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) { + JSONObject object = JSONObject.parseObject(response.getBody()); + if (object.get("code").equals("0")) { + String orderNO = object.getJSONObject("data").get("orderNumber").toString(); - memberIn.setOrderNo(orderNO); - memberIn.setStatus("0"); - memberIn.setUpdateTime(new Date()); - tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - - //修改客户资金 - shopUser.setAmount(shopUser.getAmount().add(amount)); - shopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKeySelective(shopUser); - - TbShopUserFlow flow=new TbShopUserFlow(); - flow.setShopUserId(shopUser.getId()); - flow.setBizCode("scanMemberIn"); - flow.setBizName("会员扫码充值"); - flow.setAmount(amount); - flow.setBalance(shopUser.getAmount()); - flow.setCreateTime(new Date()); - tbShopUserFlowMapper.insert(flow); - return Result.success(CodeEnum.SUCCESS,memberIn); - }else { - String status=ObjectUtil.isNotEmpty(object.getJSONObject("data"))?object.getJSONObject("data").getString("status"):null; - if(ObjectUtil.isNotNull(status)&&"7".equals(status)){ - String orderNO=object.getJSONObject("data").get("orderNumber").toString(); memberIn.setOrderNo(orderNO); + memberIn.setStatus("0"); memberIn.setUpdateTime(new Date()); tbMemberInMapper.updateByPrimaryKeySelective(memberIn); - return Result.success(CodeEnum.PAYING,memberIn); + + //修改客户资金 + shopUser.setAmount(shopUser.getAmount().add(amount)); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setAmount(amount); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + return Result.success(CodeEnum.SUCCESS, memberIn); + } else { + String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null; + if (ObjectUtil.isNotNull(status) && "7".equals(status)) { + String orderNO = object.getJSONObject("data").get("orderNumber").toString(); + memberIn.setOrderNo(orderNO); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + return Result.success(CodeEnum.PAYING, memberIn); + } + return Result.fail(object.getString("msg")); } - return Result.fail(object.getString("msg")); } + } else { + + String orderNo = DateUtils.getSsdfTimes(); + + PublicResp publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), "会员充值", "会员充值", amount.setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payTypeCode.equals("1") ? thirdApply.getSmallAppid() : null, authCode, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken()); + if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { + if ("000000".equals(publicResp.getCode())) { + MainScanResp mainScanResp = publicResp.getObjData(); + if ("TRADE_SUCCESS".equals(mainScanResp.getState())) { + + memberIn.setOrderNo(orderNo); + memberIn.setTradeNo(mainScanResp.getPayOrderId()); + memberIn.setStatus("0"); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + //修改客户资金 + shopUser.setAmount(shopUser.getAmount().add(amount)); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setAmount(amount); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + + TbActivate activate = tbActivateMapper.selectByAmount(shopInfo.getId().toString(), memberIn.getAmount()); + if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { + BigDecimal awardAmount = BigDecimal.ZERO; + switch (activate.getHandselType()) { + case "GD": + awardAmount = activate.getHandselNum(); + break; + case "RATIO": + awardAmount = memberIn.getAmount().multiply(activate.getHandselNum()); + break; + } + + shopUser.setAmount(shopUser.getAmount().add(awardAmount)); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberAwardIn"); + flow.setBizName("会员充值奖励"); + flow.setAmount(awardAmount); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + } + + + + + + + + return Result.success(CodeEnum.SUCCESS, memberIn); + + } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) { + memberIn.setOrderNo(orderNo); + memberIn.setTradeNo(mainScanResp.getPayOrderId()); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + return Result.success(CodeEnum.PAYING, memberIn); + } else { + return Result.fail(publicResp.getMsg()); + } + } + } + + } + return Result.fail("失败"); } - public Result queryScanPay(String flowId){ - if(ObjectUtil.isEmpty(flowId)){ + public Result queryScanPay(String flowId) { + if (ObjectUtil.isEmpty(flowId)) { return Result.fail(CodeEnum.PARAM); } - TbMemberIn memberIn=tbMemberInMapper.selectByPrimaryKey(Integer.valueOf(flowId)); + TbMemberIn memberIn = tbMemberInMapper.selectByPrimaryKey(Integer.valueOf(flowId)); - - TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(memberIn.getUserId()); - if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){ + TbShopUser shopUser = tbShopUserMapper.selectByPrimaryKey(memberIn.getUserId()); + if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) { return Result.fail(CodeEnum.MEMBERNOEXIST); } - if(memberIn.getStatus().equals("7")){ - TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(memberIn.getMerchantId())); - if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ + if (memberIn.getStatus().equals("7")) { + TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(memberIn.getMerchantId()); + if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { return Result.fail(CodeEnum.NOCUSTOMER); } - TradeQueryReq tradeQueryReq=new TradeQueryReq(); - tradeQueryReq.setAppId(thirdApply.getAppId()); - tradeQueryReq.setTimestamp(System.currentTimeMillis()); - tradeQueryReq.setOrderNumber(memberIn.getOrderNo()); - Map map= BeanUtil.transBean2Map(tradeQueryReq); - tradeQueryReq.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true)); - ResponseEntity response= restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"),tradeQueryReq,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"); - if("1".equals(data.getString("status"))){ - String orderNO=object.getJSONObject("data").get("orderNumber").toString(); - memberIn.setOrderNo(orderNO); - memberIn.setStatus("0"); - memberIn.setUpdateTime(new Date()); - tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + if ("ysk".equals(thirdPayType)) { + TradeQueryReq tradeQueryReq = new TradeQueryReq(); + tradeQueryReq.setAppId(thirdApply.getAppId()); + tradeQueryReq.setTimestamp(System.currentTimeMillis()); + tradeQueryReq.setOrderNumber(memberIn.getOrderNo()); - //修改客户资金 - shopUser.setAmount(shopUser.getAmount().add(memberIn.getAmount())); - shopUser.setUpdatedAt(System.currentTimeMillis()); - tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + Map map = BeanUtil.transBean2Map(tradeQueryReq); + tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + ResponseEntity response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, 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"); + if ("1".equals(data.getString("status"))) { + String orderNO = object.getJSONObject("data").get("orderNumber").toString(); - TbShopUserFlow flow=new TbShopUserFlow(); - flow.setShopUserId(shopUser.getId()); - flow.setBizCode("scanMemberIn"); - flow.setBizName("会员扫码充值"); - flow.setAmount(memberIn.getAmount()); - flow.setBalance(shopUser.getAmount()); - flow.setCreateTime(new Date()); - tbShopUserFlowMapper.insert(flow); - return Result.success(CodeEnum.SUCCESS,memberIn); + memberIn.setOrderNo(orderNO); + memberIn.setStatus("0"); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + + //修改客户资金 + shopUser.setAmount(shopUser.getAmount().add(memberIn.getAmount())); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setAmount(memberIn.getAmount()); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + return Result.success(CodeEnum.SUCCESS, memberIn); + } + } + } + } else { + PublicResp orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), memberIn.getTradeNo(), null, thirdApply.getAppToken()); + if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) { + if ("000000".equals(orderstatus.getCode())) { + if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) { + + memberIn.setStatus("0"); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + + //修改客户资金 + shopUser.setAmount(shopUser.getAmount().add(memberIn.getAmount())); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + TbShopUserFlow flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberIn"); + flow.setBizName("会员扫码充值"); + flow.setAmount(memberIn.getAmount()); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + + + TbActivate activate = tbActivateMapper.selectByAmount(shopUser.getId().toString(), memberIn.getAmount()); + if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { + BigDecimal awardAmount = BigDecimal.ZERO; + switch (activate.getHandselType()) { + case "GD": + awardAmount = activate.getHandselNum(); + break; + case "RATIO": + awardAmount = memberIn.getAmount().multiply(activate.getHandselNum()); + break; + } + + shopUser.setAmount(shopUser.getAmount().add(awardAmount)); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberAwardIn"); + flow.setBizName("会员充值奖励"); + flow.setAmount(awardAmount); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + } + return Result.success(CodeEnum.SUCCESS, memberIn); + + } } } } } - return Result.success(CodeEnum.SUCCESS,memberIn); + + return Result.success(CodeEnum.SUCCESS, memberIn); } - - @Transactional(rollbackFor = Exception.class) - public Result memberAccountPay(Map map){ - if(ObjectUtil.isEmpty(map)||map.size()<=0 - ||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) - ||!map.containsKey("memberId")||ObjectUtil.isEmpty(map.get("memberId")) - ||!map.containsKey("amount")||ObjectUtil.isEmpty(map.get("amount")) - ){ + public Result memberAccountPay(Map map) { + if (ObjectUtil.isEmpty(map) || map.size() <= 0 + || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId")) + || !map.containsKey("memberId") || ObjectUtil.isEmpty(map.get("memberId")) + || !map.containsKey("amount") || ObjectUtil.isEmpty(map.get("amount")) + ) { return Result.fail(CodeEnum.PARAM); } - String memberId=map.get("memberId")+""; + String memberId = String.valueOf(map.get("memberId")); - String shopId=map.get("shopId")+""; + String shopId = String.valueOf(map.get("shopId")); - TbShopInfo shopInfo=tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); - if(ObjectUtil.isEmpty(shopInfo)||shopInfo==null){ + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); + if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) { return Result.fail(CodeEnum.SHOPINFONOEXIST); } - TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); - if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){ + TbShopUser shopUser = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); + if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) { return Result.fail(CodeEnum.MEMBERNOEXIST); } - int count= tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId,"cash"); - if(count<1){ + int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId, "cash"); + if (count < 1) { return Result.fail(CodeEnum.PAYTYPENOEXIST); } - BigDecimal amount= new BigDecimal(map.get("amount")+"").setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal amount = new BigDecimal(String.valueOf(map.get("amount"))).setScale(2, RoundingMode.DOWN); - TbMemberIn memberIn=new TbMemberIn(); + TbMemberIn memberIn = new TbMemberIn(); memberIn.setAmount(amount); memberIn.setUserId(shopUser.getId()); memberIn.setCode(shopUser.getCode()); @@ -358,7 +499,7 @@ public class MemberService { shopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(shopUser); - TbShopUserFlow flow=new TbShopUserFlow(); + TbShopUserFlow flow = new TbShopUserFlow(); flow.setShopUserId(shopUser.getId()); flow.setBizCode("cashMemberIn"); flow.setBizName("会员现金充值"); @@ -367,22 +508,47 @@ public class MemberService { flow.setCreateTime(new Date()); tbShopUserFlowMapper.insert(flow); - return Result.success(CodeEnum.SUCCESS); + TbActivate activate = tbActivateMapper.selectByAmount(shopInfo.getId().toString(), memberIn.getAmount()); + if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { + BigDecimal awardAmount = BigDecimal.ZERO; + switch (activate.getHandselType()) { + case "GD": + awardAmount = activate.getHandselNum(); + break; + case "RATIO": + awardAmount = memberIn.getAmount().multiply(activate.getHandselNum()); + break; + } + shopUser.setAmount(shopUser.getAmount().add(awardAmount)); + shopUser.setUpdatedAt(System.currentTimeMillis()); + tbShopUserMapper.updateByPrimaryKeySelective(shopUser); + + flow = new TbShopUserFlow(); + flow.setShopUserId(shopUser.getId()); + flow.setBizCode("scanMemberAwardIn"); + flow.setBizName("会员充值奖励"); + flow.setAmount(awardAmount); + flow.setBalance(shopUser.getAmount()); + flow.setCreateTime(new Date()); + tbShopUserFlowMapper.insert(flow); + } + + + return Result.success(CodeEnum.SUCCESS); } - public Result queryMemberAccount(String memberId,int page, int pageSize){ - if(ObjectUtil.isEmpty(memberId)){ + public Result queryMemberAccount(String memberId, int page, int pageSize) { + if (ObjectUtil.isEmpty(memberId)) { return Result.fail(CodeEnum.PARAM); } - PageHelper.startPage(page,pageSize); - List> list=tbShopUserFlowMapper.selectByMemberAccountFlow(memberId); - PageInfo pageInfo=new PageInfo(list); - return Result.success(CodeEnum.SUCCESS,pageInfo); + PageHelper.startPage(page, pageSize); + List> list = tbShopUserFlowMapper.selectByMemberAccountFlow(memberId); + PageInfo pageInfo = new PageInfo(list); + return Result.success(CodeEnum.SUCCESS, pageInfo); } - } 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 103fc30..8de0936 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -436,12 +436,12 @@ public class PayService { return Result.fail(CodeEnum.MEMBERNOEXIST); } - if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { + if (N.gt(orderInfo.getOrderAmount(), user.getAmount())) { return Result.fail(CodeEnum.MEMBERINSUFFICIENTFUNDS); } user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); - user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount())); + user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getOrderAmount())); user.setConsumeNumber(user.getConsumeNumber() + 1); user.setUpdatedAt(System.currentTimeMillis()); tbShopUserMapper.updateByPrimaryKeySelective(user); @@ -934,6 +934,19 @@ public class PayService { if ("TRADE_SUCCESS".equals(mainScanResp.getState())) { tbQuickPay.setTradeNo(mainScanResp.getPayOrderId()); tbQuickPayMapper.insert(tbQuickPay); + + + + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("token", token); + jsonObject.put("quick", "quick"); + jsonObject.put("orderNo",tbQuickPay.getOrderNo()); + jsonObject.put("amount",tbQuickPay.getAmount()); + producer.putOrderCollect(jsonObject.toJSONString()); + + + return Result.success(CodeEnum.SUCCESS, tbQuickPay); } 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 5b5f1de..9372465 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/DateUtils.java @@ -19,7 +19,7 @@ public class DateUtils { private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss"); - private final static SimpleDateFormat sdfTimesSs = new SimpleDateFormat("yyyyMMddHHmmss"); + private final static SimpleDateFormat sdfTimesSs = new SimpleDateFormat("yyyyMMddHHmmssSSS"); diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index 1650fcb..067c195 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -5,8 +5,8 @@ - - + + @@ -19,8 +19,8 @@ - + @@ -51,14 +51,10 @@ - -
--> +
- - - -
\ No newline at end of file diff --git a/src/main/resources/mapper/TbActivateMapper.xml b/src/main/resources/mapper/TbActivateMapper.xml new file mode 100644 index 0000000..e70bf21 --- /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 diff --git a/src/main/resources/mapper/TbMemberInMapper.xml b/src/main/resources/mapper/TbMemberInMapper.xml index 13d4cee..fa4a76b 100644 --- a/src/main/resources/mapper/TbMemberInMapper.xml +++ b/src/main/resources/mapper/TbMemberInMapper.xml @@ -27,7 +27,7 @@ delete from tb_member_in where id = #{id,jdbcType=INTEGER} - + insert into tb_member_in (id, user_id, merchant_id, code, amount, status, order_no, trade_no, create_time,