Skip to content

Commit 6d35c40

Browse files
committed
fix: #341
1 parent 5e0bd4c commit 6d35c40

File tree

12 files changed

+68
-26
lines changed

12 files changed

+68
-26
lines changed

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAddressService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public int update(LitemallAddress address) {
3939
return addressMapper.updateByPrimaryKeySelective(address);
4040
}
4141

42-
public void delete(Integer userId, Integer id) {
43-
LitemallAddressExample example = new LitemallAddressExample();
44-
example.or().andUserIdEqualTo(userId).andIdEqualTo(id).andDeletedEqualTo(false);
45-
addressMapper.logicalDeleteByExample(example);
42+
public void delete(Integer id) {
43+
addressMapper.logicalDeleteByPrimaryKey(id);
4644
}
4745

4846
public LitemallAddress findDefault(Integer userId) {

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallAftersaleService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public LitemallAftersale findById(Integer id) {
2323
return aftersaleMapper.selectByPrimaryKey(id);
2424
}
2525

26+
public LitemallAftersale findById(Integer userId, Integer id) {
27+
LitemallAftersaleExample example = new LitemallAftersaleExample();
28+
example.or().andIdEqualTo(id).andUserIdEqualTo(userId).andDeletedEqualTo(false);
29+
return aftersaleMapper.selectOneByExample(example);
30+
}
31+
2632
public List<LitemallAftersale> queryList(Integer userId, Short status, Integer page, Integer limit, String sort, String order) {
2733
LitemallAftersaleExample example = new LitemallAftersaleExample();
2834
LitemallAftersaleExample.Criteria criteria = example.or();

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCartService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public LitemallCart findById(Integer id) {
5757
return cartMapper.selectByPrimaryKey(id);
5858
}
5959

60+
public LitemallCart findById(Integer userId, Integer id) {
61+
LitemallCartExample example = new LitemallCartExample();
62+
example.or().andUserIdEqualTo(userId).andIdEqualTo(id).andDeletedEqualTo(false);
63+
return cartMapper.selectOneByExample(example);
64+
}
65+
6066
public int updateCheck(Integer userId, List<Integer> idsList, Boolean checked) {
6167
LitemallCartExample example = new LitemallCartExample();
6268
example.or().andUserIdEqualTo(userId).andProductIdIn(idsList).andDeletedEqualTo(false);

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallFootprintService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public LitemallFootprint findById(Integer id) {
2828
return footprintMapper.selectByPrimaryKey(id);
2929
}
3030

31+
public LitemallFootprint findById(Integer userId, Integer id) {
32+
LitemallFootprintExample example = new LitemallFootprintExample();
33+
example.or().andIdEqualTo(id).andUserIdEqualTo(userId).andDeletedEqualTo(false);
34+
return footprintMapper.selectOneByExample(example);
35+
}
36+
3137
public void deleteById(Integer id) {
3238
footprintMapper.logicalDeleteByPrimaryKey(id);
3339
}

litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGrouponService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ public LitemallGroupon queryById(Integer id) {
8080
return mapper.selectOneByExample(example);
8181
}
8282

83+
/**
84+
* 根据ID查询记录
85+
*
86+
* @param userId
87+
* @param id
88+
* @return
89+
*/
90+
public LitemallGroupon queryById(Integer userId, Integer id) {
91+
LitemallGrouponExample example = new LitemallGrouponExample();
92+
example.or().andIdEqualTo(id).andUserIdEqualTo(id).andDeletedEqualTo(false);
93+
return mapper.selectOneByExample(example);
94+
}
95+
8396
/**
8497
* 返回某个发起的团购参与人数
8598
*

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public Object submit(Integer userId, String body) {
289289
return ResponseUtil.fail(GROUPON_JOIN, "团购活动已经参加!");
290290
}
291291
// (2)不允许参加自己开团的团购
292-
LitemallGroupon groupon = grouponService.queryById(grouponLinkId);
292+
LitemallGroupon groupon = grouponService.queryById(userId, grouponLinkId);
293293
if(groupon.getCreatorUserId().equals(userId)){
294294
return ResponseUtil.fail(GROUPON_JOIN, "团购活动已经参加!");
295295
}
@@ -912,6 +912,10 @@ public Object goods(Integer userId, Integer orderId, Integer goodsId) {
912912
if (userId == null) {
913913
return ResponseUtil.unlogin();
914914
}
915+
LitemallOrder order = orderService.findById(userId, orderId);
916+
if (order == null) {
917+
return ResponseUtil.badArgument();
918+
}
915919

916920
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.findByOidAndGid(orderId, goodsId);
917921
int size = orderGoodsList.size();

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,28 @@ public Object save(@LoginUser Integer userId, @RequestBody LitemallAddress addre
133133
return error;
134134
}
135135

136-
if (address.getIsDefault()) {
137-
// 重置其他收货地址的默认选项
138-
addressService.resetDefault(userId);
139-
}
140-
141136
if (address.getId() == null || address.getId().equals(0)) {
137+
if (address.getIsDefault()) {
138+
// 重置其他收货地址的默认选项
139+
addressService.resetDefault(userId);
140+
}
141+
142142
address.setId(null);
143143
address.setUserId(userId);
144144
addressService.add(address);
145145
} else {
146-
address.setUserId(userId);
147-
if (addressService.update(address) == 0) {
148-
return ResponseUtil.updatedDataFailed();
146+
LitemallAddress litemallAddress = addressService.query(userId, address.getId());
147+
if (litemallAddress == null) {
148+
return ResponseUtil.badArgumentValue();
149149
}
150+
151+
if (address.getIsDefault()) {
152+
// 重置其他收货地址的默认选项
153+
addressService.resetDefault(userId);
154+
}
155+
156+
address.setUserId(userId);
157+
addressService.update(address);
150158
}
151159
return ResponseUtil.ok(address.getId());
152160
}
@@ -167,8 +175,12 @@ public Object delete(@LoginUser Integer userId, @RequestBody LitemallAddress add
167175
if (id == null) {
168176
return ResponseUtil.badArgument();
169177
}
178+
LitemallAddress litemallAddress = addressService.query(userId, id);
179+
if (litemallAddress == null) {
180+
return ResponseUtil.badArgumentValue();
181+
}
170182

171-
addressService.delete(userId, id);
183+
addressService.delete(id);
172184
return ResponseUtil.ok();
173185
}
174186
}

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAftersaleController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public Object detail(@LoginUser Integer userId, @NotNull Integer orderId) {
9494
}
9595

9696
LitemallOrder order = orderService.findById(userId, orderId);
97+
if (order == null){
98+
return ResponseUtil.badArgumentValue();
99+
}
97100
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
98101
LitemallAftersale aftersale = aftersaleService.findByOrderId(userId, orderId);
99102

@@ -129,9 +132,6 @@ public Object submit(@LoginUser Integer userId, @RequestBody LitemallAftersale a
129132
if(order == null){
130133
return ResponseUtil.badArgumentValue();
131134
}
132-
if(!order.getUserId().equals(userId)){
133-
return ResponseUtil.badArgumentValue();
134-
}
135135

136136
// 订单必须完成才能进入售后流程。
137137
if(!OrderUtil.isConfirmStatus(order) && !OrderUtil.isAutoConfirmStatus(order)){
@@ -177,7 +177,7 @@ public Object cancel(@LoginUser Integer userId, @RequestBody LitemallAftersale a
177177
if(id == null){
178178
return ResponseUtil.badArgument();
179179
}
180-
LitemallAftersale aftersaleOne = aftersaleService.findById(id);
180+
LitemallAftersale aftersaleOne = aftersaleService.findById(userId, id);
181181
if(aftersaleOne == null){
182182
return ResponseUtil.badArgument();
183183
}

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ public Object update(@LoginUser Integer userId, @RequestBody LitemallCart cart)
258258
if (userId == null) {
259259
return ResponseUtil.unlogin();
260260
}
261-
if (cart == null) {
262-
return ResponseUtil.badArgument();
263-
}
264261
Integer productId = cart.getProductId();
265262
Integer number = cart.getNumber().intValue();
266263
Integer goodsId = cart.getGoodsId();
@@ -274,7 +271,7 @@ public Object update(@LoginUser Integer userId, @RequestBody LitemallCart cart)
274271

275272
//判断是否存在该订单
276273
// 如果不存在,直接返回错误
277-
LitemallCart existCart = cartService.findById(id);
274+
LitemallCart existCart = cartService.findById(userId, id);
278275
if (existCart == null) {
279276
return ResponseUtil.badArgumentValue();
280277
}
@@ -448,7 +445,7 @@ public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addres
448445
if (cartId == null || cartId.equals(0)) {
449446
checkedGoodsList = cartService.queryByUidAndChecked(userId);
450447
} else {
451-
LitemallCart cart = cartService.findById(cartId);
448+
LitemallCart cart = cartService.findById(userId, cartId);
452449
if (cart == null) {
453450
return ResponseUtil.badArgumentValue();
454451
}

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCouponController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Object selectlist(@LoginUser Integer userId, Integer cartId, Integer grou
139139
if (cartId == null || cartId.equals(0)) {
140140
checkedGoodsList = cartService.queryByUidAndChecked(userId);
141141
} else {
142-
LitemallCart cart = cartService.findById(cartId);
142+
LitemallCart cart = cartService.findById(userId, cartId);
143143
if (cart == null) {
144144
return ResponseUtil.badArgumentValue();
145145
}

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxFootprintController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Object delete(@LoginUser Integer userId, @RequestBody String body) {
5454
if (footprintId == null) {
5555
return ResponseUtil.badArgument();
5656
}
57-
LitemallFootprint footprint = footprintService.findById(footprintId);
57+
LitemallFootprint footprint = footprintService.findById(userId, footprintId);
5858

5959
if (footprint == null) {
6060
return ResponseUtil.badArgumentValue();

litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxGrouponController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Object detail(@LoginUser Integer userId, @NotNull Integer grouponId) {
8787
return ResponseUtil.unlogin();
8888
}
8989

90-
LitemallGroupon groupon = grouponService.queryById(grouponId);
90+
LitemallGroupon groupon = grouponService.queryById(userId, grouponId);
9191
if (groupon == null) {
9292
return ResponseUtil.badArgumentValue();
9393
}

0 commit comments

Comments
 (0)