修改点歌逻辑

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/product/productInfo",
"cashierService/notify/**",//登录部分接口不校验 "cashierService/notify/**",//登录部分接口不校验
"notify/**", "notify/**",
"cashierService/table/**" //回调部分接口不校验 "cashierService/table/**", //回调部分接口不校验
// 点歌部分不需要登录
"/cashierService/song/detail",
"/cashierService/song/record",
"/cashierService/song"
); );
@Autowired @Autowired

View File

@@ -75,6 +75,19 @@ public class LoginContoller {
return loginService.wxBusinessLogin(openid,shopId); 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; 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) { private Map getParameterMap(HttpServletRequest request) {
RequestWrapper requestWrapper = new RequestWrapper(request); RequestWrapper requestWrapper = new RequestWrapper(request);

View File

@@ -1,6 +1,5 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO; import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO;
import com.chaozhanggui.system.cashierservice.service.TbShopSongService; import com.chaozhanggui.system.cashierservice.service.TbShopSongService;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -24,6 +23,7 @@ public class ShopSongController {
/** /**
* 获取所有歌曲,支持搜索及分页 * 获取所有歌曲,支持搜索及分页
*
* @param page 页数 * @param page 页数
* @param size 数量 * @param size 数量
* @param keyWord 搜索关键字 * @param keyWord 搜索关键字
@@ -42,20 +42,22 @@ public class ShopSongController {
@GetMapping("/detail") @GetMapping("/detail")
public Result getRecord( public Result getRecord(
@RequestHeader("openId") String openId,
@RequestParam Integer id @RequestParam Integer id
) { ) {
return Result.successWithData(shopSongService.getDetail(TokenUtil.getUserId(), id)); return Result.successWithData(shopSongService.getDetail(openId, id));
} }
@GetMapping("/record") @GetMapping("/record")
public Result getRecord( public Result getRecord(
@RequestHeader("openId") String openId,
@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size, @RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) Integer state, @RequestParam(required = false) Integer state,
@RequestParam(defaultValue = "true") boolean isDesc @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, @RequestHeader("openId") String openId,
@RequestBody SongOrderDTO songOrderDTO @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" + " tb_shop_song_order AS a\n" +
" LEFT JOIN tb_shop_song AS b ON a.song_id = b.id\n" + " LEFT JOIN tb_shop_song AS b ON a.song_id = b.id\n" +
" WHERE\n" + " WHERE\n" +
" a.user_id = #{userId}\n" + " a.open_id = #{openId}\n" +
" <if test=\"state!=null\">AND a.state = #{state}</if></script>") " <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};") @Select("select * from fycashier.tb_shop_song_order where order_no=#{orderNo};")
TbShopSongOrder selectByOrderNo(@Param("orderNo") String orderNo); TbShopSongOrder selectByOrderNo(@Param("orderNo") String orderNo);

View File

@@ -29,7 +29,7 @@ public class TbShopSongOrder implements Serializable {
/** /**
* 用户id * 用户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())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getSongId() == null ? other.getSongId() == null : this.getSongId().equals(other.getSongId())) && (this.getSongId() == null ? other.getSongId() == null : this.getSongId().equals(other.getSongId()))
&& (this.getSongName() == null ? other.getSongName() == null : this.getSongName().equals(other.getSongName())) && (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.getPayMoney() == null ? other.getPayMoney() == null : this.getPayMoney().equals(other.getPayMoney()))
&& (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (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 + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getSongId() == null) ? 0 : getSongId().hashCode()); result = prime * result + ((getSongId() == null) ? 0 : getSongId().hashCode());
result = prime * result + ((getSongName() == null) ? 0 : getSongName().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 + ((getPayMoney() == null) ? 0 : getPayMoney().hashCode());
result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().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(", id=").append(id);
sb.append(", songId=").append(songId); sb.append(", songId=").append(songId);
sb.append(", songName=").append(songName); sb.append(", songName=").append(songName);
sb.append(", userId=").append(userId); sb.append(", openId=").append(openId);
sb.append(", payMoney=").append(payMoney); sb.append(", payMoney=").append(payMoney);
sb.append(", state=").append(state); sb.append(", state=").append(state);
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);

View File

@@ -72,6 +72,9 @@ public class PayService {
@Autowired @Autowired
TbShopPayTypeMapper tbShopPayTypeMapper; TbShopPayTypeMapper tbShopPayTypeMapper;
@Autowired
private TbShopSongOrderMapper tbShopSongOrderMapper;
@Value("${ysk.url}") @Value("${ysk.url}")
private String url; private String url;
@@ -117,13 +120,15 @@ public class PayService {
private String thirdUrl; private String thirdUrl;
@Value("${thirdPay.callInBack}") @Value("${thirdPay.callInBack}")
private String callInBack; private String callInBack;
@Value("${thirdPay.callFSTBack}") @Value("${thirdPay.callFSTBack}")
private String callFSTBack; private String callFSTBack;
@Value("${thirdPay.songOrderBack}")
private String songOrderBack;
@Autowired @Autowired
ThirdPayService thirdPayService; ThirdPayService thirdPayService;
@@ -131,7 +136,6 @@ public class PayService {
TbUserInfoMapper tbUserInfoMapper; TbUserInfoMapper tbUserInfoMapper;
@Resource @Resource
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper; private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
@Autowired @Autowired
@@ -181,7 +185,6 @@ public class PayService {
} }
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
@@ -300,17 +303,10 @@ public class PayService {
} }
return Result.fail("失败"); return Result.fail("失败");
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result accountPay(String orderId, String memberId, String token, String pwd) { public Result accountPay(String orderId, String memberId, String token, String pwd) {
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberId)) { if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(memberId)) {
@@ -474,8 +470,7 @@ public class PayService {
jsonObject.put("orderId", orderId); jsonObject.put("orderId", orderId);
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} } else {
else {
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(orderInfo.getShopId().toString()); TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(orderInfo.getShopId().toString());
if (tbMerchantAccount == null) { if (tbMerchantAccount == null) {
throw new MsgException("生成订单错误"); throw new MsgException("生成订单错误");
@@ -513,8 +508,7 @@ public class PayService {
payment.setOrderId(orderInfo.getOrderNo()); payment.setOrderId(orderInfo.getOrderNo());
payment.setCreatedAt(System.currentTimeMillis()); payment.setCreatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.insert(payment); tbOrderPaymentMapper.insert(payment);
} } else {
else {
if (payType.equals("wechatPay")) { if (payType.equals("wechatPay")) {
payment.setPayName("微信支付"); payment.setPayName("微信支付");
payment.setPayType("wechatPay"); payment.setPayType("wechatPay");
@@ -560,8 +554,7 @@ public class PayService {
return Result.fail("支付失败"); return Result.fail("支付失败");
} }
} }
} } else {
else {
String reqbody = ""; String reqbody = "";
if (body.length() > 15) { if (body.length() > 15) {
@@ -634,7 +627,6 @@ public class PayService {
} }
if ("ysk".equals(thirdPayType)) { if ("ysk".equals(thirdPayType)) {
TradeQueryReq req = new TradeQueryReq(); TradeQueryReq req = new TradeQueryReq();
req.setAppId(thirdApply.getAppId()); req.setAppId(thirdApply.getAppId());
@@ -681,7 +673,6 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
log.info("发送打印数据"); log.info("发送打印数据");
producer.printMechine(orderInfo.getId() + ""); producer.printMechine(orderInfo.getId() + "");
@@ -734,7 +725,6 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
log.info("发送打印数据"); log.info("发送打印数据");
producer.printMechine(orderInfo.getId() + ""); producer.printMechine(orderInfo.getId() + "");
sendOrderToClient(orderInfo); sendOrderToClient(orderInfo);
@@ -778,7 +768,6 @@ public class PayService {
} }
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("支付通道不存在"); return Result.fail("支付通道不存在");
@@ -855,7 +844,6 @@ public class PayService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String callBackPay(String payOrderNO) { public String callBackPay(String payOrderNO) {
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPayOrderNo(payOrderNO); TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPayOrderNo(payOrderNO);
@@ -897,7 +885,6 @@ public class PayService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String callBackPayFST(String payOrderNO) { public String callBackPayFST(String payOrderNO) {
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPayOrderNo(payOrderNO); TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPayOrderNo(payOrderNO);
@@ -979,7 +966,6 @@ public class PayService {
} }
public Result getShopByMember(String userId, String shopId, int page, int pageSize) { public Result getShopByMember(String userId, String shopId, int page, int pageSize) {
PageHelper.startPage(page, pageSize); PageHelper.startPage(page, pageSize);
List<ShopUserListVo> list = tbShopUserMapper.selectByUserId(userId, shopId); List<ShopUserListVo> list = tbShopUserMapper.selectByUserId(userId, shopId);
@@ -1005,7 +991,6 @@ public class PayService {
} }
/** /**
* 生成长度为12的随机串 * 生成长度为12的随机串
* *
@@ -1111,7 +1096,6 @@ public class PayService {
} }
public String fstMemberInSuccess(String payOrderNO, String tradeNo) { public String fstMemberInSuccess(String payOrderNO, String tradeNo) {
TbMemberIn memberIn = tbMemberInMapper.selectByOrderNo(payOrderNO); TbMemberIn memberIn = tbMemberInMapper.selectByOrderNo(payOrderNO);
if (ObjectUtil.isEmpty(memberIn)) { if (ObjectUtil.isEmpty(memberIn)) {
@@ -1223,6 +1207,7 @@ public class PayService {
/** /**
* 点歌支付成功 * 点歌支付成功
*
* @param mchOrderNo 商户订单编号 * @param mchOrderNo 商户订单编号
* @param orderNo * @param orderNo
* @return * @return
@@ -1245,6 +1230,75 @@ public class PayService {
return "success"; return "success";
} }
public Result paySongOrder(String openId, String shopId, Integer orderId, String ip, TbMerchantThirdApply thirdApply) throws JsonProcessingException {
if (ObjectUtil.isEmpty(openId) || Objects.isNull(openId)) {
return Result.fail("付款用户[openId]参数不能为空");
}
TbShopSongOrder songOrder = tbShopSongOrderMapper.selectByPrimaryKey(Long.valueOf(orderId));
if (songOrder.getState() != 0 && songOrder.getState() != -1) {
return Result.fail("订单状态异常,不允许支付");
}
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(songOrder.getOrderNo());
if (ObjectUtil.isEmpty(payment) || payment == null) {
payment = new TbOrderPayment();
payment.setPayTypeId("ysk");
payment.setAmount(songOrder.getPayMoney());
payment.setPaidAmount(songOrder.getPayMoney());
payment.setHasRefundAmount(BigDecimal.ZERO);
payment.setPayName("微信支付");
payment.setPayType("wechatPay");
payment.setReceived(payment.getAmount());
payment.setChangeFee(BigDecimal.ZERO);
payment.setShopId(shopId);
payment.setOrderId(songOrder.getOrderNo());
payment.setCreatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.insert(payment);
} else {
payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKey(payment);
}
String reqbody = "点歌:" + songOrder.getSongName();
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, songOrder.getOrderNo(), thirdApply.getStoreId(),
songOrderBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
WxScanPayResp wxScanPayResp = publicResp.getObjData();
if ("TRADE_AWAIT".equals(wxScanPayResp.getState())) {
payment.setTradeNumber(wxScanPayResp.getPayOrderId());
payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.SUCCESS, mapper.readTree(wxScanPayResp.getPayInfo()));
} else {
return Result.fail(publicResp.getMsg());
}
}
}
return Result.fail("失败");
}
@Transactional(rollbackFor = Exception.class)
public String songOrderSuccess(String mchOrderNo, String orderNo) {
TbShopSongOrder songOrder = tbShopSongOrderMapper.selectByOrderNo(mchOrderNo);
if (ObjectUtil.isEmpty(songOrder)) {
return "订单信息不存在";
}
log.info("更新点歌订单:{}", songOrder);
shopSongOrderService.successPay(mchOrderNo);
return "SUCCESS";
}
// public Result returnOrder(){ // public Result returnOrder(){
// //
@@ -1295,7 +1349,4 @@ public class PayService {
// } // }
} }

View File

@@ -25,24 +25,23 @@ public interface TbShopSongService {
*/ */
PageInfo<?> all(Integer shopId, Integer page, Integer size, String keyWord, boolean 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); Object getRecord(String openId, Integer page, Integer size, Integer state, boolean isDesc);
/** /**
* 创建订单 * 创建订单
* *
* @param userId 用户id
* @param songOrderDTO 订单信息 * @param songOrderDTO 订单信息
* @param openId * @param openId
* @return 支付信息 * @return 支付信息
*/ */
JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId); JsonNode createOrder(SongOrderDTO songOrderDTO, String openId);
/** /**
* 订单详情 * 订单详情
* *
* @param userId 用户id * @param openId 用户id
* @param id 订单id * @param id 订单id
* @return 订单信息 * @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.TbShopSongOrder;
import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO; import com.chaozhanggui.system.cashierservice.entity.dto.SongOrderDTO;
import com.chaozhanggui.system.cashierservice.exception.MsgException; 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.TbShopSongOrderService;
import com.chaozhanggui.system.cashierservice.service.TbShopSongService; import com.chaozhanggui.system.cashierservice.service.TbShopSongService;
import com.chaozhanggui.system.cashierservice.dao.TbShopSongMapper; 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.IpUtil;
import com.chaozhanggui.system.cashierservice.util.PayUtils; import com.chaozhanggui.system.cashierservice.util.PayUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@@ -47,14 +50,16 @@ public class TbShopSongServiceImpl implements TbShopSongService{
private final PayUtils payUtils; private final PayUtils payUtils;
private final TbShopSongMapper shopSongMapper; 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.redisTemplate = redisTemplate;
this.shopSongOrderService = shopSongOrderService; this.shopSongOrderService = shopSongOrderService;
this.shopSongOrderMapper = shopSongOrderMapper; this.shopSongOrderMapper = shopSongOrderMapper;
this.tbMerchantThirdApplyMapper = tbMerchantThirdApplyMapper; this.tbMerchantThirdApplyMapper = tbMerchantThirdApplyMapper;
this.payUtils = payUtils; this.payUtils = payUtils;
this.shopSongMapper = shopSongMapper; this.shopSongMapper = shopSongMapper;
this.payService = payService;
} }
@Override @Override
@@ -65,9 +70,9 @@ public class TbShopSongServiceImpl implements TbShopSongService{
} }
@Override @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); 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<>(); ArrayList<Map<String, Object>> infos = new ArrayList<>();
for (int i = 0; i < songOrders.size(); i++) { for (int i = 0; i < songOrders.size(); i++) {
@@ -80,14 +85,14 @@ public class TbShopSongServiceImpl implements TbShopSongService{
@Override @Override
@Transactional @Transactional
public JsonNode createOrder(Integer userId, SongOrderDTO songOrderDTO, String openId) { public JsonNode createOrder(SongOrderDTO songOrderDTO, String openId) {
TbShopSong song = shopSongMapper.selectById(songOrderDTO.getSongId()); TbShopSong song = shopSongMapper.selectById(songOrderDTO.getSongId());
if (song == null) { if (song == null) {
throw new MsgException("歌曲不存在, 歌曲id: {}", songOrderDTO.getSongId()); 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(); TbShopSongOrder shopSongOrder = new TbShopSongOrder();
shopSongOrder.setUserId(userId); shopSongOrder.setOpenId(openId);
shopSongOrder.setOrderNo(orderNo); shopSongOrder.setOrderNo(orderNo);
shopSongOrder.setCreateTime(DateUtil.date()); shopSongOrder.setCreateTime(DateUtil.date());
shopSongOrder.setSongId(song.getId()); shopSongOrder.setSongId(song.getId());
@@ -97,7 +102,8 @@ public class TbShopSongServiceImpl implements TbShopSongService{
shopSongOrder.setFromName(shopSongOrder.getFromName()); shopSongOrder.setFromName(shopSongOrder.getFromName());
shopSongOrder.setToName(shopSongOrder.getToName()); shopSongOrder.setToName(shopSongOrder.getToName());
shopSongOrder.setNote(songOrderDTO.getNote()); shopSongOrder.setNote(songOrderDTO.getNote());
shopSongOrder.setShopId(shopSongOrder.getShopId()); shopSongOrder.setShopId(songOrderDTO.getShopId());
shopSongOrder.setPayMoney(song.getPrice());
shopSongOrderMapper.insert(shopSongOrder); shopSongOrderMapper.insert(shopSongOrder);
TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyMapper.selectByShopId(songOrderDTO.getShopId()); TbMerchantThirdApply tbMerchantThirdApply = tbMerchantThirdApplyMapper.selectByShopId(songOrderDTO.getShopId());
@@ -105,13 +111,18 @@ public class TbShopSongServiceImpl implements TbShopSongService{
throw new MsgException("三方支付参数不存在"); throw new MsgException("三方支付参数不存在");
} }
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); 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 @Override
public Map<String, Object> getDetail(Integer userId, Integer id) { public Map<String, Object> getDetail(String openId, Integer id) {
Map<String, Object> map = shopSongOrderMapper.selectByUserIdAndId(userId, id); Map<String, Object> map = shopSongOrderMapper.selectByUserIdAndId(openId, id);
if (map == null) { if (map == null) {
throw new MsgException("订单不存在"); throw new MsgException("订单不存在");
} }

View File

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

View File

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

View File

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

View File

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

View File

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