details.html
<form name="goodsForm" action="submit" th:object="${goodsForm}" method="post"> <div class="col-sm-6"> <input type="hidden" name="commodityId" th:value="${goodsForm.commodityId}"/> <h4 class="yh detailsT"><span th:text="${goodsForm.commodityName}">裕道府东北有机小米食用米 粗粮黄小米 五谷杂粮月子米</span></h4> <dl class="dl-horizontal detailsInfo cf"> <dt>零售价:</dt> <dd class="price yh"><i>¥</i><span name="retailPrice" th:text="${goodsForm.retailPrice}">128</span></dd> <dt>运 费 :</dt> <dd>8元</dd> <dt>品 牌:</dt> <dd><span th:text="${goodsForm.brandName}">日思</span></dd> <dt>经销商:</dt> <dd><span th:text="${goodsForm.supplierName}">天津日思优质小站稻开发公司</span></dd> <dt>规 格:</dt> <dd>每<span th:text="${#strings.concat(goodsForm.unit).concat(goodsForm.specifications)}">袋5kg</span></dd> <dt>库 存:</dt> <dd><span th:text="${goodsForm.stock}">99</span></dd> <dt>数 量:</dt> <dd style="height:32px;"> <div class="chooseAmount mt5"> <a onclick="subNum();" href="javascript:void(0)"></a> <input type="text" name="count" id="count" class="fl inp-t" value="1"/> <a onclick="addNum();" href="javascript:void(0)"></a> </div> </dd> </dl> <p class="mt20"><button class="btnBlue yh " name="AlipaySubmit" >立即购买</button><button class="btnYellow yh" name="addCart" >加入购物车</button></p> </div> </form>
DetailsController.java
@RequestMapping(value = "submit", method = RequestMethod.POST,params="AlipaySubmit") public String executeAlipaySubmit(Model model, HttpSession session, GoodsForm goodsForm, CartForm cartForm, Device device) throws SQLException { UVO uvo=(UVO) session.getAttribute("UVO"); //匿名购买 if(uvo == null || StringUtils.isEmpty(uvo.getGuestId())){ GoodsForm goodsForm1=new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm1.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); goodsForm1.setCommodityId(goodsForm.getCommodityId()); model.addAttribute("goodsForm", goodsForm1); model.addAttribute("commodityType", commodityType); cartForm.setGuestId(uvo.getGuestId()); //设置updateTime Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cartForm.setUpdateTime(dateformat.format(date)); //设置updateUser AlipayForm alipayForm=new AlipayForm(); alipayForm=cartService.searchAlipayImmediately(cartForm); cartForm.setUpdateUser(uvo.getGuestName()); if (alipayForm == null) { model.addAttribute("commodityType", commodityType); model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm1)); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("message", "库存不够!"); model.addAttribute("orderlist", goodsService.searchGoodsListOrder()); if(device.isNormal()) { return "shop/goods/details"; } else { return "mobile/goods/details"; } } model.addAttribute("alipayForm",alipayForm); model.addAttribute("cartList", cartService.searchCartList(cartForm)); return "shop/alipay/guestAlipayConfirm"; } //非匿名购买 GoodsForm goodsForm1=new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm1.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); goodsForm1.setCommodityId(goodsForm.getCommodityId()); model.addAttribute("goodsForm", goodsForm1); model.addAttribute("commodityType", commodityType); cartForm.setGuestId(uvo.getGuestId()); //设置updateTime Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cartForm.setUpdateTime(dateformat.format(date)); //设置updateUser cartForm.setUpdateUser(uvo.getGuestName()); ReceiveForm receiveForm=new ReceiveForm(); receiveForm.setGuestId(uvo.getGuestId()); GuestForm guestForm=new GuestForm(); guestForm.setGuestId(uvo.getGuestId()); String addressDefault=guestService.searchAddressId(guestForm).getAddressId(); model.addAttribute("addressDefault", addressDefault); List<ReceiveForm> list=receiveservice.searchlist(receiveForm); model.addAttribute("list", list); // model.addAttribute("cartList", cartService.searchCartList(cartForm)); AlipayForm alipayForm=new AlipayForm(); alipayForm=cartService.searchAlipayImmediately(cartForm); model.addAttribute("alipayForm",alipayForm); if (alipayForm == null) { model.addAttribute("commodityType", commodityType); model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm1)); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("message", "库存不够!"); model.addAttribute("orderlist", goodsService.searchGoodsListOrder()); if(device.isNormal()) { return "shop/goods/details"; } else { return "mobile/goods/details"; } } model.addAttribute("cartList", cartService.searchCartList(cartForm)); return "shop/cart/cart-2"; } @RequestMapping(value = "submit", method = RequestMethod.POST,params="addCart") public String executeAddCart(Model model, HttpSession session, CartForm cartForm, Device device) throws SQLException { log.info("追加购物车"); GoodsForm goodsForm = new GoodsForm(); goodsForm.setCommodityId(cartForm.getCommodityId()); // goodsForm.setType("粮食"); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("commodityType", commodityType); model.addAttribute("goodsForm", goodsService.searchGoods(goodsForm)); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null || StringUtils.isEmpty(uvo.getGuestId()) || uvo.getGuestId().length() > 4) { if (uvo == null || StringUtils.isEmpty(uvo.getGuestId()) || "Guest".equals(uvo.getGuestId().substring(0, 5))) { uvo = new UVO(); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMddHHmmss"); uvo.setUserId("Guest" + dateformat.format(date)); uvo.setGuestId("Guest" + dateformat.format(date)); uvo.setUserName("来宾" + dateformat.format(date)); log.info("匿名购买商品销售页面初始化。"); AlipayForm alipayForm = new AlipayForm(); cartForm.setGuestId(uvo.getGuestId()); alipayForm = cartService.searchAlipay(cartForm); List<CartForm> cartList = new ArrayList<>(); model.addAttribute("cartList", cartList); if (alipayForm == null) { model.addAttribute("message", "库存不够!"); if(device.isNormal()) { return "shop/goods/details"; } else { return "mobile/goods/details"; } } model.addAttribute("alipayForm", alipayForm); if(device.isNormal()) { return "shop/alipay/guestAlipayConfirm"; } else { return "mobile/alipay/guestAlipayConfirm"; } } } cartForm.setUpdateUser(uvo.getGuestName()); Date date = new Date(); SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); cartForm.setUpdateTime(dateformat.format(date)); cartForm.setGuestId(uvo.getGuestId()); AlipayForm alipayForm = new AlipayForm(); alipayForm = cartService.searchAlipay(cartForm); if (alipayForm == null) { model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("message", "库存不够!"); model.addAttribute("orderlist", goodsService.searchGoodsListOrder()); if(device.isNormal()) { return "shop/goods/details"; } else { return "mobile/goods/details"; } } boolean result = cartService.addCart(cartForm); if (!result) { throw new SQLException("追加购物车失败!"); } List<CartForm> cartFormList=cartService.searchCartList(cartForm); for(int i=0;i<cartFormList.size();i++){ BigDecimal smallSumPrice=new BigDecimal(Double.toString(Double.valueOf(cartFormList.get(i).getCount())*Double.valueOf(cartFormList.get(i).getRetailPrice()))); cartFormList.get(i).setSmallSumPrice(String.valueOf(smallSumPrice.setScale(2, BigDecimal.ROUND_HALF_UP))); } model.addAttribute("cartList", cartFormList); model.addAttribute("list", cartService.searchAlipayHistoryList(cartForm)); if(device.isNormal()) { return "shop/cart/cart-1"; } else { return "mobile/cart/cart-1"; } } }
GoodsService.java
public GoodsForm searchGoods(GoodsForm frm) { GoodsForm result = queryDao.executeForObject("Goods.selectGoods", frm, GoodsForm.class); return result; } public List<GoodsForm> searchGoodsListOrder() { List<GoodsForm> result = queryDao.executeForObjectList("Goods.selectGoodsListOder", null,0,4); return result; }
GoodsSqlMap.xml
<select id="selectGoods" parameterClass="cn.agriculture.web.form.GoodsForm" resultClass="cn.agriculture.web.form.GoodsForm"> SELECT commodity.commodity_id as commodityId, commodity.type as commodityTypeId, supplier.supplier_name as supplierName, brand.brand_name as brandName, commodity.commodity_name as commodityName, commodity.weight as weight, commodity.is_gift as isGift, commodity.specifications as specifications, commodity.unit as unit, commodity.benchmark_price as benchmarkPrice, commodity.guide_price as guidePrice, commodity.retail_price as retailPrice, commodity.competition_level as competitionLevel, commodity.note as note, commodity.update_time as updateTime, commodity.update_user as updateUser, commodity.picture_id as pictureId, commodity.picture1_id as pictureId1, commodity.picture2_id as pictureId2, commodity.picture3_id as pictureId3, commodity.picture4_id as pictureId4, commodity.picture5_id as pictureId5, commodity.picture6_id as pictureId6, stock.stock as stock, commodity_type.commodity_type_id as commodityTypeId, commodity_type.commodity_type_name as commodityTypeName FROM commodity, supplier, brand, stock,commodity_type WHERE commodity.commodity_id = stock.commodity_id AND commodity.supplier_id = supplier.supplier_id AND commodity.brand_id = brand.brand_id AND commodity.type = commodity_type.commodity_type_id AND commodity.commodity_id = #commodityId# </select> <select id="selectGoodsListOder" parameterClass="cn.agriculture.web.form.GoodsForm" resultClass="cn.agriculture.web.form.GoodsForm"> SELECT commodity.commodity_id as commodityId, commodity.type as type, commodity_type.commodity_type_id as commodityTypeId, commodity_type.commodity_type_name as commodityTypeName, supplier.supplier_name as supplierName, brand.brand_name as brandName, commodity.commodity_name as commodityName, commodity.weight as weight, commodity.is_gift as isGift, commodity.specifications as specifications, commodity.unit as unit, commodity.benchmark_price as benchmarkPrice, commodity.guide_price as guidePrice, commodity.retail_price as retailPrice, commodity.competition_level as competitionLevel, commodity.note as note, commodity.update_time as updateTime, commodity.update_user as updateUser, commodity.picture_id as pictureId, stock.stock as stock FROM commodity, supplier, brand, stock,commodity_type WHERE commodity.commodity_id = stock.commodity_id AND commodity.supplier_id = supplier.supplier_id AND commodity.brand_id = brand.brand_id AND commodity.type = commodity_type.commodity_type_id ORDER BY cast(stock.stock as signed) DESC </select>
CartService.java
public List<CartForm> searchCartList(CartForm frm) { frm.setStatus("未付款"); List<CartForm> result = queryDao.executeForObjectList("Cart.selectCartList", frm); return result; }
CartSqlMap.xml
<select id="selectCartList" parameterClass="cn.agriculture.web.form.CartForm" resultClass="cn.agriculture.web.form.CartForm"> SELECT cart.cart_id as cartId, cart.guest_id as guestId, cart.count as count, commodity.commodity_id as commodityId, commodity.type as type, supplier.supplier_name as supplierName, brand.brand_name as brandName, commodity.commodity_name as commodityName, commodity.weight as weight, commodity.is_gift as isGift, commodity.specifications as specifications, commodity.unit as unit, commodity.benchmark_price as benchmarkPrice, commodity.guide_price as guidePrice, commodity.retail_price as retailPrice, commodity.competition_level as competitionLevel, commodity.note as note, cart.update_time as updateTime, cart.update_user as updateUser, commodity.picture_id as pictureId FROM cart, commodity, supplier, brand WHERE cart.commodity_id = commodity.commodity_id AND commodity.supplier_id = supplier.supplier_id AND commodity.brand_id = brand.brand_id AND cart.status = #status# AND cart.guest_id = #guestId# </select>