Authored by qinchao

退驻

... ... @@ -3,6 +3,7 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
public interface EntrySellerRechargeOrderMapper {
... ... @@ -26,6 +27,8 @@ public interface EntrySellerRechargeOrderMapper {
void updateByOrderCode(EntrySellerRechargeOrder order);
int updateReturnDepositByOrderCode(@Param("orderCode") long orderCode, @Param("amount") BigDecimal amount, @Param("status") Integer status, @Param("updateTime") Integer updateTime);
EntrySellerRechargeOrder selectByOrderCodeUid(long orderCode, int uid);
EntrySellerRechargeOrder selectByOrderCode(long orderCode);
... ...
... ... @@ -9,10 +9,10 @@ public interface IStoredSellerDao {
int insert(StoredSeller storedSeller);
int updateStatusByPrimaryKey(@Param("id")int id,@Param("validStatus") int validStatus ,@Param("expectStatus") int expectStatus);
int updateStatusByUid(@Param("uid")int uid,@Param("validStatus") int validStatus ,@Param("expectStatus") int expectStatus,@Param("updateTime") long updateTime);
int updateToQuitByPrimaryKey(@Param("id")int id,@Param("validStatus") int validStatus ,@Param("expectStatus") int expectStatus
/*int updateToQuitByPrimaryKey(@Param("id")int id,@Param("validStatus") int validStatus ,@Param("expectStatus") int expectStatus
,@Param("operatorUid") int operatorUid,@Param("operatorName") String operatorName
,@Param("quitTime") long quitTime,@Param("updateTime") long updateTime);
,@Param("quitTime") long quitTime,@Param("updateTime") long updateTime);*/
}
... ...
... ... @@ -139,7 +139,7 @@
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByOrderCode" parameterType="com.yohoufo.dal.order.model.BuyerOrder">
<update id="updateByOrderCode" parameterType="com.yohoufo.dal.order.model.EntrySellerRechargeOrder">
update entry_seller_recharge_order
set
<if test="status != null">
... ... @@ -152,6 +152,15 @@
where order_code = #{orderCode,jdbcType=BIGINT}
</update>
<update id="updateReturnDepositByOrderCode">
update entry_seller_recharge_order
set
status = #{status,jdbcType=INTEGER},
amount = #{amount,jdbcType=DECIMAL},
update_time = #{updateTime,jdbcType=INTEGER}
where order_code = #{orderCode}
</update>
<select id="selectByOrderCodeUid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -35,17 +35,17 @@
#{createTime},#{updateTime})
</insert>
<update id="updateStatusByPrimaryKey">
<update id="updateStatusByUid">
update stored_seller
set valid_status = #{validStatus}
where id = #{id} and valid_status = #{expectStatus}
set valid_status = #{validStatus},update_time = #{updateTime}
where uid = #{uid} and valid_status = #{expectStatus}
</update>
<update id="updateToQuitByPrimaryKey">
<!-- <update id="updateToQuitByPrimaryKey">
update stored_seller
set valid_status = #{validStatus},operator_uid = #{operatorUid},operator_name=#{operatorName},
quit_time = #{quitTime} ,update_time = #{updateTime}
where id = #{id} and valid_status = #{expectStatus}
</update>
</update>-->
</mapper>
\ No newline at end of file
... ...
... ... @@ -36,29 +36,6 @@ public class SellerOrderController {
private SellerOrderComputeHandler sellerOrderComputeHandler;
/**
* 获取商家未完成的订单数量
* @param uid
*/
@RequestMapping(params = "method=ufo.sellerOrder.getUnfinishedOrderBySellerUid")
@ResponseBody
public ApiResponse getUnfinishedOrderBySellerUid(@RequestParam(name = "uid")Integer uid){
logger.info("in ufo.sellerOrder.getUnfinishedOrderBySellerUid, uid {}", uid);
int total=sellerOrderService.getUnfinishedOrderBySellerUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(total).build();
}
/**
* 获取商家出售中的商品数量
* @param uid
*/
@RequestMapping(params = "method=ufo.sellerOrder.getCanSellSkupBySellerUid")
@ResponseBody
public ApiResponse getCanSellSkupBySellerUid(@RequestParam(name = "uid")Integer uid){
logger.info("in ufo.sellerOrder.getUnfinishedOrderBySellerUid, uid {}", uid);
int total=sellerOrderService.getCanSellSkupBySellerUid(uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(total).build();
}
/**
* 根据卖家提交价格来计算各项费用
... ...
package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.IStoredSellerDepositService;
... ... @@ -9,6 +10,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
... ... @@ -48,4 +50,19 @@ public class StoredSellerDepositController {
return new ApiResponse.ApiResponseBuilder().data(null).code(200).message("保证金充值订单生成,请支付").build();
}
/**
* 商户退驻
*/
@RequestMapping(params = "method=ufo.sellerOrder.quitStoredSeller")
public ApiResponse quitStoredSeller(@RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter StoredSellerController quitStoredSeller param uid is {}", uid);
//(1) 优先校验请求的参数
if (uid == null || uid <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
storedSellerDepositService.quitStoredSellerAndReturnDeposit(uid);
return new ApiResponse();
}
}
... ...
... ... @@ -8,4 +8,6 @@ public interface IStoredSellerDepositService {
OrderSubmitResponse depositPreStore(ShoppingRequest shoppingRequest);
OrderSubmitResponse depositRecharge(ShoppingRequest shoppingRequest);
void quitStoredSellerAndReturnDeposit(Integer uid);
}
... ...
package com.yohoufo.order.service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.error.ServiceError;
... ... @@ -22,22 +12,23 @@ import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.OrdersPayMapper;
import com.yohoufo.dal.order.OrdersPayRefundMapper;
import com.yohoufo.dal.order.SellerWalletDetailMapper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
import com.yohoufo.dal.order.model.OrdersPay;
import com.yohoufo.dal.order.model.OrdersPayRefund;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.impl.PaymentServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
... ... @@ -341,8 +332,12 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
}
// 商家退出入驻,钱包清空+转账
public boolean returnAllEarnest(Integer uid, long orderCode, String alipayAccount) {
BigDecimal money = returnEarnest(uid, orderCode);
public BigDecimal getReturnMoney(Integer uid, long orderCode){
BigDecimal money = returnEarnest(uid, orderCode);
return money;
}
public boolean returnAllEarnest(Integer uid, long orderCode,BigDecimal money, String alipayAccount) {
if (money == null) {
return false;
}
... ...
... ... @@ -4,16 +4,21 @@ import com.alibaba.fastjson.JSON;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
import com.yohobuy.ufo.model.order.common.EntrySellerDepositType;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
import com.yohoufo.order.common.Payment;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.OrderSubmitResponse;
import com.yohoufo.order.service.IStoredSellerDepositService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -40,6 +45,12 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
@Autowired
EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
@Autowired
SellerOrderService sellerOrderService;
@Autowired
MerchantOrderPaymentService merchantOrderPaymentService;
/**
* 充值保证金
*/
... ... @@ -140,6 +151,114 @@ public class StoredSellerDepositServiceImpl implements IStoredSellerDepositServi
}
/**
* 退出入驻
* @param uid
*/
@Override
public void quitStoredSellerAndReturnDeposit(Integer uid){
logger.info("StoredSellerServiceImpl quitStoredSeller enter uid is {} ",uid);
if(!isEntrySeller(uid)){
logger.error("StoredSellerServiceImpl quitStoredSeller store seller isEntrySeller false,uid is {} ",uid);
throw new ServiceException(400,"商户入驻状态为非入驻,不允许退驻!");
}
Integer expectStatus= StoredSellerStatusEnum.entered.getId();
// 检查商户是否有出售中的商品,或者有订单未完成的 ,都不可以提交
Integer total=sellerOrderService.getUnfinishedOrderBySellerUid(uid);
if(total!=null && total>0){
logger.error("quitStoredSeller not allowed cause of unfinished order ,uid {} ,total {}" ,uid,total);
throw new ServiceException(400,"商户存在未完成订单,不允许退驻!");
}
total=sellerOrderService.getCanSellSkupBySellerUid(uid);
if(total!=null && total>0){
logger.error("quitStoredSeller not allowed cause of can seller product ,uid {} ,total {}" ,uid,total);
throw new ServiceException(400,"商户存在出售中商品,不允许退驻!");
}
String aliPayAccount = getAlipayAccount(uid);
if(StringUtils.isBlank(aliPayAccount)){
logger.error("quitStoredSeller not allowed cause of aliPayAccount is blank ,uid {}" ,uid);
throw new ServiceException(400,"商户存在出售中商品,不允许退驻!");
}
ApiResponse<Integer> resp = ufoServiceCaller.call("ufo.user.updateStoredSellerQuitStatus", ApiResponse.class, uid);
logger.info("StoredSellerServiceImpl quitStoredSeller call updateStoredSellerQuitStatus ,uid is {} ,resp is {} ",uid,resp);
if(resp!=null&&resp.getCode()==200&&resp.getData()!=null&&(Integer)resp.getData()>0){
//创建一个退款订单
long orderCode = orderCodeGenerator.generate(OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE);
BigDecimal amount=BigDecimal.ZERO;
//保证金订单类型
Integer type = EntrySellerDepositType.GO_BACK.getType();
// 生成订单数据,insert db
EntrySellerRechargeOrder entrySellerRechargeOrder=new EntrySellerRechargeOrder();
entrySellerRechargeOrder.setUid(uid);
entrySellerRechargeOrder.setOrderCode(orderCode);
entrySellerRechargeOrder.setPayment(Payment.ALIPAY.getCode());
entrySellerRechargeOrder.setStatus(0);//0 未支付,1已支付
entrySellerRechargeOrder.setAmount(amount);
entrySellerRechargeOrder.setType(type);
int now = (int) (System.currentTimeMillis()/1000);
entrySellerRechargeOrder.setCreateTime(now);
entrySellerRechargeOrder.setUpdateTime(now);
logger.info("enter StoredSellerDepositServiceImpl quitStoredSellerAndReturnDeposit begin save entrySellerRechargeOrder {} ",entrySellerRechargeOrder);
int num = entrySellerRechargeOrderMapper.insert(entrySellerRechargeOrder);
logger.info("enter StoredSellerDepositServiceImpl quitStoredSellerAndReturnDeposit end save entrySellerRechargeOrder {} ,num {}",entrySellerRechargeOrder,num);
//获取退款金额
BigDecimal returnAmount = merchantOrderPaymentService.getReturnMoney(uid,orderCode);
// 执行退保证金的操作
logger.info("StoredSellerServiceImpl merchantOrderPaymentService begin ,uid {},returnAmount {} ",uid,returnAmount);
boolean returnResult=false;
if(returnAmount!=null){
returnResult=merchantOrderPaymentService.returnAllEarnest(uid,orderCode,returnAmount,aliPayAccount);
logger.info("StoredSellerServiceImpl merchantOrderPaymentService end ,uid {}",uid);
}
//退保证金成功,更新记录
int orderStatus=0;//未支付
if(returnResult){
orderStatus=1;//已支付
}
logger.info("StoredSellerServiceImpl updateReturnDepositByOrderCode ,orderCode {} ,returnAmount {} ,orderStatus {} ,ts {}",
orderCode,returnAmount,orderStatus,now);
int updateNum=entrySellerRechargeOrderMapper.updateReturnDepositByOrderCode(orderCode,
returnAmount==null?BigDecimal.ZERO:returnAmount,orderStatus,now);
logger.info("StoredSellerServiceImpl updateReturnDepositByOrderCode update num {} ,orderCode {} ,returnAmount {} ,orderStatus {} ,ts {}",updateNum,
orderCode,returnAmount,orderStatus,now);
}else{
logger.error("StoredSellerServiceImpl quitStoredSellerAndReturnDeposit update row is 0,uid {}",uid);
throw new ServiceException(400,"商户退驻失败,请重新检查状态!");
}
}
@SuppressWarnings("unchecked")
private String getAlipayAccount(int targetUid) {
ApiResponse<AuthorizeResultRespVO> resp = ufoServiceCaller.call("ufo.user.aliPayAccountQuery", ApiResponse.class, targetUid);
if (resp != null) {
AuthorizeResultRespVO data = (AuthorizeResultRespVO) resp.getData();
if (data != null && data.getAlipayAccount() != null) {
return data.getAlipayAccount();
}
}
return null;
}
private BigDecimal getValidMoney(String money) {
try {
BigDecimal bd = new BigDecimal(money);
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.user.controller.passport;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IStoredSellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -71,18 +70,18 @@ public class StoredSellerController {
/**
* 商户退驻
* 更新商户状态为"退驻"
*/
@RequestMapping(params = "method=ufo.user.quitStoredSeller")
public ApiResponse quitStoredSeller(RealNameAuthorizeReqVO reqVO) throws GatewayException {
logger.info("enter StoredSellerController applyQuitStoredSeller param reqVO is {}", reqVO);
@RequestMapping(params = "method=ufo.user.updateStoredSellerQuitStatus")
public ApiResponse updateStoredSellerQuitStatus(@RequestParam("uid") Integer uid) throws GatewayException {
logger.info("enter StoredSellerController updateStoredSellerQuitStatus param uid is {}", uid);
//(1) 优先校验请求的参数
if (reqVO == null || reqVO.getUid() <=0 ){
if (uid == null || uid <=0 ){
throw new GatewayException(400, "参数错误,uid不存在!");
}
storedSellerService.quitStoredSeller(reqVO);
return new ApiResponse();
Integer updateNum=storedSellerService.updateStoredSellerQuitStatus(uid);
return new ApiResponse(updateNum);
}
}
... ...
package com.yohoufo.user.service;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
public interface IStoredSellerService {
boolean isStoredSeller(Integer uid);
... ... @@ -11,5 +9,5 @@ public interface IStoredSellerService {
//void applyQuitStoredSeller(Integer uid);
void quitStoredSeller(RealNameAuthorizeReqVO reqVO);
Integer updateStoredSellerQuitStatus(Integer uid);
}
... ...
... ... @@ -2,13 +2,11 @@ package com.yohoufo.user.service.impl;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.enums.StoredSellerStatusEnum;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.dal.user.IStoredSellerDao;
import com.yohoufo.dal.user.model.StoredSeller;
import com.yohoufo.dal.user.model.ZhiMaCert;
import com.yohoufo.user.cache.CacheService;
import com.yohoufo.user.requestVO.RealNameAuthorizeReqVO;
import com.yohoufo.user.service.IRealNameAuthorizeService;
import com.yohoufo.user.service.IStoredSellerService;
import org.slf4j.Logger;
... ... @@ -37,67 +35,6 @@ public class StoredSellerServiceImpl implements IStoredSellerService {
private UfoServiceCaller ufoServiceCaller;
/**
* 退出入驻
* @param reqVO
*/
@Override
public void quitStoredSeller(RealNameAuthorizeReqVO reqVO){
logger.info("StoredSellerServiceImpl quitStoredSeller enter reqVO is {} ",reqVO);
Integer uid=reqVO.getUid();
StoredSeller storedSeller = getValidStoredSeller(uid);
if(null==storedSeller){
logger.error("StoredSellerServiceImpl quitStoredSeller store seller is null,uid is {} ",uid);
throw new ServiceException(400,"未找到入驻信息");
}
Integer expectStatus=StoredSellerStatusEnum.entered.getId();
if(!expectStatus.equals(storedSeller.getValidStatus())){
throw new ServiceException(400,"商户入驻状态变化,不允许退驻!");
}
// 检查商户是否有出售中的商品,或者有订单未完成的 ,都不可以提交
ApiResponse apiResponse=ufoServiceCaller.call("ufo.sellerOrder.getUnfinishedOrderBySellerUid", ApiResponse.class,uid);
if(apiResponse==null||apiResponse.getCode()!=200){
throw new ServiceException(400,"商户订单获取异常,不允许退驻!");
}
Integer total =(Integer)apiResponse.getData();
if(total!=null && total>0){
logger.error("quitStoredSeller not allowed cause of unfinished order ,total {}" ,total);
throw new ServiceException(400,"商户存在未完成订单,不允许退驻!");
}
apiResponse=ufoServiceCaller.call("ufo.sellerOrder.getCanSellSkupBySellerUid", ApiResponse.class,uid);
if(apiResponse==null||apiResponse.getCode()!=200){
throw new ServiceException(400,"商户商品获取异常,不允许退驻!");
}
total =(Integer)apiResponse.getData();
if(total!=null && total>0){
logger.error("quitStoredSeller not allowed cause of can seller product ,total {}" ,total);
throw new ServiceException(400,"商户存在出售中商品,不允许退驻!");
}
LocalDateTime now=LocalDateTime.now();
long ts=now.toEpochSecond(ZoneOffset.of("+8"));
//更新为退驻
int num = storedSellerDao.updateToQuitByPrimaryKey(storedSeller.getId(),StoredSellerStatusEnum.quit.getId(),expectStatus,
reqVO.getOperatorUid(),reqVO.getOperatorName(),
ts,ts);
//清掉缓存
cacheService.removeStoredSeller(uid);
logger.info("StoredSellerServiceImpl quitStoredSeller end ,uid is {} ,update num ",uid,num);
if(num > 0){
//TODO 执行退保证金的操作
}else{
logger.error("StoredSellerServiceImpl quitStoredSeller update row is 0,reqVo {}",reqVO);
}
}
/*@Override
public void applyQuitStoredSeller(Integer uid){
logger.info("StoredSellerServiceImpl applyQuitStoredSeller uid is {} ",uid);
... ... @@ -190,4 +127,36 @@ public class StoredSellerServiceImpl implements IStoredSellerService {
}
@Override
public Integer updateStoredSellerQuitStatus(Integer uid){
logger.info("StoredSellerServiceImpl updateStoredSellerQuitStatus uid is {} ",uid);
StoredSeller storedSeller = getValidStoredSeller(uid);
if(null==storedSeller){
logger.error("StoredSellerServiceImpl applyQuitStoredSeller store seller is null,uid is {} ",uid);
throw new ServiceException(400,"未找到入驻信息");
}
Integer expectStatus =StoredSellerStatusEnum.entered.getId();
if(!expectStatus.equals(storedSeller.getValidStatus())){
throw new ServiceException(400,"商户入驻状态变化,不允许退出!");
}
//只能操作自己的uid
if(!uid.equals(storedSeller.getUid())){
throw new ServiceException(400,"商户入驻操作错误,不允许退出!");
}
LocalDateTime now=LocalDateTime.now();
long ts=now.toEpochSecond(ZoneOffset.of("+8"));
//更新为退驻
logger.info("StoredSellerServiceImpl updateStoredSellerQuitStatus begin ,uid is {} ,ts {} ",uid,ts);
int num = storedSellerDao.updateStatusByUid(uid,StoredSellerStatusEnum.quit.getId(),expectStatus,ts);
//状态变化,清掉缓存
cacheService.removeStoredSeller(uid);
logger.info("StoredSellerServiceImpl updateStoredSellerQuitStatus end ,uid is {} ,update num {}",uid,num);
return num;
}
}
... ...