浏览代码

消息、通知、交易

qrs 2 周之前
父节点
当前提交
b1b1153ac9

+ 1 - 1
alien-entity/src/main/java/shop/alien/entity/store/LifeMessage.java

@@ -34,7 +34,7 @@ public class LifeMessage {
     @ApiModelProperty(value = "发送内容")
     private String content;
 
-    @ApiModelProperty(value = "消息类型  1-文本  2-图片 3-链接  4-二手交易创建/确认/拒绝  5-二手交易签到提醒  6-二手交易已签到")
+    @ApiModelProperty(value = "消息类型  1-文本  2-图片 3-链接  4-二手交易创建/确认/拒绝/取消  5-二手交易签到提醒  6-二手交易已签到")
     private String type;
 
     private Date currentTime;

+ 3 - 1
alien-entity/src/main/java/shop/alien/mapper/second/SecondTradeRecordMapper.java

@@ -4,6 +4,7 @@ package shop.alien.mapper.second;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import shop.alien.entity.second.SecondTradeRecord;
@@ -20,11 +21,12 @@ import java.util.List;
  * @author qrs
  * @since 2025-07-07
  */
+@Mapper
 public interface SecondTradeRecordMapper extends BaseMapper<SecondTradeRecord> {
 
     @Select("select trade.id, goods.title, goods.home_image, goods.price, trade.transaction_amount, trade.trade_status, " +
             "       trade.transaction_latitude_longitude, trade.transaction_latitude_longitude_address, trade.transaction_location " +
             "from second_trade_record trade " +
             "left join second_goods goods on goods.id = trade.goods_id ")
-    List<SecondTradeRecordVo> getTradeRecord(@Param(Constants.WRAPPER) QueryWrapper<SecondTradeRecordVo> wrapper);
+    List<SecondTradeRecordVo> getTradeRecord(@Param(Constants.WRAPPER) QueryWrapper<SecondTradeRecord> wrapper);
 }

+ 3 - 1
alien-second/src/main/java/shop/alien/second/AlienSecondApplication.java

@@ -16,7 +16,9 @@ import org.springframework.context.annotation.ComponentScan;
         "shop.alien.config.databases",
         "shop.alien.config.feign",
         "shop.alien.config.redis"})
