diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CashierCartController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CashierCartController.java deleted file mode 100644 index b59eb50..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CashierCartController.java +++ /dev/null @@ -1,64 +0,0 @@ -//package com.chaozhanggui.system.cashierservice.controller; -// -//import com.chaozhanggui.system.cashierservice.entity.TbCashierCart; -//import com.chaozhanggui.system.cashierservice.entity.dto.ProductCartDto; -//import com.chaozhanggui.system.cashierservice.service.CashierCartService; -//import com.chaozhanggui.system.cashierservice.sign.Result; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.web.bind.annotation.*; -// -//import javax.annotation.Resource; -//import java.util.List; -// -///** -// * @author lyf -// */ -//@CrossOrigin(origins = "*") -//@RestController -//@Slf4j -//@RequestMapping("/cart") -//public class CashierCartController { -// -// @Resource -// private CashierCartService cashierCartService; -// /** -// * 添加购物车 -// * @param productCartDto -// * @return -// */ -// @PostMapping("/add") -// public Result batchAdd(@RequestBody ProductCartDto productCartDto) { -// return cashierCartService.batchAdd(productCartDto); -// } -// -// /** -// * 购物车 -// * @param tableId -// * @return -// */ -// @GetMapping("/cartList") -// public Result cartList(@RequestParam Integer tableId){ -// return cashierCartService.cartList(tableId); -// } -// -// /** -// *更改数量 -// * @param -// * @return -// */ -// @GetMapping("/updateNumber") -// public Result updateNumber(@RequestParam Integer id ,@RequestParam String type){ -// return cashierCartService.updateNumber(id,type); -// } -// -// -// /** -// *清空购物车 -// * @param -// * @return -// */ -// @GetMapping("/clear") -// public Result clearCart(@RequestParam Integer tableId){ -// return cashierCartService.clearCart(tableId); -// } -//} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java index 4b33f13..5a39db3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/NotifyController.java @@ -4,6 +4,7 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.chaozhanggui.system.cashierservice.entity.Enum.PayTypeConstant; import com.chaozhanggui.system.cashierservice.interceptor.RequestWrapper; import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.util.DateUtils; @@ -24,7 +25,6 @@ public class NotifyController { - @Autowired PayService payService; @@ -55,9 +55,15 @@ public class NotifyController { JSONObject object=JSONUtil.parseObj(map.get("bizData").toString()); if(ObjectUtil.isNotEmpty(object)&&object.containsKey("state")){ if("TRADE_SUCCESS".equals(object.get("state").toString())){ + JSONObject extParam = object.getJSONObject("extParam"); String orderNo=object.get("mchOrderNo").toString(); - String tradeNo=object.get("payOrderId").toString(); - return payService.fstMemberInSuccess(orderNo,tradeNo); + if (ObjectUtil.isNotEmpty(extParam)&&ObjectUtil.isNotNull(extParam)&&PayTypeConstant.MINI_PAY.equals(extParam.getStr("payType"))) { + log.info("接收到微信点歌支付成功回调,订单编号:{}", orderNo); + return payService.songPaySuccess(orderNo, extParam.getStr("orderNo")); + }else { + String tradeNo=object.get("payOrderId").toString(); + return payService.fstMemberInSuccess(orderNo,tradeNo); + } } } } @@ -78,7 +84,11 @@ public class NotifyController { log.info("回调返回信息:{}",JSONUtil.toJsonStr(map)); if(ObjectUtil.isNotEmpty(map)&&map.containsKey("code")&&"200".equals(map.get("code")+"")){ JSONObject object=JSONUtil.parseObj(map.get("data")); - if(ObjectUtil.isNotEmpty(object)&&object.containsKey("status")&&"1".equals(object.getStr("status"))){ + if(ObjectUtil.isNotEmpty(object) + && object.containsKey("status") + && "1".equals(object.getStr("status")) + && !"0100".equals(object.getStr("payType")) + ){ String orderNo=object.getStr("orderNumber"); return payService.callBackPay(orderNo); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopSongController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopSongController.java new file mode 100644 index 0000000..528e042 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ShopSongController.java @@ -0,0 +1,69 @@ +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; +import com.chaozhanggui.system.cashierservice.util.TokenUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.*; + +@CrossOrigin(origins = "*") +@Slf4j +@RequestMapping("/song") +@RestController +public class ShopSongController { + + + private final TbShopSongService shopSongService; + + public ShopSongController(@Qualifier("tbShopSongServiceImpl") TbShopSongService shopSongService) { + this.shopSongService = shopSongService; + } + + /** + * 获取所有歌曲,支持搜索及分页 + * @param page 页数 + * @param size 数量 + * @param keyWord 搜索关键字 + * @return data + */ + @GetMapping + public Result all( + @RequestParam(defaultValue = "1") Integer page, + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(required = false) String keyWord, + @RequestParam Integer shopId, + @RequestParam(defaultValue = "true") boolean isDesc + ) { + return Result.successWithData(shopSongService.all(shopId, page, size, keyWord, isDesc)); + } + + @GetMapping("/detail") + public Result getRecord( + @RequestParam Integer id + ) { + return Result.successWithData(shopSongService.getDetail(TokenUtil.getUserId(), id)); + } + + + @GetMapping("/record") + public Result getRecord( + @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)); + } + + + @PostMapping + public Result createOrder( + @RequestHeader("openId") String openId, + @RequestBody SongOrderDTO songOrderDTO + ) { + return Result.successWithData(shopSongService.createOrder(TokenUtil.getUserId(), songOrderDTO, openId)); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantThirdApplyMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantThirdApplyMapper.java index 53707ad..c180107 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantThirdApplyMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbMerchantThirdApplyMapper.java @@ -1,7 +1,10 @@ package com.chaozhanggui.system.cashierservice.dao; +import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount; import com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Component; @Component @@ -20,4 +23,8 @@ public interface TbMerchantThirdApplyMapper { int updateByPrimaryKeyWithBLOBs(TbMerchantThirdApply record); int updateByPrimaryKey(TbMerchantThirdApply record); -} \ No newline at end of file + + @Select("select a.* from tb_merchant_third_apply as a left join tb_merchant_account as b on a.id=b.id where b.shop_id=#{shopId}") + TbMerchantThirdApply selectByShopId(@Param("shopId") Integer shopId); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongMapper.java new file mode 100644 index 0000000..c998a25 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongMapper.java @@ -0,0 +1,39 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbShopSong; +import com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.util.List; + +/** +* @author Administrator +* @description 针对表【tb_shop_song】的数据库操作Mapper +* @createDate 2024-07-09 11:52:30 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopSong +*/ +public interface TbShopSongMapper { + + int deleteByPrimaryKey(Long id); + + int insert(TbShopSong record); + + int insertSelective(TbShopSong record); + + TbShopSong selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TbShopSong record); + + int updateByPrimaryKey(TbShopSong record); + + List selectAllAndSearch(Integer shopId, String keyWord); + + @Select("select * from fycashier.tb_shop_song where id=#{songId} and status=1") + TbShopSong selectById(@Param("songId") Integer songId); + + + @Update("update fycashier.tb_shop_song set sales_number=sales_number+#{num} where id=#{id}") + int incrNum(@Param("num") Integer num,@Param("id") Integer id); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongOrderMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongOrderMapper.java new file mode 100644 index 0000000..d3382c4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopSongOrderMapper.java @@ -0,0 +1,50 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + +/** +* @author Administrator +* @description 针对表【tb_shop_song_order】的数据库操作Mapper +* @createDate 2024-07-09 15:23:30 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopSongOrder +*/ +public interface TbShopSongOrderMapper { + + int deleteByPrimaryKey(Long id); + + int insert(TbShopSongOrder record); + + int insertSelective(TbShopSongOrder record); + + TbShopSongOrder selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TbShopSongOrder record); + + int updateByPrimaryKey(TbShopSongOrder record); + + @Select("") + List> selectByUserId(@Param("userId") Integer userId, @Param("state") Integer state); + + Map selectByUserIdAndId(@Param("userId") Integer userId, @Param("id") Integer id); + + @Select("select * from fycashier.tb_shop_song_order where order_no=#{orderNo};") + TbShopSongOrder selectByOrderNo(@Param("orderNo") String orderNo); + + @Delete("DELETE FROM tb_shop_song_order\n" + + "WHERE create_time < NOW() - INTERVAL 10 MINUTE AND state=-1;\n") + int deleteExpireOrder(); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/PayTypeConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/PayTypeConstant.java new file mode 100644 index 0000000..7218c4f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/PayTypeConstant.java @@ -0,0 +1,5 @@ +package com.chaozhanggui.system.cashierservice.entity.Enum; + +public interface PayTypeConstant { + String MINI_PAY="MiniAppSongPay"; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSong.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSong.java new file mode 100644 index 0000000..80bd557 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSong.java @@ -0,0 +1,151 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName tb_shop_song + */ +@Data +public class TbShopSong implements Serializable { + /** + * + */ + private Integer id; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 歌曲图片 + */ + private String img; + + /** + * 歌曲名称 + */ + private String name; + + /** + * 原唱歌手 + */ + private String originSinger; + + /** + * 演出歌手id + */ + private Integer singerId; + + /** + * 演出歌手名称 + */ + private String singer; + + /** + * 单价 + */ + private BigDecimal price; + + /** + * 点播次数 + */ + private Integer salesNumber; + + /** + * 歌曲状态:1-开启;0-关闭 + */ + private Integer status; + + /** + * + */ + private Integer sort; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbShopSong other = (TbShopSong) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getImg() == null ? other.getImg() == null : this.getImg().equals(other.getImg())) + && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) + && (this.getOriginSinger() == null ? other.getOriginSinger() == null : this.getOriginSinger().equals(other.getOriginSinger())) + && (this.getSingerId() == null ? other.getSingerId() == null : this.getSingerId().equals(other.getSingerId())) + && (this.getSinger() == null ? other.getSinger() == null : this.getSinger().equals(other.getSinger())) + && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice())) + && (this.getSalesNumber() == null ? other.getSalesNumber() == null : this.getSalesNumber().equals(other.getSalesNumber())) + && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) + && (this.getSort() == null ? other.getSort() == null : this.getSort().equals(other.getSort())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getImg() == null) ? 0 : getImg().hashCode()); + result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); + result = prime * result + ((getOriginSinger() == null) ? 0 : getOriginSinger().hashCode()); + result = prime * result + ((getSingerId() == null) ? 0 : getSingerId().hashCode()); + result = prime * result + ((getSinger() == null) ? 0 : getSinger().hashCode()); + result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode()); + result = prime * result + ((getSalesNumber() == null) ? 0 : getSalesNumber().hashCode()); + result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); + result = prime * result + ((getSort() == null) ? 0 : getSort().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", shopId=").append(shopId); + sb.append(", img=").append(img); + sb.append(", name=").append(name); + sb.append(", originSinger=").append(originSinger); + sb.append(", singerId=").append(singerId); + sb.append(", singer=").append(singer); + sb.append(", price=").append(price); + sb.append(", salesNumber=").append(salesNumber); + sb.append(", status=").append(status); + sb.append(", sort=").append(sort); + sb.append(", createTime=").append(createTime); + sb.append(", updateTime=").append(updateTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSongOrder.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSongOrder.java new file mode 100644 index 0000000..960c914 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopSongOrder.java @@ -0,0 +1,159 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName tb_shop_song_order + */ +@Data +public class TbShopSongOrder implements Serializable { + /** + * + */ + private Integer id; + + /** + * 歌曲id + */ + private Integer songId; + + /** + * 歌曲名称 + */ + private String songName; + + /** + * 用户id + */ + private Integer userId; + + /** + * 支付金额 + */ + private BigDecimal payMoney; + + /** + * 状态 -1 未支付 0 已取消 1 已支付 2 演唱中 3 已演唱 + */ + private Integer state; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 下单来源 + */ + private Integer clientType; + + /** + * 订单编号 + */ + private String orderNo; + + /** + * 点歌人 + */ + private String fromName; + + /** + * 收歌人 + */ + private String toName; + + /** + * 祝福语 + */ + private String note; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 歌曲实际价格 + */ + private BigDecimal realMoney; + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbShopSongOrder other = (TbShopSongOrder) that; + 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.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())) + && (this.getClientType() == null ? other.getClientType() == null : this.getClientType().equals(other.getClientType())) + && (this.getOrderNo() == null ? other.getOrderNo() == null : this.getOrderNo().equals(other.getOrderNo())) + && (this.getFromName() == null ? other.getFromName() == null : this.getFromName().equals(other.getFromName())) + && (this.getToName() == null ? other.getToName() == null : this.getToName().equals(other.getToName())) + && (this.getNote() == null ? other.getNote() == null : this.getNote().equals(other.getNote())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getRealMoney() == null ? other.getRealMoney() == null : this.getRealMoney().equals(other.getRealMoney())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + 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 + ((getPayMoney() == null) ? 0 : getPayMoney().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getClientType() == null) ? 0 : getClientType().hashCode()); + result = prime * result + ((getOrderNo() == null) ? 0 : getOrderNo().hashCode()); + result = prime * result + ((getFromName() == null) ? 0 : getFromName().hashCode()); + result = prime * result + ((getToName() == null) ? 0 : getToName().hashCode()); + result = prime * result + ((getNote() == null) ? 0 : getNote().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getRealMoney() == null) ? 0 : getRealMoney().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", songId=").append(songId); + sb.append(", songName=").append(songName); + sb.append(", userId=").append(userId); + sb.append(", payMoney=").append(payMoney); + sb.append(", state=").append(state); + sb.append(", createTime=").append(createTime); + sb.append(", clientType=").append(clientType); + sb.append(", orderNo=").append(orderNo); + sb.append(", fromName=").append(fromName); + sb.append(", toName=").append(toName); + sb.append(", note=").append(note); + sb.append(", shopId=").append(shopId); + sb.append(", realMoney=").append(realMoney); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SongOrderDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SongOrderDTO.java new file mode 100644 index 0000000..8824a4f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SongOrderDTO.java @@ -0,0 +1,12 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +@Data +public class SongOrderDTO { + private Integer songId; + private String fromName; + private String toName; + private String note; + private Integer shopId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index e2d76ed..cd0951f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -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 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 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 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 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(){ // diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongOrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongOrderService.java new file mode 100644 index 0000000..2725025 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongOrderService.java @@ -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(); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongService.java new file mode 100644 index 0000000..47ef049 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopSongService.java @@ -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 getDetail(Integer userId, Integer id); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongOrderServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongOrderServiceImpl.java new file mode 100644 index 0000000..829b239 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongOrderServiceImpl.java @@ -0,0 +1,50 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +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); + } +} + + + + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongServiceImpl.java new file mode 100644 index 0000000..0c89117 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopSongServiceImpl.java @@ -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 redisTemplate; + + private final TbShopSongOrderService shopSongOrderService; + + private final TbShopSongOrderMapper shopSongOrderMapper; + + private final TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper; + + private final PayUtils payUtils; + + private final TbShopSongMapper shopSongMapper; + + public TbShopSongServiceImpl(RedisTemplate 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 all(Integer shopId, Integer page, Integer size, String keyWord, boolean isDesc) { + PageHelper.startPage(page, size); + List 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> songOrders = shopSongOrderMapper.selectByUserId(userId, state); + + ArrayList> infos = new ArrayList<>(); + for (int i = 0; i < songOrders.size(); i++) { + Map 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 getDetail(Integer userId, Integer id) { + Map map = shopSongOrderMapper.selectByUserIdAndId(userId, id); + if (map == null) { + throw new MsgException("订单不存在"); + } + return map; + } +} + + + + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java index e571b5c..d6ab516 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/sign/Result.java @@ -33,6 +33,10 @@ public class Result { */ private String icon; + public static Result successWithData(T data) { + return new Result(CodeEnum.SUCCESS, data); + } + public boolean isEncrypt() { return encrypt; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java index 8b4b4c0..3099f42 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/task/TaskScheduler.java @@ -2,11 +2,15 @@ package com.chaozhanggui.system.cashierservice.task; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.service.TbShopSongOrderService; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.NicknameGenerator; import com.chaozhanggui.system.cashierservice.util.RandomUtil; import lombok.SneakyThrows; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -19,6 +23,7 @@ import java.util.concurrent.*; @Component public class TaskScheduler { + private static final Logger log = LoggerFactory.getLogger(TaskScheduler.class); @Autowired private TbWiningUserMapper tbWiningUserMapper; @Autowired @@ -31,6 +36,13 @@ public class TaskScheduler { private TbReleaseFlowMapper releaseFlowMapper; @Autowired private TbUserCouponsMapper userCouponsMapper; + + private final TbShopSongOrderService shopSongOrderService; + + public TaskScheduler(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) { + this.shopSongOrderService = shopSongOrderService; + } + //更新订单状态 // @Scheduled(fixedRate = 1000000) public void orderStatus() throws InterruptedException { @@ -160,4 +172,10 @@ public class TaskScheduler { long randomMilliseconds = ThreadLocalRandom.current().nextLong(startTimestamp, endTimestamp); return randomMilliseconds; } + + @Scheduled(fixedRate = 60000) + public void clearSongOrder() { + log.info("定时任务执行,清楚过期歌曲订单"); + shopSongOrderService.clearExpireOrder(); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java index 0e6eab3..87ad9f6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java @@ -32,6 +32,8 @@ public class WxScanPayReq implements Serializable { private String returnUrl; + private String extParam; + public WxScanPayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) { this.subject = subject; this.body = body; @@ -46,4 +48,20 @@ public class WxScanPayReq implements Serializable { this.notifyUrl = notifyUrl; this.returnUrl = returnUrl; } + + public WxScanPayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl, String extParam) { + this.subject = subject; + this.body = body; + this.amount = amount; + this.currency = currency; + this.payType = payType; + this.subAppid = subAppid; + this.userId = userId; + this.clientIp = clientIp; + this.mchOrderNo = mchOrderNo; + this.storeId = storeId; + this.notifyUrl = notifyUrl; + this.returnUrl = returnUrl; + this.extParam = extParam; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java index 4b1f928..d0cc415 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java @@ -100,6 +100,33 @@ public class ThirdPayService { PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + try { + String str = JSONUtil.toJSONString(sortFields(scanPayReq)); + param.setBizData(str); + String tt = sortFieldsAndPrint(param); + String MD5 = tt.concat("appSecret=" + key); + log.info("加签原传:{}", MD5); + String sign = MD5Util.encrypt(MD5); + param.setSign(sign); + String reqbody = JSONUtil.toJSONString(param); + log.info("请求参数:{}", reqbody); + String response = HttpRequest.post(url.concat(ltpay)).body(reqbody).execute().body(); + log.info("返回结果:{}", response); + PublicResp resp =JSONUtil.parseJSONStr2T(response,PublicResp.class); + resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),WxScanPayResp.class)); + return resp; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + public PublicResp scanpay(String url,String appId, String subject, String body, Long amount,String payType, String subAppId, String userId, + String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl, + String key, String extParam){ + WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,notifyUrl,returnUrl, extParam); + PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis())); + + try { String str = JSONUtil.toJSONString(sortFields(scanPayReq)); param.setBizData(str); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/PayUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/PayUtils.java new file mode 100644 index 0000000..1d4f60a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/PayUtils.java @@ -0,0 +1,117 @@ +package com.chaozhanggui.system.cashierservice.util; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.dao.TbMemberInMapper; +import com.chaozhanggui.system.cashierservice.entity.Enum.PayTypeConstant; +import com.chaozhanggui.system.cashierservice.entity.TbMemberIn; +import com.chaozhanggui.system.cashierservice.entity.TbMerchantThirdApply; +import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp; +import com.chaozhanggui.system.cashierservice.thirdpay.resp.WxScanPayResp; +import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import java.math.BigDecimal; +import java.util.Date; + + +@Component +public class PayUtils { + private static final Logger log = LoggerFactory.getLogger(PayUtils.class); + @Value("${thirdPay.payType}") + private String thirdPayType; + @Value("${thirdPay.url}") + private String thirdUrl; + + @Value("${thirdPay.callInBack}") + private String callInBack; + + @Value("${thirdPay.callFSTBack}") + private String callFSTBack; + + @Value("${ysk.url}") + private String url; + + @Value("${ysk.callBackurl}") + private String callBackurl; + + @Value("${ysk.callBackGroupurl}") + private String callBackGroupurl; + + @Value("${ysk.callBackIn}") + private String callBackIn; + + private final RestTemplate restTemplate; + + private final ThirdPayService thirdPayService; + private final TbMemberInMapper tbMemberInMapper; + + + + public PayUtils(RestTemplate restTemplate, ThirdPayService thirdPayService, TbMemberInMapper tbMemberInMapper) { + this.restTemplate = restTemplate; + this.thirdPayService = thirdPayService; + this.tbMemberInMapper = tbMemberInMapper; + } + + public JsonNode getWxPay(String ip, String songOrderNo, + Integer userId, + String code, + Integer shopId, + BigDecimal money, + Integer merchantId, + String openId, TbMerchantThirdApply thirdApply) { + TbMemberIn memberIn=new TbMemberIn(); + memberIn.setAmount(money); + memberIn.setUserId(userId); + memberIn.setCode(code); + memberIn.setShopId(shopId); + memberIn.setStatus("100"); + memberIn.setMerchantId(merchantId); + memberIn.setCreateTime(new Date()); + String orderNo=DateUtils.getsdfTimesSS(); + log.info("开始发送支付请求,携带参数:{}", memberIn); + JSONObject ext = new JSONObject(); + ext.put("payType", PayTypeConstant.MINI_PAY); + ext.put("orderNo", songOrderNo); + PublicResp publicResp= thirdPayService + .scanpay(thirdUrl,thirdApply.getAppId(), + "会员充值","会员充值",money.setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(), + "WECHAT", + thirdApply.getSmallAppid(), + openId,ip, orderNo, + thirdApply.getStoreId(),callInBack,null,thirdApply.getAppToken(), ext.toJSONString()); + log.info("支付请求发送完毕,响应内容:{}", publicResp); + if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){ + if("000000".equals(publicResp.getCode())){ + WxScanPayResp wxScanPayResp= publicResp.getObjData(); + if("TRADE_AWAIT".equals(wxScanPayResp.getState())){ + + memberIn.setOrderNo(orderNo); + memberIn.setTradeNo(wxScanPayResp.getPayOrderId()); + memberIn.setUpdateTime(new Date()); + tbMemberInMapper.updateByPrimaryKeySelective(memberIn); + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.readTree(wxScanPayResp.getPayInfo()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + }else{ + throw new MsgException(publicResp.getMsg()); + } + } + } + return null; + } + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java index 02007bc..f05eb79 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/TokenUtil.java @@ -6,7 +6,10 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -118,6 +121,13 @@ public class TokenUtil { } return jsonObject; } + + public static Integer getUserId() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + JSONObject jsonObject = parseParamFromToken(request.getHeader("token")); + return jsonObject.getInteger("userId"); + + } // public static void main(String[] args) throws Exception { // System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw")); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); diff --git a/src/main/resources/mapper/TbShopSongMapper.xml b/src/main/resources/mapper/TbShopSongMapper.xml new file mode 100644 index 0000000..6f213b7 --- /dev/null +++ b/src/main/resources/mapper/TbShopSongMapper.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + id,shop_id,img, + name,origin_singer,singer_id, + singer,price,sales_number, + status,sort,create_time, + update_time + + + + + + + delete from tb_shop_song + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_song + ( id,shop_id,img + ,name,origin_singer,singer_id + ,singer,price,sales_number + ,status,sort,create_time + ,update_time) + values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{img,jdbcType=VARCHAR} + ,#{name,jdbcType=VARCHAR},#{originSinger,jdbcType=VARCHAR},#{singerId,jdbcType=INTEGER} + ,#{singer,jdbcType=VARCHAR},#{price,jdbcType=DECIMAL},#{salesNumber,jdbcType=INTEGER} + ,#{status,jdbcType=TINYINT},#{sort,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP} + ,#{updateTime,jdbcType=TIMESTAMP}) + + + insert into tb_shop_song + + id, + shop_id, + img, + name, + origin_singer, + singer_id, + singer, + price, + sales_number, + status, + sort, + create_time, + update_time, + + + #{id,jdbcType=INTEGER}, + #{shopId,jdbcType=INTEGER}, + #{img,jdbcType=VARCHAR}, + #{name,jdbcType=VARCHAR}, + #{originSinger,jdbcType=VARCHAR}, + #{singerId,jdbcType=INTEGER}, + #{singer,jdbcType=VARCHAR}, + #{price,jdbcType=DECIMAL}, + #{salesNumber,jdbcType=INTEGER}, + #{status,jdbcType=TINYINT}, + #{sort,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, + + + + update tb_shop_song + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + img = #{img,jdbcType=VARCHAR}, + + + name = #{name,jdbcType=VARCHAR}, + + + origin_singer = #{originSinger,jdbcType=VARCHAR}, + + + singer_id = #{singerId,jdbcType=INTEGER}, + + + singer = #{singer,jdbcType=VARCHAR}, + + + price = #{price,jdbcType=DECIMAL}, + + + sales_number = #{salesNumber,jdbcType=INTEGER}, + + + status = #{status,jdbcType=TINYINT}, + + + sort = #{sort,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_song + set + shop_id = #{shopId,jdbcType=INTEGER}, + img = #{img,jdbcType=VARCHAR}, + name = #{name,jdbcType=VARCHAR}, + origin_singer = #{originSinger,jdbcType=VARCHAR}, + singer_id = #{singerId,jdbcType=INTEGER}, + singer = #{singer,jdbcType=VARCHAR}, + price = #{price,jdbcType=DECIMAL}, + sales_number = #{salesNumber,jdbcType=INTEGER}, + status = #{status,jdbcType=TINYINT}, + sort = #{sort,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + diff --git a/src/main/resources/mapper/TbShopSongOrderMapper.xml b/src/main/resources/mapper/TbShopSongOrderMapper.xml new file mode 100644 index 0000000..5efb7e5 --- /dev/null +++ b/src/main/resources/mapper/TbShopSongOrderMapper.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + id,song_id,song_name, + user_id,pay_money,state, + create_time,client_type,order_no, + from_name,to_name,note, + shop_id,real_money + + + + + + delete from tb_shop_song_order + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_song_order + ( id,song_id,song_name + ,user_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} + ,#{createTime,jdbcType=TIMESTAMP},#{clientType,jdbcType=TINYINT},#{orderNo,jdbcType=VARCHAR} + ,#{fromName,jdbcType=VARCHAR},#{toName,jdbcType=VARCHAR},#{note,jdbcType=VARCHAR} + ,#{shopId,jdbcType=INTEGER},#{realMoney,jdbcType=DECIMAL}) + + + insert into tb_shop_song_order + + id, + song_id, + song_name, + user_id, + pay_money, + state, + create_time, + client_type, + order_no, + from_name, + to_name, + note, + shop_id, + real_money, + + + #{id,jdbcType=INTEGER}, + #{songId,jdbcType=INTEGER}, + #{songName,jdbcType=VARCHAR}, + #{userId,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}, + + + + update tb_shop_song_order + + + song_id = #{songId,jdbcType=INTEGER}, + + + song_name = #{songName,jdbcType=VARCHAR}, + + + user_id = #{userId,jdbcType=INTEGER}, + + + pay_money = #{payMoney,jdbcType=DECIMAL}, + + + state = #{state,jdbcType=TINYINT}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + client_type = #{clientType,jdbcType=TINYINT}, + + + order_no = #{orderNo,jdbcType=VARCHAR}, + + + from_name = #{fromName,jdbcType=VARCHAR}, + + + to_name = #{toName,jdbcType=VARCHAR}, + + + note = #{note,jdbcType=VARCHAR}, + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + real_money = #{realMoney,jdbcType=DECIMAL}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_song_order + set + song_id = #{songId,jdbcType=INTEGER}, + song_name = #{songName,jdbcType=VARCHAR}, + user_id = #{userId,jdbcType=INTEGER}, + pay_money = #{payMoney,jdbcType=DECIMAL}, + state = #{state,jdbcType=TINYINT}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + client_type = #{clientType,jdbcType=TINYINT}, + order_no = #{orderNo,jdbcType=VARCHAR}, + from_name = #{fromName,jdbcType=VARCHAR}, + to_name = #{toName,jdbcType=VARCHAR}, + note = #{note,jdbcType=VARCHAR}, + shop_id = #{shopId,jdbcType=INTEGER}, + real_money = #{realMoney,jdbcType=DECIMAL} + where id = #{id,jdbcType=INTEGER} + + + +