"...src/main/java/me/zhengjie/rest/SysLogController.java" did not exist on "905c8c649c3af675275200db5443e49cc13f6a6b"
Commit 7b90484d authored by Junling Bu's avatar Junling Bu
Browse files

chore: 错误码避免magic number

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