微信小程序点歌接口
This commit is contained in:
@@ -29,6 +29,7 @@ import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -141,6 +142,12 @@ public class PayService {
|
||||
@Autowired
|
||||
TbActivateMapper tbActivateMapper;
|
||||
|
||||
private final TbShopSongOrderService shopSongOrderService;
|
||||
|
||||
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) {
|
||||
this.shopSongOrderService = shopSongOrderService;
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result payOrder(String openId,String orderId,String ip) throws Exception {
|
||||
@@ -257,7 +264,8 @@ public class PayService {
|
||||
reqbody=body.toString();
|
||||
}
|
||||
|
||||
PublicResp<WxScanPayResp> publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callFSTBack,null,thirdApply.getAppToken());
|
||||
PublicResp<WxScanPayResp> publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),
|
||||
reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip,DateUtils.getsdfTimesSS(),thirdApply.getStoreId(),callFSTBack,null,thirdApply.getAppToken());
|
||||
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
||||
if("000000".equals(publicResp.getCode())){
|
||||
WxScanPayResp wxScanPayResp= publicResp.getObjData();
|
||||
@@ -822,7 +830,9 @@ public class PayService {
|
||||
}
|
||||
}else {
|
||||
String orderNo=DateUtils.getsdfTimesSS();
|
||||
PublicResp<WxScanPayResp> publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip, orderNo,thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken());
|
||||
PublicResp<WxScanPayResp> publicResp= thirdPayService
|
||||
.scanpay(thirdUrl,thirdApply.getAppId(),
|
||||
"会员充值","会员充值",new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"WECHAT",thirdApply.getSmallAppid(),openId,ip, orderNo,thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken());
|
||||
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
||||
if("000000".equals(publicResp.getCode())){
|
||||
WxScanPayResp wxScanPayResp= publicResp.getObjData();
|
||||
@@ -1211,6 +1221,30 @@ public class PayService {
|
||||
PushToClientChannelHandlerAdapter.getInstance().AppSendInfoV1(orderInfo.getShopId(),orderInfo.getOrderNo(), client);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点歌支付成功
|
||||
* @param mchOrderNo 商户订单编号
|
||||
* @param orderNo
|
||||
* @return
|
||||
*/
|
||||
public String songPaySuccess(String mchOrderNo, String orderNo) {
|
||||
TbMemberIn memberIn= tbMemberInMapper.selectByOrderNo(mchOrderNo);
|
||||
if(ObjectUtil.isEmpty(memberIn)){
|
||||
return "充值记录不存在";
|
||||
}
|
||||
|
||||
if(!"7".equals(memberIn.getStatus())){
|
||||
return "订单已处理";
|
||||
}
|
||||
memberIn.setTradeNo(orderNo);
|
||||
memberIn.setStatus("0");
|
||||
memberIn.setUpdateTime(new Date());
|
||||
tbMemberInMapper.updateByPrimaryKeySelective(memberIn);
|
||||
|
||||
shopSongOrderService.successPay(orderNo);
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
// public Result returnOrder(){
|
||||
//
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_shop_song_order】的数据库操作Service
|
||||
* @createDate 2024-07-06 17:54:20
|
||||
*/
|
||||
public interface TbShopSongOrderService {
|
||||
|
||||
void successPay(String orderNo);
|
||||
|
||||
void clearExpireOrder();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_shop_song】的数据库操作Service
|
||||
* @createDate 2024-07-06 14:43:39
|
||||
*/
|
||||
public interface TbShopSongService {
|
||||
|
||||
|
||||
/**
|
||||
* 分页获取数据
|
||||
*
|
||||
* @param shopId 用户id
|
||||
* @param page 页数
|
||||
* @param size 数量
|
||||
* @param keyWord 搜索关键字
|
||||
* @param isDesc 是否降序
|
||||
*/
|
||||
PageInfo<?> all(Integer shopId, Integer page, Integer size, String keyWord, boolean isDesc);
|
||||
|
||||
Object getRecord(Integer userId, Integer page, Integer size, Integer state, boolean isDesc);
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param songOrderDTO 订单信息
|
||||
* @param openId
|
||||
* @return 支付信息
|
||||
*/
|
||||
JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId);
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param id 订单id
|
||||
* @return 订单信息
|
||||
*/
|
||||
Map<String, Object> getDetail(Integer userId, Integer id);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopSongMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbShopSongOrderService;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopSongOrderMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_shop_song_order】的数据库操作Service实现
|
||||
* @createDate 2024-07-06 17:54:20
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TbShopSongOrderServiceImpl
|
||||
implements TbShopSongOrderService{
|
||||
private final TbShopSongMapper shopSongMapper;
|
||||
|
||||
private final TbShopSongOrderMapper shopSongOrderMapper;
|
||||
|
||||
public TbShopSongOrderServiceImpl(TbShopSongMapper shopSongMapper, TbShopSongOrderMapper shopSongOrderMapper) {
|
||||
this.shopSongMapper = shopSongMapper;
|
||||
this.shopSongOrderMapper = shopSongOrderMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void successPay(String orderNo) {
|
||||
TbShopSongOrder shopSongOrder = shopSongOrderMapper.selectByOrderNo(orderNo);
|
||||
if (shopSongOrder.getState().equals(1)) {
|
||||
log.warn("点歌支付成功,重复支付,订单编号:{}", orderNo);
|
||||
return;
|
||||
}
|
||||
shopSongOrder.setState(1);
|
||||
shopSongOrder.setRealMoney(shopSongOrder.getPayMoney());
|
||||
shopSongOrderMapper.updateByPrimaryKeySelective(shopSongOrder);
|
||||
shopSongMapper.incrNum(1, shopSongOrder.getSongId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearExpireOrder() {
|
||||
int i = shopSongOrderMapper.deleteExpireOrder();
|
||||
log.info("历史歌曲订单删除了{}条", i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbMerchantThirdApplyMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopSongOrderMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopSong;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbShopSongOrderService;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbShopSongService;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopSongMapper;
|
||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.PayUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_shop_song】的数据库操作Service实现
|
||||
* @createDate 2024-07-06 14:43:39
|
||||
*/
|
||||
@Service
|
||||
public class TbShopSongServiceImpl implements TbShopSongService{
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
private final TbShopSongOrderService shopSongOrderService;
|
||||
|
||||
private final TbShopSongOrderMapper shopSongOrderMapper;
|
||||
|
||||
private final TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper;
|
||||
|
||||
private final PayUtils payUtils;
|
||||
|
||||
private final TbShopSongMapper shopSongMapper;
|
||||
|
||||
public TbShopSongServiceImpl(RedisTemplate<String, Object> redisTemplate, @Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, TbShopSongOrderMapper shopSongOrderMapper, TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper, PayUtils payUtils, TbShopSongMapper shopSongMapper) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.shopSongOrderService = shopSongOrderService;
|
||||
this.shopSongOrderMapper = shopSongOrderMapper;
|
||||
this.tbMerchantThirdApplyMapper = tbMerchantThirdApplyMapper;
|
||||
this.payUtils = payUtils;
|
||||
this.shopSongMapper = shopSongMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<TbShopSong> all(Integer shopId, Integer page, Integer size, String keyWord, boolean isDesc) {
|
||||
PageHelper.startPage(page, size);
|
||||
List<TbShopSong> shopSongs = shopSongMapper.selectAllAndSearch(shopId, keyWord);
|
||||
return new PageInfo<>(shopSongs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRecord(Integer userId, Integer page, Integer size, Integer state, boolean isDesc) {
|
||||
PageHelper.startPage(page, size);
|
||||
List<Map<String, Object>> songOrders = shopSongOrderMapper.selectByUserId(userId, state);
|
||||
|
||||
ArrayList<Map<String, Object>> infos = new ArrayList<>();
|
||||
for (int i = 0; i < songOrders.size(); i++) {
|
||||
Map<String, Object> toMap = songOrders.get(i);
|
||||
toMap.put("preCount", i);
|
||||
infos.add(toMap);
|
||||
}
|
||||
return new PageInfo<>(infos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId) {
|
||||
TbShopSong song = shopSongMapper.selectById(songOrderDTO.getSongId());
|
||||
if (song == null) {
|
||||
throw new MsgException("歌曲不存在, 歌曲id: {}", songOrderDTO.getSongId());
|
||||
}
|
||||
String orderNo = "WX" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmssSSS")+ RandomUtil.randomInt(1000, 9999);
|
||||
TbShopSongOrder shopSongOrder = new TbShopSongOrder();
|
||||
shopSongOrder.setUserId(userId);
|
||||
shopSongOrder.setOrderNo(orderNo);
|
||||
shopSongOrder.setCreateTime(DateUtil.date());
|
||||
shopSongOrder.setSongId(song.getId());
|
||||
shopSongOrder.setClientType(0);
|
||||
shopSongOrder.setSongName(song.getName());
|
||||
shopSongOrder.setState(-1);
|
||||
shopSongOrder.setFromName(shopSongOrder.getFromName());
|
||||
shopSongOrder.setToName(shopSongOrder.getToName());
|
||||
shopSongOrder.setNote(songOrderDTO.getNote());
|
||||
shopSongOrder.setShopId(shopSongOrder.getShopId());
|
||||
shopSongOrderMapper.insert(shopSongOrder);
|
||||
|
||||
TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyMapper.selectByShopId(songOrderDTO.getShopId());
|
||||
if (tbMerchantThirdApply == null) {
|
||||
throw new MsgException("三方支付参数不存在");
|
||||
}
|
||||
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
|
||||
return payUtils.getWxPay(IpUtil.getIpAddr(attr.getRequest()), orderNo, userId, "", songOrderDTO.getShopId(), song.getPrice(),tbMerchantThirdApply.getId(),
|
||||
openId, tbMerchantThirdApply);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDetail(Integer userId, Integer id) {
|
||||
Map<String, Object> map = shopSongOrderMapper.selectByUserIdAndId(userId, id);
|
||||
if (map == null) {
|
||||
throw new MsgException("订单不存在");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user