添加会员充值奖励

This commit is contained in:
韩鹏辉 2024-05-29 10:38:36 +08:00
parent 640036afc5
commit 664e57e145
9 changed files with 758 additions and 329 deletions

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -56,40 +56,180 @@ public class DutyService {
JSONObject jsonObject = JSON.parseObject(message); JSONObject jsonObject = JSON.parseObject(message);
String token = jsonObject.getString("token"); String token = jsonObject.getString("token");
String type = jsonObject.getString("type"); String type = jsonObject.getString("type");
boolean quick = jsonObject.containsKey("quick");
TbToken tbToken = tbTokenMapper.selectByToken(token); TbToken tbToken = tbTokenMapper.selectByToken(token);
String day = DateUtils.getDay(); String day = DateUtils.getDay();
if (type.equals("return") || type.equals("create")) { if (quick) {
if (Objects.isNull(tbToken)) {
throw new MsgException("当前用户不存在");
}
Integer tokenId = tbToken.getId(); 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()); JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken());
Integer shopId = tokenJson.getInteger("shopId"); Integer shopId = tokenJson.getInteger("shopId");
Integer userId = tokenJson.getInteger("staffId"); Integer userId = tokenJson.getInteger("staffId");
String loginName = tokenJson.getString("loginName"); String loginName = tokenJson.getString("loginName");
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
if (Objects.isNull(orderInfo) && orderId > 0) {
throw new MsgException("订单不存在");
}
List<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId); TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId);
// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenId(tokenId);
ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0"); 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<TbOrderDetail> 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.selectByShopIdAndTrade(shopId, day);
// ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByTokenIdAndTradeDay(tokenId, day, orderInfo.getShopId()); // 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<ShopUserDutyDetail> 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<Integer> skuIds = new ArrayList<>();
for (TbOrderDetail orderDetail : list) {
skuIds.add(orderDetail.getProductSkuId());
}
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
for (ShopUserDutyDetail shopUserDutyDetail : details) {
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
}
List<ShopUserDutyDetail> 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<TbOrderDetail> list = orderDetailMapper.selectAllByOrderId(orderId);
BigDecimal cashAmount = BigDecimal.ZERO;
if (orderInfo.getPayType().equals("cash")) { if (orderInfo.getPayType().equals("cash")) {
cashAmount = orderInfo.getPayAmount(); 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)) { if (Objects.isNull(shopUserDuty)) {
shopUserDuty = new ShopUserDuty(userId, tbToken.getCreateTime(), 1, orderInfo.getOrderAmount(), shopInfo.getShopName(), "0", shopUserDuty = new ShopUserDuty(Integer.valueOf(orderInfo.getShopId()), new Date(), 1, orderInfo.getOrderAmount(), "", "0",
orderInfo.getOrderAmount(), shopId, BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, ""); orderInfo.getOrderAmount(), Integer.valueOf(orderInfo.getShopId()), BigDecimal.ZERO, cashAmount, BigDecimal.ZERO, "");
shopUserDuty.setTokenId(tokenId); shopUserDuty.setTokenId(0);
shopUserDuty.setReturnAmount(BigDecimal.ZERO); shopUserDuty.setType("wx");
if (Objects.nonNull(shopInfo)) {
shopUserDuty.setUserName(shopInfo.getShopName());
}
shopUserDuty.setTradeDay(DateUtils.getDay()); shopUserDuty.setTradeDay(DateUtils.getDay());
shopUserDuty.setReturnAmount(BigDecimal.ZERO);
shopUserDutyMapper.insert(shopUserDuty); shopUserDutyMapper.insert(shopUserDuty);
List<ShopUserDutyDetail> detaiList = new ArrayList<>(); List<ShopUserDutyDetail> detaiList = new ArrayList<>();
for (TbOrderDetail orderDetail : list) { for (TbOrderDetail orderDetail : list) {
@ -102,8 +242,7 @@ public class DutyService {
shopUserDutyDetail.setProductId(orderDetail.getProductId()); shopUserDutyDetail.setProductId(orderDetail.getProductId());
shopUserDutyDetail.setProductName(orderDetail.getProductName()); shopUserDutyDetail.setProductName(orderDetail.getProductName());
detaiList.add(shopUserDutyDetail); detaiList.add(shopUserDutyDetail);
// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum());
subInventory(shopId,orderDetail.getProductSkuId(),orderDetail.getNum());
} }
if (detaiList.size() > 0) { if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList); shopUserDutyDetailMapper.batchInsert(detaiList);
@ -143,9 +282,9 @@ public class DutyService {
detaiList.add(shopUserDutyDetail); detaiList.add(shopUserDutyDetail);
} }
// productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum()); productSkuMapper.updateByskuId(orderDetail.getProductSkuId(), orderDetail.getNum());
subInventory(shopId,orderDetail.getProductSkuId(),orderDetail.getNum());
} }
if (detaiList.size() > 0) { if (detaiList.size() > 0) {
shopUserDutyDetailMapper.batchInsert(detaiList); shopUserDutyDetailMapper.batchInsert(detaiList);
} }
@ -161,130 +300,19 @@ public class DutyService {
shopUserDutyPay.setAmount(orderInfo.getOrderAmount()); shopUserDutyPay.setAmount(orderInfo.getOrderAmount());
shopUserDutyPayMapper.insert(shopUserDutyPay); 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<TbOrderDetail> 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<ShopUserDutyDetail> 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 { } else {
shopUserDuty.setAmount(shopUserDuty.getAmount().add(orderInfo.getPayAmount())); if (type.equals("close")) {
shopUserDuty.setCashAmount(shopUserDuty.getCashAmount().add(cashAmount)); JSONObject tokenJson = TokenUtil.parseParamFromToken(tbToken.getToken());
shopUserDuty.setIncomeAmount(shopUserDuty.getIncomeAmount().add(orderInfo.getPayAmount())); Integer shopId = tokenJson.getInteger("shopId");
shopUserDuty.setOrderNum(shopUserDuty.getOrderNum() + 1); Integer staffId = tokenJson.getInteger("staffId");
shopUserDutyMapper.updateByPrimaryKeySelective(shopUserDuty); ShopUserDuty shopUserDuty = shopUserDutyMapper.selectByShopIdAndStatus(shopId, "0");
List<Integer> skuIds = new ArrayList<>(); cloudPrinterService.handoverprintData(token, shopUserDuty.getId(), "");
for (TbOrderDetail orderDetail : list) {
skuIds.add(orderDetail.getProductSkuId());
}
List<ShopUserDutyDetail> details = shopUserDutyDetailMapper.selectByDuctId(shopUserDuty.getId(), skuIds);
Map<Integer, ShopUserDutyDetail> map = new HashMap<>();
for (ShopUserDutyDetail shopUserDutyDetail : details) {
map.put(shopUserDutyDetail.getSkuId(), shopUserDutyDetail);
}
List<ShopUserDutyDetail> 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(), "");
// shopUserDutyMapper.updateStatusByTokenId(day, shopId, staffId); // shopUserDutyMapper.updateStatusByTokenId(day, shopId, staffId);
shopUserDutyMapper.updateStatusById(shopUserDuty.getId(),staffId); shopUserDutyMapper.updateStatusById(shopUserDuty.getId(), staffId);
}
} }
} }
} catch (Exception e) { }catch (Exception e) {
e.getMessage(); e.getMessage();
} }
} }