-@MapperScan({"shop.alien.mapper"})
+@MapperScan({
+        "shop.alien.mapper",
+        "shop.alien.mapper.second"})
 @EnableSwaggerBootstrapUI
 @SpringBootApplication
 public class AlienSecondApplication {

+ 38 - 39
alien-second/src/main/java/shop/alien/second/controller/SecondTradeRecordController.java

@@ -32,17 +32,8 @@ public class SecondTradeRecordController {
 
     private final SecondTradeRecordService secondTradeRecordService;
 
-    @ApiOperation("交易窗")
-    @ApiOperationSupport(order = 1)
-    @ApiImplicitParams({@ApiImplicitParam(name = "sideId", value = "对方的id", dataType = "Integer", paramType = "query", required = true)})
-    @GetMapping("/getTradeRecord")
-    public R<List<SecondTradeRecordVo>> getTradeRecord(@RequestParam int sideId) throws Exception {
-        log.info("SecondTradeRecordController.getTradeRecord?sideId={}", sideId);
-        return R.data(secondTradeRecordService.getTradeRecord(sideId));
-    }
-
     @ApiOperation("创建交易")
-    @ApiOperationSupport(order = 2)
+    @ApiOperationSupport(order = 1)
     @PostMapping("/createTrade")
     public R<Boolean> createTrade(@RequestBody SecondTradeRecord entity) throws Exception {
         log.info("SecondTradeRecordController.createTrade?entity={}", entity.toString());
@@ -50,9 +41,8 @@ public class SecondTradeRecordController {
         return R.fail("创建失败");
     }
 
-
     @ApiOperation("确认商品是否可以交易")
-    @ApiOperationSupport(order = 3)
+    @ApiOperationSupport(order = 2)
     @ApiImplicitParams({@ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "Integer", paramType = "query", required = true)})
     @GetMapping("/goodsTradeConfirm")
     public R<Boolean> goodsTradeConfirm(@RequestParam int goodsId) throws Exception {
@@ -60,6 +50,32 @@ public class SecondTradeRecordController {
         return R.data(secondTradeRecordService.goodsTradeConfirm(goodsId));
     }
 
+    @ApiOperation("确认/拒绝交易")
+    @ApiOperationSupport(order = 3)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "messageId", value = "消息id", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "type", value = "0-拒绝  1-确认", dataType = "Integer", paramType = "query", required = true)})
+    @GetMapping("/tradeConfirm")
+    public R<Boolean> tradeConfirm(@RequestParam int tradeId, @RequestParam int messageId, @RequestParam int type) throws Exception {
+        log.info("SecondTradeRecordController.tradeConfirm?tradeId={}, messageId={}, type={}", tradeId, messageId, type);
+        if (secondTradeRecordService.tradeConfirm(tradeId, messageId, type)) return R.success("操作成功");
+        return R.fail("操作失败");
+    }
+
+    @ApiOperation("取消交易")
+    @ApiOperationSupport(order = 6)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "cancelReason", value = "取消原因", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "cancelReasonSupplement", value = "取消原因补充", dataType = "String", paramType = "query")})
+    @GetMapping("/cancelTrade")
+    public R<Boolean> cancelTrade(@RequestParam int tradeId, @RequestParam String cancelReason, String cancelReasonSupplement) throws Exception {
+        log.info("SecondTradeRecordController.cancelTrade?tradeId={}, cancelReason={}, cancelReasonSupplement={}", tradeId, cancelReason, cancelReasonSupplement);
+        if (secondTradeRecordService.cancelTrade(tradeId, cancelReason, cancelReasonSupplement)) return R.success("取消交易成功");
+        return R.fail("取消交易失败");
+    }
+
     @ApiOperation("交易签到")
     @ApiOperationSupport(order = 4)
     @ApiImplicitParams({
@@ -72,42 +88,25 @@ public class SecondTradeRecordController {
         return R.fail("签到失败");
     }
 
-    @ApiOperation("确认拒绝交易")
+    @ApiOperation("交易完成")
     @ApiOperationSupport(order = 5)
     @ApiImplicitParams({
             @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
             @ApiImplicitParam(name = "type", value = "0-失败  1-成功", dataType = "Integer", paramType = "query", required = true),
             @ApiImplicitParam(name = "evaluate", value = "评价", dataType = "String", paramType = "query")})
-    @GetMapping("/tradeConfirm")
-    public R<Boolean> tradeConfirm(@RequestParam int tradeId, @RequestParam int type, @RequestParam String evaluate) throws Exception {
-        log.info("SecondTradeRecordController.tradeConfirm?tradeId={}, type={}, evaluate={}", tradeId, type, evaluate);
-        if (secondTradeRecordService.tradeConfirm(tradeId, type, evaluate)) return R.success("交易确认成功");
-        return R.fail("交易确认失败");
-    }
-
-    @ApiOperation("交易完成确认")
-    @ApiOperationSupport(order = 6)
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "type", value = "0-失败  1-成功", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "evaluate", value = "评价", dataType = "String", paramType = "query")})
     @GetMapping("/tradeCompleteConfirm")
-    public R<Boolean> tradeCompleteConfirm(@RequestParam int tradeId, @RequestParam int type, @RequestParam String evaluate) throws Exception {
+    public R<Boolean> tradeCompleteConfirm(@RequestParam int tradeId, @RequestParam int type, String evaluate) throws Exception {
         log.info("SecondTradeRecordController.tradeCompleteConfirm?tradeId={}, type={}, evaluate={}", tradeId, type, evaluate);
-        if (secondTradeRecordService.tradeCompleteConfirm(tradeId, type, evaluate)) return R.success("交易确认成功");
-        return R.fail("交易确认失败");
+        if (secondTradeRecordService.tradeCompleteConfirm(tradeId, type, evaluate)) return R.success("交易完成成功");
+        return R.fail("交易完成失败");
     }
 
-    @ApiOperation("取消交易")
+    @ApiOperation("交易窗")
     @ApiOperationSupport(order = 7)
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "tradeId", value = "交易id", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "cancelReason", value = "取消原因", dataType = "String", paramType = "query", required = true),
-            @ApiImplicitParam(name = "cancelReasonSupplement", value = "取消原因补充", dataType = "String", paramType = "query")})
-    @GetMapping("/cancelTrade")
-    public R<Boolean> cancelTrade(@RequestParam int tradeId, @RequestParam String cancelReason, String cancelReasonSupplement) throws Exception {
-        log.info("SecondTradeRecordController.cancelTrade?tradeId={}, cancelReason={}, cancelReasonSupplement={}", tradeId, cancelReason, cancelReasonSupplement);
-        if (secondTradeRecordService.cancelTrade(tradeId, cancelReason, cancelReasonSupplement)) return R.success("取消交易成功");
-        return R.fail("取消交易失败");
+    @ApiImplicitParams({@ApiImplicitParam(name = "sideId", value = "对方的id", dataType = "Integer", paramType = "query", required = true)})
+    @GetMapping("/getTradeRecord")
+    public R<List<SecondTradeRecordVo>> getTradeRecord(@RequestParam int sideId) throws Exception {
+        log.info("SecondTradeRecordController.getTradeRecord?sideId={}", sideId);
+        return R.data(secondTradeRecordService.getTradeRecord(sideId));
     }
 }

