chore: 错误码避免magic number
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package org.linlinjava.litemall.admin.util;
|
||||
|
||||
public class AdminResponseCode {
|
||||
public static final Integer ADMIN_INVALID_NAME = 601;
|
||||
public static final Integer ADMIN_INVALID_PASSWORD = 602;
|
||||
public static final Integer ADMIN_NAME_EXIST = 602;
|
||||
public static final Integer ADMIN_ALTER_NOT_ALLOWED = 603;
|
||||
public static final Integer ADMIN_DELETE_NOT_ALLOWED = 604;
|
||||
public static final Integer ADMIN_INVALID_ACCOUNT = 605;
|
||||
public static final Integer GOODS_UPDATE_NOT_ALLOWED = 610;
|
||||
public static final Integer GOODS_NAME_EXIST = 611;
|
||||
public static final Integer ORDER_CONFIRM_NOT_ALLOWED = 620;
|
||||
public static final Integer ORDER_REFUND_FAILED = 621;
|
||||
public static final Integer ORDER_REPLY_EXIST = 622;
|
||||
public static final Integer USER_INVALID_NAME = 630;
|
||||
public static final Integer USER_INVALID_PASSWORD = 631;
|
||||
public static final Integer USER_INVALID_MOBILE = 632;
|
||||
public static final Integer USER_NAME_EXIST = 633;
|
||||
public static final Integer USER_MOBILE_EXIST = 634;
|
||||
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/admin")
|
||||
@Validated
|
||||
@@ -80,11 +82,11 @@ public class AdminAdminController {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (!RegexUtil.isUsername(name)) {
|
||||
return ResponseUtil.fail(402, "管理员名称不符合规定");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_NAME, "管理员名称不符合规定");
|
||||
}
|
||||
String password = admin.getPassword();
|
||||
if (StringUtils.isEmpty(password) || password.length() < 6) {
|
||||
return ResponseUtil.fail(402, "管理员密码长度不能小于6");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_PASSWORD, "管理员密码长度不能小于6");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -102,7 +104,7 @@ public class AdminAdminController {
|
||||
String username = admin.getUsername();
|
||||
List<LitemallAdmin> adminList = adminService.findAdmin(username);
|
||||
if (adminList.size() > 0) {
|
||||
return ResponseUtil.fail(402, "管理员已经存在");
|
||||
return ResponseUtil.fail(ADMIN_NAME_EXIST, "管理员已经存在");
|
||||
}
|
||||
|
||||
String rawPassword = admin.getPassword();
|
||||
@@ -140,7 +142,7 @@ public class AdminAdminController {
|
||||
// TODO 这里开发者需要删除以下检验代码
|
||||
// 目前这里不允许修改超级管理员是防止演示平台上他人修改管理员密码而导致登录失败
|
||||
if (anotherAdminId == 1) {
|
||||
return ResponseUtil.fail(403, "超级管理员不能修改");
|
||||
return ResponseUtil.fail(ADMIN_ALTER_NOT_ALLOWED, "超级管理员不能修改");
|
||||
}
|
||||
|
||||
String rawPassword = admin.getPassword();
|
||||
@@ -168,7 +170,7 @@ public class AdminAdminController {
|
||||
// TODO 这里开发者需要删除以下检验代码
|
||||
// 目前这里不允许删除超级管理员是防止演示平台上他人删除管理员账号而导致登录失败
|
||||
if (anotherAdminId == 1) {
|
||||
return ResponseUtil.fail(403, "超级管理员不能删除");
|
||||
return ResponseUtil.fail(ADMIN_DELETE_NOT_ALLOWED, "超级管理员不能删除");
|
||||
}
|
||||
|
||||
adminService.deleteById(anotherAdminId);
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.ADMIN_INVALID_ACCOUNT;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/login")
|
||||
@Validated
|
||||
@@ -51,7 +53,7 @@ public class AdminAuthController {
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if (!encoder.matches(password, admin.getPassword())) {
|
||||
return ResponseUtil.fail(403, "账号密码不对");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "账号密码不对");
|
||||
}
|
||||
|
||||
Integer adminId = admin.getId();
|
||||
|
||||
@@ -27,6 +27,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.GOODS_NAME_EXIST;
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.GOODS_UPDATE_NOT_ALLOWED;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/goods")
|
||||
@Validated
|
||||
@@ -182,10 +185,10 @@ public class AdminGoodsController {
|
||||
// 检查是否存在购物车商品或者订单商品
|
||||
// 如果存在则拒绝修改商品。
|
||||
if(orderGoodsService.checkExist(id)){
|
||||
return ResponseUtil.fail(404, "商品已经在购物车中,不能修改");
|
||||
return ResponseUtil.fail(GOODS_UPDATE_NOT_ALLOWED, "商品已经在购物车中,不能修改");
|
||||
}
|
||||
if(cartService.checkExist(id)){
|
||||
return ResponseUtil.fail(404, "商品已经在订单中,不能修改");
|
||||
return ResponseUtil.fail(GOODS_UPDATE_NOT_ALLOWED, "商品已经在订单中,不能修改");
|
||||
}
|
||||
|
||||
// 开启事务管理
|
||||
@@ -285,7 +288,7 @@ public class AdminGoodsController {
|
||||
|
||||
String name = goods.getName();
|
||||
if (goodsService.checkExistByName(name)) {
|
||||
return ResponseUtil.fail(403, "商品名已经存在");
|
||||
return ResponseUtil.fail(GOODS_NAME_EXIST, "商品名已经存在");
|
||||
}
|
||||
|
||||
// 开启事务管理
|
||||
|
||||
@@ -29,6 +29,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/order")
|
||||
@Validated
|
||||
@@ -124,7 +126,7 @@ public class AdminOrderController {
|
||||
|
||||
// 如果订单不是退款状态,则不能退款
|
||||
if (!order.getOrderStatus().equals(OrderUtil.STATUS_REFUND)) {
|
||||
return ResponseUtil.fail(403, "订单不能确认收货");
|
||||
return ResponseUtil.fail(ORDER_CONFIRM_NOT_ALLOWED, "订单不能确认收货");
|
||||
}
|
||||
|
||||
// 开启事务管理
|
||||
@@ -150,7 +152,7 @@ public class AdminOrderController {
|
||||
} catch (Exception ex) {
|
||||
txManager.rollback(status);
|
||||
logger.error("系统内部错误", ex);
|
||||
return ResponseUtil.fail(403, "订单退款失败");
|
||||
return ResponseUtil.fail(ORDER_REFUND_FAILED, "订单退款失败");
|
||||
}
|
||||
|
||||
//TODO 发送邮件和短信通知,这里采用异步发送
|
||||
@@ -199,7 +201,7 @@ public class AdminOrderController {
|
||||
|
||||
// 如果订单不是已付款状态,则不能发货
|
||||
if (!order.getOrderStatus().equals(OrderUtil.STATUS_PAY)) {
|
||||
return ResponseUtil.fail(403, "订单不能确认收货");
|
||||
return ResponseUtil.fail(ORDER_CONFIRM_NOT_ALLOWED, "订单不能确认收货");
|
||||
}
|
||||
|
||||
order.setOrderStatus(OrderUtil.STATUS_SHIP);
|
||||
@@ -240,7 +242,7 @@ public class AdminOrderController {
|
||||
}
|
||||
// 目前只支持回复一次
|
||||
if (commentService.findById(commentId) != null) {
|
||||
return ResponseUtil.fail(404, "订单商品已回复!");
|
||||
return ResponseUtil.fail(ORDER_REPLY_EXIST, "订单商品已回复!");
|
||||
}
|
||||
String content = JacksonUtil.parseString(body, "content");
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.ADMIN_INVALID_ACCOUNT;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/profile")
|
||||
@Validated
|
||||
@@ -44,7 +46,7 @@ public class AdminProfileController {
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if (!encoder.matches(oldPassword, admin.getPassword())) {
|
||||
return ResponseUtil.fail(405, "账号密码不对");
|
||||
return ResponseUtil.fail(ADMIN_INVALID_ACCOUNT, "账号密码不对");
|
||||
}
|
||||
|
||||
String encodedNewPassword = encoder.encode(newPassword);
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.admin.util.AdminResponseCode.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/user")
|
||||
@Validated
|
||||
@@ -67,18 +69,18 @@ public class AdminUserController {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (!RegexUtil.isUsername(username)) {
|
||||
return ResponseUtil.fail(402, "用户名不符合规定");
|
||||
return ResponseUtil.fail(USER_INVALID_NAME, "用户名不符合规定");
|
||||
}
|
||||
String password = user.getPassword();
|
||||
if (StringUtils.isEmpty(password) || password.length() < 6) {
|
||||
return ResponseUtil.fail(402, "用户密码长度不能小于6");
|
||||
return ResponseUtil.fail(USER_INVALID_PASSWORD, "用户密码长度不能小于6");
|
||||
}
|
||||
String mobile = user.getMobile();
|
||||
if (StringUtils.isEmpty(mobile)) {
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if (!RegexUtil.isMobileExact(mobile)) {
|
||||
return ResponseUtil.fail(402, "用户手机号码格式不正确");
|
||||
return ResponseUtil.fail(USER_INVALID_MOBILE, "用户手机号码格式不正确");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -96,14 +98,14 @@ public class AdminUserController {
|
||||
String mobile = user.getMobile();
|
||||
List<LitemallUser> userList = userService.queryByUsername(username);
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "用户名已注册");
|
||||
return ResponseUtil.fail(USER_NAME_EXIST, "用户名已注册");
|
||||
}
|
||||
userList = userService.queryByMobile(mobile);
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "手机号已注册");
|
||||
return ResponseUtil.fail(USER_MOBILE_EXIST, "手机号已注册");
|
||||
}
|
||||
if (!RegexUtil.isMobileExact(mobile)) {
|
||||
return ResponseUtil.fail(403, "手机号格式不正确");
|
||||
return ResponseUtil.fail(USER_INVALID_MOBILE, "手机号格式不正确");
|
||||
}
|
||||
|
||||
String password = user.getPassword();
|
||||
|
||||
@@ -3,6 +3,39 @@ package org.linlinjava.litemall.core.util;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 响应操作结果
|
||||
* <pre>
|
||||
* {
|
||||
* errno: 错误码,
|
||||
* errmsg:错误消息,
|
||||
* data: 响应数据
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* 错误码:
|
||||
* <ul>
|
||||
* <li> 0,成功;
|
||||
* <li> 4xx,前端错误,说明前端开发者需要重新了解后端接口使用规范:
|
||||
* <ul>
|
||||
* <li> 401,参数错误,即前端没有传递后端需要的参数;
|
||||
* <li> 402,参数值错误,即前端传递的参数值不符合后端接收范围。
|
||||
* </ul>
|
||||
* <li> 5xx,后端错误,除501外,说明后端开发者应该继续优化代码,尽量避免返回后端错误码:
|
||||
* <ul>
|
||||
* <li> 501,验证失败,即后端要求用户登录;
|
||||
* <li> 502,系统内部错误,即没有合适命名的后端内部错误;
|
||||
* <li> 503,业务不支持,即后端虽然定义了接口,但是还没有实现功能;
|
||||
* <li> 504,更新数据失效,即后端采用了乐观锁更新,而并发更新时存在数据更新失效;
|
||||
* <li> 505,更新数据失败,即后端数据库更新失败(正常情况应该更新成功)。
|
||||
* </ul>
|
||||
* <li> 6xx,小商城后端业务错误码,
|
||||
* 具体见litemall-admin-api模块的AdminResponseCode。
|
||||
* <li> 7xx,管理后台后端业务错误码,
|
||||
* 具体见litemall-wx-api模块的WxResponseCode。
|
||||
* </ul>
|
||||
*/
|
||||
public class ResponseUtil {
|
||||
public static Object ok() {
|
||||
Map<String, Object> obj = new HashMap<String, Object>();
|
||||
@@ -49,14 +82,6 @@ public class ResponseUtil {
|
||||
return fail(402, "参数值不对");
|
||||
}
|
||||
|
||||
public static Object updatedDateExpired() {
|
||||
return fail(403, "更新数据已经失效");
|
||||
}
|
||||
|
||||
public static Object updatedDataFailed() {
|
||||
return fail(404, "更新数据失败");
|
||||
}
|
||||
|
||||
public static Object unlogin() {
|
||||
return fail(501, "请登录");
|
||||
}
|
||||
@@ -68,5 +93,13 @@ public class ResponseUtil {
|
||||
public static Object unsupport() {
|
||||
return fail(503, "业务不支持");
|
||||
}
|
||||
|
||||
public static Object updatedDateExpired() {
|
||||
return fail(504, "更新数据已经失效");
|
||||
}
|
||||
|
||||
public static Object updatedDataFailed() {
|
||||
return fail(505, "更新数据失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.linlinjava.litemall.wx.util;
|
||||
|
||||
public class WxResponseCode {
|
||||
public static final Integer AUTH_INVALID_ACCOUNT = 700;
|
||||
public static final Integer AUTH_CAPTCHA_UNSUPPORT = 701;
|
||||
public static final Integer AUTH_CAPTCHA_FREQUENCY = 702;
|
||||
public static final Integer AUTH_CAPTCHA_UNMATCH = 703;
|
||||
public static final Integer AUTH_NAME_REGISTERED = 704;
|
||||
public static final Integer AUTH_MOBILE_REGISTERED = 705;
|
||||
public static final Integer AUTH_MOBILE_UNREGISTERED = 706;
|
||||
public static final Integer AUTH_INVALID_MOBILE = 707;
|
||||
public static final Integer AUTH_OPENID_UNACCESS = 708;
|
||||
public static final Integer AUTH_OPENID_BINDED = 709;
|
||||
|
||||
public static final Integer GOODS_UNSHELVE = 710;
|
||||
public static final Integer GOODS_NO_STOCK = 711;
|
||||
public static final Integer GOODS_UNKNOWN = 712;
|
||||
public static final Integer GOODS_INVALID = 713;
|
||||
|
||||
public static final Integer ORDER_UNKNOWN = 720;
|
||||
public static final Integer ORDER_INVALID = 721;
|
||||
public static final Integer ORDER_CHECKOUT_FAIL = 722;
|
||||
public static final Integer ORDER_CANCEL_FAIL = 723;
|
||||
public static final Integer ORDER_PAY_FAIL = 724;
|
||||
// 订单当前状态下不支持用户的操作,例如商品未发货状态用户执行确认收货是不可能的。
|
||||
public static final Integer ORDER_INVALID_OPERATION = 725;
|
||||
public static final Integer ORDER_COMMENTED = 726;
|
||||
public static final Integer ORDER_COMMENT_EXPIRED = 727;
|
||||
|
||||
public static final Integer GROUPON_EXPIRED = 730;
|
||||
}
|
||||
@@ -35,6 +35,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.wx.util.WxResponseCode.*;
|
||||
|
||||
/**
|
||||
* 鉴权服务
|
||||
*/
|
||||
@@ -80,7 +82,7 @@ public class WxAuthController {
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if (!encoder.matches(password, user.getPassword())) {
|
||||
return ResponseUtil.fail(403, "账号密码不对");
|
||||
return ResponseUtil.fail(AUTH_INVALID_ACCOUNT, "账号密码不对");
|
||||
}
|
||||
|
||||
// userInfo
|
||||
@@ -179,14 +181,14 @@ public class WxAuthController {
|
||||
}
|
||||
|
||||
if (!notifyService.isSmsEnable()) {
|
||||
return ResponseUtil.fail(404, "小程序后台验证码服务不支持");
|
||||
return ResponseUtil.fail(AUTH_CAPTCHA_UNSUPPORT, "小程序后台验证码服务不支持");
|
||||
}
|
||||
String code = CharUtil.getRandomNum(6);
|
||||
notifyService.notifySmsTemplate(phoneNumber, NotifyType.CAPTCHA, new String[]{code});
|
||||
|
||||
boolean successful = CaptchaCodeManager.addToCache(phoneNumber, code);
|
||||
if (!successful) {
|
||||
return ResponseUtil.fail(404, "验证码未超时1分钟,不能发送");
|
||||
return ResponseUtil.fail(AUTH_CAPTCHA_FREQUENCY, "验证码未超时1分钟,不能发送");
|
||||
}
|
||||
|
||||
return ResponseUtil.ok();
|
||||
@@ -233,20 +235,20 @@ public class WxAuthController {
|
||||
|
||||
List<LitemallUser> userList = userService.queryByUsername(username);
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "用户名已注册");
|
||||
return ResponseUtil.fail(AUTH_NAME_REGISTERED, "用户名已注册");
|
||||
}
|
||||
|
||||
userList = userService.queryByMobile(mobile);
|
||||
if (userList.size() > 0) {
|
||||
return ResponseUtil.fail(403, "手机号已注册");
|
||||
return ResponseUtil.fail(AUTH_MOBILE_REGISTERED, "手机号已注册");
|
||||
}
|
||||
if (!RegexUtil.isMobileExact(mobile)) {
|
||||
return ResponseUtil.fail(403, "手机号格式不正确");
|
||||
return ResponseUtil.fail(AUTH_INVALID_MOBILE, "手机号格式不正确");
|
||||
}
|
||||
//判断验证码是否正确
|
||||
String cacheCode = CaptchaCodeManager.getCachedCaptcha(mobile);
|
||||
if (cacheCode == null || cacheCode.isEmpty() || !cacheCode.equals(code)) {
|
||||
return ResponseUtil.fail(403, "验证码错误");
|
||||
return ResponseUtil.fail(AUTH_CAPTCHA_UNMATCH, "验证码错误");
|
||||
}
|
||||
|
||||
String openId = null;
|
||||
@@ -255,18 +257,18 @@ public class WxAuthController {
|
||||
openId = result.getOpenid();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.fail(403, "openid 获取失败");
|
||||
return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "openid 获取失败");
|
||||
}
|
||||
userList = userService.queryByOpenid(openId);
|
||||
if (userList.size() > 1) {
|
||||
return ResponseUtil.fail(403, "openid 存在多个");
|
||||
return ResponseUtil.serious();
|
||||
}
|
||||
if (userList.size() == 1) {
|
||||
LitemallUser checkUser = userList.get(0);
|
||||
String checkUsername = checkUser.getUsername();
|
||||
String checkPassword = checkUser.getPassword();
|
||||
if (!checkUsername.equals(openId) || !checkPassword.equals(openId)) {
|
||||
return ResponseUtil.fail(403, "openid已绑定账号");
|
||||
return ResponseUtil.fail(AUTH_OPENID_BINDED, "openid已绑定账号");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,14 +332,14 @@ public class WxAuthController {
|
||||
//判断验证码是否正确
|
||||
String cacheCode = CaptchaCodeManager.getCachedCaptcha(mobile);
|
||||
if (cacheCode == null || cacheCode.isEmpty() || !cacheCode.equals(code))
|
||||
return ResponseUtil.fail(403, "验证码错误");
|
||||
return ResponseUtil.fail(AUTH_CAPTCHA_UNMATCH, "验证码错误");
|
||||
|
||||
List<LitemallUser> userList = userService.queryByMobile(mobile);
|
||||
LitemallUser user = null;
|
||||
if (userList.size() > 1) {
|
||||
return ResponseUtil.serious();
|
||||
} else if (userList.size() == 0) {
|
||||
return ResponseUtil.fail(403, "手机号未注册");
|
||||
return ResponseUtil.fail(AUTH_MOBILE_UNREGISTERED, "手机号未注册");
|
||||
} else {
|
||||
user = userList.get(0);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.wx.util.WxResponseCode.GOODS_NO_STOCK;
|
||||
import static org.linlinjava.litemall.wx.util.WxResponseCode.GOODS_UNSHELVE;
|
||||
|
||||
/**
|
||||
* 用户购物车服务
|
||||
*/
|
||||
@@ -106,7 +109,7 @@ public class WxCartController {
|
||||
//判断商品是否可以购买
|
||||
LitemallGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null || !goods.getIsOnSale()) {
|
||||
return ResponseUtil.fail(400, "商品已下架");
|
||||
return ResponseUtil.fail(GOODS_UNSHELVE, "商品已下架");
|
||||
}
|
||||
|
||||
LitemallGoodsProduct product = productService.findById(productId);
|
||||
@@ -115,7 +118,7 @@ public class WxCartController {
|
||||
if (existCart == null) {
|
||||
//取得规格的信息,判断规格库存
|
||||
if (product == null || number > product.getNumber()) {
|
||||
return ResponseUtil.fail(400, "库存不足");
|
||||
return ResponseUtil.fail(GOODS_NO_STOCK, "库存不足");
|
||||
}
|
||||
|
||||
cart.setId(null);
|
||||
@@ -131,7 +134,7 @@ public class WxCartController {
|
||||
//取得规格的信息,判断规格库存
|
||||
int num = existCart.getNumber() + number;
|
||||
if (num > product.getNumber()) {
|
||||
return ResponseUtil.fail(400, "库存不足");
|
||||
return ResponseUtil.fail(GOODS_NO_STOCK, "库存不足");
|
||||
}
|
||||
existCart.setNumber((short) num);
|
||||
if (cartService.updateById(existCart) == 0) {
|
||||
@@ -172,7 +175,7 @@ public class WxCartController {
|
||||
//判断商品是否可以购买
|
||||
LitemallGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null || !goods.getIsOnSale()) {
|
||||
return ResponseUtil.fail(400, "商品已下架");
|
||||
return ResponseUtil.fail(GOODS_UNSHELVE, "商品已下架");
|
||||
}
|
||||
|
||||
LitemallGoodsProduct product = productService.findById(productId);
|
||||
@@ -181,7 +184,7 @@ public class WxCartController {
|
||||
if (existCart == null) {
|
||||
//取得规格的信息,判断规格库存
|
||||
if (product == null || number > product.getNumber()) {
|
||||
return ResponseUtil.fail(400, "库存不足");
|
||||
return ResponseUtil.fail(GOODS_NO_STOCK, "库存不足");
|
||||
}
|
||||
|
||||
cart.setId(null);
|
||||
@@ -197,7 +200,7 @@ public class WxCartController {
|
||||
//取得规格的信息,判断规格库存
|
||||
int num = number;
|
||||
if (num > product.getNumber()) {
|
||||
return ResponseUtil.fail(400, "库存不足");
|
||||
return ResponseUtil.fail(GOODS_NO_STOCK, "库存不足");
|
||||
}
|
||||
existCart.setNumber((short) num);
|
||||
if (cartService.updateById(existCart) == 0) {
|
||||
@@ -249,13 +252,13 @@ public class WxCartController {
|
||||
//判断商品是否可以购买
|
||||
LitemallGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null || !goods.getIsOnSale()) {
|
||||
return ResponseUtil.fail(403, "商品已下架");
|
||||
return ResponseUtil.fail(GOODS_UNSHELVE, "商品已下架");
|
||||
}
|
||||
|
||||
//取得规格的信息,判断规格库存
|
||||
LitemallGoodsProduct product = productService.findById(productId);
|
||||
if (product == null || product.getNumber() < number) {
|
||||
return ResponseUtil.fail(403, "库存不足");
|
||||
return ResponseUtil.fail(GOODS_UNSHELVE, "库存不足");
|
||||
}
|
||||
|
||||
existCart.setNumber(number.shortValue());
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.wx.util.WxResponseCode.*;
|
||||
|
||||
/**
|
||||
* 团购服务
|
||||
* <p>
|
||||
@@ -98,10 +100,10 @@ public class WxGrouponController {
|
||||
// 订单信息
|
||||
LitemallOrder order = orderService.findById(groupon.getOrderId());
|
||||
if (null == order) {
|
||||
return ResponseUtil.fail(403, "订单不存在");
|
||||
return ResponseUtil.fail(ORDER_UNKNOWN, "订单不存在");
|
||||
}
|
||||
if (!order.getUserId().equals(userId)) {
|
||||
return ResponseUtil.fail(403, "不是当前用户的订单");
|
||||
return ResponseUtil.fail(ORDER_INVALID, "不是当前用户的订单");
|
||||
}
|
||||
Map<String, Object> orderVo = new HashMap<String, Object>();
|
||||
orderVo.put("id", order.getId());
|
||||
@@ -288,7 +290,7 @@ public class WxGrouponController {
|
||||
public Object query(@NotNull Integer goodsId) {
|
||||
LitemallGoods goods = goodsService.findById(goodsId);
|
||||
if (goods == null) {
|
||||
return ResponseUtil.fail(-1, "未找到对应的商品");
|
||||
return ResponseUtil.fail(GOODS_UNKNOWN, "未找到对应的商品");
|
||||
}
|
||||
|
||||
List<LitemallGrouponRules> rules = rulesService.queryByGoodsId(goodsId);
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.linlinjava.litemall.wx.util.WxResponseCode.*;
|
||||
|
||||
/**
|
||||
* 订单服务
|
||||
*
|
||||
@@ -197,10 +199,10 @@ public class WxOrderController {
|
||||
// 订单信息
|
||||
LitemallOrder order = orderService.findById(orderId);
|
||||
if (null == order) {
|
||||
return ResponseUtil.fail(403, "订单不存在");
|
||||
return ResponseUtil.fail(ORDER_UNKNOWN, "订单不存在");
|
||||
}
|
||||
if (!order.getUserId().equals(userId)) {
|
||||
return ResponseUtil.fail(403, "不是当前用户的订单");
|
||||
return ResponseUtil.fail(ORDER_INVALID, "不是当前用户的订单");
|
||||
}
|
||||
Map<String, Object> orderVo = new HashMap<String, Object>();
|
||||
orderVo.put("id", order.getId());
|
||||
@@ -271,7 +273,7 @@ public class WxOrderController {
|
||||
}
|
||||
//团购活动已经过期
|
||||
if (grouponRulesService.isExpired(rules)) {
|
||||
return ResponseUtil.fail(402, "团购活动已过期!");
|
||||
return ResponseUtil.fail(GROUPON_EXPIRED, "团购活动已过期!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,7 +428,7 @@ public class WxOrderController {
|
||||
} catch (Exception ex) {
|
||||
txManager.rollback(status);
|
||||
logger.error("系统内部错误", ex);
|
||||
return ResponseUtil.fail(403, "下单失败");
|
||||
return ResponseUtil.fail(ORDER_CHECKOUT_FAIL, "下单失败");
|
||||
}
|
||||
txManager.commit(status);
|
||||
|
||||
@@ -471,7 +473,7 @@ public class WxOrderController {
|
||||
// 检测是否能够取消
|
||||
OrderHandleOption handleOption = OrderUtil.build(order);
|
||||
if (!handleOption.isCancel()) {
|
||||
return ResponseUtil.fail(403, "订单不能取消");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能取消");
|
||||
}
|
||||
|
||||
// 开启事务管理
|
||||
@@ -498,7 +500,7 @@ public class WxOrderController {
|
||||
} catch (Exception ex) {
|
||||
txManager.rollback(status);
|
||||
logger.error("系统内部错误", ex);
|
||||
return ResponseUtil.fail(403, "订单取消失败");
|
||||
return ResponseUtil.fail(ORDER_CANCEL_FAIL, "订单取消失败");
|
||||
}
|
||||
txManager.commit(status);
|
||||
|
||||
@@ -537,13 +539,13 @@ public class WxOrderController {
|
||||
// 检测是否能够取消
|
||||
OrderHandleOption handleOption = OrderUtil.build(order);
|
||||
if (!handleOption.isPay()) {
|
||||
return ResponseUtil.fail(403, "订单不能支付");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能支付");
|
||||
}
|
||||
|
||||
LitemallUser user = userService.findById(userId);
|
||||
String openid = user.getWeixinOpenid();
|
||||
if (openid == null) {
|
||||
return ResponseUtil.fail(403, "订单不能支付");
|
||||
return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "订单不能支付");
|
||||
}
|
||||
WxPayMpOrderResult result = null;
|
||||
try {
|
||||
@@ -573,7 +575,7 @@ public class WxOrderController {
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseUtil.fail(403, "订单不能支付");
|
||||
return ResponseUtil.fail(ORDER_PAY_FAIL, "订单不能支付");
|
||||
}
|
||||
|
||||
if (orderService.updateWithOptimisticLocker(order) == 0) {
|
||||
@@ -726,7 +728,7 @@ public class WxOrderController {
|
||||
|
||||
OrderHandleOption handleOption = OrderUtil.build(order);
|
||||
if (!handleOption.isRefund()) {
|
||||
return ResponseUtil.fail(403, "订单不能取消");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能取消");
|
||||
}
|
||||
|
||||
// 设置订单申请退款状态
|
||||
@@ -772,7 +774,7 @@ public class WxOrderController {
|
||||
|
||||
OrderHandleOption handleOption = OrderUtil.build(order);
|
||||
if (!handleOption.isConfirm()) {
|
||||
return ResponseUtil.fail(403, "订单不能确认收货");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能确认收货");
|
||||
}
|
||||
|
||||
Short comments = orderGoodsService.getComments(orderId);
|
||||
@@ -816,7 +818,7 @@ public class WxOrderController {
|
||||
|
||||
OrderHandleOption handleOption = OrderUtil.build(order);
|
||||
if (!handleOption.isDelete()) {
|
||||
return ResponseUtil.fail(403, "订单不能删除");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能删除");
|
||||
}
|
||||
|
||||
// 订单order_status没有字段用于标识删除
|
||||
@@ -885,17 +887,17 @@ public class WxOrderController {
|
||||
}
|
||||
Short orderStatus = order.getOrderStatus();
|
||||
if (!OrderUtil.isConfirmStatus(order) && !OrderUtil.isAutoConfirmStatus(order)) {
|
||||
return ResponseUtil.fail(404, "当前商品不能评价");
|
||||
return ResponseUtil.fail(ORDER_INVALID_OPERATION, "当前商品不能评价");
|
||||
}
|
||||
if (!order.getUserId().equals(userId)) {
|
||||
return ResponseUtil.fail(404, "当前商品不属于用户");
|
||||
return ResponseUtil.fail(ORDER_INVALID, "当前商品不属于用户");
|
||||
}
|
||||
Integer commentId = orderGoods.getComment();
|
||||
if (commentId == -1) {
|
||||
return ResponseUtil.fail(404, "当前商品评价时间已经过期");
|
||||
return ResponseUtil.fail(ORDER_COMMENT_EXPIRED, "当前商品评价时间已经过期");
|
||||
}
|
||||
if (commentId != 0) {
|
||||
return ResponseUtil.fail(404, "订单商品已评价");
|
||||
return ResponseUtil.fail(ORDER_COMMENTED, "订单商品已评价");
|
||||
}
|
||||
|
||||
String content = JacksonUtil.parseString(body, "content");
|
||||
|
||||
Reference in New Issue
Block a user