Commit b7e32a66 authored by Junling Bu's avatar Junling Bu
Browse files

小商场更新

parent 02e3d98f
...@@ -117,7 +117,6 @@ public class WxAddressController { ...@@ -117,7 +117,6 @@ public class WxAddressController {
data.put("mobile", address.getMobile()); data.put("mobile", address.getMobile());
data.put("address", address.getAddress()); data.put("address", address.getAddress());
data.put("isDefault", address.getIsDefault()); data.put("isDefault", address.getIsDefault());
data.put("version", address.getVersion());
String pname = regionService.findById(address.getProvinceId()).getName(); String pname = regionService.findById(address.getProvinceId()).getName();
data.put("provinceName", pname); data.put("provinceName", pname);
String cname = regionService.findById(address.getCityId()).getName(); String cname = regionService.findById(address.getCityId()).getName();
...@@ -204,7 +203,6 @@ public class WxAddressController { ...@@ -204,7 +203,6 @@ public class WxAddressController {
if (address.getId() == null || address.getId().equals(0)) { if (address.getId() == null || address.getId().equals(0)) {
address.setId(null); address.setId(null);
address.setAddTime(LocalDateTime.now());
address.setUserId(userId); address.setUserId(userId);
addressService.add(address); addressService.add(address);
} else { } else {
......
...@@ -161,7 +161,6 @@ public class WxAuthController { ...@@ -161,7 +161,6 @@ public class WxAuthController {
user.setStatus((byte) 0); user.setStatus((byte) 0);
user.setLastLoginTime(LocalDateTime.now()); user.setLastLoginTime(LocalDateTime.now());
user.setLastLoginIp(IpUtil.client(request)); user.setLastLoginIp(IpUtil.client(request));
user.setAddTime(LocalDateTime.now());
userService.add(user); userService.add(user);
} else { } else {
...@@ -307,7 +306,6 @@ public class WxAuthController { ...@@ -307,7 +306,6 @@ public class WxAuthController {
user.setStatus((byte) 0); user.setStatus((byte) 0);
user.setLastLoginTime(LocalDateTime.now()); user.setLastLoginTime(LocalDateTime.now());
user.setLastLoginIp(IpUtil.client(request)); user.setLastLoginIp(IpUtil.client(request));
user.setAddTime(LocalDateTime.now());
userService.add(user); userService.add(user);
// userInfo // userInfo
......
...@@ -31,7 +31,7 @@ public class WxCartController { ...@@ -31,7 +31,7 @@ public class WxCartController {
@Autowired @Autowired
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired @Autowired
private LitemallProductService productService; private LitemallGoodsProductService productService;
@Autowired @Autowired
private LitemallAddressService addressService; private LitemallAddressService addressService;
@Autowired @Autowired
...@@ -124,7 +124,7 @@ public class WxCartController { ...@@ -124,7 +124,7 @@ public class WxCartController {
return ResponseUtil.fail(400, "商品已下架"); return ResponseUtil.fail(400, "商品已下架");
} }
LitemallProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
//判断购物车中是否存在此规格商品 //判断购物车中是否存在此规格商品
LitemallCart existCart = cartService.queryExist(goodsId, productId, userId); LitemallCart existCart = cartService.queryExist(goodsId, productId, userId);
if (existCart == null) { if (existCart == null) {
...@@ -141,7 +141,6 @@ public class WxCartController { ...@@ -141,7 +141,6 @@ public class WxCartController {
cart.setSpecifications(product.getSpecifications()); cart.setSpecifications(product.getSpecifications());
cart.setUserId(userId); cart.setUserId(userId);
cart.setChecked(true); cart.setChecked(true);
cart.setAddTime(LocalDateTime.now());
cartService.add(cart); cartService.add(cart);
} else { } else {
//取得规格的信息,判断规格库存 //取得规格的信息,判断规格库存
...@@ -198,7 +197,7 @@ public class WxCartController { ...@@ -198,7 +197,7 @@ public class WxCartController {
return ResponseUtil.fail(400, "商品已下架"); return ResponseUtil.fail(400, "商品已下架");
} }
LitemallProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
//判断购物车中是否存在此规格商品 //判断购物车中是否存在此规格商品
LitemallCart existCart = cartService.queryExist(goodsId, productId, userId); LitemallCart existCart = cartService.queryExist(goodsId, productId, userId);
if (existCart == null) { if (existCart == null) {
...@@ -279,7 +278,7 @@ public class WxCartController { ...@@ -279,7 +278,7 @@ public class WxCartController {
} }
//取得规格的信息,判断规格库存 //取得规格的信息,判断规格库存
LitemallProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
if (product == null || product.getNumber() < number) { if (product == null || product.getNumber() < number) {
return ResponseUtil.fail(403, "库存不足"); return ResponseUtil.fail(403, "库存不足");
} }
...@@ -501,6 +500,7 @@ public class WxCartController { ...@@ -501,6 +500,7 @@ public class WxCartController {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("addressId", addressId); data.put("addressId", addressId);
data.put("grouponRulesId", grouponRulesId); data.put("grouponRulesId", grouponRulesId);
data.put("grouponPrice", grouponPrice);
data.put("checkedAddress", checkedAddress); data.put("checkedAddress", checkedAddress);
data.put("couponId", couponId); data.put("couponId", couponId);
data.put("checkedCoupon", 0); data.put("checkedCoupon", 0);
......
...@@ -133,7 +133,6 @@ public class WxCollectController { ...@@ -133,7 +133,6 @@ public class WxCollectController {
collect.setUserId(userId); collect.setUserId(userId);
collect.setValueId(valueId); collect.setValueId(valueId);
collect.setType(type); collect.setType(type);
collect.setAddTime(LocalDateTime.now());
collectService.add(collect); collectService.add(collect);
} }
......
...@@ -74,16 +74,16 @@ public class WxCommentController { ...@@ -74,16 +74,16 @@ public class WxCommentController {
else{ else{
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Boolean hasPicture = comment.getHasPicture();
if(hasPicture == null || !hasPicture){
comment.setPicUrls(new String[0]);
}
return null; return null;
} }
/** /**
* 发表评论 * 发表评论
* *
* TODO, 对于评论,应该检测用户是否有权限评论。
* 1. 如果用户没有购买过商品,则不能发表对该商品的评论
* 2. 如果用户购买商品后规定时间内没有评论,则过期也不能再评论
*
* @param userId 用户ID * @param userId 用户ID
* @param comment 评论内容 * @param comment 评论内容
* @return 发表评论操作结果 * @return 发表评论操作结果
...@@ -105,7 +105,6 @@ public class WxCommentController { ...@@ -105,7 +105,6 @@ public class WxCommentController {
return error; return error;
} }
comment.setAddTime(LocalDateTime.now());
comment.setUserId(userId); comment.setUserId(userId);
commentService.save(comment); commentService.save(comment);
return ResponseUtil.ok(comment); return ResponseUtil.ok(comment);
......
...@@ -41,6 +41,11 @@ public class WxFeedbackController { ...@@ -41,6 +41,11 @@ public class WxFeedbackController {
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
Boolean hasPicture = feedback.getHasPicture();
if(hasPicture == null || !hasPicture){
feedback.setPicUrls(new String[0]);
}
// 测试手机号码是否正确 // 测试手机号码是否正确
String mobile = feedback.getMobile(); String mobile = feedback.getMobile();
if(StringUtils.isEmpty(mobile)){ if(StringUtils.isEmpty(mobile)){
...@@ -70,7 +75,6 @@ public class WxFeedbackController { ...@@ -70,7 +75,6 @@ public class WxFeedbackController {
feedback.setId(null); feedback.setId(null);
feedback.setUserId(userId); feedback.setUserId(userId);
feedback.setUsername(username); feedback.setUsername(username);
feedback.setAddTime(LocalDateTime.now());
//状态默认是0,1表示状态已发生变化 //状态默认是0,1表示状态已发生变化
feedback.setStatus(1); feedback.setStatus(1);
feedbackService.add(feedback); feedbackService.add(feedback);
......
...@@ -10,7 +10,6 @@ import org.linlinjava.litemall.core.validator.Sort; ...@@ -10,7 +10,6 @@ import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*; import org.linlinjava.litemall.db.service.*;
import org.linlinjava.litemall.wx.annotation.LoginUser; import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.HomeCacheManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -34,7 +33,7 @@ public class WxGoodsController { ...@@ -34,7 +33,7 @@ public class WxGoodsController {
@Autowired @Autowired
private LitemallGoodsService goodsService; private LitemallGoodsService goodsService;
@Autowired @Autowired
private LitemallProductService productService; private LitemallGoodsProductService productService;
@Autowired @Autowired
private LitemallIssueService goodsIssueService; private LitemallIssueService goodsIssueService;
@Autowired @Autowired
...@@ -99,13 +98,20 @@ public class WxGoodsController { ...@@ -99,13 +98,20 @@ public class WxGoodsController {
Object specificationList = goodsSpecificationService.getSpecificationVoList(id); Object specificationList = goodsSpecificationService.getSpecificationVoList(id);
// 商品规格对应的数量和价格 // 商品规格对应的数量和价格
List<LitemallProduct> productList = productService.queryByGid(id); List<LitemallGoodsProduct> productList = productService.queryByGid(id);
// 商品问题,这里是一些通用问题 // 商品问题,这里是一些通用问题
List<LitemallIssue> issue = goodsIssueService.query(); List<LitemallIssue> issue = goodsIssueService.query();
// 商品品牌商 // 商品品牌商
LitemallBrand brand = brandService.findById(info.getBrandId()); Integer brandId = info.getBrandId();
LitemallBrand brand = null;
if(brandId == 0){
brand = new LitemallBrand();
}
else {
brand = brandService.findById(info.getBrandId());
}
// 评论 // 评论
List<LitemallComment> comments = commentService.queryGoodsByGid(id, 0, 2); List<LitemallComment> comments = commentService.queryGoodsByGid(id, 0, 2);
...@@ -138,7 +144,6 @@ public class WxGoodsController { ...@@ -138,7 +144,6 @@ public class WxGoodsController {
// 记录用户的足迹 // 记录用户的足迹
if (userId != null) { if (userId != null) {
LitemallFootprint footprint = new LitemallFootprint(); LitemallFootprint footprint = new LitemallFootprint();
footprint.setAddTime(LocalDateTime.now());
footprint.setUserId(userId); footprint.setUserId(userId);
footprint.setGoodsId(id); footprint.setGoodsId(id);
footprintService.add(footprint); footprintService.add(footprint);
...@@ -242,7 +247,6 @@ public class WxGoodsController { ...@@ -242,7 +247,6 @@ public class WxGoodsController {
//添加到搜索历史 //添加到搜索历史
if (userId != null && !StringUtils.isNullOrEmpty(keyword)) { if (userId != null && !StringUtils.isNullOrEmpty(keyword)) {
LitemallSearchHistory searchHistoryVo = new LitemallSearchHistory(); LitemallSearchHistory searchHistoryVo = new LitemallSearchHistory();
searchHistoryVo.setAddTime(LocalDateTime.now());
searchHistoryVo.setKeyword(keyword); searchHistoryVo.setKeyword(keyword);
searchHistoryVo.setUserId(userId); searchHistoryVo.setUserId(userId);
searchHistoryVo.setFrom("wx"); searchHistoryVo.setFrom("wx");
......
...@@ -31,7 +31,6 @@ import org.springframework.transaction.TransactionDefinition; ...@@ -31,7 +31,6 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -54,7 +53,7 @@ import java.util.Map; ...@@ -54,7 +53,7 @@ import java.util.Map;
* 101 订单生成,未支付;102,下单后未支付用户取消;103,下单后未支付超时系统自动取消 * 101 订单生成,未支付;102,下单后未支付用户取消;103,下单后未支付超时系统自动取消
* 201 支付完成,商家未发货;202,订单生产,已付款未发货,但是退款取消; * 201 支付完成,商家未发货;202,订单生产,已付款未发货,但是退款取消;
* 301 商家发货,用户未确认; * 301 商家发货,用户未确认;
* 401 用户确认收货,订单结束; 402 用户没有确认收货,但是快递反馈已收获后,超过一定时间,系统自动确认收货,订单结束。 * 401 用户确认收货; 402 用户没有确认收货超过一定时间,系统自动确认收货
* *
* 当101用户未付款时,此时用户可以进行的操作是取消订单,或者付款操作 * 当101用户未付款时,此时用户可以进行的操作是取消订单,或者付款操作
* 当201支付完成而商家未发货时,此时用户可以取消订单并申请退款 * 当201支付完成而商家未发货时,此时用户可以取消订单并申请退款
...@@ -63,7 +62,6 @@ import java.util.Map; ...@@ -63,7 +62,6 @@ import java.util.Map;
* 当402系统自动确认收货以后,此时用户可以删除订单,评价商品,或者再次购买 * 当402系统自动确认收货以后,此时用户可以删除订单,评价商品,或者再次购买
* *
* 目前不支持订单退货和售后服务 * 目前不支持订单退货和售后服务
*
*/ */
@RestController @RestController
@RequestMapping("/wx/order") @RequestMapping("/wx/order")
...@@ -86,7 +84,7 @@ public class WxOrderController { ...@@ -86,7 +84,7 @@ public class WxOrderController {
@Autowired @Autowired
private LitemallRegionService regionService; private LitemallRegionService regionService;
@Autowired @Autowired
private LitemallProductService productService; private LitemallGoodsProductService productService;
@Autowired @Autowired
private WxPayService wxPayService; private WxPayService wxPayService;
@Autowired @Autowired
...@@ -101,6 +99,8 @@ public class WxOrderController { ...@@ -101,6 +99,8 @@ public class WxOrderController {
private QCodeService qCodeService; private QCodeService qCodeService;
@Autowired @Autowired
private ExpressService expressService; private ExpressService expressService;
@Autowired
private LitemallCommentService commentService;
private String detailedAddress(LitemallAddress litemallAddress) { private String detailedAddress(LitemallAddress litemallAddress) {
Integer provinceId = litemallAddress.getProvinceId(); Integer provinceId = litemallAddress.getProvinceId();
...@@ -237,23 +237,10 @@ public class WxOrderController { ...@@ -237,23 +237,10 @@ public class WxOrderController {
orderVo.put("expNo", order.getShipSn()); orderVo.put("expNo", order.getShipSn());
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(order.getId()); 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<>(); Map<String, Object> result = new HashMap<>();
result.put("orderInfo", orderVo); result.put("orderInfo", orderVo);
result.put("orderGoods", orderGoodsVoList); result.put("orderGoods", orderGoodsList);
// 订单状态为已发货且物流信息不为空 // 订单状态为已发货且物流信息不为空
//"YTO", "800669400640887922" //"YTO", "800669400640887922"
...@@ -290,6 +277,7 @@ public class WxOrderController { ...@@ -290,6 +277,7 @@ public class WxOrderController {
Integer cartId = JacksonUtil.parseInteger(body, "cartId"); Integer cartId = JacksonUtil.parseInteger(body, "cartId");
Integer addressId = JacksonUtil.parseInteger(body, "addressId"); Integer addressId = JacksonUtil.parseInteger(body, "addressId");
Integer couponId = JacksonUtil.parseInteger(body, "couponId"); Integer couponId = JacksonUtil.parseInteger(body, "couponId");
String message = JacksonUtil.parseString(body, "message");
Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId"); Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId");
Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId"); Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId");
...@@ -373,10 +361,10 @@ public class WxOrderController { ...@@ -373,10 +361,10 @@ public class WxOrderController {
order = new LitemallOrder(); order = new LitemallOrder();
order.setUserId(userId); order.setUserId(userId);
order.setOrderSn(orderService.generateOrderSn(userId)); order.setOrderSn(orderService.generateOrderSn(userId));
order.setAddTime(LocalDateTime.now());
order.setOrderStatus(OrderUtil.STATUS_CREATE); order.setOrderStatus(OrderUtil.STATUS_CREATE);
order.setConsignee(checkedAddress.getName()); order.setConsignee(checkedAddress.getName());
order.setMobile(checkedAddress.getMobile()); order.setMobile(checkedAddress.getMobile());
order.setMessage(message);
String detailedAddress = detailedAddress(checkedAddress); String detailedAddress = detailedAddress(checkedAddress);
order.setAddress(detailedAddress); order.setAddress(detailedAddress);
order.setGoodsPrice(checkedGoodsPrice); order.setGoodsPrice(checkedGoodsPrice);
...@@ -421,7 +409,7 @@ public class WxOrderController { ...@@ -421,7 +409,7 @@ public class WxOrderController {
// 商品货品数量减少 // 商品货品数量减少
for (LitemallCart checkGoods : checkedGoodsList) { for (LitemallCart checkGoods : checkedGoodsList) {
Integer productId = checkGoods.getProductId(); Integer productId = checkGoods.getProductId();
LitemallProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
Integer remainNumber = product.getNumber() - checkGoods.getNumber(); Integer remainNumber = product.getNumber() - checkGoods.getNumber();
if (remainNumber < 0) { if (remainNumber < 0) {
...@@ -429,7 +417,7 @@ public class WxOrderController { ...@@ -429,7 +417,7 @@ public class WxOrderController {
} }
product.setNumber(remainNumber); product.setNumber(remainNumber);
if(productService.updateById(product) == 0){ if(productService.updateById(product) == 0){
throw new Exception("更新数据已失效"); throw new Exception("更新数据失败");
} }
} }
...@@ -453,8 +441,6 @@ public class WxOrderController { ...@@ -453,8 +441,6 @@ public class WxOrderController {
groupon.setGrouponId(0); groupon.setGrouponId(0);
} }
groupon.setAddTime(LocalDateTime.now());
grouponService.createGroupon(groupon); grouponService.createGroupon(groupon);
} }
} catch (Exception ex) { } catch (Exception ex) {
...@@ -499,7 +485,7 @@ public class WxOrderController { ...@@ -499,7 +485,7 @@ public class WxOrderController {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Integer version = order.getVersion(); LocalDateTime preUpdateTime = order.getUpdateTime();
// 检测是否能够取消 // 检测是否能够取消
OrderHandleOption handleOption = OrderUtil.build(order); OrderHandleOption handleOption = OrderUtil.build(order);
...@@ -515,7 +501,7 @@ public class WxOrderController { ...@@ -515,7 +501,7 @@ public class WxOrderController {
// 设置订单已取消状态 // 设置订单已取消状态
order.setOrderStatus(OrderUtil.STATUS_CANCEL); order.setOrderStatus(OrderUtil.STATUS_CANCEL);
order.setEndTime(LocalDateTime.now()); order.setEndTime(LocalDateTime.now());
if(orderService.updateByIdWithVersion(version, order) == 0){ if(orderService.updateWithOptimisticLocker(order) == 0){
throw new Exception("更新数据已失效"); throw new Exception("更新数据已失效");
} }
...@@ -523,11 +509,11 @@ public class WxOrderController { ...@@ -523,11 +509,11 @@ public class WxOrderController {
List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId); List<LitemallOrderGoods> orderGoodsList = orderGoodsService.queryByOid(orderId);
for (LitemallOrderGoods orderGoods : orderGoodsList) { for (LitemallOrderGoods orderGoods : orderGoodsList) {
Integer productId = orderGoods.getProductId(); Integer productId = orderGoods.getProductId();
LitemallProduct product = productService.findById(productId); LitemallGoodsProduct product = productService.findById(productId);
Integer number = product.getNumber() + orderGoods.getNumber(); Integer number = product.getNumber() + orderGoods.getNumber();
product.setNumber(number); product.setNumber(number);
if(productService.updateById(product) == 0){ if(productService.updateById(product) == 0){
throw new Exception("更新数据已失效"); throw new Exception("更新数据失败");
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
...@@ -571,8 +557,6 @@ public class WxOrderController { ...@@ -571,8 +557,6 @@ public class WxOrderController {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Integer version = order.getVersion();
// 检测是否能够取消 // 检测是否能够取消
OrderHandleOption handleOption = OrderUtil.build(order); OrderHandleOption handleOption = OrderUtil.build(order);
if (!handleOption.isPay()) { if (!handleOption.isPay()) {
...@@ -615,7 +599,7 @@ public class WxOrderController { ...@@ -615,7 +599,7 @@ public class WxOrderController {
return ResponseUtil.fail(403, "订单不能支付"); return ResponseUtil.fail(403, "订单不能支付");
} }
if(orderService.updateByIdWithVersion(version, order) == 0){ if(orderService.updateWithOptimisticLocker(order) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDateExpired();
} }
return ResponseUtil.ok(result); return ResponseUtil.ok(result);
...@@ -666,8 +650,6 @@ public class WxOrderController { ...@@ -666,8 +650,6 @@ public class WxOrderController {
return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn);
} }
Integer version = order.getVersion();
// 检查这个订单是否已经处理过 // 检查这个订单是否已经处理过
if (OrderUtil.isPayStatus(order) && order.getPayId() != null) { if (OrderUtil.isPayStatus(order) && order.getPayId() != null) {
return WxPayNotifyResponse.success("订单已经处理成功!"); return WxPayNotifyResponse.success("订单已经处理成功!");
...@@ -681,19 +663,18 @@ public class WxOrderController { ...@@ -681,19 +663,18 @@ public class WxOrderController {
order.setPayId(payId); order.setPayId(payId);
order.setPayTime(LocalDateTime.now()); order.setPayTime(LocalDateTime.now());
order.setOrderStatus(OrderUtil.STATUS_PAY); order.setOrderStatus(OrderUtil.STATUS_PAY);
if (orderService.updateByIdWithVersion(version, order) == 0) { if (orderService.updateWithOptimisticLocker(order) == 0) {
// 这里可能存在这样一个问题,用户支付和系统自动取消订单发生在同时 // 这里可能存在这样一个问题,用户支付和系统自动取消订单发生在同时
// 如果数据库首先因为系统自动取消订单而更新了订单状态; // 如果数据库首先因为系统自动取消订单而更新了订单状态;
// 此时用户支付完成回调这里也要更新数据库,而由于乐观锁机制这里的更新会失败 // 此时用户支付完成回调这里也要更新数据库,而由于乐观锁机制这里的更新会失败
// 因此,这里会重新读取数据库检查状态是否是订单自动取消,如果是则更新成支付状态。 // 因此,这里会重新读取数据库检查状态是否是订单自动取消,如果是则更新成支付状态。
order = orderService.findBySn(orderSn); order = orderService.findBySn(orderSn);
version = order.getVersion();
int updated = 0; int updated = 0;
if(OrderUtil.isAutoCancelStatus(order)){ if(OrderUtil.isAutoCancelStatus(order)){
order.setPayId(payId); order.setPayId(payId);
order.setPayTime(LocalDateTime.now()); order.setPayTime(LocalDateTime.now());
order.setOrderStatus(OrderUtil.STATUS_PAY); order.setOrderStatus(OrderUtil.STATUS_PAY);
updated = orderService.updateByIdWithVersion(version, order); updated = orderService.updateWithOptimisticLocker(order);
} }
// 如果updated是0,那么数据库更新失败 // 如果updated是0,那么数据库更新失败
...@@ -768,8 +749,6 @@ public class WxOrderController { ...@@ -768,8 +749,6 @@ public class WxOrderController {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Integer version = order.getVersion();
OrderHandleOption handleOption = OrderUtil.build(order); OrderHandleOption handleOption = OrderUtil.build(order);
if (!handleOption.isRefund()) { if (!handleOption.isRefund()) {
return ResponseUtil.fail(403, "订单不能取消"); return ResponseUtil.fail(403, "订单不能取消");
...@@ -777,7 +756,7 @@ public class WxOrderController { ...@@ -777,7 +756,7 @@ public class WxOrderController {
// 设置订单申请退款状态 // 设置订单申请退款状态
order.setOrderStatus(OrderUtil.STATUS_REFUND); order.setOrderStatus(OrderUtil.STATUS_REFUND);
if(orderService.updateByIdWithVersion(version, order) == 0){ if(orderService.updateWithOptimisticLocker(order) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDateExpired();
} }
...@@ -817,16 +796,17 @@ public class WxOrderController { ...@@ -817,16 +796,17 @@ public class WxOrderController {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
Integer version = order.getVersion();
OrderHandleOption handleOption = OrderUtil.build(order); OrderHandleOption handleOption = OrderUtil.build(order);
if (!handleOption.isConfirm()) { if (!handleOption.isConfirm()) {
return ResponseUtil.fail(403, "订单不能确认收货"); return ResponseUtil.fail(403, "订单不能确认收货");
} }
Short comments = orderGoodsService.getComments(orderId);
order.setComments(comments);
order.setOrderStatus(OrderUtil.STATUS_CONFIRM); order.setOrderStatus(OrderUtil.STATUS_CONFIRM);
order.setConfirmTime(LocalDateTime.now()); order.setConfirmTime(LocalDateTime.now());
if(orderService.updateByIdWithVersion(version, order) == 0){ if(orderService.updateWithOptimisticLocker(order) == 0){
return ResponseUtil.updatedDateExpired(); return ResponseUtil.updatedDateExpired();
} }
return ResponseUtil.ok(); return ResponseUtil.ok();
...@@ -883,8 +863,8 @@ public class WxOrderController { ...@@ -883,8 +863,8 @@ public class WxOrderController {
* 成功则 { errno: 0, errmsg: '成功', data: xxx } * 成功则 { errno: 0, errmsg: '成功', data: xxx }
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
*/ */
@GetMapping("comment") @GetMapping("goods")
public Object comment(@LoginUser Integer userId, public Object goods(@LoginUser Integer userId,
@NotNull Integer orderId, @NotNull Integer orderId,
@NotNull Integer goodsId) { @NotNull Integer goodsId) {
if (userId == null) { if (userId == null) {
...@@ -903,4 +883,85 @@ public class WxOrderController { ...@@ -903,4 +883,85 @@ public class WxOrderController {
LitemallOrderGoods orderGoods = orderGoodsList.get(0); LitemallOrderGoods orderGoods = orderGoodsList.get(0);
return ResponseUtil.ok(orderGoods); return ResponseUtil.ok(orderGoods);
} }
/**
* 评价订单商品
* 确认商品收货后7天内可以评价
*
* @param userId 用户ID
* @param body 订单信息,{ orderId:xxx }
* @return 订单操作结果
* 成功则 { errno: 0, errmsg: '成功' }
* 失败则 { errno: XXX, errmsg: XXX }
*/
@PostMapping("comment")
public Object comment(@LoginUser Integer userId, @RequestBody String body) {
if (userId == null) {
return ResponseUtil.unlogin();
}
Integer orderGoodsId = JacksonUtil.parseInteger(body, "orderGoodsId");
if(orderGoodsId == null){
return ResponseUtil.badArgument();
}
LitemallOrderGoods orderGoods = orderGoodsService.findById(orderGoodsId);
if(orderGoods == null){
return ResponseUtil.badArgumentValue();
}
Integer orderId = orderGoods.getOrderId();
LitemallOrder order = orderService.findById(orderId);
if(order == null){
return ResponseUtil.badArgumentValue();
}
Short orderStatus = order.getOrderStatus();
if(!OrderUtil.isConfirmStatus(order) && !OrderUtil.isAutoConfirmStatus(order)) {
return ResponseUtil.fail(404, "当前商品不能评价");
}
if(!order.getUserId().equals(userId)){
return ResponseUtil.fail(404, "当前商品不属于用户");
}
Integer commentId = orderGoods.getComment();
if(commentId == -1){
return ResponseUtil.fail(404, "当前商品评价时间已经过期");
}
if(commentId != 0){
return ResponseUtil.fail(404, "订单商品已评价");
}
String content = JacksonUtil.parseString(body, "content");
Integer star = JacksonUtil.parseInteger(body, "star");
if(star == null || star < 0 || star > 5){
return ResponseUtil.badArgumentValue();
}
Boolean hasPicture = JacksonUtil.parseBoolean(body, "hasPicture");
List<String> picUrls = JacksonUtil.parseStringList(body, "picUrls");
if(hasPicture == null || !hasPicture){
picUrls = new ArrayList<>(0);
}
// 1. 创建评价
LitemallComment comment = new LitemallComment();
comment.setUserId(userId);
comment.setValueId(orderGoods.getGoodsId());
comment.setType((byte)1);
comment.setContent(content);
comment.setHasPicture(hasPicture);
comment.setPicUrls(picUrls.toArray(new String[]{}));
commentService.save(comment);
// 2. 更新订单商品的评价列表
orderGoods.setComment(comment.getId());
orderGoodsService.updateById(orderGoods);
// 3. 更新订单中未评价的订单商品可评价数量
Short commentCount = order.getComments();
if(commentCount > 0){
commentCount--;
}
order.setComments(commentCount);
orderService.updateWithOptimisticLocker(order);
return ResponseUtil.ok();
}
} }
\ No newline at end of file
...@@ -74,7 +74,8 @@ module.exports = { ...@@ -74,7 +74,8 @@ module.exports = {
OrderRefund: WxApiRoot + 'order/refund', //退款取消订单 OrderRefund: WxApiRoot + 'order/refund', //退款取消订单
OrderDelete: WxApiRoot + 'order/delete', //删除订单 OrderDelete: WxApiRoot + 'order/delete', //删除订单
OrderConfirm: WxApiRoot + 'order/confirm', //确认收货 OrderConfirm: WxApiRoot + 'order/confirm', //确认收货
OrderComment: WxApiRoot + 'order/comment', // 代评价商品信息 OrderGoods: WxApiRoot + 'order/goods', // 代评价商品信息
OrderComment: WxApiRoot + 'order/comment', // 评价订单商品信息
FeedbackAdd: WxApiRoot + 'feedback/submit', //添加反馈 FeedbackAdd: WxApiRoot + 'feedback/submit', //添加反馈
FootprintList: WxApiRoot + 'footprint/list', //足迹列表 FootprintList: WxApiRoot + 'footprint/list', //足迹列表
......
...@@ -18,6 +18,7 @@ Page({ ...@@ -18,6 +18,7 @@ Page({
cartId: 0, cartId: 0,
addressId: 0, addressId: 0,
couponId: 0, couponId: 0,
message: '',
grouponLinkId: 0, //参与的团购,如果是发起则为0 grouponLinkId: 0, //参与的团购,如果是发起则为0
grouponRulesId: 0 //团购规则ID grouponRulesId: 0 //团购规则ID
}, },
...@@ -63,6 +64,11 @@ Page({ ...@@ -63,6 +64,11 @@ Page({
url: '/pages/ucenter/addressAdd/addressAdd', url: '/pages/ucenter/addressAdd/addressAdd',
}) })
}, },
bindMessageInput: function (e) {
this.setData({
message: e.detail.value
});
},
onReady: function() { onReady: function() {
// 页面渲染完成 // 页面渲染完成
...@@ -131,6 +137,7 @@ Page({ ...@@ -131,6 +137,7 @@ Page({
cartId: this.data.cartId, cartId: this.data.cartId,
addressId: this.data.addressId, addressId: this.data.addressId,
couponId: this.data.couponId, couponId: this.data.couponId,
message: this.data.message,
grouponRulesId: this.data.grouponRulesId, grouponRulesId: this.data.grouponRulesId,
grouponLinkId: this.data.grouponLinkId grouponLinkId: this.data.grouponLinkId
}, 'POST').then(res => { }, 'POST').then(res => {
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
</view> </view>
</view> </view>
<view class="message-box">
<input class="message-item" bindinput="bindMessageInput" placeholder="如需要,可以输入订单留言" value="{{message}}" />
</view>
<view class="order-box"> <view class="order-box">
<view class="order-item"> <view class="order-item">
<view class="l"> <view class="l">
......
...@@ -140,6 +140,24 @@ page{ ...@@ -140,6 +140,24 @@ page{
height: 52.078rpx; height: 52.078rpx;
} }
.message-box{
margin-top: 20rpx;
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
}
.message-box .message-item{
height: 52.078rpx;
overflow: hidden;
background: #fff;
display: flex;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
padding-top: 26rpx;
}
.order-box{ .order-box{
margin-top: 20rpx; margin-top: 20rpx;
width: 100%; width: 100%;
......
...@@ -105,11 +105,11 @@ Page({ ...@@ -105,11 +105,11 @@ Page({
type: options.type, type: options.type,
valueId: options.valueId valueId: options.valueId
}); });
this.getOrderComment(); this.getOrderGoods();
}, },
getOrderComment: function () { getOrderGoods: function () {
let that = this; let that = this;
util.request(api.OrderComment, { util.request(api.OrderGoods, {
orderId: that.data.orderId, goodsId: that.data.valueId orderId: that.data.orderId, goodsId: that.data.valueId
}).then(function (res) { }).then(function (res) {
if (res.errno === 0) { if (res.errno === 0) {
...@@ -130,9 +130,8 @@ Page({ ...@@ -130,9 +130,8 @@ Page({
return false; return false;
} }
util.request(api.CommentPost, { util.request(api.OrderComment, {
type: that.data.type, orderGoodsId: that.data.orderGoods.id,
valueId: that.data.valueId,
content: that.data.content, content: that.data.content,
star: that.data.star, star: that.data.star,
hasPicture: that.data.hasPicture, hasPicture: that.data.hasPicture,
...@@ -142,7 +141,9 @@ Page({ ...@@ -142,7 +141,9 @@ Page({
wx.showToast({ wx.showToast({
title: '评论成功', title: '评论成功',
complete: function () { complete: function () {
wx.navigateBack(); wx.switchTab({
url: '/pages/ucenter/index/index'
})
} }
}) })
} }
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
<text class="name">{{item.goodsName}}</text> <text class="name">{{item.goodsName}}</text>
<text class="number">x{{item.number}}</text> <text class="number">x{{item.number}}</text>
</view> </view>
<view class="attr">{{item.goodsSpecificationValues}}</view> <view class="attr">{{item.specifications}}</view>
<view class="price">¥{{item.retailPrice}}</view> <view class="price">¥{{item.price}}</view>
<view class="btn active" wx:if="{{handleOption.comment}}"> <view class="btn active" wx:if="{{handleOption.comment && (item.comment == 0)}}">
<navigator url="../../commentPost/commentPost?orderId={{item.orderId}}&&valueId={{item.goodsId}}&type=0">去评价</navigator> <navigator url="../../commentPost/commentPost?orderId={{item.orderId}}&&valueId={{item.goodsId}}&type=0">去评价</navigator>
</view> </view>
<view class="btn active" wx:if="{{handleOption.rebuy}}"> <view class="btn active" wx:if="{{handleOption.rebuy}}">
...@@ -40,10 +40,6 @@ ...@@ -40,10 +40,6 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 展开 -->
<!-- <view class="data-expand p10 border-bottom" wx:if="{{ flag }}">
</view> -->
<view class="order-bottom"> <view class="order-bottom">
<view class="address"> <view class="address">
...@@ -86,5 +82,4 @@ ...@@ -86,5 +82,4 @@
</view> </view>
</view> </view>
</view> </view>
<!-- </view> -->
</view> </view>
\ No newline at end of file
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"list": [] "list": []
}, },
"miniprogram": { "miniprogram": {
"current": 33, "current": 34,
"list": [ "list": [
{ {
"id": -1, "id": -1,
...@@ -103,10 +103,10 @@ ...@@ -103,10 +103,10 @@
"query": "" "query": ""
}, },
{ {
"id": -1, "id": 12,
"name": "商品", "name": "商品",
"pathName": "pages/goods/goods", "pathName": "pages/goods/goods",
"query": "id=1181000" "query": "id=1181003"
}, },
{ {
"id": -1, "id": -1,
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
{ {
"id": -1, "id": -1,
"name": "下单", "name": "下单",
"pathName": "pages/shopping/checkout/checkout", "pathName": "pages/checkout/checkout",
"query": "" "query": ""
}, },
{ {
...@@ -233,6 +233,12 @@ ...@@ -233,6 +233,12 @@
"name": "意见反馈", "name": "意见反馈",
"pathName": "pages/ucenter/feedback/feedback", "pathName": "pages/ucenter/feedback/feedback",
"query": "" "query": ""
},
{
"id": -1,
"name": "团购专区",
"pathName": "pages/groupon/grouponList/grouponList",
"query": ""
} }
] ]
} }
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
"pages/shopping/checkout/checkout", "pages/shopping/checkout/checkout",
"pages/goods/goods", "pages/goods/goods",
"pages/groupon/myGroupon/myGroupon", "pages/groupon/myGroupon/myGroupon",
"pages/groupon/grouponDetail/grouponDetail" "pages/groupon/grouponDetail/grouponDetail",
"pages/groupon/grouponList/grouponList"
], ],
"window": { "window": {
"navigationBarTitleText": "Renard", "navigationBarTitleText": "Renard",
......
...@@ -71,7 +71,8 @@ module.exports = { ...@@ -71,7 +71,8 @@ module.exports = {
OrderRefund: WxApiRoot + 'order/refund', //退款取消订单 OrderRefund: WxApiRoot + 'order/refund', //退款取消订单
OrderDelete: WxApiRoot + 'order/delete', //删除订单 OrderDelete: WxApiRoot + 'order/delete', //删除订单
OrderConfirm: WxApiRoot + 'order/confirm', //确认收货 OrderConfirm: WxApiRoot + 'order/confirm', //确认收货
OrderComment: WxApiRoot + 'order/comment', // 代评价商品信息 OrderGoods: WxApiRoot + 'order/goods', // 代评价商品信息
OrderComment: WxApiRoot + 'order/comment', // 评价订单商品信息
FootprintList: WxApiRoot + 'footprint/list', //足迹列表 FootprintList: WxApiRoot + 'footprint/list', //足迹列表
FootprintDelete: WxApiRoot + 'footprint/delete', //删除足迹 FootprintDelete: WxApiRoot + 'footprint/delete', //删除足迹
......
...@@ -105,11 +105,11 @@ Page({ ...@@ -105,11 +105,11 @@ Page({
type: options.type, type: options.type,
valueId: options.valueId valueId: options.valueId
}); });
this.getOrderComment(); this.getOrderGoods();
}, },
getOrderComment: function () { getOrderGoods: function () {
let that = this; let that = this;
util.request(api.OrderComment, { util.request(api.OrderGoods, {
orderId: that.data.orderId, goodsId: that.data.valueId orderId: that.data.orderId, goodsId: that.data.valueId
}).then(function (res) { }).then(function (res) {
if (res.errno === 0) { if (res.errno === 0) {
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
<text class="name">{{item.goodsName}}</text> <text class="name">{{item.goodsName}}</text>
<text class="number">x{{item.number}}</text> <text class="number">x{{item.number}}</text>
</view> </view>
<view class="attr">{{item.goodsSpecificationValues}}</view> <view class="attr">{{item.specifications}}</view>
<view class="price">¥{{item.retailPrice}}</view> <view class="price">¥{{item.price}}</view>
<view class="btn active" wx:if="{{handleOption.comment}}"> <view class="btn active" wx:if="{{handleOption.comment && (item.comment == 0)}}">
<navigator url="../../commentPost/commentPost?orderId={{item.orderId}}&&valueId={{item.goodsId}}&type=0">去评价</navigator> <navigator url="../../commentPost/commentPost?orderId={{item.orderId}}&&valueId={{item.goodsId}}&type=0">去评价</navigator>
</view> </view>
<view class="btn active" wx:if="{{handleOption.rebuy}}"> <view class="btn active" wx:if="{{handleOption.rebuy}}">
......
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