View File

@ -9,12 +9,17 @@ import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; 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.BeanUtil;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.MD5Util; import com.chaozhanggui.system.cashierservice.util.MD5Util;
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -23,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,67 +56,67 @@ public class MemberService {
@Autowired @Autowired
TbShopPayTypeMapper tbShopPayTypeMapper; TbShopPayTypeMapper tbShopPayTypeMapper;
@Autowired
ThirdPayService thirdPayService;
@Value("${gateway.url}")
private String gateWayUrl;
@Autowired @Autowired
RestTemplate restTemplate; 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) {
PageHelper.startPage(page, pageSize);
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByShopId(shopId, phone);
PageInfo pageInfo = new PageInfo(tbShopUsers);
public Result queryMember(String shopId,String phone,int page,int pageSize){ return Result.success(CodeEnum.SUCCESS, pageInfo);
PageHelper.startPage(page,pageSize);
List<TbShopUser> tbShopUsers= tbShopUserMapper.selectByShopId(shopId,phone);
PageInfo pageInfo=new PageInfo(tbShopUsers);
return Result.success(CodeEnum.SUCCESS,pageInfo);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result createMember(Map<String,Object> map){ public Result createMember(Map<String, Object> map) {
if(ObjectUtil.isEmpty(map)||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) if (ObjectUtil.isEmpty(map) || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))
|| !map.containsKey("phone")||ObjectUtil.isEmpty(map.get("phone")) || !map.containsKey("phone") || ObjectUtil.isEmpty(map.get("phone"))
||!map.containsKey("nickName")||ObjectUtil.isEmpty(map.get("nickName")) || !map.containsKey("nickName") || ObjectUtil.isEmpty(map.get("nickName"))
||!map.containsKey("sex")||ObjectUtil.isEmpty(map.get("sex")) || !map.containsKey("sex") || ObjectUtil.isEmpty(map.get("sex"))
||!map.containsKey("level") ||ObjectUtil.isEmpty(map.get("level"))|| || !map.containsKey("level") || ObjectUtil.isEmpty(map.get("level")) ||
!map.containsKey("birthDay")||ObjectUtil.isEmpty(map.get("birthDay")) !map.containsKey("birthDay") || ObjectUtil.isEmpty(map.get("birthDay"))
){ ) {
return Result.fail(CodeEnum.PARAM); 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<TbShopUser> tbShopUsers= tbShopUserMapper.selectByShopId(shopId,phone); List<TbShopUser> 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); return Result.fail(CodeEnum.MEMBERHAVED);
} }
if(ObjectUtil.isNotNull(tbShopUsers)&&ObjectUtil.isNotEmpty(tbShopUsers)){ if (ObjectUtil.isNotNull(tbShopUsers) && ObjectUtil.isNotEmpty(tbShopUsers)) {
TbShopUser tbShopUser= tbShopUsers.get(0); TbShopUser tbShopUser = tbShopUsers.get(0);
String code= RandomUtil.randomNumbers(6); String code = DateUtils.getSsdfTimes();
tbShopUser.setCode(code); tbShopUser.setCode(code);
tbShopUser.setTelephone(phone); tbShopUser.setTelephone(phone);
tbShopUser.setBirthDay(map.get("birthDay")+""); tbShopUser.setBirthDay(String.valueOf(map.get("birthDay")));
tbShopUser.setName(map.get("nickName")+""); tbShopUser.setName(String.valueOf(map.get("nickName")));
tbShopUser.setSex(Byte.parseByte(map.get("sex")+"")); tbShopUser.setSex(Byte.parseByte(String.valueOf(map.get("sex"))));
tbShopUser.setLevel(Byte.parseByte(map.get("level")+"")); tbShopUser.setLevel(Byte.parseByte(String.valueOf(map.get("level"))));
tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setIsVip(Byte.parseByte("1"));
tbShopUser.setUpdatedAt(System.currentTimeMillis()); tbShopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser); tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
TbShopUser tbShopUser=new TbShopUser(); TbShopUser tbShopUser = new TbShopUser();
tbShopUser.setAmount(BigDecimal.ZERO); tbShopUser.setAmount(BigDecimal.ZERO);
tbShopUser.setCreditAmount(BigDecimal.ZERO); tbShopUser.setCreditAmount(BigDecimal.ZERO);
tbShopUser.setConsumeAmount(BigDecimal.ZERO); tbShopUser.setConsumeAmount(BigDecimal.ZERO);
@ -119,11 +125,11 @@ public class MemberService {
tbShopUser.setStatus(Byte.parseByte("1")); tbShopUser.setStatus(Byte.parseByte("1"));
tbShopUser.setShopId(shopId); tbShopUser.setShopId(shopId);
tbShopUser.setTelephone(phone); tbShopUser.setTelephone(phone);
tbShopUser.setBirthDay(map.get("birthDay")+""); tbShopUser.setBirthDay(String.valueOf(map.get("birthDay")));
tbShopUser.setName(map.get("nickName")+""); tbShopUser.setName(String.valueOf(map.get("nickName")));
tbShopUser.setSex(Byte.parseByte(map.get("sex")+"")); tbShopUser.setSex(Byte.parseByte(String.valueOf(map.get("sex"))));
tbShopUser.setLevel(Byte.parseByte(map.get("level")+"")); tbShopUser.setLevel(Byte.parseByte(String.valueOf(map.get("level"))));
String code= RandomUtil.randomNumbers(6); String code = RandomUtil.randomNumbers(6);
tbShopUser.setCode(code); tbShopUser.setCode(code);
tbShopUser.setIsVip(Byte.parseByte("1")); tbShopUser.setIsVip(Byte.parseByte("1"));
tbShopUser.setCreatedAt(System.currentTimeMillis()); tbShopUser.setCreatedAt(System.currentTimeMillis());
@ -132,53 +138,52 @@ public class MemberService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result memberScanPay(Map<String,Object> map){ public Result memberScanPay(Map<String, Object> map) {
if(ObjectUtil.isEmpty(map)||map.size()<=0 if (ObjectUtil.isEmpty(map) || map.size() <= 0
||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))
||!map.containsKey("memberId")||ObjectUtil.isEmpty(map.get("memberId")) || !map.containsKey("memberId") || ObjectUtil.isEmpty(map.get("memberId"))
||!map.containsKey("amount")||ObjectUtil.isEmpty(map.get("amount")) || !map.containsKey("amount") || ObjectUtil.isEmpty(map.get("amount"))
||!map.containsKey("authCode")||ObjectUtil.isEmpty(map.get("authCode")) || !map.containsKey("authCode") || ObjectUtil.isEmpty(map.get("authCode"))
){ ) {
return Result.fail(CodeEnum.PARAM); 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)); TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if(ObjectUtil.isEmpty(shopInfo)||shopInfo==null){ if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) {
return Result.fail(CodeEnum.SHOPINFONOEXIST); return Result.fail(CodeEnum.SHOPINFONOEXIST);
} }
TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); TbShopUser shopUser = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId));
if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){ if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) {
return Result.fail(CodeEnum.MEMBERNOEXIST); return Result.fail(CodeEnum.MEMBERNOEXIST);
} }
String authCode=map.get("authCode").toString(); String authCode = map.get("authCode").toString();
String qpay=null; String qpay = null;
String payTypeCode = authCode.substring(0, 1);// 判断收款码 String payTypeCode = authCode.substring(0, 1);// 判断收款码
switch (payTypeCode){ switch (payTypeCode) {
case "1": case "1":
qpay="scanCode"; qpay = "scanCode";
break; break;
case "2": case "2":
qpay="scanCode"; qpay = "scanCode";
break; break;
} }
int count= tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId,qpay); int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId, qpay);
if(count<1){ if (count < 1) {
return Result.fail(CodeEnum.PAYTYPENOEXIST); 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.setAmount(amount);
memberIn.setUserId(shopUser.getId()); memberIn.setUserId(shopUser.getId());
memberIn.setCode(shopUser.getCode()); memberIn.setCode(shopUser.getCode());
@ -187,165 +192,301 @@ public class MemberService {
memberIn.setCreateTime(new Date()); memberIn.setCreateTime(new Date());
tbMemberInMapper.insert(memberIn); 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); return Result.fail(CodeEnum.NOCUSTOMER);
} }
ScanPayReq scanPayReq=new ScanPayReq(); if ("ysk".equals(thirdPayType)) {
scanPayReq.setAppId(thirdApply.getAppId()); ScanPayReq scanPayReq = new ScanPayReq();
scanPayReq.setTimestamp(System.currentTimeMillis()); scanPayReq.setAppId(thirdApply.getAppId());
scanPayReq.setAuthCode(authCode); scanPayReq.setTimestamp(System.currentTimeMillis());
scanPayReq.setNotifyUrl("http://cas"); scanPayReq.setAuthCode(authCode);
scanPayReq.setConsumeFee(amount.toPlainString()); scanPayReq.setNotifyUrl("http://cas");
scanPayReq.setConsumeFee(amount.toPlainString());
Map<String,Object> reqMap= BeanUtil.transBean2Map(scanPayReq); Map<String, Object> reqMap = BeanUtil.transBean2Map(scanPayReq);
scanPayReq.setSign(MD5Util.encrypt(reqMap,thirdApply.getAppToken(),true)); scanPayReq.setSign(MD5Util.encrypt(reqMap, thirdApply.getAppToken(), true));
ResponseEntity<String> response= restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"),scanPayReq,String.class); ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
if(response.getStatusCodeValue()==200&&ObjectUtil.isNotEmpty(response.getBody())) { if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
JSONObject object = JSONObject.parseObject(response.getBody()); JSONObject object = JSONObject.parseObject(response.getBody());
if(object.get("code").equals("0")){ if (object.get("code").equals("0")) {
String orderNO=object.getJSONObject("data").get("orderNumber").toString(); 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.setOrderNo(orderNO);
memberIn.setStatus("0");
memberIn.setUpdateTime(new Date()); memberIn.setUpdateTime(new Date());
tbMemberInMapper.updateByPrimaryKeySelective(memberIn); 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<MainScanResp> 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("失败"); return Result.fail("失败");
} }
public Result queryScanPay(String flowId){ public Result queryScanPay(String flowId) {
if(ObjectUtil.isEmpty(flowId)){ if (ObjectUtil.isEmpty(flowId)) {
return Result.fail(CodeEnum.PARAM); 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());
TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(memberIn.getUserId()); if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) {
if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){
return Result.fail(CodeEnum.MEMBERNOEXIST); return Result.fail(CodeEnum.MEMBERNOEXIST);
} }
if(memberIn.getStatus().equals("7")){ if (memberIn.getStatus().equals("7")) {
TbMerchantThirdApply thirdApply= tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(memberIn.getMerchantId())); TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(memberIn.getMerchantId());
if(ObjectUtil.isEmpty(thirdApply)||ObjectUtil.isNull(thirdApply)){ if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
return Result.fail(CodeEnum.NOCUSTOMER); return Result.fail(CodeEnum.NOCUSTOMER);
} }
TradeQueryReq tradeQueryReq=new TradeQueryReq();
tradeQueryReq.setAppId(thirdApply.getAppId());
tradeQueryReq.setTimestamp(System.currentTimeMillis());
tradeQueryReq.setOrderNumber(memberIn.getOrderNo());
Map<String,Object> map= BeanUtil.transBean2Map(tradeQueryReq);
tradeQueryReq.setSign(MD5Util.encrypt(map,thirdApply.getAppToken(),true));
ResponseEntity<String> 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); if ("ysk".equals(thirdPayType)) {
memberIn.setStatus("0"); TradeQueryReq tradeQueryReq = new TradeQueryReq();
memberIn.setUpdateTime(new Date()); tradeQueryReq.setAppId(thirdApply.getAppId());
tbMemberInMapper.updateByPrimaryKeySelective(memberIn); tradeQueryReq.setTimestamp(System.currentTimeMillis());
tradeQueryReq.setOrderNumber(memberIn.getOrderNo());
//修改客户资金 Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
shopUser.setAmount(shopUser.getAmount().add(memberIn.getAmount())); tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
shopUser.setUpdatedAt(System.currentTimeMillis()); ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
tbShopUserMapper.updateByPrimaryKeySelective(shopUser); 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(); memberIn.setOrderNo(orderNO);
flow.setShopUserId(shopUser.getId()); memberIn.setStatus("0");
flow.setBizCode("scanMemberIn"); memberIn.setUpdateTime(new Date());
flow.setBizName("会员扫码充值"); tbMemberInMapper.updateByPrimaryKeySelective(memberIn);
flow.setAmount(memberIn.getAmount());
flow.setBalance(shopUser.getAmount()); //修改客户资金
flow.setCreateTime(new Date()); shopUser.setAmount(shopUser.getAmount().add(memberIn.getAmount()));
tbShopUserFlowMapper.insert(flow); shopUser.setUpdatedAt(System.currentTimeMillis());
return Result.success(CodeEnum.SUCCESS,memberIn); 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<OrderStatusQueryResp> 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) @Transactional(rollbackFor = Exception.class)
public Result memberAccountPay(Map<String,Object> map){ public Result memberAccountPay(Map<String, Object> map) {
if(ObjectUtil.isEmpty(map)||map.size()<=0 if (ObjectUtil.isEmpty(map) || map.size() <= 0
||!map.containsKey("shopId")||ObjectUtil.isEmpty(map.get("shopId")) || !map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))
||!map.containsKey("memberId")||ObjectUtil.isEmpty(map.get("memberId")) || !map.containsKey("memberId") || ObjectUtil.isEmpty(map.get("memberId"))
||!map.containsKey("amount")||ObjectUtil.isEmpty(map.get("amount")) || !map.containsKey("amount") || ObjectUtil.isEmpty(map.get("amount"))
){ ) {
return Result.fail(CodeEnum.PARAM); 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)); TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if(ObjectUtil.isEmpty(shopInfo)||shopInfo==null){ if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) {
return Result.fail(CodeEnum.SHOPINFONOEXIST); return Result.fail(CodeEnum.SHOPINFONOEXIST);
} }
TbShopUser shopUser= tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId)); TbShopUser shopUser = tbShopUserMapper.selectByPrimaryKey(Integer.valueOf(memberId));
if(ObjectUtil.isEmpty(shopUser)||!"1".equals(shopUser.getIsVip().toString())){ if (ObjectUtil.isEmpty(shopUser) || !"1".equals(shopUser.getIsVip().toString())) {
return Result.fail(CodeEnum.MEMBERNOEXIST); return Result.fail(CodeEnum.MEMBERNOEXIST);
} }
int count= tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId,"cash"); int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(shopId, "cash");
if(count<1){ if (count < 1) {
return Result.fail(CodeEnum.PAYTYPENOEXIST); 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.setAmount(amount);
memberIn.setUserId(shopUser.getId()); memberIn.setUserId(shopUser.getId());
memberIn.setCode(shopUser.getCode()); memberIn.setCode(shopUser.getCode());
@ -358,7 +499,7 @@ public class MemberService {
shopUser.setUpdatedAt(System.currentTimeMillis()); shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKeySelective(shopUser); tbShopUserMapper.updateByPrimaryKeySelective(shopUser);
TbShopUserFlow flow=new TbShopUserFlow(); TbShopUserFlow flow = new TbShopUserFlow();
flow.setShopUserId(shopUser.getId()); flow.setShopUserId(shopUser.getId());
flow.setBizCode("cashMemberIn"); flow.setBizCode("cashMemberIn");
flow.setBizName("会员现金充值"); flow.setBizName("会员现金充值");
@ -367,22 +508,47 @@ public class MemberService {
flow.setCreateTime(new Date()); flow.setCreateTime(new Date());
tbShopUserFlowMapper.insert(flow); 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){ public Result queryMemberAccount(String memberId, int page, int pageSize) {
if(ObjectUtil.isEmpty(memberId)){ if (ObjectUtil.isEmpty(memberId)) {
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
} }
PageHelper.startPage(page,pageSize); PageHelper.startPage(page, pageSize);
List<Map<String,Object>> list=tbShopUserFlowMapper.selectByMemberAccountFlow(memberId); List<Map<String, Object>> list = tbShopUserFlowMapper.selectByMemberAccountFlow(memberId);
PageInfo pageInfo=new PageInfo(list); PageInfo pageInfo = new PageInfo(list);
return Result.success(CodeEnum.SUCCESS,pageInfo); return Result.success(CodeEnum.SUCCESS, pageInfo);
} }
} }

View File

@ -436,12 +436,12 @@ public class PayService {
return Result.fail(CodeEnum.MEMBERNOEXIST); return Result.fail(CodeEnum.MEMBERNOEXIST);
} }
if (N.gt(orderInfo.getPayAmount(), user.getAmount())) { if (N.gt(orderInfo.getOrderAmount(), user.getAmount())) {
return Result.fail(CodeEnum.MEMBERINSUFFICIENTFUNDS); return Result.fail(CodeEnum.MEMBERINSUFFICIENTFUNDS);
} }
user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); 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.setConsumeNumber(user.getConsumeNumber() + 1);
user.setUpdatedAt(System.currentTimeMillis()); user.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKeySelective(user); tbShopUserMapper.updateByPrimaryKeySelective(user);
@ -934,6 +934,19 @@ public class PayService {
if ("TRADE_SUCCESS".equals(mainScanResp.getState())) { if ("TRADE_SUCCESS".equals(mainScanResp.getState())) {
tbQuickPay.setTradeNo(mainScanResp.getPayOrderId()); tbQuickPay.setTradeNo(mainScanResp.getPayOrderId());
tbQuickPayMapper.insert(tbQuickPay); 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); return Result.success(CodeEnum.SUCCESS, tbQuickPay);
} }

