添加会员支付
This commit is contained in:
@@ -122,6 +122,7 @@ public class LoginService {
|
||||
tbShopUser.setShopId(tbShopInfo.getId().toString());
|
||||
tbShopUser.setUserId(userInfo.getId().toString());
|
||||
tbShopUser.setMiniOpenId(openId);
|
||||
tbShopUser.setIsPwd("1");
|
||||
tbShopUser.setCreatedAt(System.currentTimeMillis());
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.insert(tbShopUser);
|
||||
@@ -250,12 +251,11 @@ public class LoginService {
|
||||
return Result.fail("登录失败");
|
||||
}
|
||||
|
||||
public Result createCardNo(String id, String openId) {
|
||||
public Result createCardNo(String id, String openId,String shopId) {
|
||||
if (ObjectUtil.isEmpty(id) || ObjectUtil.isEmpty(openId)) {
|
||||
return Result.fail("head 信息不允许为空");
|
||||
}
|
||||
|
||||
|
||||
TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (userInfo == null || ObjectUtil.isEmpty(userInfo)) {
|
||||
userInfo = tbUserInfoMapper.selectByOpenId(openId);
|
||||
@@ -265,12 +265,22 @@ public class LoginService {
|
||||
return Result.fail("用户信息不存在");
|
||||
}
|
||||
|
||||
String cardNo = RandomUtil.randomNumbers(10);
|
||||
userInfo.setCardNo(cardNo);
|
||||
userInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, cardNo);
|
||||
TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||
if(ObjectUtil.isEmpty(tbShopUser)||tbShopUser==null){
|
||||
return Result.fail("用户信息错误");
|
||||
}
|
||||
|
||||
String dynamicCode = RandomUtil.randomNumbers(8);
|
||||
dynamicCode= StringUtils.rightPad(tbShopUser.getId(),6,"0").concat(dynamicCode);
|
||||
|
||||
tbShopUser.setDynamicCode(dynamicCode);
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
|
||||
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, dynamicCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import com.chaozhanggui.system.cashierservice.util.BeanUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.MD5Util;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -54,6 +55,11 @@ public class PayService {
|
||||
TbOrderDetailMapper tbOrderDetailMapper;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopPayTypeMapper tbShopPayTypeMapper;
|
||||
|
||||
|
||||
@Value("${ysk.url}")
|
||||
private String url;
|
||||
|
||||
@@ -182,6 +188,100 @@ public class PayService {
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result accountPay(String orderId, String userId, String shopId,String pwd) {
|
||||
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(pwd)) {
|
||||
return Result.fail("参数错误");
|
||||
}
|
||||
|
||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||
return Result.fail("订单信息不存在");
|
||||
}
|
||||
|
||||
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
return Result.fail("订单状态异常");
|
||||
}
|
||||
|
||||
|
||||
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "deposit");
|
||||
if (count < 1) {
|
||||
return Result.fail("当前店铺未开通储值卡支付");
|
||||
}
|
||||
|
||||
TbShopUser user = tbShopUserMapper.selectByUserIdAndShopId(userId,shopId);
|
||||
|
||||
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
||||
return Result.fail("此用户非会员用户");
|
||||
}
|
||||
|
||||
|
||||
if("1".equals(user.getIsPwd())){
|
||||
return Result.fail("会员支付密码为初始化密码");
|
||||
}
|
||||
|
||||
if(!MD5Util.encrypt(pwd).equals(user.getPwd())){
|
||||
return Result.fail("会员支付密码错误");
|
||||
}
|
||||
|
||||
if (N.gt(orderInfo.getPayAmount(), user.getAmount())) {
|
||||
return Result.fail("会员卡余额不足");
|
||||
}
|
||||
|
||||
user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount()));
|
||||
user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount()));
|
||||
user.setConsumeNumber(user.getConsumeNumber() + 1);
|
||||
user.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(user);
|
||||
|
||||
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(Integer.valueOf(user.getId()));
|
||||
flow.setBizCode("accountPay");
|
||||
flow.setBizName("会员储值卡支付");
|
||||
flow.setAmount(orderInfo.getOrderAmount());
|
||||
flow.setBalance(user.getAmount());
|
||||
flow.setCreateTime(new Date());
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfo.setMemberId(userId);
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
int cartCount= tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final");
|
||||
|
||||
log.info("更新购物车:{}",cartCount);
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId),"closed");
|
||||
|
||||
//修改主单状态
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setPayOrderNo(user.getDynamicCode());
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("token",0);
|
||||
jsonObject.put("type","wxcreate");
|
||||
jsonObject.put("orderId",orderInfo.getId().toString());
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result modifyOrderStatus(Integer orderId) throws IOException {
|
||||
TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
@@ -289,10 +389,6 @@ public class PayService {
|
||||
return Result.fail("对应的用户信息不存在");
|
||||
}
|
||||
|
||||
if(ObjectUtil.isEmpty(tbShopUser.getIsVip())||!"1".equals(tbShopUser.getIsVip().toString())){
|
||||
return Result.fail("非会员用户不允许充值");
|
||||
}
|
||||
|
||||
|
||||
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
if(ObjectUtil.isEmpty(shopInfo)){
|
||||
@@ -311,7 +407,7 @@ public class PayService {
|
||||
TbMemberIn memberIn=new TbMemberIn();
|
||||
memberIn.setAmount(payAmount);
|
||||
memberIn.setUserId(Integer.valueOf(tbShopUser.getUserId()));
|
||||
memberIn.setCode(tbShopUser.getCode());
|
||||
memberIn.setCode(tbShopUser.getDynamicCode());
|
||||
memberIn.setShopId(shopInfo.getId());
|
||||
memberIn.setStatus("7");
|
||||
memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
|
||||
@@ -414,6 +510,7 @@ public class PayService {
|
||||
}
|
||||
|
||||
//修改客户资金
|
||||
tbShopUser.setIsVip(Byte.parseByte("1"));
|
||||
tbShopUser.setAmount(tbShopUser.getAmount().add(memberIn.getAmount()));
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
|
||||
Reference in New Issue
Block a user