新增小程序当前商品在购物车中的数量输出,用于前端显示“选规格”红色角标
| | |
| | | String cartIds = request.getParameter("key"); |
| | | |
| | | //Integer cartId = (request.getParameter("key") == null ? 0 : Integer.parseInt(request.getParameter("key"))); |
| | | cartIfc.delCart(cartIds); |
| | | final String matCodes = cartIfc.delCart(cartIds); |
| | | List<CartEntity> cartList = cartIfc.getCartList(userCode, sessionId, openId, cltCode, shopCcCodeEntity.getShopCcCode()); // 重新取一次数,确保购物车显示正确 |
| | | /******** 购物车 开始清单输出 *************/ |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | |
| | | json.addProperty("matcodetotal", totalAmount + ""); //购物车页面使用 /shopping/mobile/cart/index.jsp |
| | | json.addProperty("totalamount", sumTotalAmount + ""); //购物车页面使用 /shopping/mobile/cart/index.jsp |
| | | json.addProperty("cart-num", (cartList != null ? cartList.size() : 0)); |
| | | |
| | | //输出当前商品的记录条数和数量 |
| | | List<CartEntity> matCodeEntityForMatCode = cartList.stream().filter((CartEntity c) -> c.getMatCode().equals(matCodes)).collect(Collectors.toList()); |
| | | CartEntity cartEntityForMatCode = matCodeEntityForMatCode != null && matCodeEntityForMatCode.size() > 0 ? matCodeEntityForMatCode.get(0) : null; |
| | | json.addProperty("CartRowCountForMatCode",cartEntityForMatCode!=null? cartEntityForMatCode.getCartRowCountForMatCode():0); //当前商品的记录条数 |
| | | json.addProperty("CartQuantitySumForMatCode", cartEntityForMatCode!=null?cartEntityForMatCode.getCartQuantitySumForMatCode():0); //当前商品的数量 |
| | | json.addProperty("CartQuantity", 0); //当前商品在购物车中的数量,当前购物车已经删除,必须输出 0 |
| | | |
| | | |
| | | this.printJson(response, json.toString()); |
| | | } catch (Exception e) { |
| | |
| | | String wxQueryString = SettingKey.getQueryStringByWx(request); |
| | | boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request); |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | Integer myCartId = null ; |
| | | try { |
| | | DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request); |
| | | SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源 |
| | | SettingEntity settingEntity = settingIfc.getSettingEntity(); |
| | | //取网店 shopcccode |
| | | ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity, request); |
| | | |
| | | |
| | | Map<String, String[]> params = request.getParameterMap(); |
| | | for (String key : params.keySet()) { |
| | | if (!key.startsWith("quantity")) { |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | myCartId = cartId; |
| | | cartIfc.updateCartQuantity(cartId, quantity, cltCode); |
| | | |
| | | json.addProperty("CartId", cartId); |
| | | } |
| | | |
| | |
| | | json.addProperty("matcodetotal", totalAmount + ""); //购物车页面使用 /shopping/mobile/cart/index.jsp |
| | | json.addProperty("totalamount", sumTotalAmount + ""); //购物车页面使用 /shopping/mobile/cart/index.jsp |
| | | json.addProperty("cart-num", (cartList != null ? cartList.size() : 0)); |
| | | |
| | | final Integer cartId = myCartId; |
| | | //输出当前商品的记录条数和数量 |
| | | List<CartEntity> matCodeEntityForMatCode = cartList.stream().filter((CartEntity c) -> c.getCartId().equals(cartId)).collect(Collectors.toList()); |
| | | CartEntity cartEntityForMatCode = matCodeEntityForMatCode != null && matCodeEntityForMatCode.size() > 0 ? matCodeEntityForMatCode.get(0) : null; |
| | | json.addProperty("CartRowCountForMatCode",cartEntityForMatCode!=null? cartEntityForMatCode.getCartRowCountForMatCode():0); //当前商品的记录条数 |
| | | json.addProperty("CartQuantitySumForMatCode", cartEntityForMatCode!=null?cartEntityForMatCode.getCartQuantitySumForMatCode():0); //当前商品的数量 |
| | | json.addProperty("CartQuantity", cartEntityForMatCode!=null?cartEntityForMatCode.getQuantity():0); //当前商品在购物车中的数量 |
| | | |
| | | this.printJson(response, json.toString()); |
| | | return; |
| | | } else { |
| | | SettingKey.setCartHintMsg(session, "您已成功更新了购物车!"); |
| | | String url = "<script language=\"javascript\" type=\"text/javascript\">window.location.href=\"" + hostUrl |
| | |
| | | json.addProperty("CartId", cartId); |
| | | |
| | | //输出当前商品的记录条数和数量 |
| | | List<CartEntity> matCodeEntityForMatCode = cartList.stream().filter((CartEntity c) -> c.getMatCode().equals(matCode)).collect(Collectors.toList()); |
| | | List<CartEntity> matCodeEntityForMatCode = cartList.stream().filter((CartEntity c) -> c.getCartId().equals(cartId)).collect(Collectors.toList()); |
| | | CartEntity cartEntityForMatCode = matCodeEntityForMatCode != null && matCodeEntityForMatCode.size() > 0 ? matCodeEntityForMatCode.get(0) : null; |
| | | json.addProperty("CartRowCountForMatCode",cartEntityForMatCode!=null? cartEntityForMatCode.getCartRowCount():0); |
| | | json.addProperty("CartQuantitySumForMatCode", cartEntityForMatCode!=null?cartEntityForMatCode.getCartQuantitySum():0); |
| | | json.addProperty("CartRowCountForMatCode",cartEntityForMatCode!=null? cartEntityForMatCode.getCartRowCountForMatCode():0); |
| | | json.addProperty("CartQuantitySumForMatCode", cartEntityForMatCode!=null?cartEntityForMatCode.getCartQuantitySumForMatCode():0); |
| | | json.addProperty("CartQuantity", cartEntityForMatCode!=null?cartEntityForMatCode.getQuantity():0); //当前 cartid 的购物车数量 |
| | | |
| | | this.printJson(response, json.toString()); |
| | | return; |
| | |
| | | * @param cartIds |
| | | * @return |
| | | */ |
| | | public Integer delCart(String cartIds) ; |
| | | public String delCart(String cartIds) ; |
| | | |
| | | /** |
| | | * 清空购物车 |
| | |
| | | * @param cltCode |
| | | * @return |
| | | */ |
| | | public Integer updateCartQuantity(Integer cartId, double quantity,String cltCode); |
| | | public String updateCartQuantity(Integer cartId, double quantity,String cltCode); |
| | | |
| | | /** |
| | | * 刷新购物车中的价格、积分和重量 |
| | |
| | | + " skuId1 int,skuName1 varchar(50),skuId2 int,skuName2 varchar(50),skuId3 int,skuName3 varchar(50),skuId4 int,skuName4 varchar(50)," |
| | | + " skuId5 int,skuName5 varchar(50),skuId6 int,skuName6 varchar(50),skuId7 int,skuName7 varchar(50),skuId8 int,skuName8 varchar(50)," |
| | | + " skuId9 int,skuName9 varchar(50),skuId10 int,skuName10 varchar(50),isRestrictQuantity int,RestrictQuantity money, \n" |
| | | + " CartRowCountForMatCode int,CartQuantitySumForMatCode money) ; \n" |
| | | + " CartRowCountForMatCode int,CartQuantitySumForMatCode money, \n" |
| | | + " index index1 (matcode) ) ; \n" |
| | | |
| | | + " insert into @table( CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n" |
| | | + " Special,PhotoPath,PhotoPathUrl,BaseUomWeight,RecurringId,OptionJson,OptionText,\n" |
| | |
| | | |
| | | List<Map<String,Object>> list = null ; |
| | | try { |
| | | //System.out.println(getClass() + " sql: " + sql ) ; |
| | | list = this.jdbcTemplate.queryForList(sql,userCode,sessionId,openId,cltCode,shopCcCode) ; |
| | | |
| | | List<CartEntity> cartList = new ArrayList<CartEntity>() ; |
| | |
| | | cart.setCartQuantitySum(map.get("CartQuantitySum") == null ? 0: Double.parseDouble(map.get("CartQuantitySum").toString())); |
| | | cart.setIsRestrictQuantity(map.get("isRestrictQuantity") == null? 0: (Integer)map.get("isRestrictQuantity")); |
| | | cart.setRestrictQuantity(map.get("RestrictQuantity") == null ? 0: Double.parseDouble(map.get("RestrictQuantity").toString())); |
| | | cart.setCartRowCountForMatCode(map.get("CartRowCountForMatCode") == null ?0: (Integer)map.get("CartRowCountForMatCode")); |
| | | cart.setCartQuantitySumForMatCode(map.get("CartQuantitySumForMatCode") == null ? 0: Double.parseDouble(map.get("CartQuantitySumForMatCode").toString())); |
| | | } |
| | | return cart; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer delCart(String cartIds) { |
| | | public String delCart(String cartIds) { |
| | | String sql = " set nocount on ; \n" |
| | | + " delete from t710205 where CartId in (select list from getinstr(?) as a ) ; \n" |
| | | + " select @@rowcount ; \n"; |
| | | |
| | | Integer ret = null ; |
| | | + " declare @cartIds varchar(max) = ?, @matCodes varchar(max) \n" |
| | | + " select @matCodes = isnull(@matCodes,'') + case when isnull(@matCodes,'') = '' then '' else ',' end + isnull(matcode,'') \n" |
| | | + " from t710205 where CartId in (select list from getinstr(@cartIds) as a ) \n" |
| | | + " delete from t710205 where CartId in (select list from getinstr(@cartIds) as a ) ; \n" |
| | | + " select isnull(@matCodes,'') as MatCodes ; \n"; |
| | | try { |
| | | ret = this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[] { cartIds}) ; |
| | | return this.jdbcTemplate.queryForObject(sql, String.class, new Object[] { cartIds}) ; |
| | | }catch(DataAccessException e ) { |
| | | if (e instanceof EmptyResultDataAccessException){ |
| | | return null ; |
| | |
| | | e.printStackTrace(); |
| | | throw e; |
| | | } |
| | | return ret ; |
| | | } |
| | | |
| | | |
| | |
| | | return ret ; |
| | | } |
| | | @Override |
| | | public Integer updateCartQuantity(Integer cartId,double quantity,String cltCode) { |
| | | public String updateCartQuantity(Integer cartId,double quantity,String cltCode) { |
| | | String sql = " set nocount on ; \n" |
| | | + " declare @myrowcount int ,@Quantity money = ?,@CartId int = ? \n" |
| | | + " declare @myrowcount int ,@Quantity money = ?,@CartId int = ? ,@MatCode varchar(50) \n" |
| | | + " update a set Quantity = @Quantity from t710205 a where CartId = @CartId \n" |
| | | + " select @myrowcount = @@rowcount \n" |
| | | + " exec p710205v8 @CartId = @CartId \n" //刷新购物车中的价格、积分和重量 |
| | | + " select @myrowcount ; \n"; |
| | | + " select @MatCode = MatCode from t710205 where CartId = @CartId ; \n" |
| | | + " select isnull(@MatCode,'') as MatCode \n"; |
| | | |
| | | Integer ret = null ; |
| | | try { |
| | | //System.out.println(this.getClass()+ " start updateCartQuantity: SpObserver.getCurrentInstance():" +SpObserver.getCurrentInstance()+" SessionKey.SHOPPING_DBID:"+dbId ); |
| | | ret = this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {quantity,cartId}) ; |
| | | return this.jdbcTemplate.queryForObject(sql, String.class,new Object[] {quantity,cartId}) ; |
| | | }catch(DataAccessException e ) { |
| | | if (e instanceof EmptyResultDataAccessException){ |
| | | return null ; |
| | |
| | | } |
| | | //刷新购物车中的价格、积分和重量 |
| | | //this.refrshCart(cartId,cltCode); |
| | | |
| | | return ret ; |
| | | } |
| | | |
| | | @Override |