|
|
package com.yoho.ufo.order.service.impl;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.order.dal.SellerWalletDetailMapper;
|
|
|
import com.yoho.order.dal.SellerWalletMapper;
|
|
|
import com.yoho.order.dal.StoredSellerMapper;
|
|
|
import com.yoho.order.model.MerchantReq;
|
|
|
import com.yoho.order.model.SellerWallet;
|
|
|
import com.yoho.order.model.SellerWalletDetail;
|
|
|
import com.yoho.ufo.dal.*;
|
|
|
import com.yoho.ufo.dal.model.Goods;
|
|
|
import com.yoho.ufo.dal.model.Product;
|
|
|
import com.yoho.ufo.dal.model.Storage;
|
|
|
import com.yoho.ufo.dal.model.StoragePrice;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.size.Size;
|
|
|
import com.yoho.ufo.model.goodsmanage.StorageProductBo;
|
|
|
import com.yoho.ufo.service.model.PageResponseBO;
|
|
|
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -13,12 +23,11 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.order.dal.SellerWalletDetailMapper;
|
|
|
import com.yoho.order.model.MerchantReq;
|
|
|
import com.yoho.order.model.SellerWalletDetail;
|
|
|
import com.yoho.ufo.service.model.PageResponseBO;
|
|
|
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class MerchantServiceImpl {
|
...
|
...
|
@@ -29,35 +38,225 @@ public class MerchantServiceImpl { |
|
|
|
|
|
@Autowired
|
|
|
private SellerWalletDetailMapper mapper;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private SellerWalletMapper sellerWalletMapper;
|
|
|
@Autowired
|
|
|
private StoredSellerMapper storedSellerMapper;
|
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
@Autowired
|
|
|
private GoodsMapper goodsMapper;
|
|
|
@Autowired
|
|
|
private StorageMapper storageMapper;
|
|
|
@Autowired
|
|
|
private UfoSizeMapper ufoSizeMapper;
|
|
|
@Autowired
|
|
|
private StoragePriceMapper storagePriceMapper;
|
|
|
|
|
|
public MerchantOrderAttachInfo earnestDetail(MerchantReq req) {
|
|
|
return exchange(mapper.selectById(req.getId()));
|
|
|
SellerWalletDetail sellerWalletDetail = mapper.selectById(req.getId());
|
|
|
MerchantOrderAttachInfo info = new MerchantOrderAttachInfo();
|
|
|
if(StringUtils.isNotBlank(sellerWalletDetail.getAttachValue())) {
|
|
|
info = JSON.parseObject(sellerWalletDetail.getAttachValue(), MerchantOrderAttachInfo.class);
|
|
|
}
|
|
|
info.setId(sellerWalletDetail.getId());
|
|
|
info.setUid(sellerWalletDetail.getUid());
|
|
|
info.setType(sellerWalletDetail.getType());
|
|
|
info.setTime(sdf.get().format(new Date(sellerWalletDetail.getCreateTime() * 1000L)));
|
|
|
SellerWalletDetail.Type curType = null;
|
|
|
//如果类型不存在,则不进行处理
|
|
|
if(info.getType()==null || (curType = SellerWalletDetail.Type.of(new int[]{info.getType().intValue()}))==null){
|
|
|
return info;
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.RE_CHARGE)){
|
|
|
return dealReCharge(info,sellerWalletDetail);//保证金充值
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_ONSHELF)){
|
|
|
return dealSellerOnShelf(info,sellerWalletDetail);//卖家上架商品
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_OFFSHELF)){
|
|
|
return dealSellerOffShelf(info,sellerWalletDetail);//卖家下架商品
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.TRADE_COMPLETE)){
|
|
|
return dealTradeComplete(info,sellerWalletDetail);//商品交易完成
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_TRADEFAILED)){
|
|
|
return dealSellerTradeFailed(info,sellerWalletDetail);//卖家原因交易失败
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_ADDPRICE)){
|
|
|
return dealSellerAddPrice(info,sellerWalletDetail);//卖家上调价格
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_REDUCEPRICE)){
|
|
|
return dealSellerReducePrice(info,sellerWalletDetail);//卖家下调价格
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.BUYER_CANCEL)){
|
|
|
return dealBuyerCancel(info,sellerWalletDetail);//买家付款后取消订单
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SYSTEM_OFFSHELF)){
|
|
|
return dealSystemOffShelf(info,sellerWalletDetail);//系统下架商品
|
|
|
}
|
|
|
if(curType.equals(SellerWalletDetail.Type.SELLER_QUIT)){
|
|
|
return dealSellerQuit(info,sellerWalletDetail);//卖家退出入驻
|
|
|
}
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealReCharge(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
if(info.getPayment()!=null){
|
|
|
info.setRechargeType(1==info.getPayment().intValue()?"支付宝":"微信");//充值方式
|
|
|
}
|
|
|
info.setSeriNo(info.getOrderCode()==null?null:info.getOrderCode().toString());//充值流水
|
|
|
info.setRechargeTime(info.getTime());//充值时间
|
|
|
info.setRechargeMoney(sellerWalletDetail.getAmount());//充值金额
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSellerOnShelf(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setOnShelfTime(info.getTime());
|
|
|
info.setLockEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().abs().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private void initProductInfo(MerchantOrderAttachInfo info){
|
|
|
//根据orderCode查商品信息
|
|
|
info.setProductCount(info.getProductCount()==null?1:info.getProductCount());
|
|
|
StorageProductBo bo = initStorageProduct(info);
|
|
|
if(null == bo || bo.getProduct()==null || bo.getStorage() == null){
|
|
|
LOGGER.info("dealSellerOnShelf StorageProductBo is null!StorageProductBo is {},MerchantOrderAttachInfo is {}",bo,info);
|
|
|
return ;
|
|
|
}
|
|
|
info.setProductName(bo.getProduct().getProductName());
|
|
|
info.setSkup(bo.getProduct().getSkup());
|
|
|
List<Goods> goodsList = goodsMapper.selectByProductId(Arrays.asList(bo.getProduct().getId()));
|
|
|
if(!CollectionUtils.isEmpty(goodsList)){
|
|
|
info.setProductColor(goodsList.get(0).getGoodsName());
|
|
|
}
|
|
|
Size size = null;
|
|
|
if(bo.getStorage().getSizeId()!=null &&(size = ufoSizeMapper.selectOneById(bo.getStorage().getSizeId()))!=null){
|
|
|
info.setProductSize(size.getSizeName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private StorageProductBo initStorageProduct(MerchantOrderAttachInfo info){
|
|
|
if(null != info.getStorageId()){
|
|
|
Storage storage = storageMapper.selectByPrimaryKey(info.getStorageId());
|
|
|
if(storage!=null){
|
|
|
Product product = null != storage.getProductId()?productMapper.selectByPrimaryKey(storage.getProductId()):null;
|
|
|
return new StorageProductBo(storage,product);
|
|
|
}
|
|
|
}
|
|
|
if(info.getSkup()!=null){
|
|
|
StoragePrice storagePrice = storagePriceMapper.selectBySkup(info.getSkup());
|
|
|
Storage storage = storageMapper.selectByPrimaryKey(storagePrice.getStorageId());
|
|
|
Product product = productMapper.selectByPrimaryKey(storagePrice.getProductId());
|
|
|
return new StorageProductBo(storage,product);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
private MerchantOrderAttachInfo dealSellerOffShelf(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setUnShelfTime(info.getTime());
|
|
|
info.setReleaseEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().abs().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealTradeComplete(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setTradeCompleteTime(info.getTime());
|
|
|
info.setReleaseEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().abs().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSellerTradeFailed(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setCancelOrderTime(info.getTime());
|
|
|
info.setReleaseEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().abs().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSellerAddPrice(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setAdjustPriceTime(info.getTime());
|
|
|
info.setBeforeAdjustPrice(info.getBeforeProductPrice()==null?null:info.getBeforeProductPrice().toString());
|
|
|
info.setBeforeAdjustLockMoney(info.getBeforeEarnestMoney());
|
|
|
info.setAfterAdjustPrice(info.getAfterProductPrice()==null?null:info.getAfterProductPrice().toString());
|
|
|
info.setAfterAdjustLockMoney((info.getAfterEarnestMoney()));
|
|
|
if(info.getAfterAdjustLockMoney()!=null && info.getBeforeAdjustLockMoney()!=null){
|
|
|
BigDecimal afterLockMoney = new BigDecimal(info.getAfterAdjustLockMoney());
|
|
|
info.setAddLockEarnestMoney(afterLockMoney.subtract(new BigDecimal(info.getBeforeAdjustLockMoney())).abs().toString());
|
|
|
}
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSellerReducePrice(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setAdjustPriceTime(info.getTime());
|
|
|
info.setBeforeAdjustPrice(info.getBeforeProductPrice()==null?null:info.getBeforeProductPrice().toString());
|
|
|
info.setBeforeAdjustLockMoney(info.getBeforeEarnestMoney());
|
|
|
info.setAfterAdjustPrice(info.getAfterProductPrice()==null?null:info.getAfterProductPrice().toString());
|
|
|
info.setAfterAdjustLockMoney((info.getAfterEarnestMoney()));
|
|
|
if(info.getAfterAdjustLockMoney()!=null && info.getBeforeAdjustLockMoney()!=null){
|
|
|
BigDecimal afterLockMoney = new BigDecimal(info.getAfterAdjustLockMoney());
|
|
|
info.setReduceLockEarnestMoney(afterLockMoney.subtract(new BigDecimal(info.getBeforeAdjustLockMoney())).abs().toString());
|
|
|
}
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealBuyerCancel(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setBuyerCancelTime(info.getTime());
|
|
|
info.setReleaseEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSystemOffShelf(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setUnShelfTime(info.getTime());
|
|
|
info.setReleaseEarnestMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().toString());
|
|
|
initProductInfo(info);
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
private MerchantOrderAttachInfo dealSellerQuit(MerchantOrderAttachInfo info,SellerWalletDetail sellerWalletDetail) {
|
|
|
info.setRefundSeriNo(null == info.getOrderCode()?null:info.getOrderCode().toString());
|
|
|
info.setRefundTime(info.getTime());
|
|
|
info.setRefundType(1==info.getPayment().intValue()?"支付宝":"微信");
|
|
|
info.setRefundMoney(sellerWalletDetail.getAmount()==null?null:sellerWalletDetail.getAmount().toString());
|
|
|
return info;
|
|
|
}
|
|
|
|
|
|
|
|
|
public PageResponseBO<MerchantOrderAttachInfo> earnestList(MerchantReq req) {
|
|
|
|
|
|
Integer stratTime = parse(req.getStartTime());
|
|
|
Integer endTime = parse(req.getEndTime());
|
|
|
|
|
|
int total = mapper.selectMerchantInfoCount(req.getUid(), stratTime, endTime, req.getStateList());
|
|
|
List<Integer> uids = null;
|
|
|
if(StringUtils.isNotBlank(req.getMerchantName()) || req.getUid() !=null){
|
|
|
uids = storedSellerMapper.selectUidByCertNameAndUid(req.getMerchantName(),req.getUid());
|
|
|
if(CollectionUtils.isEmpty(uids)){
|
|
|
return new PageResponseBO<>();
|
|
|
}
|
|
|
}
|
|
|
int total = mapper.selectMerchantInfoCount(CollectionUtils.isEmpty(uids)?null:uids, stratTime, endTime, req.getStateList(),req.getOrderCode());
|
|
|
if(total == 0) {
|
|
|
return new PageResponseBO<>();
|
|
|
}
|
|
|
|
|
|
List<SellerWalletDetail> beanList = mapper.selectMerchantInfo(req.getUid(), stratTime, endTime, req.getStateList(), req.getStart(), req.getRows());
|
|
|
List<MerchantOrderAttachInfo> boList = new ArrayList<>();
|
|
|
List<SellerWalletDetail> beanList = mapper.selectMerchantInfo(CollectionUtils.isEmpty(uids)?null:uids, stratTime, endTime, req.getStateList(),req.getOrderCode(), req.getStart(), req.getRows());
|
|
|
Map<Integer,Map<String,Object>> storedSellerMap = this.storedSellerMapper.selectNameByUids(beanList.stream().map(cell->cell.getUid()).collect(Collectors.toList()));
|
|
|
List<MerchantOrderAttachInfo> boList = new ArrayList<>();
|
|
|
for(SellerWalletDetail detail : beanList) {
|
|
|
boList.add(exchange(detail));
|
|
|
MerchantOrderAttachInfo info = JSON.parseObject(detail.getAttachValue(), MerchantOrderAttachInfo.class);
|
|
|
info=info == null?new MerchantOrderAttachInfo():info;
|
|
|
info.setOrderCode(detail.getOrderCode());
|
|
|
info.setTime(sdf.get().format(new Date(detail.getCreateTime() * 1000L)));
|
|
|
info.setMerchantName((String)storedSellerMap.get(detail.getUid()).get("cert_name"));
|
|
|
info.setUid(detail.getUid());
|
|
|
boList.add(info);
|
|
|
}
|
|
|
|
|
|
PageResponseBO<MerchantOrderAttachInfo> result=new PageResponseBO<>();
|
|
|
result.setList(boList);
|
|
|
result.setPage(req.getPage());
|
|
|
result.setSize(req.getSize());
|
|
|
result.setTotal(total);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -99,4 +298,43 @@ public class MerchantServiceImpl { |
|
|
}
|
|
|
}
|
|
|
|
|
|
public PageResponseBO<MerchantOrderAttachInfo> listSellerWallets(MerchantReq req) {
|
|
|
List<Integer> uids = null;
|
|
|
if(StringUtils.isNotBlank(req.getMerchantName())){
|
|
|
uids = storedSellerMapper.selectUidByCertName(req.getMerchantName());
|
|
|
if(CollectionUtils.isEmpty(uids)){
|
|
|
return new PageResponseBO<>();
|
|
|
}
|
|
|
}
|
|
|
int total = this.sellerWalletMapper.selectTotalByUidAndMerchantUids(req.getUid(),uids);
|
|
|
if(total == 0){
|
|
|
return new PageResponseBO<>();
|
|
|
}
|
|
|
List<SellerWallet> sellerWallets = this.sellerWalletMapper.selectByUidAndMerchantUids(req.getUid(),uids,req.getStart(),req.getSize());
|
|
|
List<MerchantOrderAttachInfo> infos = initMerchantOrderAttachInfos(sellerWallets);
|
|
|
PageResponseBO<MerchantOrderAttachInfo> result = new PageResponseBO<>();
|
|
|
result.setTotal(total);
|
|
|
result.setList(infos);
|
|
|
result.setPage(req.getPage());
|
|
|
result.setSize(req.getSize());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<MerchantOrderAttachInfo> initMerchantOrderAttachInfos(List<SellerWallet> sellerWallets) {
|
|
|
List<MerchantOrderAttachInfo> infos = new ArrayList<>();
|
|
|
Map<Integer,Map<String,Object>> storedSellerMap = this.storedSellerMapper.selectNameByUids(sellerWallets.stream().map(cell->cell.getUid()).collect(Collectors.toList()));
|
|
|
for (SellerWallet sellerWallet : sellerWallets) {
|
|
|
MerchantOrderAttachInfo info = new MerchantOrderAttachInfo();
|
|
|
BigDecimal amount = sellerWallet.getAmount();
|
|
|
BigDecimal lockMoney = sellerWallet.getLockAmount();
|
|
|
info.setId(sellerWallet.getId());
|
|
|
info.setAccountAmount(null == amount?null:amount.toString());
|
|
|
info.setLockEarnestMoney(null == lockMoney?null:lockMoney.toString());
|
|
|
info.setAvailEarnestMoney(null == amount?null:null == lockMoney?amount.toString():amount.subtract(sellerWallet.getLockAmount()).toString());
|
|
|
info.setUid(sellerWallet.getUid());
|
|
|
info.setMerchantName((String)storedSellerMap.get(sellerWallet.getUid()).get("cert_name"));
|
|
|
infos.add(info);
|
|
|
}
|
|
|
return infos;
|
|
|
}
|
|
|
} |
...
|
...
|
|