View File

@ -19,7 +19,7 @@ public class DateUtils {
private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss"); private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");
private final static SimpleDateFormat sdfTimesSs = new SimpleDateFormat("yyyyMMddHHmmss"); private final static SimpleDateFormat sdfTimesSs = new SimpleDateFormat("yyyyMMddHHmmssSSS");

View File

@ -5,8 +5,8 @@
<!-- 第二种mybatis逆向生成xml配置 --> <!-- 第二种mybatis逆向生成xml配置 -->
<generatorConfiguration> <generatorConfiguration>
<!-- 需要指明数据库连接器的绝对路径 --> <!-- 需要指明数据库连接器的绝对路径 -->
<!-- <classPathEntry location="C:\Users\admin\.m1\repository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar" />--> <!-- <classPathEntry location="C:\Users\admin\.m1\repository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar" />-->
<classPathEntry location="E:\app\maven\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar"/> <classPathEntry location="D:\.m2\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar"/>
<context id="msqlTables" targetRuntime="MyBatis3"> <context id="msqlTables" targetRuntime="MyBatis3">
<!-- 生成的pojo将implements Serializable--> <!-- 生成的pojo将implements Serializable-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
@ -19,8 +19,8 @@
<!-- 数据库链接URL、用户名、密码 --> <!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection connectionURL="jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8" <jdbcConnection connectionURL="jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8"
driverClass="com.mysql.cj.jdbc.Driver" password="mysqlroot@123" userId="root" > driverClass="com.mysql.cj.jdbc.Driver" password="Twc6MrzzjBiWSsjh" userId="fycashier" >
<property name="nullCatalogMeansCurrent" value="true"/> <property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection> </jdbcConnection>
@ -51,14 +51,10 @@
<!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>--> <!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>-->
<table tableName="tb_shop_user_duty_pay" domainObjectName="ShopUserDutyPay" <table tableName="tb_activate" domainObjectName="TbActivate"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" > enableSelectByExample="false" selectByExampleQueryId="false" >
</table> </table>
</context> </context>
</generatorConfiguration> </generatorConfiguration>

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chaozhanggui.system.cashierservice.dao.TbActivateMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbActivate">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="shop_id" jdbcType="INTEGER" property="shopId" />
<result column="min_num" jdbcType="INTEGER" property="minNum" />
<result column="max_num" jdbcType="INTEGER" property="maxNum" />
<result column="handsel_num" jdbcType="DECIMAL" property="handselNum" />
<result column="handsel_type" jdbcType="VARCHAR" property="handselType" />
<result column="is_del" jdbcType="VARCHAR" property="isDel" />
</resultMap>
<sql id="Base_Column_List">
id, shop_id, min_num, max_num, handsel_num, handsel_type, is_del
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_activate
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tb_activate
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbActivate">
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>
<insert id="insertSelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbActivate">
insert into tb_activate
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="shopId != null">
shop_id,
</if>
<if test="minNum != null">
min_num,
</if>
<if test="maxNum != null">
max_num,
</if>
<if test="handselNum != null">
handsel_num,
</if>
<if test="handselType != null">
handsel_type,
</if>
<if test="isDel != null">
is_del,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="shopId != null">
#{shopId,jdbcType=INTEGER},
</if>
<if test="minNum != null">
#{minNum,jdbcType=INTEGER},
</if>
<if test="maxNum != null">
#{maxNum,jdbcType=INTEGER},
</if>
<if test="handselNum != null">
#{handselNum,jdbcType=DECIMAL},
</if>
<if test="handselType != null">
#{handselType,jdbcType=VARCHAR},
</if>
<if test="isDel != null">
#{isDel,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.system.cashierservice.entity.TbActivate">
update tb_activate
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="minNum != null">
min_num = #{minNum,jdbcType=INTEGER},
</if>
<if test="maxNum != null">
max_num = #{maxNum,jdbcType=INTEGER},
</if>
<if test="handselNum != null">
handsel_num = #{handselNum,jdbcType=DECIMAL},
</if>
<if test="handselType != null">
handsel_type = #{handselType,jdbcType=VARCHAR},
</if>
<if test="isDel != null">
is_del = #{isDel,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.chaozhanggui.system.cashierservice.entity.TbActivate">
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}
</update>
<select id="selectByAmount" resultMap="BaseResultMap">
select * from tb_activate where shop_id=#{shopId} and is_del=0 and min_num &lt;= #{amount} and max_num &gt;= #{amount}
</select>
</mapper>

View File

@ -27,7 +27,7 @@
delete from tb_member_in delete from tb_member_in
where id = #{id,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
</delete> </delete>
<insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbMemberIn"> <insert id="insert" parameterType="com.chaozhanggui.system.cashierservice.entity.TbMemberIn" keyProperty="id" useGeneratedKeys="true">
insert into tb_member_in (id, user_id, merchant_id, insert into tb_member_in (id, user_id, merchant_id,
code, amount, status, code, amount, status,
order_no, trade_no, create_time, order_no, trade_no, create_time,