修改点歌逻辑

This commit is contained in:
GYJ 2024-07-10 18:45:23 +08:00
parent 89af38dc15
commit 4b2996adb3
14 changed files with 402 additions and 298 deletions

View File

@ -55,7 +55,12 @@ public class LoginFilter implements Filter {
"cashierService/product/productInfo",
"cashierService/notify/**",//登录部分接口不校验
"notify/**",
"cashierService/table/**" //回调部分接口不校验
"cashierService/table/**", //回调部分接口不校验
// 点歌部分不需要登录
"/cashierService/song/detail",
"/cashierService/song/record",
"/cashierService/song"
);
@Autowired
@ -182,4 +187,4 @@ public class LoginFilter implements Filter {
}
return false;
}
}
}

View File

@ -75,6 +75,19 @@ public class LoginContoller {
return loginService.wxBusinessLogin(openid,shopId);
}
@GetMapping("/wx/business/openId")
public Result getOpenId(
@RequestParam String code
) {
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, customAppId, customSecrete);
String openid = SessionKeyOpenId.getString("openid");
if(Objects.isNull(openid)){
return Result.fail("获取微信id失败");
}
return Result.successWithData(openid);
}
/**
* 小程序登录
*

View File

@ -147,6 +147,25 @@ public class NotifyController {
return null;
}
/**
* 点歌支付回调
* @param request
* @return
*/
@RequestMapping("songOrderCallBack")
public String songOrderCallBack(HttpServletRequest request) {
Map<String, Object> map = getParameterMap(request);
log.info("点歌支付回调返回信息:{}", JSONUtil.toJsonStr(map));
if (ObjectUtil.isNotEmpty(map) && map.containsKey("code") && "000000".equals(map.get("code") + "")) {
JSONObject object = JSONUtil.parseObj(map.get("bizData"));
if (ObjectUtil.isNotEmpty(object) && object.containsKey("state") && "TRADE_SUCCESS".equals(object.getStr("state"))) {
String orderNo = object.getStr("mchOrderNo");
return payService.songOrderSuccess(orderNo, DateUtils.getTime(new Date()));
}
}
return null;
}
private Map getParameterMap(HttpServletRequest request) {
RequestWrapper requestWrapper = new RequestWrapper(request);

View File

@ -1,6 +1,5 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO;
import com.chaozhanggui.system.cashierservice.service.TbShopSongService;
import com.chaozhanggui.system.cashierservice.sign.Result;
@ -24,8 +23,9 @@ public class ShopSongController {
/**
* 获取所有歌曲支持搜索及分页
* @param page 页数
* @param size 数量
*
* @param page 页数
* @param size 数量
* @param keyWord 搜索关键字
* @return data
*/
@ -42,20 +42,22 @@ public class ShopSongController {
@GetMapping("/detail")
public Result getRecord(
@RequestHeader("openId") String openId,
@RequestParam Integer id
) {
return Result.successWithData(shopSongService.getDetail(TokenUtil.getUserId(), id));
return Result.successWithData(shopSongService.getDetail(openId, id));
}
@GetMapping("/record")
public Result getRecord(
@RequestHeader("openId") String openId,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) Integer state,
@RequestParam(defaultValue = "true") boolean isDesc
) {
return Result.successWithData(shopSongService.getRecord(TokenUtil.getUserId(), page, size, state, isDesc));
return Result.successWithData(shopSongService.getRecord(openId, page, size, state, isDesc));
}
@ -64,6 +66,6 @@ public class ShopSongController {
@RequestHeader("openId") String openId,
@RequestBody SongOrderDTO songOrderDTO
) {
return Result.successWithData(shopSongService.createOrder(TokenUtil.getUserId(), songOrderDTO, openId));
return Result.successWithData(shopSongService.createOrder(songOrderDTO, openId));
}
}

View File

@ -34,11 +34,11 @@ public interface TbShopSongOrderMapper {
" tb_shop_song_order AS a\n" +
" LEFT JOIN tb_shop_song AS b ON a.song_id = b.id\n" +
" WHERE\n" +
" a.user_id = #{userId}\n" +
" a.open_id = #{openId}\n" +
" <if test=\"state!=null\">AND a.state = #{state}</if></script>")
List<Map<String, Object>> selectByUserId(@Param("userId") Integer userId, @Param("state") Integer state);
List<Map<String, Object>> selectByUserId(@Param("openId") String openId, @Param("state") Integer state);
Map<String, Object> selectByUserIdAndId(@Param("userId") Integer userId, @Param("id") Integer id);
Map<String, Object> selectByUserIdAndId(@Param("openId") String openId, @Param("id") Integer id);
@Select("select * from fycashier.tb_shop_song_order where order_no=#{orderNo};")
TbShopSongOrder selectByOrderNo(@Param("orderNo") String orderNo);

View File

@ -6,13 +6,13 @@ import java.util.Date;
import lombok.Data;
/**
*
*
* @TableName tb_shop_song_order
*/
@Data
public class TbShopSongOrder implements Serializable {
/**
*
*
*/
private Integer id;
@ -29,7 +29,7 @@ public class TbShopSongOrder implements Serializable {
/**
* 用户id
*/
private Integer userId;
private String openId;
/**
* 支付金额
@ -98,7 +98,7 @@ public class TbShopSongOrder implements Serializable {
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getSongId() == null ? other.getSongId() == null : this.getSongId().equals(other.getSongId()))
&& (this.getSongName() == null ? other.getSongName() == null : this.getSongName().equals(other.getSongName()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
&& (this.getPayMoney() == null ? other.getPayMoney() == null : this.getPayMoney().equals(other.getPayMoney()))
&& (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
@ -118,7 +118,7 @@ public class TbShopSongOrder implements Serializable {
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getSongId() == null) ? 0 : getSongId().hashCode());
result = prime * result + ((getSongName() == null) ? 0 : getSongName().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
result = prime * result + ((getPayMoney() == null) ? 0 : getPayMoney().hashCode());
result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
@ -141,7 +141,7 @@ public class TbShopSongOrder implements Serializable {
sb.append(", id=").append(id);
sb.append(", songId=").append(songId);
sb.append(", songName=").append(songName);
sb.append(", userId=").append(userId);
sb.append(", openId=").append(openId);
sb.append(", payMoney=").append(payMoney);
sb.append(", state=").append(state);
sb.append(", createTime=").append(createTime);
@ -156,4 +156,4 @@ public class TbShopSongOrder implements Serializable {
sb.append("]");
return sb.toString();
}
}
}

View File

@ -25,24 +25,23 @@ public interface TbShopSongService {
*/
PageInfo<?> all(Integer shopId, Integer page, Integer size, String keyWord, boolean isDesc);
Object getRecord(Integer userId, Integer page, Integer size, Integer state, boolean isDesc);
Object getRecord(String openId, Integer page, Integer size, Integer state, boolean isDesc);
/**
* 创建订单
*
* @param userId 用户id
* @param songOrderDTO 订单信息
* @param openId
* @return 支付信息
*/
JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId);
JsonNode createOrder(SongOrderDTO songOrderDTO, String openId);
/**
* 订单详情
*
* @param userId 用户id
* @param openId 用户id
* @param id 订单id
* @return 订单信息
*/
Map<String, Object> getDetail(Integer userId, Integer id);
Map<String, Object> getDetail(String openId, Integer id);
}

View File

@ -9,11 +9,14 @@ 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.PayService;
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.sign.Result;
import com.chaozhanggui.system.cashierservice.util.IpUtil;
import com.chaozhanggui.system.cashierservice.util.PayUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -47,14 +50,16 @@ public class TbShopSongServiceImpl implements TbShopSongService{
private final PayUtils payUtils;
private final TbShopSongMapper shopSongMapper;
private final PayService payService;
public TbShopSongServiceImpl(RedisTemplate<String, Object> redisTemplate, @Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, TbShopSongOrderMapper shopSongOrderMapper, TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper, PayUtils payUtils, TbShopSongMapper shopSongMapper) {
public TbShopSongServiceImpl(RedisTemplate<String, Object> redisTemplate, @Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, TbShopSongOrderMapper shopSongOrderMapper, TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper, PayUtils payUtils, TbShopSongMapper shopSongMapper, PayService payService) {
this.redisTemplate = redisTemplate;
this.shopSongOrderService = shopSongOrderService;
this.shopSongOrderMapper = shopSongOrderMapper;
this.tbMerchantThirdApplyMapper = tbMerchantThirdApplyMapper;
this.payUtils = payUtils;
this.shopSongMapper = shopSongMapper;
this.payService = payService;
}
@Override
@ -65,9 +70,9 @@ public class TbShopSongServiceImpl implements TbShopSongService{
}
@Override
public Object getRecord(Integer userId, Integer page, Integer size, Integer state, boolean isDesc) {
public Object getRecord(String openId, Integer page, Integer size, Integer state, boolean isDesc) {
PageHelper.startPage(page, size);
List<Map<String, Object>> songOrders = shopSongOrderMapper.selectByUserId(userId, state);
List<Map<String, Object>> songOrders = shopSongOrderMapper.selectByUserId(openId, state);
ArrayList<Map<String, Object>> infos = new ArrayList<>();
for (int i = 0; i < songOrders.size(); i++) {
@ -80,14 +85,14 @@ public class TbShopSongServiceImpl implements TbShopSongService{
@Override
@Transactional
public JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId) {
public JsonNode createOrder(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);
String orderNo = "SONG" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmssSSS")+ RandomUtil.randomInt(1000, 9999);
TbShopSongOrder shopSongOrder = new TbShopSongOrder();
shopSongOrder.setUserId(userId);
shopSongOrder.setOpenId(openId);
shopSongOrder.setOrderNo(orderNo);
shopSongOrder.setCreateTime(DateUtil.date());
shopSongOrder.setSongId(song.getId());
@ -97,7 +102,8 @@ public class TbShopSongServiceImpl implements TbShopSongService{
shopSongOrder.setFromName(shopSongOrder.getFromName());
shopSongOrder.setToName(shopSongOrder.getToName());
shopSongOrder.setNote(songOrderDTO.getNote());
shopSongOrder.setShopId(shopSongOrder.getShopId());
shopSongOrder.setShopId(songOrderDTO.getShopId());
shopSongOrder.setPayMoney(song.getPrice());
shopSongOrderMapper.insert(shopSongOrder);
TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyMapper.selectByShopId(songOrderDTO.getShopId());
@ -105,13 +111,18 @@ public class TbShopSongServiceImpl implements TbShopSongService{
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);
try {
Result result = payService.paySongOrder(openId, String.valueOf(shopSongOrder.getShopId()), shopSongOrder.getId(), IpUtil.getIpAddr(attr.getRequest()), tbMerchantThirdApply);
return (JsonNode) result.getData();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
@Override
public Map<String, Object> getDetail(Integer userId, Integer id) {
Map<String, Object> map = shopSongOrderMapper.selectByUserIdAndId(userId, id);
public Map<String, Object> getDetail(String openId, Integer id) {
Map<String, Object> map = shopSongOrderMapper.selectByUserIdAndId(openId, id);
if (map == null) {
throw new MsgException("订单不存在");
}

View File

@ -55,6 +55,7 @@ ysk:
thirdPay:
callInBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/fstmemberInCallBack
callFSTBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyfstCallBack
songOrderBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/songOrderCallBack
server:
port: 9888
prod: dev1

View File

@ -53,6 +53,7 @@ ysk:
thirdPay:
callInBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/fstmemberInCallBack
callFSTBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/notifyfstCallBack
songOrderBack: https://wxcashiertest.sxczgkj.cn/cashierService/notify/songOrderCallBack
server:
port: 9889
prod: devyhq

View File

@ -54,6 +54,7 @@ ysk:
thirdPay:
callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack
callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack
songOrderBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/songOrderCallBack
prod: prod1
queue: cart_queue_putprod1
subscribe:

View File

@ -54,6 +54,7 @@ ysk:
thirdPay:
callInBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/fstmemberInCallBack
callFSTBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/notifyfstCallBack
songOrderBack: https://cashier.sxczgkj.cn${server.servlet.context-path}notify/songOrderCallBack
prod: prod2
queue: cart_queue_putprod2

View File

@ -8,7 +8,7 @@
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="songId" column="song_id" jdbcType="INTEGER"/>
<result property="songName" column="song_name" jdbcType="VARCHAR"/>
<result property="userId" column="user_id" jdbcType="INTEGER"/>
<result property="openId" column="open_id" jdbcType="INTEGER"/>
<result property="payMoney" column="pay_money" jdbcType="DECIMAL"/>
<result property="state" column="state" jdbcType="TINYINT"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
@ -23,7 +23,7 @@
<sql id="Base_Column_List">
id,song_id,song_name,
user_id,pay_money,state,
open_id,pay_money,state,
create_time,client_type,order_no,
from_name,to_name,note,
shop_id,real_money
@ -43,12 +43,12 @@
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder" useGeneratedKeys="true">
insert into tb_shop_song_order
( id,song_id,song_name
,user_id,pay_money,state
,open_id,pay_money,state
,create_time,client_type,order_no
,from_name,to_name,note
,shop_id,real_money)
values (#{id,jdbcType=INTEGER},#{songId,jdbcType=INTEGER},#{songName,jdbcType=VARCHAR}
,#{userId,jdbcType=INTEGER},#{payMoney,jdbcType=DECIMAL},#{state,jdbcType=TINYINT}
,#{openId,jdbcType=INTEGER},#{payMoney,jdbcType=DECIMAL},#{state,jdbcType=TINYINT}
,#{createTime,jdbcType=TIMESTAMP},#{clientType,jdbcType=TINYINT},#{orderNo,jdbcType=VARCHAR}
,#{fromName,jdbcType=VARCHAR},#{toName,jdbcType=VARCHAR},#{note,jdbcType=VARCHAR}
,#{shopId,jdbcType=INTEGER},#{realMoney,jdbcType=DECIMAL})
@ -59,7 +59,7 @@
<if test="id != null">id,</if>
<if test="songId != null">song_id,</if>
<if test="songName != null">song_name,</if>
<if test="userId != null">user_id,</if>
<if test="openId != null">open_id,</if>
<if test="payMoney != null">pay_money,</if>
<if test="state != null">state,</if>
<if test="createTime != null">create_time,</if>
@ -75,7 +75,7 @@
<if test="id != null">#{id,jdbcType=INTEGER},</if>
<if test="songId != null">#{songId,jdbcType=INTEGER},</if>
<if test="songName != null">#{songName,jdbcType=VARCHAR},</if>
<if test="userId != null">#{userId,jdbcType=INTEGER},</if>
<if test="openId != null">#{openId,jdbcType=INTEGER},</if>
<if test="payMoney != null">#{payMoney,jdbcType=DECIMAL},</if>
<if test="state != null">#{state,jdbcType=TINYINT},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
@ -97,8 +97,8 @@
<if test="songName != null">
song_name = #{songName,jdbcType=VARCHAR},
</if>
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
<if test="openId != null">
open_id = #{openId,jdbcType=INTEGER},
</if>
<if test="payMoney != null">
pay_money = #{payMoney,jdbcType=DECIMAL},
@ -138,7 +138,7 @@
set
song_id = #{songId,jdbcType=INTEGER},
song_name = #{songName,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=INTEGER},
open_id = #{openId,jdbcType=INTEGER},
pay_money = #{payMoney,jdbcType=DECIMAL},
state = #{state,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
@ -159,7 +159,7 @@
tb_shop_song_order AS a
LEFT JOIN tb_shop_song AS b ON a.song_id = b.id
WHERE
a.user_id = #{userId}
a.open_id = #{openId}
AND a.id=#{id}
</select>
</mapper>