|
|
|
@ -16,12 +16,24 @@ import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService; |
|
|
|
import org.jeecg.modules.pay.MpWxPayService; |
|
|
|
import org.jeecg.modules.studytourActivity.entity.StudytourActivity; |
|
|
|
import org.jeecg.modules.studytourActivity.service.IStudytourActivityService; |
|
|
|
import org.jeecg.modules.studytourCommissionLog.entity.StudytourCommissionLog; |
|
|
|
import org.jeecg.modules.studytourCommissionLog.service.IStudytourCommissionLogService; |
|
|
|
import org.jeecg.modules.studytourMedal.entity.StudytourMedal; |
|
|
|
import org.jeecg.modules.studytourMedal.service.IStudytourMedalService; |
|
|
|
import org.jeecg.modules.studytourMedalActivity.entity.StudytourMedalActivity; |
|
|
|
import org.jeecg.modules.studytourMedalActivity.service.IStudytourMedalActivityService; |
|
|
|
import org.jeecg.modules.studytourMedalUser.entity.StudytourMedalUser; |
|
|
|
import org.jeecg.modules.studytourMedalUser.service.IStudytourMedalUserService; |
|
|
|
import org.jeecg.modules.studytourNotice.entity.StudytourNotice; |
|
|
|
import org.jeecg.modules.studytourNotice.service.IStudytourNoticeService; |
|
|
|
import org.jeecg.modules.studytourOrder.entity.StudytourOrder; |
|
|
|
import org.jeecg.modules.studytourOrder.entity.StudytourOrderPerson; |
|
|
|
import org.jeecg.modules.studytourOrder.service.IStudytourOrderPersonService; |
|
|
|
import org.jeecg.modules.studytourOrder.service.IStudytourOrderService; |
|
|
|
import org.jeecg.modules.studytourPerson.entity.StudytourPerson; |
|
|
|
import org.jeecg.modules.studytourPerson.service.IStudytourPersonService; |
|
|
|
import org.jeecg.modules.studytourRecord.entity.StudytourRecord; |
|
|
|
import org.jeecg.modules.studytourRecord.service.IStudytourRecordService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
@ -58,6 +70,24 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
//订单出行人信息 |
|
|
|
@Resource |
|
|
|
private IStudytourOrderPersonService studytourOrderPersonService; |
|
|
|
//勋章信息 |
|
|
|
@Resource |
|
|
|
private IStudytourMedalService studytourMedalService; |
|
|
|
//活动勋章信息 |
|
|
|
@Resource |
|
|
|
private IStudytourMedalActivityService studytourMedalActivityService; |
|
|
|
//用户勋章信息 |
|
|
|
@Resource |
|
|
|
private IStudytourMedalUserService studytourMedalUserService; |
|
|
|
//用户成长档案信息 |
|
|
|
@Resource |
|
|
|
private IStudytourRecordService studytourRecordService; |
|
|
|
//开营通知信息 |
|
|
|
@Resource |
|
|
|
private IStudytourNoticeService studytourNoticeService; |
|
|
|
//佣金记录信息 |
|
|
|
@Resource |
|
|
|
private IStudytourCommissionLogService studytourCommissionLogService; |
|
|
|
/******************************************************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
@ -245,7 +275,8 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
public Result<?> updateOrder(String token, StudytourOrder studytourOrder) { |
|
|
|
log.info("开始修改订单"); |
|
|
|
//权限验证 |
|
|
|
HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);//小程序权限验证 |
|
|
|
//HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);//小程序权限验证 |
|
|
|
HanHaiMember hanHaiMember = hanHaiMemberService.getById(token); |
|
|
|
|
|
|
|
try{ |
|
|
|
//查询订单是否存在 |
|
|
|
@ -260,6 +291,16 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
|
|
|
|
//修改订单信息 |
|
|
|
studytourOrderService.updateById(studytourOrder); |
|
|
|
|
|
|
|
if("2".equals(studytourOrder.getStatus())){ |
|
|
|
|
|
|
|
//1、添加用户勋章 |
|
|
|
getMedal(order); |
|
|
|
|
|
|
|
//2、添加成长档案 |
|
|
|
addExperience(order); |
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK("操作成功"); |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
@ -406,10 +447,16 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
//如果订单存在则修改订单状态 |
|
|
|
if (null != studytourOrder){ |
|
|
|
if("0".equals(studytourOrder.getStatus())){ |
|
|
|
|
|
|
|
//1、修改订单状态 |
|
|
|
studytourOrder.setStatus("1");//订单状态 |
|
|
|
studytourOrder.setPayTime(CommonUtils.getCurrentTime());//订单支付时间 |
|
|
|
studytourOrderService.updateById(studytourOrder); |
|
|
|
|
|
|
|
//2、添加开营通知 |
|
|
|
addNotice(studytourOrder); |
|
|
|
|
|
|
|
//3、添加分佣信息 |
|
|
|
addCommission(studytourOrder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -420,5 +467,210 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
//获取勋章 |
|
|
|
public void getMedal(StudytourOrder studytourOrder){ |
|
|
|
log.info("给用户添加勋章信息"); |
|
|
|
try{ |
|
|
|
//查询关联活动信息 |
|
|
|
StudytourActivity activity = studytourActivityService.getById(studytourOrder.getActivityId()); |
|
|
|
if(null != activity){ |
|
|
|
//查询活动勋章信息 |
|
|
|
List<StudytourMedalActivity> medalActivityList = studytourMedalActivityService.lambdaQuery().eq(StudytourMedalActivity::getActivityId, activity.getId()).list(); |
|
|
|
|
|
|
|
//查询用户持有的勋章信息 |
|
|
|
List<StudytourMedalUser> studytourMedalUserList = studytourMedalUserService.lambdaQuery().eq(StudytourMedalUser::getUserId, studytourOrder.getUserId()).list(); |
|
|
|
|
|
|
|
//需要添加的勋章列表 |
|
|
|
List<StudytourMedalUser> medalUserList = new ArrayList<>(); |
|
|
|
|
|
|
|
//判断用户是否已经持有该勋章,如果已经持有,则不再添加 |
|
|
|
for (StudytourMedalActivity studytourMedalActivity : medalActivityList) { |
|
|
|
boolean flag = true; |
|
|
|
for (StudytourMedalUser medalUser : studytourMedalUserList) { |
|
|
|
if(studytourMedalActivity.getMedalId().equals(medalUser.getMedalId())){ |
|
|
|
flag = false; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if(flag){ |
|
|
|
StudytourMedalUser medalUser = new StudytourMedalUser(); |
|
|
|
medalUser.setActivityId(studytourMedalActivity.getActivityId());//关联活动 |
|
|
|
medalUser.setMedalId(studytourMedalActivity.getMedalId());//关联勋章 |
|
|
|
medalUser.setUserId(studytourOrder.getUserId());//关联用户 |
|
|
|
medalUser.setIsLight("0");//未点亮 |
|
|
|
medalUserList.add(medalUser); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(medalUserList.size() > 0){ |
|
|
|
boolean result = studytourMedalUserService.saveBatch(medalUserList); |
|
|
|
if(!result){ |
|
|
|
log.error("用户勋章添加失败"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
log.info("用户已领取完该活动的所有勋章"); |
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
log.error("活动不存在"); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("用户勋章添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//添加成长档案 |
|
|
|
public void addExperience(StudytourOrder studytourOrder){ |
|
|
|
try{ |
|
|
|
//0、校验是否已经有了该活动的成长档案 |
|
|
|
List<StudytourRecord> recordList = studytourRecordService |
|
|
|
.lambdaQuery() |
|
|
|
.eq(StudytourRecord::getActivityId, studytourOrder.getActivityId()) |
|
|
|
.eq(StudytourRecord::getUserId, studytourOrder.getUserId()) |
|
|
|
.list(); |
|
|
|
if(recordList.size() < 1){ |
|
|
|
//没有该活动的成长档案,进行添加 |
|
|
|
StudytourRecord studytourRecord = new StudytourRecord(); |
|
|
|
studytourRecord.setActivityId(studytourOrder.getActivityId());//关联活动 |
|
|
|
studytourRecord.setUserId(studytourOrder.getUserId());//关联用户 |
|
|
|
boolean result = studytourRecordService.save(studytourRecord); |
|
|
|
if(!result){ |
|
|
|
log.error("用户成长档案添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("用户成长档案添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//添加开营通知 |
|
|
|
public void addNotice(StudytourOrder studytourOrder){ |
|
|
|
try{ |
|
|
|
//1、查询活动信息 |
|
|
|
StudytourActivity activity = studytourActivityService.getById(studytourOrder.getActivityId()); |
|
|
|
if(null != activity){ |
|
|
|
StudytourNotice notice = new StudytourNotice(); |
|
|
|
notice.setTitle(activity.getTitle());//通知标题 |
|
|
|
notice.setNoticeDate(CommonUtils.getValidDate(studytourOrder.getStartDate(), activity.getNoticeDay()));//通知时间 |
|
|
|
notice.setTeacherPhone(activity.getPhone());//导师电话 |
|
|
|
notice.setIsRead("0");//0-未读 1-已读 |
|
|
|
notice.setContent(activity.getNotice());//通知内容 |
|
|
|
notice.setUserId(studytourOrder.getUserId());//关联用户 |
|
|
|
boolean result = studytourNoticeService.save(notice); |
|
|
|
if(!result){ |
|
|
|
log.error("开营通知添加失败"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
log.error("活动不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("开营通知添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//分销佣金 |
|
|
|
public void addCommission(StudytourOrder studytourOrder){ |
|
|
|
try{ |
|
|
|
//订单用户信息 |
|
|
|
HanHaiMember hanHaiMember = hanHaiMemberService.getById(studytourOrder.getUserId()); |
|
|
|
|
|
|
|
//判断用户是否有一级分佣人 |
|
|
|
if(null != hanHaiMember && StringUtils.isNotEmpty(hanHaiMember.getVid())){ |
|
|
|
log.info("一级分佣开始"); |
|
|
|
//0、查询一级分佣人信息 |
|
|
|
HanHaiMember member1 = hanHaiMemberService.getById(hanHaiMember.getVid()); |
|
|
|
|
|
|
|
if(null != member1){ |
|
|
|
//1、查询活动一级分佣信息 |
|
|
|
log.info("查询一级分佣信息"); |
|
|
|
StudytourActivity activity = studytourActivityService.getById(studytourOrder.getActivityId()); |
|
|
|
String commissionType1 = activity.getCommissionType1();//一级分佣类型 |
|
|
|
BigDecimal commissionRatio1 = activity.getCommissionRatio1();//一级分佣比例 |
|
|
|
BigDecimal commissionAmount1 = activity.getCommissionAmount1();//一级分佣金额 |
|
|
|
|
|
|
|
//2、获取分佣金额 |
|
|
|
log.info("获取一级分佣金额"); |
|
|
|
BigDecimal commission1 = new BigDecimal(0); |
|
|
|
if("0".equals(commissionType1)){ |
|
|
|
//按比例进行分佣 |
|
|
|
commission1 = studytourOrder.getPayAmount().multiply(commissionRatio1); |
|
|
|
}else{ |
|
|
|
//按照固定金额进行分佣 |
|
|
|
commission1 = commissionAmount1; |
|
|
|
} |
|
|
|
|
|
|
|
//3、一级分佣人用户余额增加、佣金记录增加 |
|
|
|
log.info("一级分佣人用户余额增加、佣金记录增加"); |
|
|
|
commission1 = commission1.setScale(2, BigDecimal.ROUND_DOWN);//直接删除多余的小数位,如2.35会变成2.3 |
|
|
|
BigDecimal newPrice1 = member1.getPrice().add(commission1);//余额 |
|
|
|
BigDecimal newCommission1 = member1.getCommission().add(commission1);//总佣金 |
|
|
|
member1.setPrice(newPrice1); |
|
|
|
member1.setCommission(newCommission1); |
|
|
|
hanHaiMemberService.updateById(member1); |
|
|
|
|
|
|
|
//4、增加一级分佣人佣金记录信息 |
|
|
|
log.info("一级分佣人佣金记录信息增加"); |
|
|
|
StudytourCommissionLog commissionLog1 = new StudytourCommissionLog(); |
|
|
|
commissionLog1.setAmount(commission1);//佣金金额 |
|
|
|
commissionLog1.setCommissionId(hanHaiMember.getId());//佣金来源用户 |
|
|
|
commissionLog1.setUserId(member1.getId());//佣金获得用户 |
|
|
|
studytourCommissionLogService.save(commissionLog1); |
|
|
|
|
|
|
|
//判断用户是否有二级分佣人 |
|
|
|
if(StringUtils.isNotEmpty(member1.getVid())){ |
|
|
|
log.info("二级分佣开始"); |
|
|
|
//0、查询二级分佣人信息 |
|
|
|
HanHaiMember member2 = hanHaiMemberService.getById(member1.getVid()); |
|
|
|
|
|
|
|
if(null != member2){ |
|
|
|
//1、活动二级分佣信息 |
|
|
|
log.info("查询二级分佣信息"); |
|
|
|
String commissionType2 = activity.getCommissionType2();//二级级分佣类型 |
|
|
|
BigDecimal commissionRatio2 = activity.getCommissionRatio2();//二级分佣比例 |
|
|
|
BigDecimal commissionAmount2 = activity.getCommissionAmount2();//二级分佣金额 |
|
|
|
|
|
|
|
//2、获取分佣金额 |
|
|
|
log.info("获取二级分佣金额"); |
|
|
|
BigDecimal commission2 = new BigDecimal(0); |
|
|
|
if("0".equals(commissionType2)){ |
|
|
|
//按比例进行分佣 |
|
|
|
commission2 = studytourOrder.getPayAmount().multiply(commissionRatio2); |
|
|
|
}else{ |
|
|
|
//按照固定金额进行分佣 |
|
|
|
commission2 = commissionAmount2; |
|
|
|
} |
|
|
|
|
|
|
|
//3、二级分佣人用户余额增加、佣金记录增加 |
|
|
|
log.info("二级分佣人用户余额增加、佣金记录增加"); |
|
|
|
commission2 = commission2.setScale(2, BigDecimal.ROUND_DOWN);//直接删除多余的小数位,如2.35会变成2.3 |
|
|
|
BigDecimal newPrice2 = member2.getPrice().add(commission2);//余额 |
|
|
|
BigDecimal newCommission2 = member2.getCommission().add(commission2);//总佣金 |
|
|
|
member2.setPrice(newPrice2); |
|
|
|
member2.setCommission(newCommission2); |
|
|
|
hanHaiMemberService.updateById(member2); |
|
|
|
|
|
|
|
//4、增加一级分佣人佣金记录信息 |
|
|
|
log.info("二级分佣人佣金记录信息增加"); |
|
|
|
StudytourCommissionLog commissionLog2 = new StudytourCommissionLog(); |
|
|
|
commissionLog2.setAmount(commission2);//佣金金额 |
|
|
|
commissionLog2.setCommissionId(hanHaiMember.getId());//佣金来源用户 |
|
|
|
commissionLog2.setUserId(member2.getId());//佣金获得用户 |
|
|
|
studytourCommissionLogService.save(commissionLog2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |