Commit 6b6c8dc3 by YG8999

退款及登陆方式修改

parent 8f767caa
......@@ -20,6 +20,7 @@ import share.system.domain.vo.SOrderVo;
import share.system.domain.vo.MqttxVo;
import share.system.request.CreateOrderRequest;
import share.system.request.OrderComputedPriceRequest;
import share.system.request.OrderRefundRequest;
import share.system.response.ComputedOrderPriceResponse;
import share.system.response.OrderPayResultResponse;
import share.system.service.DeviceLogService;
......@@ -130,4 +131,14 @@ public class SOrderController extends BaseController
log.info("StoreOrderController method computedPrice 出参 {}", JsonConvertUtil.write2JsonStr(response));
return R.ok(response);
}
/**
* 申请退款
*/
@ApiOperation(value = "退款")
@RequestMapping(value = "/refund", method = RequestMethod.POST)
public R<Boolean> refund(@RequestBody OrderRefundRequest request) {
return R.ok(sOrderService.autoRefund(request));
}
}
......@@ -13,6 +13,7 @@ import share.common.utils.JsonConvertUtil;
import share.system.domain.TemplateMessage;
import share.system.request.RegisterThirdSConsumerRequest;
import share.system.request.WxBindingPhoneRequest;
import share.system.request.WxRegisterPhoneRequest;
import share.system.response.LoginResponse;
import share.system.service.SConsumerCenterService;
import share.system.service.SystemNotificationService;
......@@ -57,6 +58,16 @@ public class WeChatController {
}
/**
* 绑定注册微信手机号, 通过微信code获取手机号
*/
@ApiOperation(value = "绑定注册微信手机号")
@RequestMapping(value = "/register/wx/phone", method = RequestMethod.POST)
public R<LoginResponse> registerWechatPhone(@RequestBody @Validated WxRegisterPhoneRequest request) {
log.info("登录接口改造增加渠道参数" + JsonConvertUtil.write2JsonStr(request));
return R.ok(sConsumerCenterService.registerWechatPhone(request));
}
/**
* 微信注册绑定手机号
*/
@ApiOperation(value = "微信注册绑定手机号")
......
......@@ -154,4 +154,8 @@ public class SOrder extends BaseEntity
@TableField(exist = false)
private String roomName;
//是否可以申请退款
@TableField(exist = false)
private Boolean isRefund;
}
......@@ -186,4 +186,8 @@ public class SOrderVo
@ApiModelProperty(name = "联系人电话")
private String phone;
//是否可以申请退款
@ApiModelProperty(name = "是否可以申请退款")
private Boolean isRefund;
}
package share.system.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import share.common.constant.RegularConstants;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
/**
* 微信绑定手机号请求对象
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="WxRegisterPhoneRequest", description="微信绑定手机号请求对象")
public class WxRegisterPhoneRequest implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "手机号", required = true)
private String phone;
@ApiModelProperty(value = "类型:public-公众号,routine-小程序,iosWx-苹果微信,androidWx-安卓微信, ios-ios登录")
@NotBlank(message = "类型不能为空")
private String type;
@ApiModelProperty(value = "新用户登录时返回的key")
private String key;
@ApiModelProperty(value = "小程序获取手机号加密数据")
private String encryptedData;
@ApiModelProperty(value = "加密算法的初始向量")
private String iv;
@ApiModelProperty(value = "小程序登陆code")
@NotBlank(message = "登陆code不能为空")
private String loginCode;
@ApiModelProperty(value = "小程序手机号code")
@NotBlank(message = "手机号code不能为空")
private String phoneCode;
}
......@@ -141,4 +141,11 @@ public interface ISOrderService extends IService<SOrder>
* 退款成功
*/
void refundSuccessful(SOrder sOrder);
/**
* 小程序申请退款
* @param request
* @return
*/
boolean autoRefund(OrderRefundRequest request);
}
......@@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
import share.system.domain.SConsumer;
import share.system.request.RegisterThirdSConsumerRequest;
import share.system.request.WxBindingPhoneRequest;
import share.system.request.WxRegisterPhoneRequest;
import share.system.response.LoginResponse;
import java.math.BigDecimal;
......@@ -39,4 +40,5 @@ public interface SConsumerCenterService extends IService<SConsumer> {
LoginResponse registerLoginPhone(WxBindingPhoneRequest request);
LoginResponse registerWechatPhone(WxRegisterPhoneRequest request);
}
......@@ -25,9 +25,11 @@ import share.common.utils.wx.WxUtil;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerToken;
import share.system.domain.vo.WeChatMiniAuthorizeVo;
import share.system.domain.vo.WeChatPhoneNumberVo;
import share.system.mapper.SConsumerMapper;
import share.system.request.RegisterThirdSConsumerRequest;
import share.system.request.WxBindingPhoneRequest;
import share.system.request.WxRegisterPhoneRequest;
import share.system.response.LoginResponse;
import share.system.service.*;
import share.system.domain.vo.FrontTokenComponent;
......@@ -256,6 +258,74 @@ public class SConsumerCenterServiceImpl extends ServiceImpl<SConsumerMapper, SCo
return loginResponse;
}
@Override
public LoginResponse registerWechatPhone(WxRegisterPhoneRequest request) {
WeChatPhoneNumberVo weChatPhoneNumberVo = wechatNewService.getPhoneNumber(request.getPhoneCode());
if (weChatPhoneNumberVo == null && StrUtil.isEmpty(weChatPhoneNumberVo.getPurePhoneNumber())) {
throw new BaseException("微信用户未绑定手机号码");
} else {
request.setPhone(weChatPhoneNumberVo.getPurePhoneNumber());
}
// 进入创建用户绑定手机号流程
//访问微信小程序的API 通过 code 来获取 用户信息
WeChatMiniAuthorizeVo response = wechatNewService.miniAuthCode(request.getLoginCode());
RegisterThirdSConsumerRequest registerThirdSConsumerRequest = new RegisterThirdSConsumerRequest();
registerThirdSConsumerRequest.setOpenId(response.getOpenId());
boolean isNew = true;
SConsumer sConsumer = sConsumerService.getByPhone(request.getPhone());
if (ObjectUtil.isNull(sConsumer)) {
sConsumer = sConsumerService.registerByThird(registerThirdSConsumerRequest);
sConsumer.setPhone(request.getPhone());
sConsumer.setAccount(request.getPhone());
sConsumer.setPwd(CommonUtil.createPwd(request.getPhone()));
sConsumer.setCreateTime(DateUtil.nowDateTime());
} else {// 已有账户,关联到之前得账户即可
// 查询是否用对应得token
SConsumerToken sConsumerToken = sConsumerTokenService.getTokenByUserId(sConsumer.getId());
if (ObjectUtil.isNotNull(sConsumerToken)) {
// throw new BaseException("该手机号已被注册");
sConsumerTokenService.deleteTokenById(sConsumer.getId());
}
isNew = false;
}
SConsumer finalSConsumer = sConsumer;
boolean finalIsNew = isNew;
Boolean execute = Boolean.FALSE;
try {
if (finalIsNew) {// 新用户
Long id = sConsumerService.saveSConsumer(finalSConsumer);
finalSConsumer.setId(id);
}
sConsumerTokenService.bind(registerThirdSConsumerRequest.getOpenId(), finalSConsumer.getId());
sConsumer.setLastLoginTime(DateUtil.nowDateTime());
sConsumerService.updateById(sConsumer);
execute = Boolean.TRUE;
} catch (Exception e) {
logger.error("微信注册绑定手机号出错");
logger.error(e.toString());
}
if (!execute) {
logger.error("微信用户注册生成失败,nickName = " + registerThirdSConsumerRequest.getNickName());
}
LoginResponse loginResponse = new LoginResponse();
try {
String token = frontTokenComponent.createToken(finalSConsumer);
loginResponse.setToken(token);
} catch (Exception e) {
logger.error(StrUtil.format("绑定手机号,自动登录生成token失败,uid={}", finalSConsumer.getId()));
e.printStackTrace();
}
loginResponse.setType("login");
loginResponse.setUid(sConsumer.getId());
loginResponse.setNikeName(sConsumer.getNickName());
loginResponse.setPhone(sConsumer.getPhone());
return loginResponse;
}
/**
......
......@@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
......@@ -14,6 +15,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import share.common.constant.Constants;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
......@@ -45,6 +47,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private static final Logger logger = LoggerFactory.getLogger(SOrderServiceImpl.class);
@Value("${order.allow-refund-time}")
private Long allowRefundTime;
@Autowired
private SOrderMapper sOrderMapper;
......@@ -136,6 +140,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (ObjectUtil.isNotNull(item.getCouponId())) {
SConsumerCoupon byId = consumerCouponService.getById(item.getCouponId());
item.setCouponName(byId.getName());
// 判断是否可以退款
item.setIsRefund(isRefund(item, byId));
} else {
// 判断是否可以退款
item.setIsRefund(isRefund(item, null));
}
if (ObjectUtil.isNotNull(item.getPackId())) {
SPack byId = packService.getById(item.getPackId());
......@@ -156,6 +165,30 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
/**
* 验证是否可以申请退款
* @param order 订单信息
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrder order, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (order != null && OrderStatusEnum.UNUSED.getCode().equals(order.getStatus())){
Date startTime = order.getPreStartDate();
Date nowTime = cn.hutool.core.date.DateUtil.date();
if (startTime.compareTo(nowTime) <=0) {
return Boolean.FALSE;
}
long between = cn.hutool.core.date.DateUtil.between(nowTime,
startTime, DateUnit.SECOND);
if (between > allowRefundTime) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
/**
* 新增订单
*
* @param sOrder 订单
......@@ -346,7 +379,17 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
public SOrder getByOrderNo(String orderNo) {
LambdaQueryWrapper<SOrder> lqw = Wrappers.lambdaQuery();
lqw.eq(SOrder::getOrderNo, orderNo);
return getOne(lqw);
SOrder order = getOne(lqw);
if (ObjectUtil.isNotNull(order.getCouponId())) {
SConsumerCoupon byId = consumerCouponService.getById(order.getCouponId());
order.setCouponName(byId.getName());
// 判断是否可以退款
order.setIsRefund(isRefund(order, byId));
} else {
// 判断是否可以退款
order.setIsRefund(isRefund(order, null));
}
return order;
}
@Override
......@@ -467,6 +510,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (ObjectUtil.isNotEmpty(one.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(one.getCouponId());
one.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
one.setIsRefund(isRefund(one, consumerCoupon));
} else {
// 判断是否可以退款
one.setIsRefund(isRefund(one, null));
}
return one;
}
......@@ -527,6 +575,51 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
}
@Override
public boolean autoRefund(OrderRefundRequest request) {
SOrder sOrder = getInfoException(request.getOrderNo());
if (!YesNoEnum.yes.getIndex().equals(sOrder.getPayStatus())) {
throw new BaseException("未支付无法退款");
}
if (sOrder.getRefundPrice().add(request.getAmount()).compareTo(sOrder.getPayPrice()) > 0) {
throw new BaseException("退款金额大于支付金额,请修改退款金额");
}
if (request.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
if (sOrder.getPayPrice().compareTo(BigDecimal.ZERO) != 0) {
throw new BaseException("退款金额不能为0,请修改退款金额");
}
}
//退款
if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getValue()) && request.getAmount().compareTo(BigDecimal.ZERO) > 0) {
try {
orderRefundService.refund(request, sOrder);
} catch (Exception e) {
e.printStackTrace();
throw new BaseException("微信申请退款失败!");
}
}
//修改订单退款状态,为退款中
sOrder.setRefundStatus(RefundStatusEnum.INREFUND.getCode());
sOrder.setRefundPrice(request.getAmount());
Boolean execute = Boolean.FALSE;
try {
sOrder.setRefundReason(request.getRefundReason());
updateById(sOrder);
//微信退款
if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getValue()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) {
// 退款task, 定时任务退优惠券
redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, sOrder.getId());
}
execute = Boolean.TRUE;
} catch (Exception e) {
logger.error(e.toString());
}
if (!execute) {
throw new BaseException("订单更新失败");
}
return execute;
}
/**
* 订单DO集合转换VO集合,按距离排序
*
......@@ -554,6 +647,14 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
vo.setRoomName(room.getName());
}
});
if (ObjectUtil.isNotEmpty(o.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(o.getCouponId());
// 判断是否可以退款
vo.setIsRefund(isRefund(o, consumerCoupon));
} else {
// 判断是否可以退款
vo.setIsRefund(isRefund(o, null));
}
voList.add(vo);
});
}
......
Markdown is supported
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