+ 7 - 7
alien-second/src/main/java/shop/alien/second/service/SecondTradeRecordService.java

@@ -17,17 +17,17 @@ import java.util.List;
  * @since 2025-07-07
  */
 public interface SecondTradeRecordService extends IService<SecondTradeRecord> {
-    List<SecondTradeRecordVo> getTradeRecord(int sideId) throws Exception;
-
     boolean createTrade(SecondTradeRecord entity) throws Exception;
 
-    boolean tradeSignIn(int tradeId, int messageId) throws Exception;
+    boolean goodsTradeConfirm(int goodsId) throws Exception;
 
-    boolean tradeConfirm(int tradeId, int type, String evaluate) throws Exception;
+    boolean tradeConfirm(int tradeId, int messageId, int type) throws Exception;
 
-    boolean tradeCompleteConfirm(int tradeId, int type, String evaluate) throws Exception;
+    boolean cancelTrade(int tradeId, String cancelReason, String cancelReasonSupplement) throws Exception;
 
-    boolean goodsTradeConfirm(int goodsId) throws Exception;
+    boolean tradeSignIn(int tradeId, int messageId) throws Exception;
 
-    boolean cancelTrade(int tradeId, String cancelReason, String cancelReasonSupplement) throws Exception;
+    boolean tradeCompleteConfirm(int tradeId, int type, String evaluate) throws Exception;
+
+    List<SecondTradeRecordVo> getTradeRecord(int sideId) throws Exception;
 }

+ 244 - 92
alien-second/src/main/java/shop/alien/second/service/impl/SecondTradeRecordServiceImpl.java

@@ -12,9 +12,11 @@ import shop.alien.entity.second.SecondTradeRecord;
 import shop.alien.entity.second.vo.SecondTradeRecordVo;
 import shop.alien.entity.store.LifeMessage;
 import shop.alien.entity.store.LifeUser;
+import shop.alien.entity.store.StoreDictionary;
 import shop.alien.entity.store.vo.WebsocketVo;
 import shop.alien.mapper.LifeMessageMapper;
 import shop.alien.mapper.LifeUserMapper;
+import shop.alien.mapper.StoreDictionaryMapper;
 import shop.alien.mapper.second.SecondGoodsMapper;
 import shop.alien.mapper.second.SecondTradeRecordMapper;
 import shop.alien.second.feign.AlienStoreFeign;
@@ -42,20 +44,7 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
     private final LifeMessageMapper lifeMessageMapper;
     private final LifeUserMapper lifeUserMapper;
     private final AlienStoreFeign alienStoreFeign;
