Commit a34a95f8 authored by youc's avatar youc
Browse files

Merge branch 'master' of https://gitee.com/youc-project/litemall

parents f9f41412 a697e696
......@@ -14,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -32,9 +33,9 @@ public class WxCartController {
@Autowired
private LitemallProductService productService;
@Autowired
private LitemallGoodsSpecificationService goodsSpecificationService;
@Autowired
private LitemallAddressService addressService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
/**
* 购物车
......@@ -55,7 +56,7 @@ public class WxCartController {
*/
@GetMapping("index")
public Object index(@LoginUser Integer userId) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
......@@ -103,17 +104,17 @@ public class WxCartController {
*/
@PostMapping("add")
public Object add(@LoginUser Integer userId, @RequestBody LitemallCart cart) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
if(cart == null){
if (cart == null) {
return ResponseUtil.badArgument();
}
Integer productId = cart.getProductId();
Integer number = cart.getNumber().intValue();
Integer goodsId = cart.getGoodsId();
if(!ObjectUtils.allNotNull(productId, number, goodsId)){
if (!ObjectUtils.allNotNull(productId, number, goodsId)) {
return ResponseUtil.badArgument();
}
......@@ -126,9 +127,9 @@ public class WxCartController {
LitemallProduct product = productService.findById(productId);
//判断购物车中是否存在此规格商品
LitemallCart existCart = cartService.queryExist(goodsId, productId, userId);
if(existCart == null){
if (existCart == null) {
//取得规格的信息,判断规格库存
if(product == null || number > product.getNumber() ){
if (product == null || number > product.getNumber()) {
return ResponseUtil.fail(400, "库存不足");
}
......@@ -140,15 +141,15 @@ public class WxCartController {
cart.setSpecifications(product.getSpecifications());
cart.setUserId(userId);
cart.setChecked(true);
cart.setAddTime(LocalDateTime.now());
cartService.add(cart);
}
else{
} else {
//取得规格的信息,判断规格库存
int num = existCart.getNumber() + number;
if(num > product.getNumber()){
if (num > product.getNumber()) {
return ResponseUtil.fail(400, "库存不足");
}
existCart.setNumber((short)num);
existCart.setNumber((short) num);
cartService.update(existCart);
}
......@@ -157,7 +158,7 @@ public class WxCartController {
/**
* 立即购买商品
*
* <p>
* 和 前面一个方法add的区别在于
* 1. 如果购物车内已经存在购物车货品,前者的逻辑是数量添加,这里的逻辑是数量覆盖
* 2. 添加成功以后,前者的逻辑是返回当前购物车商品数量,这里的逻辑是返回对应购物车项的ID
......@@ -175,17 +176,17 @@ public class WxCartController {
*/
@PostMapping("fastadd")
public Object fastadd(@LoginUser Integer userId, @RequestBody LitemallCart cart) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
if(cart == null){
if (cart == null) {
return ResponseUtil.badArgument();
}
Integer productId = cart.getProductId();
Integer number = cart.getNumber().intValue();
Integer goodsId = cart.getGoodsId();
if(!ObjectUtils.allNotNull(productId, number, goodsId)){
if (!ObjectUtils.allNotNull(productId, number, goodsId)) {
return ResponseUtil.badArgument();
}
......@@ -198,9 +199,9 @@ public class WxCartController {
LitemallProduct product = productService.findById(productId);
//判断购物车中是否存在此规格商品
LitemallCart existCart = cartService.queryExist(goodsId, productId, userId);
if(existCart == null){
if (existCart == null) {
//取得规格的信息,判断规格库存
if(product == null || number > product.getNumber() ){
if (product == null || number > product.getNumber()) {
return ResponseUtil.fail(400, "库存不足");
}
......@@ -213,14 +214,13 @@ public class WxCartController {
cart.setUserId(userId);
cart.setChecked(true);
cartService.add(cart);
}
else{
} else {
//取得规格的信息,判断规格库存
int num = number;
if(num > product.getNumber()){
if (num > product.getNumber()) {
return ResponseUtil.fail(400, "库存不足");
}
existCart.setNumber((short)num);
existCart.setNumber((short) num);
cartService.update(existCart);
}
......@@ -239,32 +239,32 @@ public class WxCartController {
*/
@PostMapping("update")
public Object update(@LoginUser Integer userId, @RequestBody LitemallCart cart) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
if(cart == null){
if (cart == null) {
return ResponseUtil.badArgument();
}
Integer productId = cart.getProductId();
Integer number = cart.getNumber().intValue();
Integer goodsId = cart.getGoodsId();
Integer id = cart.getId();
if(!ObjectUtils.allNotNull(id, productId, number, goodsId)){
if (!ObjectUtils.allNotNull(id, productId, number, goodsId)) {
return ResponseUtil.badArgument();
}
//判断是否存在该订单
// 如果不存在,直接返回错误
LitemallCart existCart = cartService.findById(id);
if(existCart == null){
if (existCart == null) {
return ResponseUtil.badArgumentValue();
}
// 判断goodsId和productId是否与当前cart里的值一致
if(!existCart.getGoodsId().equals(goodsId)){
if (!existCart.getGoodsId().equals(goodsId)) {
return ResponseUtil.badArgumentValue();
}
if(!existCart.getProductId().equals(productId)){
if (!existCart.getProductId().equals(productId)) {
return ResponseUtil.badArgumentValue();
}
......@@ -276,7 +276,7 @@ public class WxCartController {
//取得规格的信息,判断规格库存
LitemallProduct product = productService.findById(productId);
if(product == null || product.getNumber() < number){
if (product == null || product.getNumber() < number) {
return ResponseUtil.fail(403, "库存不足");
}
......@@ -302,20 +302,20 @@ public class WxCartController {
*/
@PostMapping("checked")
public Object checked(@LoginUser Integer userId, @RequestBody String body) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
if(body == null){
if (body == null) {
return ResponseUtil.badArgument();
}
List<Integer> productIds = JacksonUtil.parseIntegerList(body, "productIds");
if(productIds == null){
if (productIds == null) {
return ResponseUtil.badArgument();
}
Integer checkValue = JacksonUtil.parseInteger(body, "isChecked");
if(checkValue == null){
if (checkValue == null) {
return ResponseUtil.badArgument();
}
Boolean isChecked = (checkValue == 1);
......@@ -340,16 +340,16 @@ public class WxCartController {
*/
@PostMapping("delete")
public Object delete(@LoginUser Integer userId, @RequestBody String body) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
if(body == null){
if (body == null) {
return ResponseUtil.badArgument();
}
List<Integer> productIds = JacksonUtil.parseIntegerList(body, "productIds");
if(productIds == null || productIds.size() == 0){
if (productIds == null || productIds.size() == 0) {
return ResponseUtil.badArgument();
}
......@@ -373,13 +373,13 @@ public class WxCartController {
*/
@GetMapping("goodscount")
public Object goodscount(@LoginUser Integer userId) {
if(userId == null){
if (userId == null) {
return ResponseUtil.ok(0);
}
int goodsCount = 0;
List<LitemallCart> cartList = cartService.queryByUid(userId);
for(LitemallCart cart : cartList){
for (LitemallCart cart : cartList) {
goodsCount += cart.getNumber();
}
......@@ -419,31 +419,29 @@ public class WxCartController {
* 失败则 { errno: XXX, errmsg: XXX }
*/
@GetMapping("checkout")
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId) {
if(userId == null){
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer grouponRulesId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
// 收货地址
LitemallAddress checkedAddress = null;
if(addressId == null || addressId.equals(0)){
if (addressId == null || addressId.equals(0)) {
checkedAddress = addressService.findDefault(userId);
// 如果仍然没有地址,则是没有收获地址
// 返回一个空的地址id=0,这样前端则会提醒添加地址
if(checkedAddress == null){
if (checkedAddress == null) {
checkedAddress = new LitemallAddress();
checkedAddress.setId(0);
addressId = 0;
}
else{
} else {
addressId = checkedAddress.getId();
}
}
else {
} else {
checkedAddress = addressService.findById(addressId);
// 如果null, 则报错
if(checkedAddress == null){
if (checkedAddress == null) {
return ResponseUtil.badArgumentValue();
}
}
......@@ -452,14 +450,20 @@ public class WxCartController {
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 商品价格
List<LitemallCart> checkedGoodsList = null;
if(cartId == null || cartId.equals(0)) {
if (cartId == null || cartId.equals(0)) {
checkedGoodsList = cartService.queryByUidAndChecked(userId);
}
else {
} else {
LitemallCart cart = cartService.findById(cartId);
if (cart == null){
if (cart == null) {
return ResponseUtil.badArgumentValue();
}
checkedGoodsList = new ArrayList<>(1);
......@@ -467,8 +471,13 @@ public class WxCartController {
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
for (LitemallCart cart : checkedGoodsList) {
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(cart.getGoodsId())) {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().subtract(grouponPrice).multiply(new BigDecimal(cart.getNumber())));
} else {
checkedGoodsPrice = checkedGoodsPrice.add(cart.getPrice().multiply(new BigDecimal(cart.getNumber())));
}
}
// 根据订单商品总价计算运费,满88则免运费,否则8元;
BigDecimal freightPrice = new BigDecimal(0.00);
......@@ -485,6 +494,7 @@ public class WxCartController {
Map<String, Object> data = new HashMap<>();
data.put("addressId", addressId);
data.put("grouponRulesId", grouponRulesId);
data.put("checkedAddress", checkedAddress);
data.put("couponId", couponId);
data.put("checkedCoupon", 0);
......@@ -514,7 +524,7 @@ public class WxCartController {
*/
@GetMapping("checkedCouponList")
public Object checkedCouponList(@LoginUser Integer userId) {
if(userId == null){
if (userId == null) {
return ResponseUtil.unlogin();
}
return ResponseUtil.unsupport();
......
......@@ -3,6 +3,7 @@ package org.linlinjava.litemall.wx.web;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallCategory;
import org.linlinjava.litemall.db.service.LitemallCategoryService;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -80,6 +81,12 @@ public class WxCatalogController {
*/
@GetMapping("all")
public Object queryAll() {
//优先从缓存中读取
if (HomeCacheManager.hasData(HomeCacheManager.CATALOG)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.CATALOG));
}
// 所有一级分类目录
List<LitemallCategory> l1CatList = categoryService.queryL1();
......@@ -105,6 +112,9 @@ public class WxCatalogController {
data.put("allList", allList);
data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory);
//缓存数据
HomeCacheManager.loadData(HomeCacheManager.CATALOG, data);
return ResponseUtil.ok(data);
}
......
......@@ -10,6 +10,7 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -54,6 +55,8 @@ public class WxGoodsController {
private LitemallSearchHistoryService searchHistoryService;
@Autowired
private LitemallGoodsSpecificationService goodsSpecificationService;
@Autowired
private LitemallGrouponRulesService rulesService;
/**
......@@ -123,6 +126,9 @@ public class WxGoodsController {
commentList.put("count", commentCount);
commentList.put("data", commentsVo);
//团购信息
List<LitemallGrouponRules> rules = rulesService.queryByGoodsId(id);
// 用户收藏
int userHasCollect = 0;
if (userId != null) {
......@@ -147,10 +153,10 @@ public class WxGoodsController {
data.put("productList", productList);
data.put("attribute", goodsAttributeList);
data.put("brand", brand);
data.put("groupon", rules);
//商品分享图片地址
data.put("shareImage", info.getShareUrl());
return ResponseUtil.ok(data);
}
......@@ -231,7 +237,7 @@ public class WxGoodsController {
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size,
@Sort(accepts = {"add_time", "retail_price"}) @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order){
@Order @RequestParam(defaultValue = "desc") String order) {
//添加到搜索历史
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
......
package org.linlinjava.litemall.wx.web;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.db.util.OrderUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/wx/groupon")
@Validated
public class WxGrouponController {
@Autowired
private LitemallGrouponRulesService rulesService;
@Autowired
private LitemallGrouponService grouponService;
@Autowired
private LitemallGoodsService goodsService;
@Autowired
private LitemallOrderService orderService;
@Autowired
private LitemallOrderGoodsService orderGoodsService;
@Autowired
private LitemallUserService userService;
@GetMapping("detail")
public Object detail(@LoginUser Integer userId, @NotNull Integer grouponId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
LitemallGroupon groupon = grouponService.queryById(grouponId);
if (groupon == null) {
return ResponseUtil.badArgumentValue();
}
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
if (rules == null) {
return ResponseUtil.badArgumentValue();
}
// 订单信息
LitemallOrder order = orderService.findById(groupon.getOrderId());
if (null == order) {
return ResponseUtil.fail(403, "订单不存在");
}
if (!order.getUserId().equals(userId)) {
return ResponseUtil.fail(403, "不是当前用户的订单");
}
Map<String, Object> orderVo = new HashMap<String, Object>();
orderVo.put("id", order.getId());
orderVo.put("orderSn", order.getOrderSn());
orderVo.put("addTime", LocalDate.now());
orderVo.put("consignee", order.getConsignee());
orderVo.put("mobile", order.getMobile());
orderVo.put("address", order.getAddress());
orderVo.put("goodsPrice", order.getGoodsPrice());
orderVo.put("freightPrice", order.getFreightPrice());
orderVo.put("actualPrice", order.getActualPrice());
orderVo.put("orderStatusText", OrderUtil.orderStatusText(order));
orderVo.put("handleOption", OrderUtil.build(order));
orderVo.put("expCode", order.getShipChannel());
orderVo.put("expNo", order.getShipSn());
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
List<Map<String, Object>> orderGoodsVoList = new ArrayList<>(orderGoodsList.size());
for (LitemallOrderGoods orderGoods : orderGoodsList) {
Map<String, Object> orderGoodsVo = new HashMap<>();
orderGoodsVo.put("id", orderGoods.getId());
orderGoodsVo.put("orderId", orderGoods.getOrderId());
orderGoodsVo.put("goodsId", orderGoods.getGoodsId());
orderGoodsVo.put("goodsName", orderGoods.getGoodsName());
orderGoodsVo.put("number", orderGoods.getNumber());
orderGoodsVo.put("retailPrice", orderGoods.getPrice());
orderGoodsVo.put("picUrl", orderGoods.getPicUrl());
orderGoodsVo.put("goodsSpecificationValues", orderGoods.getSpecifications());
orderGoodsVoList.add(orderGoodsVo);
}
Map<String, Object> result = new HashMap<>();
result.put("orderInfo", orderVo);
result.put("orderGoods", orderGoodsVoList);
UserVo creator = userService.findUserVoById(groupon.getCreatorUserId());
List<UserVo> joiners = new ArrayList<>();
joiners.add(creator);
int linkGrouponId;
// 这是一个团购发起记录
if (groupon.getGrouponId() == 0) {
linkGrouponId = groupon.getId();
} else {
linkGrouponId = groupon.getGrouponId();
}
List<LitemallGroupon> groupons = grouponService.queryJoiners(linkGrouponId);
UserVo joiner;
for (LitemallGroupon grouponItem : groupons) {
joiner = userService.findUserVoById(grouponItem.getUserId());
joiners.add(joiner);
}
result.put("linkGrouponId", linkGrouponId);
result.put("creator", creator);
result.put("joiners", joiners);
result.put("groupon", groupon);
result.put("rules", rules);
return ResponseUtil.ok(result);
}
@GetMapping("join")
public Object join(@NotNull Integer grouponId) {
LitemallGroupon groupon = grouponService.queryById(grouponId);
if (groupon == null) {
return ResponseUtil.badArgumentValue();
}
LitemallGrouponRules rules = rulesService.queryById(groupon.getRulesId());
if (rules == null) {
return ResponseUtil.badArgumentValue();
}
LitemallGoods goods = goodsService.findById(rules.getGoodsId());
if (goods == null) {
return ResponseUtil.badArgumentValue();
}
Map<String, Object> result = new HashMap<>();
result.put("groupon", groupon);
result.put("goods", goods);
return ResponseUtil.ok(result);
}
@GetMapping("my")
public Object my(@LoginUser Integer userId, @RequestParam(defaultValue = "0") Integer showType) {
if (userId == null) {
return ResponseUtil.unlogin();
}
List<LitemallGroupon> myGroupons;
if (showType == 0) {
myGroupons = grouponService.queryMyGroupon(userId);
} else {
myGroupons = grouponService.queryMyJoinGroupon(userId);
}
List<Map<String, Object>> grouponVoList = new ArrayList<>(myGroupons.size());
LitemallOrder order;
LitemallGrouponRules rules;
LitemallUser creator;
for (LitemallGroupon groupon : myGroupons) {
order = orderService.findById(groupon.getOrderId());
rules = rulesService.queryById(groupon.getRulesId());
creator = userService.findById(groupon.getCreatorUserId());
Map<String, Object> grouponVo = new HashMap<>();
//填充团购信息
grouponVo.put("id", groupon.getId());
grouponVo.put("groupon", groupon);
grouponVo.put("rules", rules);
grouponVo.put("creator", creator.getNickname());
int linkGrouponId;
// 这是一个团购发起记录
if (groupon.getGrouponId() == 0) {
linkGrouponId = groupon.getId();
grouponVo.put("isCreator", creator.getId() == userId);
} else {
linkGrouponId = groupon.getGrouponId();
grouponVo.put("isCreator", false);
}
int joinerCount = grouponService.countGroupon(linkGrouponId);
grouponVo.put("joinerCount", joinerCount + 1);
//填充订单信息
grouponVo.put("orderId", order.getId());
grouponVo.put("orderSn", order.getOrderSn());
grouponVo.put("actualPrice", order.getActualPrice());
grouponVo.put("orderStatusText", OrderUtil.orderStatusText(order));
grouponVo.put("handleOption", OrderUtil.build(order));
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
List<Map<String, Object>> orderGoodsVoList = new ArrayList<>(orderGoodsList.size());
for (LitemallOrderGoods orderGoods : orderGoodsList) {
Map<String, Object> orderGoodsVo = new HashMap<>();
orderGoodsVo.put("id", orderGoods.getId());
orderGoodsVo.put("goodsName", orderGoods.getGoodsName());
orderGoodsVo.put("number", orderGoods.getNumber());
orderGoodsVo.put("picUrl", orderGoods.getPicUrl());
orderGoodsVoList.add(orderGoodsVo);
}
grouponVo.put("goodsList", orderGoodsVoList);
grouponVoList.add(grouponVo);
}
Map<String, Object> result = new HashMap<>();
result.put("count", grouponVoList.size());
result.put("data", grouponVoList);
return ResponseUtil.ok(result);
}
@GetMapping("query")
public Object query(@NotNull Integer goodsId) {
LitemallGoods goods = goodsService.findById(goodsId);
if (goods == null) {
return ResponseUtil.fail(-1, "未找到对应的商品");
}
List<LitemallGrouponRules> rules = rulesService.queryByGoodsId(goodsId);
return ResponseUtil.ok(rules);
}
}
......@@ -4,12 +4,14 @@ import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -29,6 +31,20 @@ public class WxHomeController {
private LitemallTopicService topicService;
@Autowired
private LitemallCategoryService categoryService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
@GetMapping("/cache")
public Object cache(@NotNull String key) {
if (!key.equals("litemall_cache")) {
return ResponseUtil.fail();
}
// 清除缓存
HomeCacheManager.clearAll();
return ResponseUtil.ok("缓存已清除");
}
/**
* app首页
......@@ -52,6 +68,12 @@ public class WxHomeController {
*/
@GetMapping("/index")
public Object index() {
//优先从缓存中读取
if (HomeCacheManager.hasData(HomeCacheManager.INDEX)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.INDEX));
}
Map<String, Object> data = new HashMap<>();
List<LitemallAd> banner = adService.queryIndex();
......@@ -72,6 +94,26 @@ public class WxHomeController {
List<LitemallTopic> topicList = topicService.queryList(0, SystemConfig.getTopicLimit());
data.put("topicList", topicList);
//优惠专区
List<LitemallGrouponRules> grouponRules = grouponRulesService.queryByIndex(0, 4);
List<LitemallGoods> grouponGoods = new ArrayList<>();
List<Map<String, Object>> grouponList = new ArrayList<>();
for (LitemallGrouponRules rule : grouponRules) {
LitemallGoods goods = goodsService.findById(rule.getGoodsId());
if (goods == null)
continue;
if (!grouponGoods.contains(goods)) {
Map<String, Object> item = new HashMap<>();
item.put("goods", goods);
item.put("groupon_price", goods.getRetailPrice().subtract(rule.getDiscount()));
item.put("groupon_member", rule.getDiscountMember());
grouponList.add(item);
grouponGoods.add(goods);
}
}
data.put("grouponList", grouponList);
List<Map> categoryList = new ArrayList<>();
List<LitemallCategory> catL1List = categoryService.queryL1WithoutRecommend(0, SystemConfig.getCatlogListLimit());
for (LitemallCategory catL1 : catL1List) {
......@@ -96,6 +138,8 @@ public class WxHomeController {
}
data.put("floorGoodsList", categoryList);
//缓存数据
HomeCacheManager.loadData(HomeCacheManager.INDEX, data);
return ResponseUtil.ok(data);
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.notify.NotifyService;
import org.linlinjava.litemall.core.notify.NotifyType;
import org.linlinjava.litemall.core.qcode.QCodeService;
import org.linlinjava.litemall.core.util.DateTimeUtil;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
......@@ -82,15 +83,18 @@ public class WxOrderController {
private LitemallRegionService regionService;
@Autowired
private LitemallProductService productService;
@Autowired
private WxPayService wxPayService;
@Autowired
private NotifyService notifyService;
@Autowired
private LitemallUserFormIdService formIdService;
@Autowired
private LitemallGrouponRulesService grouponRulesService;
@Autowired
private LitemallGrouponService grouponService;
@Autowired
private QCodeService qCodeService;
public WxOrderController() {
}
......@@ -153,6 +157,13 @@ public class WxOrderController {
orderVo.put("orderStatusText", OrderUtil.orderStatusText(order));
orderVo.put("handleOption", OrderUtil.build(order));
LitemallGroupon groupon = grouponService.queryByOrderId(order.getId());
if (groupon != null) {
orderVo.put("isGroupin", true);
} else {
orderVo.put("isGroupin", false);
}
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId());
List<Map<String, Object>> orderGoodsVoList = new ArrayList<>(orderGoodsList.size());
for (LitemallOrderGoods orderGoods : orderGoodsList) {
......@@ -167,6 +178,7 @@ public class WxOrderController {
orderVoList.add(orderVo);
}
Map<String, Object> result = new HashMap<>();
result.put("count", count);
result.put("data", orderVoList);
......@@ -267,6 +279,9 @@ public class WxOrderController {
Integer cartId = JacksonUtil.parseInteger(body, "cartId");
Integer addressId = JacksonUtil.parseInteger(body, "addressId");
Integer couponId = JacksonUtil.parseInteger(body, "couponId");
Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId");
Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId");
if (cartId == null || addressId == null || couponId == null) {
return ResponseUtil.badArgument();
}
......@@ -278,6 +293,13 @@ public class WxOrderController {
// 使用优惠券减免的金额
BigDecimal couponPrice = new BigDecimal(0.00);
// 团购优惠
BigDecimal grouponPrice = new BigDecimal(0.00);
LitemallGrouponRules grouponRules = grouponRulesService.queryById(grouponRulesId);
if (grouponRules != null) {
grouponPrice = grouponRules.getDiscount();
}
// 货品价格
List<LitemallCart> checkedGoodsList = null;
if (cartId.equals(0)) {
......@@ -292,8 +314,13 @@ public class WxOrderController {
}
BigDecimal checkedGoodsPrice = new BigDecimal(0.00);
for (LitemallCart checkGoods : checkedGoodsList) {
// 只有当团购规格商品ID符合才进行团购优惠
if (grouponRules != null && grouponRules.getGoodsId().equals(checkGoods.getGoodsId())) {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().subtract(grouponPrice).multiply(new BigDecimal(checkGoods.getNumber())));
} else {
checkedGoodsPrice = checkedGoodsPrice.add(checkGoods.getPrice().multiply(new BigDecimal(checkGoods.getNumber())));
}
}
// 根据订单商品总价计算运费,满88则免运费,否则8元;
BigDecimal freightPrice = new BigDecimal(0.00);
......@@ -304,7 +331,6 @@ public class WxOrderController {
// 可以使用的其他钱,例如用户积分
BigDecimal integralPrice = new BigDecimal(0.00);
// 订单费用
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
......@@ -332,6 +358,14 @@ public class WxOrderController {
order.setIntegralPrice(integralPrice);
order.setOrderPrice(orderTotalPrice);
order.setActualPrice(actualPrice);
// 有团购活动
if (grouponRules != null) {
order.setGrouponPrice(grouponPrice); // 团购价格
} else {
order.setGrouponPrice(new BigDecimal(0.00)); // 团购价格
}
// 添加订单表项
orderService.add(order);
orderId = order.getId();
......@@ -369,6 +403,30 @@ public class WxOrderController {
product.setNumber(remainNumber);
productService.updateById(product);
}
//如果是团购项目,添加团购信息
if (grouponRulesId != null && grouponRulesId > 0) {
LitemallGroupon groupon = new LitemallGroupon();
groupon.setOrderId(orderId);
groupon.setPayed(false);
groupon.setUserId(userId);
groupon.setRulesId(grouponRulesId);
//参与者
if (grouponLinkId != null && grouponLinkId > 0) {
LitemallGroupon baseGroupon = grouponService.queryById(grouponLinkId);
groupon.setCreatorUserId(baseGroupon.getCreatorUserId());
groupon.setGrouponId(grouponLinkId);
groupon.setShareUrl(baseGroupon.getShareUrl());
} else {
groupon.setCreatorUserId(userId);
groupon.setGrouponId(0);
}
groupon.setAddTime(LocalDateTime.now());
grouponService.createGroupon(groupon);
}
} catch (Exception ex) {
txManager.rollback(status);
logger.error("系统内部错误", ex);
......@@ -545,6 +603,7 @@ public class WxOrderController {
String orderSn = result.getOutTradeNo();
String payId = result.getTransactionId();
// 分转化成元
String totalFee = BaseWxPayResult.fenToYuan(result.getTotalFee());
......@@ -568,6 +627,20 @@ public class WxOrderController {
order.setOrderStatus(OrderUtil.STATUS_PAY);
orderService.updateById(order);
// 支付成功,有团购信息,更新团购信息
LitemallGroupon groupon = grouponService.queryByOrderId(order.getId());
if (groupon != null) {
LitemallGrouponRules grouponRules = grouponRulesService.queryById(groupon.getRulesId());
//仅当发起者才创建分享图片
if (groupon.getGrouponId() == 0) {
String url = qCodeService.createGrouponShareImage(grouponRules.getGoodsName(), grouponRules.getPicUrl(), groupon);
groupon.setShareUrl(url);
}
groupon.setPayed(true);
grouponService.update(groupon);
}
//TODO 发送邮件和短信通知,这里采用异步发送
// 订单支付成功以后,会发送短信给用户,以及发送邮件给管理员
notifyService.notifyMail("新订单通知", order.toString());
......
......@@ -30,7 +30,9 @@
"pages/cart/cart",
"pages/checkout/checkout",
"pages/goods/goods",
"pages/about/about"
"pages/about/about",
"pages/groupon/myGroupon/myGroupon",
"pages/groupon/grouponDetail/grouponDetail"
],
"window": {
"navigationBarBackgroundColor": "#FFFFFF",
......
......@@ -4,9 +4,9 @@
// 局域网测试使用
// var WxApiRoot = 'http://192.168.0.101:8080/wx/';
// 云平台部署时使用
var WxApiRoot = 'http://122.152.206.172:8080/wx/';
// var WxApiRoot = 'http://122.152.206.172:8080/wx/';
// 云平台上线时使用
// var WxApiRoot = 'https://www.menethil.com.cn/wx/';
var WxApiRoot = 'https://www.menethil.com.cn/wx/';
module.exports = {
IndexUrl: WxApiRoot + 'home/index', //首页数据接口
......@@ -79,5 +79,9 @@ module.exports = {
UserFormIdCreate: WxApiRoot + 'formid/create', //用户FromId,用于发送模版消息
GroupOn: WxApiRoot + 'groupon/query', //团购API-查询
GroupOnMy: WxApiRoot + 'groupon/my', //团购API-我的团购
GroupOnDetail: WxApiRoot + 'groupon/detail', //团购API-详情
GroupOnJoin: WxApiRoot + 'groupon/join', //团购API-详情
StorageUpload: WxApiRoot + 'storage/upload' //图片上传
};
\ No newline at end of file
'use strict';
Component({
externalClasses: ['custom-class'],
/**
* 组件的属性列表
* 用于组件自定义设置
*/
properties: {
// 颜色状态
type: {
type: String,
value: ''
},
// 自定义颜色
color: {
type: String,
value: ''
},
// 左侧内容
leftText: {
type: String,
value: ''
},
// 右侧内容
rightText: {
type: String,
value: ''
}
}
});
\ No newline at end of file
<view class="custom-class zan-capsule zan-capsule--{{type}}">
<block wx:if="{{color}}">
<view class="zan-capsule__left" style="background: {{ color }}; border-color: {{ color }}">{{ leftText }}</view>
<view class="zan-capsule__right" style="color: {{ color }}; border-color: {{ color }}">{{ rightText }}</view>
</block>
<block wx:else>
<view class="zan-capsule__left">{{ leftText }}</view>
<view class="zan-capsule__right">{{ rightText }}</view>
</block>
</view>
\ No newline at end of file
.zan-capsule {
display: inline-block;
font-size: 12px;
vertical-align: middle;
line-height: 19px;
-webkit-transform: scale(0.83);
transform: scale(0.83);
}
.zan-capsule__left, .zan-capsule__right {
display: inline-block;
line-height: 17px;
height: 19px;
vertical-align: middle;
box-sizing: border-box;
}
.zan-capsule__left {
padding: 0 2px;
color: #fff;
background: #999;
border-radius: 2px 0 0 2px;
border: 1rpx solid #999;
}
.zan-capsule__right {
padding: 0 5px;
color: #999;
border-radius: 0 2px 2px 0;
border: 1rpx solid #999;
}
.zan-capsule--danger .zan-capsule__left {
color: #fff;
background: #f24544;
border-color: #f24544;
}
.zan-capsule--danger .zan-capsule__right {
color: #f24544;
border-color: #f24544;
}
......@@ -12,31 +12,42 @@ Page({
goodsTotalPrice: 0.00, //商品总价
freightPrice: 0.00, //快递费
couponPrice: 0.00, //优惠券的价格
grouponPrice: 0.00, //团购优惠价格
orderTotalPrice: 0.00, //订单总价
actualPrice: 0.00, //实际需要支付的总价
cartId: 0,
addressId: 0,
couponId: 0
couponId: 0,
grouponLinkId: 0, //参与的团购,如果是发起则为0
grouponRulesId: 0 //团购规则ID
},
onLoad: function (options) {
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
},
getCheckoutInfo: function () {
//获取checkou信息
getCheckoutInfo: function() {
let that = this;
util.request(api.CartCheckout, { cartId: that.data.cartId, addressId: that.data.addressId, couponId: that.data.couponId }).then(function (res) {
util.request(api.CartCheckout, {
cartId: that.data.cartId,
addressId: that.data.addressId,
couponId: that.data.couponId,
grouponRulesId: that.data.grouponRulesId
}).then(function(res) {
if (res.errno === 0) {
that.setData({
checkedGoodsList: res.data.checkedGoodsList,
checkedAddress: res.data.checkedAddress,
actualPrice: res.data.actualPrice,
checkedCoupon: res.data.checkedCoupon,
couponList: res.data.couponList,
couponPrice: res.data.couponPrice,
grouponPrice: res.data.grouponPrice,
freightPrice: res.data.freightPrice,
goodsTotalPrice: res.data.goodsTotalPrice,
orderTotalPrice: res.data.orderTotalPrice,
addressId: res.data.addressId,
couponId: res.data.couponId
couponId: res.data.couponId,
grouponRulesId: res.data.grouponRulesId,
});
}
wx.hideLoading();
......@@ -52,15 +63,15 @@ Page({
url: '/pages/ucenter/addressAdd/addressAdd',
})
},
onReady: function () {
onReady: function() {
// 页面渲染完成
},
onShow: function () {
onShow: function() {
// 页面显示
wx.showLoading({
title: '加载中...',
})
});
try {
var cartId = wx.getStorageSync('cartId');
if (cartId) {
......@@ -82,87 +93,78 @@ Page({
'couponId': couponId
});
}
var grouponRulesId = wx.getStorageSync('grouponRulesId');
if (grouponRulesId) {
this.setData({
'grouponRulesId': grouponRulesId
});
}
var grouponLinkId = wx.getStorageSync('grouponLinkId');
if (grouponLinkId) {
this.setData({
'grouponLinkId': grouponLinkId
});
}
} catch (e) {
// Do something when catch error
console.log(e);
}
this.getCheckoutInfo();
},
onHide: function () {
onHide: function() {
// 页面隐藏
},
onUnload: function () {
onUnload: function() {
// 页面关闭
},
submitOrder: function () {
submitOrder: function() {
if (this.data.addressId <= 0) {
util.showErrorToast('请选择收货地址');
return false;
}
util.request(api.OrderSubmit, { cartId: this.data.cartId, addressId: this.data.addressId, couponId: this.data.couponId }, 'POST').then(res => {
util.request(api.OrderSubmit, {
cartId: this.data.cartId,
addressId: this.data.addressId,
couponId: this.data.couponId,
grouponRulesId: this.data.grouponRulesId,
grouponLinkId: this.data.grouponLinkId
}, 'POST').then(res => {
if (res.errno === 0) {
const orderId = res.data.orderId;
// 模拟支付成功,同理,后台也仅仅是返回一个成功的消息而已
// wx.showModal({
// title: '目前不能微信支付',
// content: '点击确定模拟支付成功,点击取消模拟未支付成功',
// success: function(res) {
// if (res.confirm) {
// util.request(api.OrderPrepay, { orderId: orderId }, 'POST').then(res => {
// if (res.errno === 0) {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=1&orderId=' + orderId
// });
// }
// else{
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
// }
// });
// }
// else if (res.cancel) {
// wx.redirectTo({
// url: '/pages/payResult/payResult?status=0&orderId=' + orderId
// });
// }
// }
// });
util.request(api.OrderPrepay, {
orderId: orderId
}, 'POST').then(function (res) {
}, 'POST').then(function(res) {
if (res.errno === 0) {
const payParam = res.data;
console.log("支付过程开始")
console.log("支付过程开始");
wx.requestPayment({
'timeStamp': payParam.timeStamp,
'nonceStr': payParam.nonceStr,
'package': payParam.packageValue,
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function (res) {
console.log("支付过程成功")
'success': function(res) {
console.log("支付过程成功");
wx.redirectTo({
url: '/pages/payResult/payResult?status=1&orderId=' + orderId
});
},
'fail': function (res) {
console.log("支付过程失败")
'fail': function(res) {
console.log("支付过程失败");
wx.redirectTo({
url: '/pages/payResult/payResult?status=0&orderId=' + orderId
});
},
'complete': function (res) {
'complete': function(res) {
console.log("支付过程结束")
}
});
}
else{
} else {
wx.redirectTo({
url: '/pages/payResult/payResult?status=0&orderId=' + orderId
});
......@@ -176,4 +178,4 @@ Page({
}
});
}
})
\ No newline at end of file
});
\ No newline at end of file
......@@ -8,6 +8,8 @@ Page({
data: {
id: 0,
goods: {},
groupon: [], //该商品支持的团购规格
grouponLink: {}, //参与的团购
attribute: [],
issueList: [],
comment: [],
......@@ -26,16 +28,21 @@ Page({
hasCollectImage: '/static/images/icon_collect_checked.png',
collectImage: '/static/images/icon_collect.png',
shareImage: '',
isGroupon: false, //标识是否是一个参团购买
soldout: false
},
onPullDownRefresh() {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.getGoodsInfo();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
// 页面分享
onShareAppMessage: function() {
let that = this;
return {
title: that.data.goods.name,
desc: '唯爱与美食不可辜负',
path: '/pages/index/index?goodId=' + this.data.id
}
},
// 保存分享图
saveShare: function() {
let that = this;
wx.downloadFile({
......@@ -69,6 +76,24 @@ Page({
})
},
//从分享的团购进入
getGrouponInfo: function(grouponId) {
let that = this;
util.request(api.GroupOnJoin, {
grouponId: grouponId
}).then(function(res) {
if (res.errno === 0) {
that.setData({
grouponLink: res.data.groupon,
id: res.data.goods.id
});
//获取商品详情
that.getGoodsInfo();
}
});
},
// 获取商品信息
getGoodsInfo: function() {
let that = this;
util.request(api.GoodsDetail, {
......@@ -107,9 +132,26 @@ Page({
productList: res.data.productList,
userHasCollect: res.data.userHasCollect,
shareImage: res.data.shareImage,
checkedSpecPrice: res.data.info.retailPrice
checkedSpecPrice: res.data.info.retailPrice,
groupon: res.data.groupon
});
//如果是通过分享的团购参加团购,则团购项目应该与分享的一致并且不可更改
if (that.data.isGroupon) {
let groupons = that.data.groupon;
for (var i = 0; i < groupons.length; i++) {
if (groupons[i].id != that.data.grouponLink.rulesId) {
groupons.splice(i, 1);
}
}
groupons[0].checked = true;
//重设团购规格
that.setData({
groupon: groupons
});
}
if (res.data.userHasCollect == 1) {
that.setData({
collectImage: that.data.hasCollectImage
......@@ -121,12 +163,13 @@ Page({
}
WxParse.wxParse('goodsDetail', 'html', res.data.info.detail, that);
//获取推荐商品
that.getGoodsRelated();
}
});
},
// 获取推荐商品
getGoodsRelated: function() {
let that = this;
util.request(api.GoodsRelated, {
......@@ -138,8 +181,39 @@ Page({
});
}
});
},
// 团购选择
clickGroupon: function(event) {
let that = this;
//参与团购,不可更改选择
if (that.data.isGroupon) {
return;
}
let specName = event.currentTarget.dataset.name;
let specValueId = event.currentTarget.dataset.valueId;
let _grouponList = this.data.groupon;
for (let i = 0; i < _grouponList.length; i++) {
if (_grouponList[i].id == specValueId) {
if (_grouponList[i].checked) {
_grouponList[i].checked = false;
} else {
_grouponList[i].checked = true;
}
} else {
_grouponList[i].checked = false;
}
}
this.setData({
groupon: _grouponList,
});
},
// 规格选择
clickSkuValue: function(event) {
let that = this;
let specName = event.currentTarget.dataset.name;
......@@ -173,6 +247,20 @@ Page({
//重新计算哪些值不可以点击
},
//获取选中的团购信息
getCheckedGrouponValue: function() {
let checkedValues = {};
let _grouponList = this.data.groupon;
for (let i = 0; i < _grouponList.length; i++) {
if (_grouponList[i].checked) {
checkedValues = _grouponList[i];
}
}
return checkedValues;
},
//获取选中的规格信息
getCheckedSpecValue: function() {
let checkedValues = [];
......@@ -194,10 +282,7 @@ Page({
return checkedValues;
},
//根据已选的值,计算其它值的状态
setSpecValueStatus: function() {
},
//判断规格是否选择完整
isCheckedAllSpec: function() {
return !this.getCheckedSpecValue().some(function(v) {
......@@ -206,13 +291,15 @@ Page({
}
});
},
getCheckedSpecKey: function() {
let checkedValue = this.getCheckedSpecValue().map(function(v) {
return v.valueText;
});
return checkedValue;
},
// 规格改变时,重新计算价格及显示信息
changeSpecInfo: function() {
let checkedNameValue = this.getCheckedSpecValue();
......@@ -236,7 +323,6 @@ Page({
});
}
if (this.isCheckedAllSpec()) {
this.setData({
checkedSpecText: this.data.tmpSpecText
......@@ -274,6 +360,8 @@ Page({
}
},
// 获取选中的产品(根据规格)
getCheckedProductItem: function(key) {
return this.data.productList.filter(function(v) {
if (v.specifications.toString() == key.toString()) {
......@@ -283,16 +371,22 @@ Page({
}
});
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
if (options.id) {
this.setData({
id: parseInt(options.id)
});
this.getGoodsInfo();
},
onReady: function() {
// 页面渲染完成
}
if (options.grouponId) {
this.setData({
isGroupon: true,
});
this.getGrouponInfo(options.grouponId);
}
},
onShow: function() {
// 页面显示
......@@ -305,29 +399,10 @@ Page({
}
});
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
switchAttrPop: function() {
if (this.data.openAttr == false) {
this.setData({
openAttr: !this.data.openAttr
});
}
},
closeAttr: function() {
this.setData({
openAttr: false,
});
},
//添加或是取消收藏
addCollectOrNot: function() {
let that = this;
//添加或是取消收藏
util.request(api.CollectAddOrDelete, {
type: 0,
valueId: this.data.id
......@@ -356,11 +431,8 @@ Page({
});
},
openCartPage: function() {
wx.switchTab({
url: '/pages/cart/cart'
});
},
//立即购买(先自动加入购物车)
addFast: function() {
var that = this;
if (this.data.openAttr == false) {
......@@ -400,6 +472,9 @@ Page({
return false;
}
//验证团购是否有效
let checkedGroupon = this.getCheckedGrouponValue();
//立即购买
util.request(api.CartFastAdd, {
goodsId: this.data.goods.id,
......@@ -412,6 +487,8 @@ Page({
// 如果storage中设置了cartId,则是立即购买,否则是购物车购买
try {
wx.setStorageSync('cartId', res.data);
wx.setStorageSync('grouponRulesId', checkedGroupon.id);
wx.setStorageSync('grouponLinkId', that.data.grouponLink.id);
wx.navigateTo({
url: '/pages/checkout/checkout'
})
......@@ -429,6 +506,8 @@ Page({
},
//添加到购物车
addToCart: function() {
var that = this;
if (this.data.openAttr == false) {
......@@ -505,6 +584,7 @@ Page({
}
},
cutNumber: function() {
this.setData({
number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
......@@ -514,5 +594,46 @@ Page({
this.setData({
number: this.data.number + 1
});
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
switchAttrPop: function() {
if (this.data.openAttr == false) {
this.setData({
openAttr: !this.data.openAttr
});
}
},
closeAttr: function() {
this.setData({
openAttr: false,
});
},
openCartPage: function() {
wx.switchTab({
url: '/pages/cart/cart'
});
},
onReady: function() {
// 页面渲染完成
},
// 下拉刷新
onPullDownRefresh() {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.getGoodsInfo();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
//根据已选的值,计算其它值的状态
setSpecValueStatus: function() {
},
})
\ No newline at end of file
......@@ -4,7 +4,8 @@
<image src="{{item}}" background-size="cover"></image>
</swiper-item>
</swiper>
<view class="service-policy">
<!-- 分享 -->
<view class="service-policy" wx:if="{{!isGroupon}}">
<button class="savesharebtn" bindtap="saveShare">分享朋友圈</button>
<button class="sharebtn" open-type="share">分享给朋友</button>
</view>
......@@ -12,7 +13,11 @@
<view class="c">
<text class="name">{{goods.name}}</text>
<text class="desc">{{goods.goodsBrief}}</text>
<text class="price">¥{{checkedSpecPrice}}</text>
<view class="price">
<view class="counterPrice">原价:¥{{goods.counterPrice}}</view>
<view class="retailPrice">现价:¥{{checkedSpecPrice}}</view>
</view>
<view class="brand" wx:if="{{brand.name}}">
<navigator url="../brandDetail/brandDetail?id={{brand.id}}">
<text>{{brand.name}}</text>
......@@ -46,7 +51,6 @@
<view class="imgs" wx:if="{{item.picList.length > 0}}">
<image class="img" wx:for="{{item.picList}}" wx:key="*this" wx:for-item="iitem" src="{{iitem}} "></image>
</view>
<!-- <view class="spec">白色 2件</view> -->
</view>
</view>
</view>
......@@ -65,7 +69,6 @@
<template is="wxParse" data="{{wxParseData:goodsDetail.nodes}}" />
</view>
<view class="common-problem">
<view class="h">
<view class="line"></view>
......@@ -84,6 +87,7 @@
</view>
</view>
<!-- 大家都在看 -->
<view class="related-goods" wx:if="{{relatedGoods.length > 0}}">
<view class="h">
<view class="line"></view>
......@@ -100,6 +104,8 @@
</view>
</view>
</view>
<!-- 规格选择界面 -->
<view class="attr-pop-box" hidden="{{!openAttr}}">
<view class="attr-pop">
<view class="close" bindtap="closeAttr">
......@@ -114,6 +120,8 @@
</view>
</view>
</view>
<!-- 规格列表 -->
<view class="spec-con">
<view class="spec-item" wx:for="{{specificationList}}" wx:key="name">
<view class="name">{{item.name}}</view>
......@@ -122,6 +130,16 @@
</view>
</view>
<view class="spec-con" wx:if="{{groupon.length > 0}}">
<view class="spec-item">
<view class="name">团购立减</view>
<view class="values">
<view class="value {{vitem.checked ? 'selected' : ''}}" bindtap="clickGroupon" wx:for="{{groupon}}" wx:for-item="vitem" wx:key="{{vitem.id}}" data-value-id="{{vitem.id}}" data-name="{{vitem.specification}}">¥{{vitem.discount}} ({{vitem.discountMember}}人)</view>
</view>
</view>
</view>
<!-- 数量 -->
<view class="number-item">
<view class="name">数量</view>
<view class="selnum">
......@@ -130,24 +148,30 @@
<view class="add" bindtap="addNumber">+</view>
</view>
</view>
</view>
</view>
</view>
<!-- 联系客服 -->
<view class="contact">
<contact-button style="opacity:0;position:absolute;" type="default-dark" session-from="weapp" size="27">
</contact-button>
</view>
<!-- 底部按钮 -->
<view class="bottom-btn">
<view class="l l-collect" bindtap="addCollectOrNot">
<view class="l l-collect" bindtap="addCollectOrNot" wx:if="{{!isGroupon}}">
<image class="icon" src="{{ collectImage }}"></image>
</view>
<view class="l l-cart">
<view class="l l-cart" wx:if="{{!isGroupon}}">
<view class="box">
<text class="cart-count">{{cartGoodsCount}}</text>
<image bindtap="openCartPage" class="icon" src="/static/images/ic_menu_shoping_nor.png"></image>
</view>
</view>
<view class="c" bindtap="addFast" wx:if="{{!soldout}}">立即购买</view>
<view class="r" bindtap="addToCart" wx:if="{{!soldout}}">加入购物车</view>
<view class="r" bindtap="addToCart" wx:if="{{!soldout}}" wx:if="{{!isGroupon}}">加入购物车</view>
<view class="c" bindtap="addFast" wx:if="{{!soldout}}">{{isGroupon?'参加团购':'立即购买'}}</view>
<view class="n" wx:if="{{soldout}}">商品已售空</view>
</view>
\ No newline at end of file
......@@ -71,10 +71,23 @@
}
.goods-info .price {
height: 35rpx;
font-size: 35rpx;
line-height: 35rpx;
color: #b4282d;
height: 70rpx;
align-content: center;
}
.goods-info .counterPrice {
float: left;
padding-left: 120rpx;
text-decoration: line-through;
font-size: 30rpx;
color: #999;
}
.goods-info .retailPrice {
/* float: right; */
padding-left: 60rpx;
font-size: 30rpx;
color: #a78845;
}
.goods-info .brand {
......@@ -418,6 +431,7 @@
width: 750rpx;
height: auto;
overflow: hidden;
padding-bottom: 80rpx;
}
.related-goods .h {
......
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({
data: {
id: 0,
orderId: 0,
groupon: {},
linkGrouponId: 0,
joiners: [],
orderInfo: {},
orderGoods: [],
expressInfo: {},
flag: false,
handleOption: {}
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
id: options.id
});
this.getOrderDetail();
},
// 页面分享
onShareAppMessage: function() {
let that = this;
return {
title: '邀请团购',
desc: '唯爱与美食不可辜负',
path: '/pages/index/index?grouponId=' + this.data.linkGrouponId
}
},
shareGroupon: function() {
let that = this;
wx.showActionSheet({
itemList: ['分享给朋友', '分享到朋友圈'],
success: function(res) {
if (res.tapIndex == 0) {
wx.showModal({
title: '提示',
content: '点击右上角 "..." 转发给朋友',
showCancel: false
});
} else if (res.tapIndex == 1) {
that.saveShare();
} else {
console.log(res.tapIndex);
}
},
fail: function(res) {
console.log(res.errMsg);
}
})
},
// 保存分享图
saveShare: function() {
let that = this;
wx.downloadFile({
url: that.data.groupon.shareUrl,
success: function(res) {
console.log(res)
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(res) {
wx.showModal({
title: '存图成功',
content: '图片成功保存到相册了,可以分享到朋友圈了',
showCancel: false,
confirmText: '好的',
confirmColor: '#a78845',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
}
}
})
},
fail: function(res) {
console.log('fail')
}
})
},
fail: function() {
console.log('fail')
}
})
},
onPullDownRefresh() {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.getOrderDetail();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
//获取物流信息
getOrderExpress: function() {
let that = this;
util.request(api.ExpressQuery, {
expCode: that.data.orderInfo.expCode,
expNo: that.data.orderInfo.expNo
}, 'POST').then(function(res) {
if (res.errno === 0) {
that.setData({
expressInfo: res.data
});
}
});
},
expandDetail: function() {
let that = this;
this.setData({
flag: !that.data.flag
})
},
getOrderDetail: function() {
let that = this;
util.request(api.GroupOnDetail, {
grouponId: that.data.id
}).then(function(res) {
if (res.errno === 0) {
that.setData({
joiners: res.data.joiners,
groupon: res.data.groupon,
linkGrouponId: res.data.linkGrouponId,
orderId: res.data.orderInfo.id,
orderInfo: res.data.orderInfo,
orderGoods: res.data.orderGoods,
handleOption: res.data.orderInfo.handleOption
});
// 请求物流信息,仅当订单状态为发货时才请求
if (res.data.orderInfo.handleOption.confirm) {
that.getOrderExpress();
}
}
});
},
// “去付款”按钮点击效果
payOrder: function() {
let that = this;
util.request(api.OrderPrepay, {
orderId: that.data.orderId
}, 'POST').then(function(res) {
if (res.errno === 0) {
const payParam = res.data;
console.log("支付过程开始");
wx.requestPayment({
'timeStamp': payParam.timeStamp,
'nonceStr': payParam.nonceStr,
'package': payParam.packageValue,
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function(res) {
console.log("支付过程成功");
util.redirect('/pages/ucenter/order/order');
},
'fail': function(res) {
console.log("支付过程失败");
util.showErrorToast('支付失败');
},
'complete': function(res) {
console.log("支付过程结束")
}
});
}
});
},
// “取消订单”点击效果
cancelOrder: function() {
let that = this;
let orderInfo = that.data.orderInfo;
wx.showModal({
title: '',
content: '确定要取消此订单?',
success: function(res) {
if (res.confirm) {
util.request(api.OrderCancel, {
orderId: orderInfo.id
}, 'POST').then(function(res) {
if (res.errno === 0) {
wx.showToast({
title: '取消订单成功'
});
util.redirect('/pages/ucenter/order/order');
} else {
util.showErrorToast(res.errmsg);
}
});
}
}
});
},
// “取消订单并退款”点击效果
refundOrder: function() {
let that = this;
let orderInfo = that.data.orderInfo;
wx.showModal({
title: '',
content: '确定要取消此订单?',
success: function(res) {
if (res.confirm) {
util.request(api.OrderRefund, {
orderId: orderInfo.id
}, 'POST').then(function(res) {
if (res.errno === 0) {
wx.showToast({
title: '取消订单成功'
});
util.redirect('/pages/ucenter/order/order');
} else {
util.showErrorToast(res.errmsg);
}
});
}
}
});
},
// “删除”点击效果
deleteOrder: function() {
let that = this;
let orderInfo = that.data.orderInfo;
wx.showModal({
title: '',
content: '确定要删除此订单?',
success: function(res) {
if (res.confirm) {
util.request(api.OrderDelete, {
orderId: orderInfo.id
}, 'POST').then(function(res) {
if (res.errno === 0) {
wx.showToast({
title: '删除订单成功'
});
util.redirect('/pages/ucenter/order/order');
} else {
util.showErrorToast(res.errmsg);
}
});
}
}
});
},
// “确认收货”点击效果
confirmOrder: function() {
let that = this;
let orderInfo = that.data.orderInfo;
wx.showModal({
title: '',
content: '确认收货?',
success: function(res) {
if (res.confirm) {
util.request(api.OrderConfirm, {
orderId: orderInfo.id
}, 'POST').then(function(res) {
if (res.errno === 0) {
wx.showToast({
title: '确认收货成功!'
});
util.redirect('/pages/ucenter/order/order');
} else {
util.showErrorToast(res.errmsg);
}
});
}
}
});
},
onReady: function() {
// 页面渲染完成
},
onShow: function() {
// 页面显示
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
}
});
\ No newline at end of file
{
"navigationBarTitleText": "团购详情"
}
\ No newline at end of file
<view class="container">
<view class="order-info">
<view class="item-a">下单时间:{{orderInfo.addTime}}</view>
<view class="item-b">订单编号:{{orderInfo.orderSn}}</view>
<view class="item-c">
<view class="l">实付:
<text class="cost">¥{{orderInfo.actualPrice}}</text>
</view>
<view class="r">
<view class="btn active" bindtap="shareGroupon">邀请参团</view>
</view>
</view>
</view>
<view class="menu-list-pro">
<view class="h">
<view class="label">参与团购 ( {{joiners.length}}人)</view>
<view class="status">查看全部</view>
</view>
<view class="menu-list-item" wx:for-items="{{joiners}}" wx:key="id" data-id="{{item.id}}">
<image class="icon" src="{{item.avatar}}"></image>
<text class="txt">{{item.nickname}}</text>
</view>
</view>
<view class="order-goods">
<view class="h">
<view class="label">商品信息</view>
<view class="status">{{orderInfo.orderStatusText}}</view>
</view>
<view class="goods">
<view class="item" wx:for="{{orderGoods}}" wx:key="id">
<view class="img">
<image src="{{item.picUrl}}"></image>
</view>
<view class="info">
<view class="t">
<text class="name">{{item.goodsName}}</text>
<text class="number">x{{item.number}}</text>
</view>
<view class="attr">{{item.goodsSpecificationValues}}</view>
<view class="price">¥{{item.retailPrice}}</view>
</view>
</view>
</view>
<view class="order-bottom">
<view class="address">
<view class="t">
<text class="name">{{orderInfo.consignee}}</text>
<text class="mobile">{{orderInfo.mobile}}</text>
</view>
<view class="b">{{orderInfo.address}}</view>
</view>
<view class="total">
<view class="t">
<text class="label">商品合计:</text>
<text class="txt">¥{{orderInfo.goodsPrice}}</text>
</view>
<view class="t">
<text class="label">运费:</text>
<text class="txt">¥{{orderInfo.freightPrice}}</text>
</view>
</view>
<view class="pay-fee">
<text class="label">实付:</text>
<text class="txt">¥{{orderInfo.actualPrice}}</text>
</view>
</view>
</view>
<!-- 物流信息,仅收货状态下可见 -->
<view class="order-express" bindtap="expandDetail" wx:if="{{ handleOption.confirm }}">
<view class="expand">
<view class="title">
<view class="t">快递公司:{{expressInfo.expName}}</view>
<view class="b">物流单号:{{expressInfo.expCode}}</view>
</view>
<image class="ti" src="/static/images/address_right.png" background-size="cover"></image>
</view>
<!-- <view class="order-express" > -->
<view class="traces" wx:for="{{expressInfo.Traces}}" wx:key="item" wx:for-item="iitem" wx:if="{{ flag }}">
<view class="trace">
<view class="acceptStation">{{iitem.AcceptStation}}</view>
<view class="acceptTime">{{iitem.AcceptTime}}</view>
</view>
</view>
</view>
<!-- </view> -->
</view>
\ No newline at end of file
page {
height: 100%;
width: 100%;
background: #f4f4f4;
}
.order-info {
padding-top: 25rpx;
background: #fff;
height: auto;
overflow: hidden;
}
.item-a {
padding-left: 31.25rpx;
height: 42.5rpx;
padding-bottom: 12.5rpx;
line-height: 30rpx;
font-size: 30rpx;
color: #666;
}
.item-b {
padding-left: 31.25rpx;
height: 29rpx;
line-height: 29rpx;
margin-top: 12.5rpx;
margin-bottom: 41.5rpx;
font-size: 30rpx;
color: #666;
}
.item-c {
margin-left: 31.25rpx;
border-top: 1px solid #f4f4f4;
height: 103rpx;
line-height: 103rpx;
}
.item-c .l {
float: left;
}
.item-c .r {
height: 103rpx;
float: right;
display: flex;
align-items: center;
padding-right: 16rpx;
}
.item-c .r .btn {
float: right;
}
.item-c .cost {
color: #b4282d;
}
.item-c .btn {
line-height: 66rpx;
border-radius: 5rpx;
text-align: center;
margin: 0 15rpx;
padding: 0 20rpx;
height: 66rpx;
}
.item-c .btn.active {
background: #a78845;
color: #fff;
}
.order-goods {
margin-top: 20rpx;
background: #fff;
}
.order-goods .h {
height: 93.75rpx;
line-height: 93.75rpx;
margin-left: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
padding-right: 31.25rpx;
}
.order-goods .h .label {
float: left;
font-size: 30rpx;
color: #333;
}
.order-goods .h .status {
float: right;
font-size: 30rpx;
color: #b4282d;
}
.order-goods .item {
display: flex;
align-items: center;
height: 192rpx;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-goods .item:last-child {
border-bottom: none;
}
.order-goods .item .img {
height: 145.83rpx;
width: 145.83rpx;
background: #f4f4f4;
}
.order-goods .item .img image {
height: 145.83rpx;
width: 145.83rpx;
}
.order-goods .item .info {
flex: 1;
height: 145.83rpx;
margin-left: 20rpx;
}
.order-goods .item .t {
margin-top: 8rpx;
height: 33rpx;
line-height: 33rpx;
margin-bottom: 10.5rpx;
}
.order-goods .item .t .name {
display: block;
float: left;
height: 33rpx;
line-height: 33rpx;
color: #333;
font-size: 30rpx;
}
.order-goods .item .t .number {
display: block;
float: right;
height: 33rpx;
text-align: right;
line-height: 33rpx;
color: #333;
font-size: 30rpx;
}
.order-goods .item .attr {
height: 29rpx;
line-height: 29rpx;
color: #666;
margin-bottom: 25rpx;
font-size: 25rpx;
}
.order-goods .item .price {
display: block;
float: left;
height: 30rpx;
line-height: 30rpx;
color: #333;
font-size: 30rpx;
}
.order-goods .item .btn {
height: 50rpx;
line-height: 50rpx;
border-radius: 5rpx;
text-align: center;
display: block;
float: right;
margin: 0 15rpx;
padding: 0 20rpx;
}
.order-goods .item .btn.active {
background: #b4282d;
color: #fff;
}
.order-bottom {
margin-top: 20rpx;
padding-left: 31.25rpx;
height: auto;
overflow: hidden;
background: #fff;
}
.order-bottom .address {
height: 128rpx;
padding-top: 25rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-bottom .address .t {
height: 35rpx;
line-height: 35rpx;
margin-bottom: 7.5rpx;
}
.order-bottom .address .name {
display: inline-block;
height: 35rpx;
width: 140rpx;
line-height: 35rpx;
font-size: 30rpx;
}
.order-bottom .address .mobile {
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 30rpx;
}
.order-bottom .address .b {
height: 35rpx;
line-height: 35rpx;
font-size: 30rpx;
}
.order-bottom .total {
height: 106rpx;
padding-top: 20rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-bottom .total .t {
height: 30rpx;
line-height: 30rpx;
margin-bottom: 7.5rpx;
display: flex;
}
.order-bottom .total .label {
width: 150rpx;
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 30rpx;
}
.order-bottom .total .txt {
flex: 1;
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 30rpx;
}
.order-bottom .pay-fee {
height: 81rpx;
line-height: 81rpx;
}
.order-bottom .pay-fee .label {
display: inline-block;
width: 140rpx;
color: #b4282d;
}
.order-bottom .pay-fee .txt {
display: inline-block;
width: 140rpx;
color: #b4282d;
}
.order-express {
margin-top: 20rpx;
width: 100%;
height: 100rpx;
background: #fff;
}
.order-express .expand {
/* margin-top: 20rpx; */
width: 100%;
height: 100rpx;
background: #fff;
/* border: 10rpx #a78845; */
}
.order-express .title {
float: left;
margin-bottom: 20rpx;
padding: 10rpx;
}
.order-express .ti {
float: right;
width: 52rpx;
height: 52rpx;
margin-right: 16rpx;
margin-top: 28rpx;
}
.order-express .t {
font-size: 29rpx;
margin-left: 10.25rpx;
color: #a78845;
}
.order-express .b {
font-size: 29rpx;
margin-left: 10.25rpx;
color: #a78845;
}
.order-express .traces {
padding: 17.5rpx;
background: #fff;
border-bottom: 1rpx solid #f1e6cdcc;
}
.order-express .trace {
padding-bottom: 17.5rpx;
padding-top: 17.5rpx;
background: #fff;
}
.order-express .acceptTime {
margin-top: 20rpx;
margin-right: 40rpx;
text-align: right;
font-size: 26rpx;
}
.order-express .acceptStation {
font-size: 26rpx;
}
.menu-list-pro {
margin-top: 20rpx;
overflow-x: scroll;
white-space: nowrap;
text-overflow: ellipsis;
height: 260rpx;
width: 100%;
overflow: hidden;
border-bottom: 1rpx #cfc9ca;
background-color: #fff;
}
.menu-list-pro .h {
height: 93.75rpx;
line-height: 93.75rpx;
margin-left: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
padding-right: 31.25rpx;
}
.menu-list-pro .h .label {
float: left;
font-size: 30rpx;
color: #333;
}
.menu-list-pro .h .status {
float: right;
font-size: 30rpx;
color: #a78845;
}
.menu-list-pro .menu-list-item {
display: block;
float: left;
height: 110rpx;
width: 80rpx;
margin-top: 30rpx;
margin-bottom: 30rpx;
margin-left: 40rpx;
}
.menu-list-pro .icon {
height: 80rpx;
width: 80rpx;
border-radius: 12rpx;
box-shadow: 0px 4rpx 4rpx 0px #cfc9ca;
}
.menu-list-pro .txt {
display: block;
float: left;
width: 80rpx;
margin-top: 5rpx;
font-size: 22rpx;
color: #a78845;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment