소스 검색

8.1 购物车入参验证

Mechrevo 1 년 전
부모
커밋
1929f5af85

+ 9 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_goods_cart/TbGoodsCartApiController.java

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 
 
 /**
@@ -28,6 +29,13 @@ public class TbGoodsCartApiController {
 		AjaxJson ajaxJson = tbGoodsCartService.addGoodsInShopCart(goodsCartInfoDto);
 		return ajaxJson;
 	}
-	
+
+	/** 清理购物车,可批量 */
+	@RequestMapping("cleanCart")
+	public AjaxJson cleanCart(@RequestBody List<Long> ids){
+		AjaxJson ajaxJson = AjaxJson.getSuccessData(tbGoodsCartService.cleanCart(ids));
+		return ajaxJson;
+	}
+
 
 }

+ 17 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_goods_cart/TbGoodsCartService.java

@@ -5,6 +5,9 @@ import java.util.List;
 
 import com.pj.api.client.admin.AdminInterface;
 import com.pj.api.dto.AppUserDto;
+import com.pj.common.core.exception.ServiceException;
+import com.pj.current.dto.APPLoginUserInfo;
+import com.pj.current.satoken.StpAPPUserUtil;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.enummj.DeleteStatus;
 import com.pj.tb_goods_cart.dto.GoodsCartInfoDto;
@@ -87,7 +90,7 @@ public class TbGoodsCartService extends ServiceImpl<TbGoodsCartMapper, TbGoodsCa
 		//当前商品的单位
 		tbGoodsCart.setGoodsUnit(tbGoodsTransit.getGoodsUnits());
 		//商品价格
-		tbGoodsCart.setTotalPrice((goodsCartInfoDto.getBuyWeight() == null? 0 : goodsCartInfoDto.getBuyWeight())
+		tbGoodsCart.setTotalPrice((goodsCartInfoDto.getBuyWeight() == null? tbGoodsCart.getBuyWeight() : goodsCartInfoDto.getBuyWeight())
 				*
 				(tbGoodsTransit.getPrice() == null? 0 : tbGoodsTransit.getPrice()));
 		//设置基本属性
@@ -102,6 +105,19 @@ public class TbGoodsCartService extends ServiceImpl<TbGoodsCartMapper, TbGoodsCa
 		return AjaxJson.getSuccess("添加购物车成功!");
 	}
 
+	/** 删除购物车,可批量 */
+	public int cleanCart(List<Long> ids){
+		if(ids.size() == 0)return 0;
+		//检查登录
+		APPLoginUserInfo appLoginInfo = StpAPPUserUtil.getAPPLoginInfo();
+		if(appLoginInfo == null || appLoginInfo.getLoginId() == null)
+			throw new ServiceException("当前登录账号信息已失效!");
+		//清理购物车
+		int batchIds = tbGoodsCartMapper.deleteBatchIds(ids);
+		System.out.println("已清空 " + batchIds + " 个商品!");
+		return batchIds;
+	}
+
 	/**
 	 * todo:采购支付,暂时预留
 	 */

+ 1 - 1
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -161,7 +161,7 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
 		if(!StringUtils.isNotBlank(phone) || !StringUtils.isNotBlank(password))
 			return AjaxJson.getError("错误登录!");
 		//登陆查询
-		LambdaQueryWrapper<AppUser> queryWrapper = new LambdaQueryWrapper<>();
+ 		LambdaQueryWrapper<AppUser> queryWrapper = new LambdaQueryWrapper<>();
 		queryWrapper.eq(AppUser::getPhone,phone);
 		queryWrapper.eq(AppUser::getDeleteStatus, DeleteStatus.DELETE_STATUS_ON.getCode()); //未被逻辑删除
 		List<AppUser> userList = appUserMapper.selectList(queryWrapper);