|
|
|
@ -1,14 +1,34 @@ |
|
|
|
package org.jeecg.modules.applet.service.impl; |
|
|
|
|
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
|
|
|
import com.xkcoding.http.util.StringUtil; |
|
|
|
import org.jeecg.common.api.IAppletUserService; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.exception.JeecgBootException; |
|
|
|
import org.jeecg.common.system.util.AppletUserUtil; |
|
|
|
import org.jeecg.common.system.vo.AppletUser; |
|
|
|
import org.jeecg.modules.applet.service.AppletApiVipService; |
|
|
|
import org.jeecg.modules.common.IdUtils; |
|
|
|
import org.jeecg.modules.demo.appletCoupon.entity.AppletCoupon; |
|
|
|
import org.jeecg.modules.demo.appletCoupon.service.IAppletCouponService; |
|
|
|
import org.jeecg.modules.demo.appletMemberOrder.entity.AppletMemberOrder; |
|
|
|
import org.jeecg.modules.demo.appletMemberOrder.service.IAppletMemberOrderService; |
|
|
|
import org.jeecg.modules.demo.appletVip.entity.AppletSetmeal; |
|
|
|
import org.jeecg.modules.demo.appletVip.entity.AppletVip; |
|
|
|
import org.jeecg.modules.demo.appletVip.service.IAppletSetmealService; |
|
|
|
import org.jeecg.modules.demo.appletVip.service.IAppletVipService; |
|
|
|
import org.jeecg.modules.demo.appletWater.entity.AppletWater; |
|
|
|
import org.jeecg.modules.demo.appletWater.service.IAppletWaterService; |
|
|
|
import org.jeecg.modules.pay.MpWxPayService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@ -17,6 +37,17 @@ public class AppletApiVipServiceImpl implements AppletApiVipService { |
|
|
|
private IAppletVipService appletApiVipService; |
|
|
|
@Autowired |
|
|
|
private IAppletSetmealService appletSetmealService; |
|
|
|
@Autowired |
|
|
|
private IAppletMemberOrderService appletMemberOrderService; |
|
|
|
@Autowired |
|
|
|
private IAppletCouponService appletCouponService; |
|
|
|
@Autowired |
|
|
|
private IAppletWaterService appletWaterService; |
|
|
|
@Autowired |
|
|
|
private IAppletUserService appletUserService; |
|
|
|
//支付接口 |
|
|
|
@Autowired |
|
|
|
private MpWxPayService mpWxPayService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询会员列表 |
|
|
|
@ -34,10 +65,164 @@ public class AppletApiVipServiceImpl implements AppletApiVipService { |
|
|
|
List<AppletVip> list = appletApiVipService.list(); |
|
|
|
for (AppletVip vip : list) { |
|
|
|
vip.setSetmeals(appletSetmealService |
|
|
|
.lambdaQuery() |
|
|
|
.eq(AppletSetmeal::getVipId,vip.getId()) |
|
|
|
.lambdaQuery() |
|
|
|
.eq(AppletSetmeal::getVipId, vip.getId()) |
|
|
|
.list()); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 开通会员 |
|
|
|
* |
|
|
|
* @param order |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Object getOpe(AppletMemberOrder order) { |
|
|
|
|
|
|
|
if (StringUtil.isEmpty(order.getMemberId())) { |
|
|
|
throw new JeecgBootException("会员id不能为空"); |
|
|
|
} |
|
|
|
if (StringUtil.isEmpty(order.getSetmealId())) { |
|
|
|
throw new JeecgBootException("套餐id不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
AppletVip vip = appletApiVipService.getById(order.getMemberId()); |
|
|
|
AppletSetmeal setmeal = appletSetmealService.getById(order.getSetmealId()); |
|
|
|
if (vip == null) { |
|
|
|
throw new JeecgBootException("会员不存在"); |
|
|
|
} |
|
|
|
if (setmeal == null) { |
|
|
|
throw new JeecgBootException("套餐不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
//获取用户id |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
String openid = AppletUserUtil.getCurrentAppletUserOpenid(); |
|
|
|
|
|
|
|
order.setUserId(userId); |
|
|
|
order.setStatus("0"); |
|
|
|
order.setOrderNo(IdUtils.generateNoORD()); |
|
|
|
|
|
|
|
order.setPrice(setmeal.getDiscountedprice()); |
|
|
|
order.setDay(setmeal.getEndTime()); |
|
|
|
order.setSetmealTitle(setmeal.getTitle()); |
|
|
|
order.setRate(setmeal.getProportion()); |
|
|
|
|
|
|
|
order.setMemberTitle(vip.getTitle()); |
|
|
|
|
|
|
|
// 获取当前时间 |
|
|
|
Date now = new Date(); |
|
|
|
// 获取套餐天数 |
|
|
|
Integer days = setmeal.getEndTime(); |
|
|
|
if (days != null && days > 0) { |
|
|
|
// 计算结束时间:当前时间 + 套餐天数 |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.setTime(now); |
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, days); |
|
|
|
order.setEndTime(calendar.getTime()); |
|
|
|
} else { |
|
|
|
// 如果天数为空或无效,默认设置为当前时间 |
|
|
|
order.setEndTime(now); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtil.isNotEmpty(order.getCouponId())) { |
|
|
|
// 计算优惠 |
|
|
|
AppletCoupon coupon = appletCouponService.getById(order.getCouponId()); |
|
|
|
if (coupon == null) { |
|
|
|
throw new JeecgBootException("优惠卷不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO 需要判断忧患卷的状态等 |
|
|
|
|
|
|
|
order.setDiscount(coupon.getMoney()); |
|
|
|
|
|
|
|
if (coupon.getMoney() != null) { |
|
|
|
order.setPrice(order.getPrice().subtract(coupon.getMoney())); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int price = order.getPrice().multiply(new BigDecimal(100)).intValue(); |
|
|
|
|
|
|
|
if (price > 0) { |
|
|
|
appletMemberOrderService.save(order); |
|
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
"购买" + order.getMemberTitle(), |
|
|
|
"127.0.0.1", |
|
|
|
order.getId(), |
|
|
|
price, |
|
|
|
order.getId(), |
|
|
|
openid, |
|
|
|
order.toString()); |
|
|
|
|
|
|
|
return appOrder; |
|
|
|
} else { |
|
|
|
//直接修改订单状态 |
|
|
|
order.setStatus("1"); |
|
|
|
|
|
|
|
} |
|
|
|
appletMemberOrderService.save(order); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object payNotify(String requestBody) { |
|
|
|
WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody); |
|
|
|
String outTradeNo = notify.getOutTradeNo(); |
|
|
|
|
|
|
|
AppletMemberOrder order = appletMemberOrderService.getById(outTradeNo); |
|
|
|
|
|
|
|
if (order != null) { |
|
|
|
order.setStatus("1"); |
|
|
|
appletMemberOrderService.updateById(order); |
|
|
|
|
|
|
|
//支付流水 |
|
|
|
appletWaterService.save(AppletWater.builder() |
|
|
|
.user(order.getUserId()) |
|
|
|
.money(order.getPrice()) |
|
|
|
.number(IdUtils.generateNoLS()) |
|
|
|
.title("开通" + order.getMemberTitle()) |
|
|
|
.type("0") |
|
|
|
.build()); |
|
|
|
|
|
|
|
AppletUser user = appletUserService.getById(order.getUserId()); |
|
|
|
if (user != null && user.getInviter() != null && order.getRate() != null) { |
|
|
|
AppletUser userInviter = appletUserService.getById(user.getInviter()); |
|
|
|
if (userInviter != null) { |
|
|
|
|
|
|
|
//计算分销金额 |
|
|
|
BigDecimal price = order.getPrice().multiply(new BigDecimal(order.getRate())); |
|
|
|
|
|
|
|
appletWaterService.save(AppletWater.builder() |
|
|
|
.source(order.getUserId()) |
|
|
|
.user(userInviter.getId()) |
|
|
|
.money(price) |
|
|
|
.number(IdUtils.generateNoLS()) |
|
|
|
.title("开通" + order.getMemberTitle() + "分销金额") |
|
|
|
.orderId(order.getId()) |
|
|
|
.type("0") |
|
|
|
.build()); |
|
|
|
//佣金 |
|
|
|
BigDecimal commission = userInviter.getCommission() == null ? BigDecimal.ZERO : userInviter.getCommission(); |
|
|
|
userInviter.setCommission(commission.add(price)); |
|
|
|
|
|
|
|
// 更新邀请人的总佣金到price字段 |
|
|
|
BigDecimal totalPrice = userInviter.getPrice() == null ? BigDecimal.ZERO : userInviter.getPrice(); |
|
|
|
userInviter.setPrice(totalPrice.add(price)); |
|
|
|
appletUserService.updateById(userInviter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "<xml>" + |
|
|
|
" <return_code><![CDATA[SUCCESS]]></return_code>" + |
|
|
|
" <return_msg><![CDATA[OK]]></return_msg>" + |
|
|
|
" </xml>"; |
|
|
|
} |
|
|
|
|
|
|
|
} |