-
-    @Override
-    public List<SecondTradeRecordVo> getTradeRecord(int sideId) throws Exception {
-        try {
-            int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
-            QueryWrapper<SecondTradeRecordVo> wrapper = new QueryWrapper<>();
-            wrapper.apply("(trade.buyer_id = '" + sideId + "' and trade.seller_id = '" + userId + "') || (trade.buyer_id = '" + userId + "' and trade.seller_id = '" + sideId + "')");
-            wrapper.orderByDesc("trade.created_time");
-            return secondTradeRecordMapper.getTradeRecord(wrapper);
-        } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.getTradeRecord Error Mgs={}", e.getMessage());
-            throw new Exception(e);
-        }
-    }
+    private final StoreDictionaryMapper storeDictionaryMapper;
 
     /**
      * 创建交易
@@ -77,50 +66,209 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
             // 查询商品
             goods = secondGoodsMapper.selectById(trade.getGoodsId());
 
-            // 封装交易信息
-            JSONObject message = new JSONObject();
-            message.put("title", goods.getTitle());
-            message.put("homeImage", goods.getHomeImage());
-            message.put("tradeId", trade.getId());
-            message.put("transactionAmount", trade.getTransactionAmount());
-            message.put("transactionLatitudeLongitude", trade.getTransactionLatitudeLongitude());
-            message.put("transactionLatitudeLongitudeAddress", trade.getTransactionLatitudeLongitudeAddress());
-            message.put("transactionLocation", trade.getTransactionLocation());
-            message.put("transactionTime", trade.getTransactionTime());
-            message.put("tradeStatus", 1);
+            // 发送消息
+            sendMsg(goods, trade, 1, "4");
+
+            return true;
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.createTrade Error Mgs={}", e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
+    /**
+     * 发送消息
+     * @param goods        商品信息
+     * @param trade        交易信息
+     * @param tradeStatus  1-待确认  2-已拒绝  3-待交易  6-交易取消
+     */
+    private void sendMsg(SecondGoods goods, SecondTradeRecord trade, Integer tradeStatus, String messageType) {
+        // 封装交易信息
+        JSONObject message = new JSONObject();
+        message.put("title", goods.getTitle());
+        message.put("homeImage", goods.getHomeImage());
+        message.put("tradeId", trade.getId());
+        message.put("transactionAmount", trade.getTransactionAmount());
+        message.put("transactionLatitudeLongitude", trade.getTransactionLatitudeLongitude());
+        message.put("transactionLatitudeLongitudeAddress", trade.getTransactionLatitudeLongitudeAddress());
+        message.put("transactionLocation", trade.getTransactionLocation());
+        message.put("transactionTime", trade.getTransactionTime());
+        message.put("tradeStatus", tradeStatus);
+        if (6 == tradeStatus) {
+            message.put("cancelUserId", trade.getCancelUserId());
+            message.put("cancelReason", trade.getCancelReason());
+            message.put("cancelReasonSupplement", trade.getCancelReasonSupplement());
+
+            // 查询字典表
+            LambdaQueryWrapper<StoreDictionary> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(StoreDictionary::getTypeName, "cancelTradeReason");
+            wrapper.eq(StoreDictionary::getDictId, trade.getCancelReason());
+            StoreDictionary storeDictionary = storeDictionaryMapper.selectOne(wrapper);
+            message.put("cancelReasonName", null == storeDictionary ? "" : storeDictionary.getDictDetail());
+        }
+
+        // 发起交易人信息
+        Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+        String phoneId = JwtUtil.getCurrentUserInfo().getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
+
+        // 获取交易对方信息
+        LifeUser lifeUser = lifeUserMapper.selectById(Objects.equals(userId, trade.getBuyerId()) ? trade.getSellerId() : trade.getBuyerId());
+        String receiverId = "user_" + lifeUser.getUserPhone();
+
+        // 消息
+        LifeMessage lifeMessage = new LifeMessage();
+        lifeMessage.setSenderId(phoneId);
+        lifeMessage.setReceiverId(receiverId);
+        lifeMessage.setType(messageType);
+        lifeMessage.setContent(message.toJSONString());
+        lifeMessageMapper.insert(lifeMessage);
+
+        // 给买家与卖家发送交易消息
+        alienStoreFeign.sendMsgToClientByPhoneId(phoneId, phoneId, receiverId, "message", messageType, message.toJSONString(), lifeMessage.getId());
+        alienStoreFeign.sendMsgToClientByPhoneId(receiverId, phoneId, receiverId, "message", messageType, message.toJSONString(), lifeMessage.getId());
+    }
+
+    @Override
+    public boolean goodsTradeConfirm(int goodsId) throws Exception {
+        try {
+            LambdaQueryWrapper<SecondTradeRecord> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(SecondTradeRecord::getGoodsId, goodsId);
+            queryWrapper.in(SecondTradeRecord::getTradeStatus, 1, 3, 4);
+            return secondTradeRecordMapper.selectCount(queryWrapper) == 0;
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.goodsTrade Error Mgs={}", e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
+    @Override
+    public boolean tradeConfirm(int tradeId, int messageId, int type) throws Exception {
+        try {
+            // 修改交易状态
+            SecondTradeRecord tradeRecord = new SecondTradeRecord();
+            tradeRecord.setId(tradeId);
+            if (type == 1) {
+                tradeRecord.setTradeStatus(3);
+            } else {
+                tradeRecord.setTradeStatus(2);
+            }
+            secondTradeRecordMapper.updateById(tradeRecord);
+
+            // 交易信息
+            SecondTradeRecord trade = secondTradeRecordMapper.selectById(tradeId);
+
+            // 商品信息
+            SecondGoods goods = secondGoodsMapper.selectById(trade.getGoodsId());
+
+            // 发送消息
+            sendMsg(goods, trade, trade.getTradeStatus(), "4");
+
+//            // 发起交易人信息
+//            Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+//            String phoneId = JwtUtil.getCurrentUserInfo().getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
+//
+//            // 获取交易对方信息
+//            LifeUser lifeUser = lifeUserMapper.selectById(Objects.equals(userId, trade.getBuyerId()) ? trade.getSellerId() : trade.getBuyerId());
+//            String receiverId = "user_" + lifeUser.getUserPhone();
+//
+//            // 封装交易信息
+//            JSONObject message = new JSONObject();
+//            message.put("title", goods.getTitle());
+//            message.put("homeImage", goods.getHomeImage());
+//            message.put("tradeId", trade.getId());
+//            message.put("transactionAmount", trade.getTransactionAmount());
+//            message.put("transactionLatitudeLongitude", trade.getTransactionLatitudeLongitude());
+//            message.put("transactionLatitudeLongitudeAddress", trade.getTransactionLatitudeLongitudeAddress());
+//            message.put("transactionLocation", trade.getTransactionLocation());
+//            message.put("transactionTime", trade.getTransactionTime());
+//            message.put("tradeStatus", 3);
+//
+//            // 保存消息记录
+//            LifeMessage lifeMessage = new LifeMessage();
+//            lifeMessage.setSenderId(phoneId);
+//            lifeMessage.setReceiverId(receiverId);
+//            lifeMessage.setType("4");
+//            lifeMessage.setContent(message.toJSONString());
+//            lifeMessageMapper.insert(lifeMessage);
+//
+//            // 给买家与卖家发送交易消息
+//            alienStoreFeign.sendMsgToClientByPhoneId(phoneId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
+//            alienStoreFeign.sendMsgToClientByPhoneId(receiverId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
 
+            return true;
+        } catch (Exception e) {
+            log.error("SecondTradeRecordServiceImpl.tradeConfirm Error Mgs={}", e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
+    @Override
+    public boolean cancelTrade(int tradeId, String cancelReason, String cancelReasonSupplement) throws Exception {
+        try {
             // 发起交易人信息
             Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
             String phoneId = JwtUtil.getCurrentUserInfo().getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
 
-            // 获取交易对方信息
-            LifeUser lifeUser = lifeUserMapper.selectById(Objects.equals(userId, trade.getBuyerId()) ? trade.getSellerId() : trade.getBuyerId());
-            String receiverId = "user_" + lifeUser.getUserPhone();
-
-            // 消息
-            LifeMessage lifeMessage = new LifeMessage();
-            lifeMessage.setSenderId(phoneId);
-            lifeMessage.setReceiverId(receiverId);
-            lifeMessage.setType("4");
-            lifeMessage.setContent(message.toJSONString());
-            lifeMessageMapper.insert(lifeMessage);
-
-            // 给买家与卖家发送交易消息
-//            WebsocketVo websocketVo = new WebsocketVo();
-//            websocketVo.setSenderId(phoneId);
-//            websocketVo.setReceiverId("user_" + lifeUser.getUserPhone());
-//            websocketVo.setCategory("message");
-//            websocketVo.setType("4");
-//            websocketVo.setText(message.toJSONString());
-//            websocketVo.setMessageId(lifeMessage.getId());
-
-            // 给买家与卖家发送交易消息
-            alienStoreFeign.sendMsgToClientByPhoneId(phoneId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
-            alienStoreFeign.sendMsgToClientByPhoneId(receiverId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
+            // 修改交易状态
+            SecondTradeRecord tradeRecord = new SecondTradeRecord();
+            tradeRecord.setId(tradeId);
+            tradeRecord.setTradeStatus(6);
+            tradeRecord.setCancelUserId(userId);
+            tradeRecord.setCancelReason(cancelReason);
+            tradeRecord.setCancelReasonSupplement(cancelReasonSupplement);
+            secondTradeRecordMapper.updateById(tradeRecord);
+
+            // 交易信息
+            SecondTradeRecord trade = secondTradeRecordMapper.selectById(tradeId);
+
+            // 商品信息
+            SecondGoods goods = secondGoodsMapper.selectById(trade.getGoodsId());
+
+            // 发送消息
+            sendMsg(goods, trade, 6, "4");
+
+//            // 获取交易对方信息
+//            LifeUser lifeUser = lifeUserMapper.selectById(Objects.equals(userId, trade.getBuyerId()) ? trade.getSellerId() : trade.getBuyerId());
+//            String receiverId = "user_" + lifeUser.getUserPhone();
+//
+//            // 封装交易信息
+//
+//            JSONObject message = new JSONObject();
+//            message.put("title", goods.getTitle());
+//            message.put("homeImage", goods.getHomeImage());
+//            message.put("tradeId", trade.getId());
+//            message.put("transactionAmount", trade.getTransactionAmount());
+//            message.put("transactionLatitudeLongitude", trade.getTransactionLatitudeLongitude());
+//            message.put("transactionLatitudeLongitudeAddress", trade.getTransactionLatitudeLongitudeAddress());
+//            message.put("transactionLocation", trade.getTransactionLocation());
+//            message.put("transactionTime", trade.getTransactionTime());
+//            message.put("tradeStatus", 6);
+//            message.put("cancelUserId", trade.getCancelUserId());
+//            message.put("cancelReason", trade.getCancelReason());
+//            message.put("cancelReasonSupplement", trade.getCancelReasonSupplement());
+//
+//            // 查询字典表
+//            LambdaQueryWrapper<StoreDictionary> wrapper = new LambdaQueryWrapper<>();
+//            wrapper.eq(StoreDictionary::getTypeName, "cancelTradeReason");
+//            wrapper.eq(StoreDictionary::getDictId, trade.getCancelReason());
+//            StoreDictionary storeDictionary = storeDictionaryMapper.selectOne(wrapper);
+//            message.put("cancelReasonName", null == storeDictionary ? "" : storeDictionary.getDictDetail());
+//
+//            // 保存消息记录
+//            LifeMessage lifeMessage = new LifeMessage();
+//            lifeMessage.setSenderId(phoneId);
+//            lifeMessage.setReceiverId(receiverId);
+//            lifeMessage.setType("4");
+//            lifeMessage.setContent(message.toJSONString());
+//            lifeMessageMapper.insert(lifeMessage);
+//
+//            // 给买家与卖家发送交易消息
+//            alienStoreFeign.sendMsgToClientByPhoneId(phoneId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
+//            alienStoreFeign.sendMsgToClientByPhoneId(receiverId, phoneId, receiverId, "message", "4", message.toJSONString(), lifeMessage.getId());
 
             return true;
         } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.createTrade Error Mgs={}", e.getMessage());
+            log.error("SecondTradeRecordServiceImpl.cancelTrade Error Mgs={}", e.getMessage());
             throw new Exception(e);
         }
     }
@@ -129,40 +277,60 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
     public boolean tradeSignIn(int tradeId, int messageId) throws Exception {
         try {
             int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
-            SecondTradeRecord tradeRecord = secondTradeRecordMapper.selectById(tradeId);
+            SecondTradeRecord trade = secondTradeRecordMapper.selectById(tradeId);
             SecondTradeRecord record = new SecondTradeRecord();
             record.setId(tradeId);
-            if (userId == tradeRecord.getBuyerId()) {
+            if (userId == trade.getBuyerId()) {
                 record.setBuyerSignIn(1);
-            } else if (userId == tradeRecord.getSellerId()) {
+            } else if (userId == trade.getSellerId()) {
                 record.setSellerSignIn(1);
             } else {
                 return false;
             }
             secondTradeRecordMapper.updateById(record);
 
-//            LifeMessage message = new LifeMessage();
-//            message.setId(messageId);
-//            message.setContent(messageContent);
-//            message.setType("6");
-//            message.setCreatedTime(new Date());
-//            lifeMessageMapper.updateById(message);
-            lifeMessageMapper.deleteById(messageId);
+            // 商品信息
+            SecondGoods goods = secondGoodsMapper.selectById(trade.getGoodsId());
 
-            return true;
-        } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.tradeSignIn Error Mgs={}", e.getMessage());
-            throw new Exception(e);
-        }
-    }
+            // 发送消息
+            sendMsg(goods, trade, 3, "6");
 
-    @Override
-    public boolean tradeConfirm(int tradeId, int type, String evaluate) throws Exception {
-        try {
+            // 封装交易信息
+//            JSONObject message = new JSONObject();
+//            message.put("title", goods.getTitle());
+//            message.put("homeImage", goods.getHomeImage());
+//            message.put("tradeId", trade.getId());
+//            message.put("transactionAmount", trade.getTransactionAmount());
+//            message.put("transactionLatitudeLongitude", trade.getTransactionLatitudeLongitude());
+//            message.put("transactionLatitudeLongitudeAddress", trade.getTransactionLatitudeLongitudeAddress());
+//            message.put("transactionLocation", trade.getTransactionLocation());
+//            message.put("transactionTime", trade.getTransactionTime());
+//            message.put("tradeStatus", 3);
+//
+//            // 发起交易人信息
+////            Integer userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
+//            String phoneId = JwtUtil.getCurrentUserInfo().getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
+//
+//            // 获取交易对方信息
+//            LifeUser lifeUser = lifeUserMapper.selectById(Objects.equals(userId, trade.getBuyerId()) ? trade.getSellerId() : trade.getBuyerId());
+//            String receiverId = "user_" + lifeUser.getUserPhone();
+//
+//            // 消息
+//            LifeMessage lifeMessage = new LifeMessage();
+//            lifeMessage.setSenderId(phoneId);
+//            lifeMessage.setReceiverId(receiverId);
+//            lifeMessage.setType("6");
+//            lifeMessage.setContent(message.toJSONString());
+//            lifeMessageMapper.insert(lifeMessage);
+//
+//            // 给买家与卖家发送交易消息
+//            alienStoreFeign.sendMsgToClientByPhoneId(phoneId, phoneId, receiverId, "message", "6", message.toJSONString(), lifeMessage.getId());
+//            alienStoreFeign.sendMsgToClientByPhoneId(r
+//           eceiverId, phoneId, receiverId, "message", "6", message.toJSONString(), lifeMessage.getId());
 
             return true;
         } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.tradeConfirm Error Mgs={}", e.getMessage());
+            log.error("SecondTradeRecordServiceImpl.tradeSignIn Error Mgs={}", e.getMessage());
             throw new Exception(e);
         }
     }
@@ -193,31 +361,15 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
     }
 
     @Override
-    public boolean goodsTradeConfirm(int goodsId) throws Exception {
-        try {
-            LambdaQueryWrapper<SecondTradeRecord> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.eq(SecondTradeRecord::getGoodsId, goodsId);
-            queryWrapper.in(SecondTradeRecord::getTradeStatus, 0, 1);
-            return secondTradeRecordMapper.selectCount(queryWrapper) == 0;
-        } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.goodsTrade Error Mgs={}", e.getMessage());
-            throw new Exception(e);
-        }
-    }
-
-    @Override
-    public boolean cancelTrade(int tradeId, String cancelReason, String cancelReasonSupplement) throws Exception {
+    public List<SecondTradeRecordVo> getTradeRecord(int sideId) throws Exception {
         try {
             int userId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getInteger("userId");
-            SecondTradeRecord record = new SecondTradeRecord();
-            record.setId(tradeId);
-            record.setTradeStatus(3);
-            record.setCancelUserId(userId);
-            record.setCancelReason(cancelReason);
-            record.setCancelReasonSupplement(cancelReasonSupplement);
-            return secondTradeRecordMapper.updateById(record) > 0;
+            QueryWrapper<SecondTradeRecord> wrapper = new QueryWrapper<>();
+            wrapper.apply("(trade.buyer_id = '" + sideId + "' and trade.seller_id = '" + userId + "') || (trade.buyer_id = '" + userId + "' and trade.seller_id = '" + sideId + "')");
+            wrapper.orderByDesc("trade.created_time");
+            return secondTradeRecordMapper.getTradeRecord(wrapper);
         } catch (Exception e) {
-            log.error("SecondTradeRecordServiceImpl.cancelTrade Error Mgs={}", e.getMessage());
+            log.error("SecondTradeRecordServiceImpl.getTradeRecord Error Mgs={}", e.getMessage());
             throw new Exception(e);
         }
     }