diff --git a/pictures/02ab31d4-b06b-4671-ba70-18c9e2119f81.png b/pictures/02ab31d4-b06b-4671-ba70-18c9e2119f81.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/02ab31d4-b06b-4671-ba70-18c9e2119f81.png differ diff --git a/pictures/0b72f8a7-65e6-4f95-8080-7af7513e73ce.png b/pictures/0b72f8a7-65e6-4f95-8080-7af7513e73ce.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/0b72f8a7-65e6-4f95-8080-7af7513e73ce.png differ diff --git a/pictures/0c39c303-21ee-4d4e-ac31-7f82059de935.png b/pictures/0c39c303-21ee-4d4e-ac31-7f82059de935.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/0c39c303-21ee-4d4e-ac31-7f82059de935.png differ diff --git a/pictures/1f1e33a7-ec89-42d8-bd0c-ae04d1aeb827.png b/pictures/1f1e33a7-ec89-42d8-bd0c-ae04d1aeb827.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/1f1e33a7-ec89-42d8-bd0c-ae04d1aeb827.png differ diff --git a/pictures/20f21a5a-ee51-4ce0-82d4-2eb8b36bf78e.png b/pictures/20f21a5a-ee51-4ce0-82d4-2eb8b36bf78e.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/20f21a5a-ee51-4ce0-82d4-2eb8b36bf78e.png differ diff --git a/pictures/2b03774f-edd1-40c6-8761-b1b9cb76fd0d.png b/pictures/2b03774f-edd1-40c6-8761-b1b9cb76fd0d.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/2b03774f-edd1-40c6-8761-b1b9cb76fd0d.png differ diff --git a/pictures/2d13f692-a37e-4128-bb3e-2768a4d8fe76.png b/pictures/2d13f692-a37e-4128-bb3e-2768a4d8fe76.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/2d13f692-a37e-4128-bb3e-2768a4d8fe76.png differ diff --git a/pictures/358350b9-28fd-4376-8ff7-089a43ae9767.png b/pictures/358350b9-28fd-4376-8ff7-089a43ae9767.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/358350b9-28fd-4376-8ff7-089a43ae9767.png differ diff --git a/pictures/3fded08a-e643-4c66-9c2d-329b93d9eadf.png b/pictures/3fded08a-e643-4c66-9c2d-329b93d9eadf.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/3fded08a-e643-4c66-9c2d-329b93d9eadf.png differ diff --git a/pictures/4029206a-5727-446d-a33d-dcf3f1607201.png b/pictures/4029206a-5727-446d-a33d-dcf3f1607201.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/4029206a-5727-446d-a33d-dcf3f1607201.png differ diff --git a/pictures/4a3a08db-1f30-4ed8-9f28-7a0e491feed2.png b/pictures/4a3a08db-1f30-4ed8-9f28-7a0e491feed2.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/4a3a08db-1f30-4ed8-9f28-7a0e491feed2.png differ diff --git a/pictures/500a1855-8498-4a5d-997f-824058239c77.png b/pictures/500a1855-8498-4a5d-997f-824058239c77.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/500a1855-8498-4a5d-997f-824058239c77.png differ diff --git a/pictures/54797d70-aa13-46ad-a49d-560272e32689.png b/pictures/54797d70-aa13-46ad-a49d-560272e32689.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/54797d70-aa13-46ad-a49d-560272e32689.png differ diff --git a/pictures/54e78461-4956-48db-9eb2-b3676329dad3.png b/pictures/54e78461-4956-48db-9eb2-b3676329dad3.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/54e78461-4956-48db-9eb2-b3676329dad3.png differ diff --git a/pictures/57ab7945-7483-43aa-b206-50ec431b2267.png b/pictures/57ab7945-7483-43aa-b206-50ec431b2267.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/57ab7945-7483-43aa-b206-50ec431b2267.png differ diff --git a/pictures/5e6b100b-694e-4549-a133-9513d35f3e11.png b/pictures/5e6b100b-694e-4549-a133-9513d35f3e11.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/5e6b100b-694e-4549-a133-9513d35f3e11.png differ diff --git a/pictures/5f7dc5a9-f39a-4ab5-9431-62646a775346.png b/pictures/5f7dc5a9-f39a-4ab5-9431-62646a775346.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/5f7dc5a9-f39a-4ab5-9431-62646a775346.png differ diff --git a/pictures/5f97a6bf-fb0c-4e46-ba1f-c587dcbdd8b2.png b/pictures/5f97a6bf-fb0c-4e46-ba1f-c587dcbdd8b2.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/5f97a6bf-fb0c-4e46-ba1f-c587dcbdd8b2.png differ diff --git a/pictures/6021e3eb-8fe8-420a-9edb-812bc3910d5a.png b/pictures/6021e3eb-8fe8-420a-9edb-812bc3910d5a.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/6021e3eb-8fe8-420a-9edb-812bc3910d5a.png differ diff --git a/pictures/6667ac92-2f41-455f-8c49-ff3af2544e0c.png b/pictures/6667ac92-2f41-455f-8c49-ff3af2544e0c.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/6667ac92-2f41-455f-8c49-ff3af2544e0c.png differ diff --git a/pictures/6fe48754-b089-440f-a1c9-6298371fae6a.png b/pictures/6fe48754-b089-440f-a1c9-6298371fae6a.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/6fe48754-b089-440f-a1c9-6298371fae6a.png differ diff --git a/pictures/7a5e1a42-c436-4c35-95e5-b130d7b7d916.png b/pictures/7a5e1a42-c436-4c35-95e5-b130d7b7d916.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/7a5e1a42-c436-4c35-95e5-b130d7b7d916.png differ diff --git a/pictures/7b1e52fd-674d-46ca-8288-6da81c6b5bd5.png b/pictures/7b1e52fd-674d-46ca-8288-6da81c6b5bd5.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/7b1e52fd-674d-46ca-8288-6da81c6b5bd5.png differ diff --git a/pictures/83570b19-1d0e-40f9-937d-f58aebfc1a3a.png b/pictures/83570b19-1d0e-40f9-937d-f58aebfc1a3a.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/83570b19-1d0e-40f9-937d-f58aebfc1a3a.png differ diff --git a/pictures/85ee1a21-d9a9-4926-9007-be4ab3271054.png b/pictures/85ee1a21-d9a9-4926-9007-be4ab3271054.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/85ee1a21-d9a9-4926-9007-be4ab3271054.png differ diff --git a/pictures/89ad8264-076e-4470-a053-b78d0271b945.png b/pictures/89ad8264-076e-4470-a053-b78d0271b945.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/89ad8264-076e-4470-a053-b78d0271b945.png differ diff --git a/pictures/8aa1df20-b93c-4340-b336-0b736b3af9cd.png b/pictures/8aa1df20-b93c-4340-b336-0b736b3af9cd.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/8aa1df20-b93c-4340-b336-0b736b3af9cd.png differ diff --git a/pictures/8c0a1a48-6483-410a-9565-02896fcdcc89.png b/pictures/8c0a1a48-6483-410a-9565-02896fcdcc89.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/8c0a1a48-6483-410a-9565-02896fcdcc89.png differ diff --git a/pictures/8f45e0d4-8606-4c62-8ff3-e27863ad9280.png b/pictures/8f45e0d4-8606-4c62-8ff3-e27863ad9280.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/8f45e0d4-8606-4c62-8ff3-e27863ad9280.png differ diff --git a/pictures/985ede9f-a38e-4c9c-94d6-11b22b272004.png b/pictures/985ede9f-a38e-4c9c-94d6-11b22b272004.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/985ede9f-a38e-4c9c-94d6-11b22b272004.png differ diff --git a/pictures/ae15d76b-d287-42c5-bdfb-6c1a9469b525.png b/pictures/ae15d76b-d287-42c5-bdfb-6c1a9469b525.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/ae15d76b-d287-42c5-bdfb-6c1a9469b525.png differ diff --git a/pictures/b099a833-feee-4b7c-8065-b33b90204493.png b/pictures/b099a833-feee-4b7c-8065-b33b90204493.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/b099a833-feee-4b7c-8065-b33b90204493.png differ diff --git a/pictures/b4fade07-8681-4848-a003-fcc60353e80e.png b/pictures/b4fade07-8681-4848-a003-fcc60353e80e.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/b4fade07-8681-4848-a003-fcc60353e80e.png differ diff --git a/pictures/b88a8de4-f172-43c6-93eb-d9457517c189.png b/pictures/b88a8de4-f172-43c6-93eb-d9457517c189.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/b88a8de4-f172-43c6-93eb-d9457517c189.png differ diff --git a/pictures/bce9c501-8ba7-4e32-a81a-f4bca06a3caa.png b/pictures/bce9c501-8ba7-4e32-a81a-f4bca06a3caa.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/bce9c501-8ba7-4e32-a81a-f4bca06a3caa.png differ diff --git a/pictures/d0e83aba-3ee9-41a4-9bb7-250ef742ffe5.png b/pictures/d0e83aba-3ee9-41a4-9bb7-250ef742ffe5.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/d0e83aba-3ee9-41a4-9bb7-250ef742ffe5.png differ diff --git a/pictures/d500db37-73ab-4988-99f8-39f7231f132b.png b/pictures/d500db37-73ab-4988-99f8-39f7231f132b.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/d500db37-73ab-4988-99f8-39f7231f132b.png differ diff --git a/pictures/d95e60b4-effe-44b8-b1f3-29c2556c9c9e.png b/pictures/d95e60b4-effe-44b8-b1f3-29c2556c9c9e.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/d95e60b4-effe-44b8-b1f3-29c2556c9c9e.png differ diff --git a/pictures/da07c6d7-42d9-48b7-8584-666446f5dcbf.png b/pictures/da07c6d7-42d9-48b7-8584-666446f5dcbf.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/da07c6d7-42d9-48b7-8584-666446f5dcbf.png differ diff --git a/pictures/dcbdd874-4406-4003-bf60-2e03a5b70868.png b/pictures/dcbdd874-4406-4003-bf60-2e03a5b70868.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/dcbdd874-4406-4003-bf60-2e03a5b70868.png differ diff --git a/pictures/dfdeb489-c5d8-46dd-a32a-c39d2568e25e.png b/pictures/dfdeb489-c5d8-46dd-a32a-c39d2568e25e.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/dfdeb489-c5d8-46dd-a32a-c39d2568e25e.png differ diff --git a/pictures/ed2aef5c-e30d-4e34-ae69-d622fe6d0da9.png b/pictures/ed2aef5c-e30d-4e34-ae69-d622fe6d0da9.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/ed2aef5c-e30d-4e34-ae69-d622fe6d0da9.png differ diff --git a/pictures/f0e5c97e-d827-4ed9-a6bc-4ab14b369292.png b/pictures/f0e5c97e-d827-4ed9-a6bc-4ab14b369292.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f0e5c97e-d827-4ed9-a6bc-4ab14b369292.png differ diff --git a/pictures/f5bd42ba-1194-47f2-ba69-55e509082333.png b/pictures/f5bd42ba-1194-47f2-ba69-55e509082333.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f5bd42ba-1194-47f2-ba69-55e509082333.png differ diff --git a/pictures/f6b8153f-b3e7-4f6c-889c-170a29a38c7f.png b/pictures/f6b8153f-b3e7-4f6c-889c-170a29a38c7f.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f6b8153f-b3e7-4f6c-889c-170a29a38c7f.png differ diff --git a/pictures/f731135b-812e-4019-9834-05739f058abb.png b/pictures/f731135b-812e-4019-9834-05739f058abb.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f731135b-812e-4019-9834-05739f058abb.png differ diff --git a/pictures/f80405a6-cfe7-460e-95a3-86c16dd1de32.png b/pictures/f80405a6-cfe7-460e-95a3-86c16dd1de32.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f80405a6-cfe7-460e-95a3-86c16dd1de32.png differ diff --git a/pictures/f902d0e4-0527-49b4-a9f4-e3c5925b211a.png b/pictures/f902d0e4-0527-49b4-a9f4-e3c5925b211a.png new file mode 100644 index 0000000..a487741 Binary files /dev/null and b/pictures/f902d0e4-0527-49b4-a9f4-e3c5925b211a.png differ diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/component/Constants.java b/src/main/java/cn/edu/ecnu/stu/bookstore/component/Constants.java index 07c4fe7..aebbbed 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/component/Constants.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/component/Constants.java @@ -27,4 +27,6 @@ public interface Constants { String BALANCE_ERROR = "余额不足"; String URL_PREFIX = "http://127.0.0.1:8080"; + String ORDER_NON_EXIST_ERROR = "订单不存在"; + String ORDER_HAS_PAID_ERROR = "订单已支付"; } diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java index 7208c49..ddda94c 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java @@ -12,9 +12,9 @@ import java.util.Map; @Mapper public interface OrderMapper { - @Insert("insert into t_order(order_id, buyer_id, from_address, to_address, price, status, store_id, create_time) values " + + @Insert("insert into t_order(order_id, buyer_id, from_address, to_address, price, status, store_id) values " + "(#{order.orderId}, #{order.buyerId}, #{order.fromAddress}, #{order.toAddress}, #{order.price}, #{order.status.value}, " + - "#{order.storeId}, #{order.createTime})") + "#{order.storeId})") int insert(@Param("order")Order order); int insertOrderBook(@Param("orderId") String orderId, @Param("books") List> books); @@ -26,4 +26,6 @@ public interface OrderMapper { void updateOrderStatus(@Param("orderId") String orderId, @Param("status") OrderStatus status); List select(@Param("buyerId") Integer buyerId, @Param("status") OrderStatus status); + + Order selectById(@Param("orderId") String orderId); } diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/StoreMapper.java b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/StoreMapper.java index 1ef1e25..4d36292 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/StoreMapper.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/StoreMapper.java @@ -17,4 +17,8 @@ public interface StoreMapper { @Insert("insert into t_store(store_id, seller_id) values(#{store.storeId}, #{store.sellerId})") int insert(@Param("store") Store store); + + @Select("select store_id, seller_id, create_time from t_store where store_id = #{storeId}") + Store getStoreById(@Param("storeId") String storeId); + } diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/UserMapper.java b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/UserMapper.java index 18a6eac..c590057 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/UserMapper.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/mapper/UserMapper.java @@ -32,5 +32,5 @@ public interface UserMapper { int minusBalance(@Param("userId") int userId, @Param("price") BigDecimal price); @Update("update t_user set balance = balance + #{addValue} where id = #{userId}") - void addFunds(@Param("userId") Integer userId,@Param("addValue") BigDecimal addValue); + void addBalance(@Param("userId") Integer userId,@Param("addValue") BigDecimal addValue); } diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/pojo/Order.java b/src/main/java/cn/edu/ecnu/stu/bookstore/pojo/Order.java index a131638..0953a04 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/pojo/Order.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/pojo/Order.java @@ -1,6 +1,7 @@ package cn.edu.ecnu.stu.bookstore.pojo; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @@ -10,6 +11,7 @@ import java.sql.Date; @Data @NoArgsConstructor @AllArgsConstructor +@Builder public class Order { private String orderId; diff --git a/src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/BuyerService.java b/src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/BuyerService.java index 67d75f6..30a3f53 100644 --- a/src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/BuyerService.java +++ b/src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/BuyerService.java @@ -4,11 +4,9 @@ import cn.edu.ecnu.stu.bookstore.component.AppException; import cn.edu.ecnu.stu.bookstore.component.Constants; import cn.edu.ecnu.stu.bookstore.mapper.BookMapper; import cn.edu.ecnu.stu.bookstore.mapper.OrderMapper; +import cn.edu.ecnu.stu.bookstore.mapper.StoreMapper; import cn.edu.ecnu.stu.bookstore.mapper.UserMapper; -import cn.edu.ecnu.stu.bookstore.pojo.Book; -import cn.edu.ecnu.stu.bookstore.pojo.Order; -import cn.edu.ecnu.stu.bookstore.pojo.OrderStatus; -import cn.edu.ecnu.stu.bookstore.pojo.User; +import cn.edu.ecnu.stu.bookstore.pojo.*; import cn.edu.ecnu.stu.bookstore.pojo.vo.NewOrderVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; @@ -34,6 +32,9 @@ public class BuyerService { private UserMapper userMapper; @Autowired + private StoreMapper storeMapper; + + @Autowired private PasswordEncoder encoder; @Autowired @@ -49,12 +50,16 @@ public class BuyerService { bookMap.put((String) map.get("id"), (Integer) map.get("count")); } String storeId = newOrderVO.getStoreId(); + Store store = storeMapper.getStoreById(storeId); + if(store == null) + throw new AppException(Constants.CLIENT_ERROR, Constants.STORE_NON_EXIST_ERROR); - buyerService.insertOrder(storeId, bookMap, bookList); + buyerService.insertOrder(store, bookMap, bookList); } @Transactional - public void insertOrder(String storeId, HashMap bookMap, List> bookList) { + public void insertOrder(Store store, HashMap bookMap, List> bookList) { + String storeId = store.getStoreId(); List books = bookMapper.batchSelect(storeId, bookMap.keySet()); if(books.size() != bookList.size()) throw new AppException(Constants.CLIENT_ERROR, Constants.BOOK_ERROR); @@ -73,9 +78,11 @@ public class BuyerService { } User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String orderId = UUID.randomUUID().toString(); - Order order = new Order(orderId, user.getId(), null, null, sum, OrderStatus.WAIT_PAYMENT, storeId, null); + Order order = Order.builder().orderId(orderId).buyerId(user.getId()).storeId(storeId) + .price(sum).status(OrderStatus.WAIT_PAYMENT) + .build(); orderMapper.insert(order); - orderMapper.insertOrderBook(order.getOrderId(), list); + orderMapper.insertOrderBook(orderId, list); for (Map map : list) { Book book = (Book)map.get("book"); bookMapper.minusStockLevel(book.getBookId(), (int)map.get("count")); @@ -86,23 +93,29 @@ public class BuyerService { User user = userMapper.selectOneById(userId); if(!encoder.matches(password, user.getPassword())) throw new AppException(Constants.CLIENT_ERROR, Constants.PASSWORD_ERROR); - BigDecimal price = orderMapper.selectPrice(orderId); - if(price.compareTo(user.getBalance()) > 0) + Order order = orderMapper.selectById(orderId); + if(order == null) + throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_NON_EXIST_ERROR); + if(!order.getStatus().equals(OrderStatus.WAIT_PAYMENT)) + throw new AppException(Constants.CLIENT_ERROR, Constants.ORDER_HAS_PAID_ERROR); + if(order.getPrice().compareTo(user.getBalance()) > 0) throw new AppException(Constants.CLIENT_ERROR, Constants.BALANCE_ERROR); - buyerService.updateBalanceAndOrder(orderId, userId, price); + buyerService.updateBalanceAndOrder(storeMapper.getStoreById(order.getStoreId()).getSellerId(), order); } @Transactional - public void updateBalanceAndOrder(String orderId, Integer userId, BigDecimal price) { - orderMapper.updateOrderStatus(orderId, OrderStatus.WAIT_SEND); - userMapper.minusBalance(userId, price); + public void updateBalanceAndOrder(Integer sellerId, Order order) { + orderMapper.updateOrderStatus(order.getOrderId(), OrderStatus.WAIT_SEND); + BigDecimal price = order.getPrice(); + userMapper.minusBalance(order.getBuyerId(), price); + userMapper.addBalance(sellerId, price); } public void addFunds(String username, String password, BigDecimal addValue) { User user = userMapper.selectOneByName(username); if(!encoder.matches(password, user.getPassword())) throw new AppException(Constants.CLIENT_ERROR, Constants.PASSWORD_ERROR); - userMapper.addFunds(user.getId(), addValue); + userMapper.addBalance(user.getId(), addValue); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 671f8b7..d27d583 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,6 +16,6 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource redis: - host: 106.75.98.95 + host: 106.75.116.246 port: 6379 password: qwe030318 diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderMapper.xml index 11ce08f..de4b74f 100644 --- a/src/main/resources/mapper/OrderMapper.xml +++ b/src/main/resources/mapper/OrderMapper.xml @@ -25,4 +25,8 @@ select order_id, buyer_id, from_address, to_address, price, status, store_id, create_time from t_order where buyer_id = #{buyerId} and status = #{status.value} + \ No newline at end of file diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index 1c579d5..0f0f95b 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -4,8 +4,8 @@ - insert into t_user(username, password, balance, address, phone) - values (#{user.username}, #{user.password}, #{user.balance}, #{user.address}, #{user.phone}) + insert into t_user(username, password, address, phone) + values (#{user.username}, #{user.password}, #{user.address}, #{user.phone}) diff --git a/src/test/java/cn/edu/ecnu/stu/bookstore/BuyerTest.java b/src/test/java/cn/edu/ecnu/stu/bookstore/BuyerTest.java index 1c17906..b1c4dc2 100644 --- a/src/test/java/cn/edu/ecnu/stu/bookstore/BuyerTest.java +++ b/src/test/java/cn/edu/ecnu/stu/bookstore/BuyerTest.java @@ -10,7 +10,6 @@ import com.alibaba.fastjson.JSONObject; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import javax.annotation.PostConstruct; import java.math.BigDecimal; import java.util.*;