Browse Source

支持多商家,修改结算功能

multiwx
xh-pan1 2 years ago
parent
commit
b3c506d215
  1. 420
      cereshop-business/src/main/java/com/shop/cereshop/business/service/business/impl/CerePlatformBusinessServiceImpl.java

420
cereshop-business/src/main/java/com/shop/cereshop/business/service/business/impl/CerePlatformBusinessServiceImpl.java

@ -0,0 +1,420 @@
/*
* Copyright (C) 2017-2021
* All rights reserved, Designed By 深圳中科鑫智科技有限公司
* Copyright authorization contact 18814114118
*/
package com.shop.cereshop.business.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shop.cereshop.business.dao.business.CerePlatformBusinessDAO;
import com.shop.cereshop.business.dao.buyer.CereBuyerUserDAO;
import com.shop.cereshop.business.dao.order.CereShopOrderDAO;
import com.shop.cereshop.business.dao.product.CereProductStatsByDayDAO;
import com.shop.cereshop.business.dao.shop.CereShopVisitDAO;
import com.shop.cereshop.business.page.business.Business;
import com.shop.cereshop.business.page.index.*;
import com.shop.cereshop.business.page.shop.ShopConversion;
import com.shop.cereshop.business.page.shop.ShopCrossDetail;
import com.shop.cereshop.business.param.business.BusinessUpdateParam;
import com.shop.cereshop.business.param.index.IndexParam;
import com.shop.cereshop.business.param.shop.ShopCrossDetailGetAllParam;
import com.shop.cereshop.business.pay.xs.service.XsPayService;
import com.shop.cereshop.business.service.business.CerePlatformBusinessService;
import com.shop.cereshop.business.service.log.CerePlatformLogService;
import com.shop.cereshop.business.service.shop.*;
import com.shop.cereshop.business.utils.ContextUtil;
import com.shop.cereshop.business.utils.EncodeUtil;
import com.shop.cereshop.commons.constant.IntegerEnum;
import com.shop.cereshop.commons.constant.ParamEnum;
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness;
import com.shop.cereshop.commons.domain.business.CerePlatformBusinessUser;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.order.CereShopOrder;
import com.shop.cereshop.commons.domain.product.CereProductStatsByDay;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.utils.EmptyUtils;
import com.shop.cereshop.commons.utils.StringUtils;
import com.shop.cereshop.commons.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class CerePlatformBusinessServiceImpl implements CerePlatformBusinessService {
@Autowired
private CerePlatformBusinessDAO cerePlatformBusinessDAO;
// @Autowired
// private CereShopCrossDetailService cereShopCrossDetailService;
@Autowired
private CereShopPersonalService cereShopPersonalService;
@Autowired
private CereShopIndividualBusinessesService cereShopIndividualBusinessesService;
@Autowired
private CereShopEnterpriseService cereShopEnterpriseService;
@Autowired
private CereShopOtherOrganizationsService cereShopOtherOrganizationsService;
@Autowired
private CerePlatformLogService cerePlatformLogService;
@Autowired
private XsPayService xsPayService;
@Autowired
private CereShopVisitDAO cereShopVisitDAO;
@Autowired
private CereBuyerUserDAO cereBuyerUserDAO;
@Autowired
private CereShopOrderDAO cereShopOrderDAO;
@Autowired
private CereProductStatsByDayDAO cereProductStatsByDayDAO;
@Autowired
private EncodeUtil encodeUtil;
// @Autowired
// private CereShopCrossDetailService cereShopCrossDetailService;
@Override
public CerePlatformBusiness selectByPrimaryKey(Long businessId) {
return cerePlatformBusinessDAO.selectByPrimaryKey(businessId);
}
@Override
public Business getById(Long businessId) throws CoBusinessException {
//查询商家信息
Business business = cerePlatformBusinessDAO.findBusiness(businessId);
if(business!=null){
//查询商家退货地址信息
// CereShopReturn cereShopReturn=cereShopReturnService.findByShopId(shopId);
// business.setShopReturn(cereShopReturn);
//查询认证数据
if(IntegerEnum.getByName("主体类型-个人").equals(business.getAuthenType())){
//个人认证
business.setPersonal(cereShopPersonalService.findByBusinessId(businessId));
}else if(IntegerEnum.getByName("主体类型-个体工商户").equals(business.getAuthenType())){
//个体工商户户认证
business.setIndividualBusinesses(cereShopIndividualBusinessesService.findByBusinessId(businessId));
}else if(IntegerEnum.getByName("主体类型-企业").equals(business.getAuthenType())){
//企业认证
business.setEnterprise(cereShopEnterpriseService.findByBusinessId(businessId));
}else if(IntegerEnum.getByName("主体类型-其他组织").equals(business.getAuthenType())){
//其他组织认证
business.setOtherOrganizations(cereShopOtherOrganizationsService.findByBusinessId(businessId));
}
}
return business;
}
@Override
public Business registerByXs(Long businessId) throws CoBusinessException {
Business shop=cerePlatformBusinessDAO.findBusiness(businessId);
if(StringUtils.isEmpty(shop.getXsPayId())){
//如果不为空则是之前已经注册了为空表示需要注册
try {
String responeMsg = xsPayService.registerByXs(businessId, "0");
JSONObject jsonObject = JSONObject.parseObject(responeMsg);
String shareParId = jsonObject.getJSONObject("content").getString("shareParId");
shop.setXsPayId(shareParId);
CerePlatformBusiness cerePlatformBusiness = new CerePlatformBusiness();
cerePlatformBusiness.setBusinessId(businessId);
cerePlatformBusiness.setXsPayId(shareParId);
cerePlatformBusinessDAO.updateById(cerePlatformBusiness);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return shop;
}
@Override
@Transactional(isolation= Isolation.DEFAULT,propagation= Propagation.REQUIRED,rollbackFor = {CoBusinessException.class, Exception.class})
public void update(BusinessUpdateParam param, CerePlatformBusinessUser user) throws CoBusinessException {
String time= TimeUtils.yyMMddHHmmss();
CerePlatformBusiness cerePlatformBusiness=new CerePlatformBusiness();
cerePlatformBusiness.setBusinessId(param.getBusinessId());
cerePlatformBusiness.setBusinessLogo(param.getBusinessLogo());
cerePlatformBusiness.setBusinessName(param.getBusinessName());
cerePlatformBusiness.setBusinessBrief(param.getBusinessBrief());
cerePlatformBusiness.setBusinessAdress(param.getBusinessAdress());
cerePlatformBusiness.setChargePersonPhone(param.getChargePersonPhone());
cerePlatformBusiness.setChargePersonName(param.getChargePersonName());
// cerePlatformBusiness.setBusinessPhone(param.getBusinessPhone());
cerePlatformBusiness.setShareDays(param.getShareDays());
cerePlatformBusiness.setUpdateTime(time);
cerePlatformBusinessDAO.updateByPrimaryKeySelective(cerePlatformBusiness);
// if(!EmptyUtils.isEmpty(param.getShopReturn())){
// //查询是否有退货地址信息
// CereShopReturn shopReturn=cereShopReturnService.findByShopId(param.getShopId());
// if(shopReturn!=null){
// //更新退货地址
// shopReturn.setReturnAdress(param.getShopReturn().getReturnAdress());
// shopReturn.setReturnPerson(param.getShopReturn().getReturnPerson());
// shopReturn.setReturnPhone(param.getShopReturn().getReturnPhone());
// cereShopReturnService.update(shopReturn);
// }else {
// param.getShopReturn().setShopId(param.getShopId());
// cereShopReturnService.insert(param.getShopReturn());
// }
// }
// if(!EmptyUtils.isEmpty(param.getCrossDetail())){
// //查询是否有退货地址信息
// CereShopCrossDetail crossDetail=cereShopCrossDetailService.findByShopId(param.getShopId());
// if(crossDetail!=null){
// //更新退货地址
// crossDetail.setReturnAdress(param.getShopReturn().getReturnAdress());
// crossDetail.setReturnPerson(param.getShopReturn().getReturnPerson());
// crossDetail.setReturnPhone(param.getShopReturn().getReturnPhone());
// cereShopCrossDetailService.update(crossDetail);
// }else {
// crossDetail.setShopId(param.getBusinessId());
// cereShopCrossDetailService.insert(crossDetail);
// }
// }
//新增日志
cerePlatformLogService.addLog(user,"商家管理","商户端操作","修改商家logo",cerePlatformBusiness.getBusinessId(),time);
}
@Override
public void updateState(CerePlatformBusiness cerePlatformBusiness) throws CoBusinessException {
cerePlatformBusinessDAO.updateByPrimaryKeySelective(cerePlatformBusiness);
}
@Override
public Index index(IndexParam param) throws CoBusinessException {
String project = ContextUtil.getProject();
Index index=new Index();
//查询今日商家访问人数
index.setTotal(cerePlatformBusinessDAO.getTotal(project, param.getBusinessId()));
//查询今日待处理订单数
index.setStayOrders(cerePlatformBusinessDAO.getStayOrders(project,param.getBusinessId()));
//查询今日待处理售后订单数
index.setStayAfters(cerePlatformBusinessDAO.getStayAfters(project,param.getBusinessId()));
//查询今日成交金额
index.setMoney(cerePlatformBusinessDAO.getMoney(project,param.getBusinessId()));
//根据时间条件获取对应统计时间数据
List<String> weeks = getVisitWeeks(param.getCondition());
//查询月度访问人数数据
VisitWeek visitWeek=new VisitWeek();
List<Integer> weekDayVisitCountList = new ArrayList<>();
for (String weekDay:weeks) {
String startTime = weekDay + " 00:00:00";
String endTime = weekDay + " 23:59:59";
Integer visitCount = cerePlatformBusinessDAO.getVisit(project, param.getBusinessId(), startTime, endTime);
weekDayVisitCountList.add(visitCount);
}
//设置总访问人数
String startTime = weeks.get(0) + " 00:00:00";
String endTime = weeks.get(weeks.size() - 1) + " 23:59:59";
index.setCount(cerePlatformBusinessDAO.getVisit(project, param.getBusinessId(), startTime, endTime));
visitWeek.setTotal(weekDayVisitCountList);
visitWeek.setTime(weeks);
index.setVisitWeek(visitWeek);
//查询订单转化数据
ShopConversion shopConversion=new ShopConversion();
//初始化文字描述
List<String> names=new ArrayList<>();
List<BigDecimal> rates=new ArrayList<>();
//查询访问人数
BigDecimal visits = cerePlatformBusinessDAO.findVisits(project, param.getBusinessId(), param.getCondition(), ParamEnum.CONVERSION_VISIT.getCode());
//查询加购人数
BigDecimal carts = cerePlatformBusinessDAO.findVisits(project, param.getBusinessId(), param.getCondition(), ParamEnum.CONVERSION_CART.getCode());
//查询结算人数
BigDecimal checks = cerePlatformBusinessDAO.findVisits(project, param.getBusinessId(), param.getCondition(), ParamEnum.CONVERSION_CHECK.getCode());
//查询调取支付人数
BigDecimal pays = cerePlatformBusinessDAO.findVisits(project, param.getBusinessId(), param.getCondition(), ParamEnum.CONVERSION_PAY.getCode());
//查询支付成功人数
BigDecimal success = cerePlatformBusinessDAO.findVisits(project, param.getBusinessId(), param.getCondition(), ParamEnum.CONVERSION_PAY_SUCCESS.getCode());
//计算转化率
BigDecimal hundred=new BigDecimal(100);
if(!EmptyUtils.isEmptyBigdecimal(visits)){
names.add("访问");
rates.add(hundred);
if(!EmptyUtils.isEmptyBigdecimal(carts)){
names.add("加购");
rates.add(carts.divide(visits,2,BigDecimal.ROUND_HALF_UP).multiply(hundred).setScale(0,BigDecimal.ROUND_HALF_UP));
}
if(!EmptyUtils.isEmptyBigdecimal(checks)){
names.add("结算");
rates.add(checks.divide(visits,2,BigDecimal.ROUND_HALF_UP).multiply(hundred).setScale(0,BigDecimal.ROUND_HALF_UP));
}
if(!EmptyUtils.isEmptyBigdecimal(pays)){
names.add("调取支付");
rates.add(pays.divide(visits,2,BigDecimal.ROUND_HALF_UP).multiply(hundred).setScale(0,BigDecimal.ROUND_HALF_UP));
}
if(!EmptyUtils.isEmptyBigdecimal(success)){
names.add("支付成功");
rates.add(success.divide(visits,2,BigDecimal.ROUND_HALF_UP).multiply(hundred).setScale(0,BigDecimal.ROUND_HALF_UP));
}
shopConversion.setRates(rates);
}
shopConversion.setNames(names);
index.setConversion(shopConversion);
//计算总的转化数
BigDecimal rate=carts.add(checks).add(pays).add(success);
//计算总转化率=加购人数+结账人数+调用支付人数+支付成功人数/访问人数
if(!EmptyUtils.isEmptyBigdecimal(rate)&&!EmptyUtils.isEmptyBigdecimal(visits)){
index.setRate(rate.divide(visits,2,BigDecimal.ROUND_HALF_UP).multiply(hundred).setScale(0,BigDecimal.ROUND_HALF_UP));
}
//根据时间条件查询热卖商品数据(10条)
List<HotSellProduct> products=cerePlatformBusinessDAO.getHotProducts(project, param.getBusinessId(),param.getCondition());
index.setHotSellProducts(products);
return index;
}
@Override
public List<CerePlatformBusiness> selectAll() {
return cerePlatformBusinessDAO.selectAll();
}
@Override
public List<UserVisitDTO> selectUserVisitForExport(IndexParam param) {
List<String> days = getVisitWeeks(param.getCondition());
List<UserVisitDTO> visitDTOList = new ArrayList<>();
Map<Long, Integer> purchaseCountMap = new HashMap<>();
for (String day:days) {
List<UserVisitDTO> userVisitList = cereShopVisitDAO.selectDistinctVisitUser(param.getBusinessId(), day + " 00:00:00", day + "23:59:59");
log.info("userVisitList {}", userVisitList.size());
if (CollectionUtils.isNotEmpty(userVisitList)) {
Map<Long, Integer> visitCountMap = userVisitList.stream().collect(Collectors.toMap(UserVisitDTO::getBuyerUserId, UserVisitDTO::getVisitCount));
List<CereBuyerUser> userList = cereBuyerUserDAO.selectBatchIds(userVisitList
.stream().map(UserVisitDTO::getBuyerUserId).collect(Collectors.toList()));
log.info("userList {}", userList);
for (CereBuyerUser user:userList) {
UserVisitDTO visitDTO = new UserVisitDTO();
visitDTO.setDate(day);
visitDTO.setBuyerUserId(user.getBuyerUserId());
visitDTO.setNickName(encodeUtil.encodeInfo(user.getName()));
visitDTO.setPhone(encodeUtil.encodePhone(user.getPhone()));
visitDTO.setRegisterDate(user.getCreateTime());
Integer purchaseCount = purchaseCountMap.get(user.getBuyerUserId());
if (purchaseCount == null) {
purchaseCount = cereShopOrderDAO.selectCount(Wrappers.<CereShopOrder>lambdaQuery()
.eq(CereShopOrder::getBuyerUserId, user.getBuyerUserId())
.eq(CereShopOrder::getPaymentState, IntegerEnum.YES.getCode()));
purchaseCountMap.put(user.getBuyerUserId(), purchaseCount);
}
visitDTO.setRepurchase(purchaseCount > 1 ? IntegerEnum.YES.getName() : IntegerEnum.NO.getName());
visitDTO.setTerminal(IntegerEnum.terminalMap.get(user.getTerminal()).getName());
visitDTO.setVisitCount(visitCountMap.get(user.getBuyerUserId()));
visitDTOList.add(visitDTO);
}
}
}
return visitDTOList;
}
@Override
public List<OrderConvertDTO> selectOrderConvertForExport(IndexParam param) {
List<String> days = getVisitWeeks(param.getCondition());
String startTime = days.get(0) + " 00:00:00";
String endTime = days.get(days.size() - 1) + " 23:59:59";
List<OrderConvertDTO> list1 = cereShopOrderDAO.selectWaitToPayStatsByDate(param.getBusinessId(), startTime, endTime);
List<OrderConvertDTO> list2 = cereShopOrderDAO.selectPayStatsByDate(param.getBusinessId(), startTime, endTime);
List<OrderConvertDTO> list3 = cereShopOrderDAO.selectDeliverStatsByDate(param.getBusinessId(), startTime, endTime);
List<OrderConvertDTO> list4 = cereShopOrderDAO.selectAfterSaleStatsByDate(param.getBusinessId(), startTime, endTime);
Map<String, Integer> map1 = list1.stream().collect(Collectors.toMap(OrderConvertDTO::getDate, OrderConvertDTO::getWaitToPayCount));
Map<String, Integer> map2 = list2.stream().collect(Collectors.toMap(OrderConvertDTO::getDate, OrderConvertDTO::getPayCount));
Map<String, Integer> map3 = list3.stream().collect(Collectors.toMap(OrderConvertDTO::getDate, OrderConvertDTO::getDeliverCount));
Map<String, Integer> map4 = list4.stream().collect(Collectors.toMap(OrderConvertDTO::getDate, OrderConvertDTO::getAfterSaleCount));
List<OrderConvertDTO> result = new ArrayList<>();
for (String day:days) {
OrderConvertDTO dto = new OrderConvertDTO();
dto.setDate(day);
dto.setWaitToPayCount(map1.getOrDefault(day, 0));
dto.setPayCount(map2.getOrDefault(day, 0));
dto.setDeliverCount(map3.getOrDefault(day, 0));
dto.setAfterSaleCount(map4.getOrDefault(day, 0));
result.add(dto);
}
return result;
}
@Override
public List<HotProductDTO> selectHotProductForExport(IndexParam param) {
List<String> days = getVisitWeeks(param.getCondition());
String startTime = days.get(0);
String endTime = days.get(days.size() - 1);
List<HotProductDTO> result = new ArrayList<>();
List<CereProductStatsByDay> statsList = cereProductStatsByDayDAO.selectStatsByTime(param.getBusinessId(), startTime, endTime);
for (CereProductStatsByDay stat:statsList) {
HotProductDTO dto = new HotProductDTO();
BeanUtils.copyProperties(stat, dto);
dto.setDate(stat.getCreateDate());
result.add(dto);
}
return result;
}
@Override
public void insert(CerePlatformBusiness cerePlatformBusiness) throws CoBusinessException {
cerePlatformBusinessDAO.insert(cerePlatformBusiness);
}
@Override
public void update(CerePlatformBusiness cerePlatformBusiness) throws CoBusinessException {
cerePlatformBusinessDAO.updateByPrimaryKeySelective(cerePlatformBusiness);
}
private List<String> getVisitWeeks(Integer condition) {
List<String> weeks=new ArrayList<>();
if(IntegerEnum.CONDITION_TODAY.getCode().equals(condition)){
//封装今日时间
weeks.add(TimeUtils.today());
}else if(IntegerEnum.CONDITION_YESTERDAY.getCode().equals(condition)){
//封装昨日时间
weeks.add(TimeUtils.yesterday());
}else if(IntegerEnum.CONDITION_WEEK.getCode().equals(condition)){
//封装近7天时间
weeks=TimeUtils.getRecentSevenDay();
}else if(IntegerEnum.CONDITION_THIRD.getCode().equals(condition)){
//封装过去30天
String today = TimeUtils.today();
try {
for (int i=29;i>0;i--) {
weeks.add(TimeUtils.getMoreDayAfter(today + " 00:00:00", -1 * i).substring(0, 10));
}
} catch (Exception e) {
e.printStackTrace();
}
weeks.add(today);
}
return weeks;
}
@Override
public List<CerePlatformBusiness> getByIdList(List<Long> businessIdList){
return cerePlatformBusinessDAO.getByIdList(businessIdList);
}
}
Loading…
Cancel
Save