Authored by chenchao

Merge remote-tracking branch 'origin/test6.9.10' into test6.9.10

package com.yohoufo.order.controller;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
... ... @@ -9,8 +10,11 @@ import com.yohoufo.common.lock.RedisLock;
import com.yohoufo.common.lock.RedisLockFactory;
import com.yohoufo.common.utils.ExecutorServiceUtils;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.PaymentServiceImpl;
import com.yohoufo.order.service.impl.TransferService;
import com.yohoufo.order.utils.NamedThreadFactory;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
... ... @@ -35,6 +40,9 @@ public class OrderHelpController {
private TransferService transferService;
@Autowired
private PaymentServiceImpl paymentService;
@Autowired
private RedisLockFactory redisLockFactory;
/**
... ... @@ -57,6 +65,28 @@ public class OrderHelpController {
@IgnoreSession
@IgnoreSignature
@InnerApi
@RequestMapping(value = "/transAllEarnest")
public ApiResponse transAllEarnest(@RequestBody TransferAllEarnestRequest req) {
return new ApiResponse.ApiResponseBuilder()
.code(200)
.message(paymentService.transAllEarnest(req.getOrderCode(), req.getUid(), req.getAmount(), req.getAliPayAccount()) ? "ok" : "ko")
.build();
}
@Data
public static class TransferAllEarnestRequest {
long orderCode;
Integer uid;
BigDecimal amount;
AuthorizeResultRespVO aliPayAccount;
}
/**
* 转账
*/
@IgnoreSession
@IgnoreSignature
@InnerApi
@RequestMapping(value = "/lock")
public ApiResponse lock(String key, @RequestParam(required = false, defaultValue = "100") int taskNum) {
ExecutorService executorService = new ThreadPoolExecutor(5, 10,
... ...
... ... @@ -22,7 +22,7 @@ public class AppraiseExpressStageBuilder {
/**
* 平台确认收货
*
* 1卖家发货 == 2平台鉴定 点亮1
* 1卖家发货 == 2平台鉴定 点亮2
*/
private static final int DEPOSIT_PLATFORM_RECEIPT = 11;
... ...
... ... @@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.common.*;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
... ... @@ -504,9 +505,9 @@ public class AppraiseService {
return apiResponse;
}
// 1.瑕疵,鉴定为假,虚假发货,质检不通过取消
// 1.鉴定为假,质检不通过
List<Integer> APPRAISE_FAIL_STATUS_CODE = Lists.newArrayList(AppraiseOrderStatus.CHECKING_FAKE.getCode(),
AppraiseOrderStatus.SHAM_SEND_OUT.getCode(), AppraiseOrderStatus.QUALITY_CHECK_FAKE.getCode());
AppraiseOrderStatus.QUALITY_CHECK_FAKE.getCode());
// 2.无法鉴定
List<Integer> CANNOT_APPRAISE_STATUS_CODE = Lists.newArrayList(
... ... @@ -588,9 +589,21 @@ public class AppraiseService {
// 子订单对应商品 1:1
AppraiseOrderGoods oneAppraiseOrderGood = appraiseOrderGoods.get(0);
inBoxFacade.sendInboxSmsWhenAppraiseFinished(uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
if (APPRAISE_FAIL_STATUS_CODE.contains(appraiseOrder.getStatus())
|| APPRAISE_SUCCESS_STATUS_CODE.contains(appraiseOrder.getStatus())){
inBoxFacade.sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum.INBOX_DELIVERY_APPRAISE_FINISHED,
InboxBusinessTypeEnum.SMS_DELIVERY_APPRAISE_FINISHED,
uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
}else if(CANNOT_APPRAISE_STATUS_CODE.contains(appraiseOrder.getStatus())){
inBoxFacade.sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum.INBOX_DELIVERY_CANNOT_APPRAISE,
InboxBusinessTypeEnum.SMS_DELIVERY_CANNOT_APPRAISE,
uid, oneAppraiseOrderGood.getProductName(),
oneAppraiseOrderGood.getProductCode(),
wayBillCode);
}
}
if (appraiseOrder.getAttributes() == OrderAttributes.DEPOSITE.getCode()) { // 鉴定寄存的订单,需要同步修改寄存表的状态
... ... @@ -1741,13 +1754,14 @@ public class AppraiseService {
List<Integer> skupList = buyerOrderGoodses.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
sellerOrderGoodsMapper.updateDeptNoBySkups(skupList, appraiseExpressInfoBo.getDepotNum());
expressRecordMapper.updateDeptNoByOrder(orderCodeList, EnumExpressType.EXPRESS_TYPE_1.getCode(), appraiseExpressInfoBo.getDepotNum());
productProxyService.setBatchDepotNum(skupList, appraiseExpressInfoBo.getDepotNum());
}
// 更新鉴定订单的鉴定室
appraiseOrderGoodsMapper.updateBatchDepotNo(orderCodeList, appraiseExpressInfoBo.getDepotNum());
expressRecordMapper.updateDeptNoByOrder(orderCodeList, EnumExpressType.EXPRESS_TYPE_1.getCode(), appraiseExpressInfoBo.getDepotNum());
}
}
... ...
... ... @@ -546,7 +546,9 @@ public class PaymentServiceImpl implements IPaymentService {
@Database(ForceMaster = true)
public boolean transAllEarnest(long orderCode, Integer uid, BigDecimal amount,
AuthorizeResultRespVO aliPayAccount) {
logger.info("退还商家所有保证金,转账开始,orderCode = {}, uid={}, amount={}, alipayAccount={}", orderCode, uid, amount, aliPayAccount);
String logTag = String.format("transfer all earnest {}-{}", orderCode, uid);
logger.info("{}, amount is {} and alipay account is {}", logTag, amount, aliPayAccount);
int now = (int) (System.currentTimeMillis() / 1000);
// 查看是否已经有转账记录
... ... @@ -563,6 +565,7 @@ public class PaymentServiceImpl implements IPaymentService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(2);
record.setPayType(1);
record.setTradeType(1);
... ... @@ -574,7 +577,7 @@ public class PaymentServiceImpl implements IPaymentService {
if (amount == null || amount.compareTo(new BigDecimal("0.1")) < 0) {
logger.warn("transAllEarnestErr transferMon计算费用结果为 {}, 小于0.1或为null", amount);
logger.warn("{}, amount {} less 0.1 or null", logTag, amount);
alarm("转账金额小于0.1或为null", "ufo.order.transAllEarnest", "退还商家入驻所有金额,订单号:" + orderCode + "操作类型(" + 6 + ")计算金额结果为" + amount);
record.setTradeStatus(BillTradeStatus.AMOUNT_IS_ILLEGAL.getCode());
addTradeBills(record);
... ... @@ -582,20 +585,20 @@ public class PaymentServiceImpl implements IPaymentService {
}
if (StringUtils.isBlank(aliPayAccount.getAlipayAccount()) && StringUtils.isBlank(aliPayAccount.getAlipayId())) {
logger.warn("transAllEarnestErr uid {} 支付宝账号不合法", account);
logger.warn("{}, alipay account is not exist", logTag);
record.setTradeStatus(BillTradeStatus.NOT_EXIST_ALIPAY_ACCOUNT.getCode());
addTradeBills(record);
throw new ServiceException(400, "uid[" + uid + "]支付宝账号不合法");
}
logger.info("transAllEarnest参数检查成功!");
logger.info("{}, data check ok.", logTag);
tradeBillsMapper.insert(record);
// 转账
JSONObject jsonObject = null;
boolean exceedMillionAndSuccess = false;
transfer.setUpdateTime(now);
try {
logger.info("transAllEarnest开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", orderCode, account, amount);
logger.info("{}, transfer start", logTag);
shoppingRiskWatchDog.checkAlipayBlackUser(aliPayAccount.getUid(), aliPayAccount);
if (alipayTransferChancelSelector.isTransferWithAlipayExceedMillionTransfer()) {
transfer.setInterfaceType(2);
... ... @@ -615,7 +618,7 @@ public class PaymentServiceImpl implements IPaymentService {
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount);
if (jsonObject == null) {
logger.warn("transAllEarnestErr 转账失败 , orderCode is {}", orderCode);
logger.warn("{}, transfer fail.", logTag);
transfer.setStatus(3);
throw new ServiceException(500, "转账失败:阿里接口返回null");
}
... ... @@ -627,7 +630,7 @@ public class PaymentServiceImpl implements IPaymentService {
&& (code = jsonObject.getInteger("code")) == 10000
&& jsonObject.containsKey("order_id")
&& StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
logger.info("转账成功,targeAccount is {}, amount is {}", account, amount);
logger.info("{}, transfer success, account is {}, amount is {}", logTag, account, amount);
transfer.setAlipayTradeId(orderId);
transfer.setStatus(1);
return true;
... ... @@ -644,16 +647,15 @@ public class PaymentServiceImpl implements IPaymentService {
return true;
}
} else {
logger.warn("transAllEarnestErr 返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId);
logger.warn("{}, transfer fail, return_code is {} and return_order_id is {}", logTag, code, orderId);
throw new ServiceException(500, "转账失败:code或者order_id不是成功状态");
}
} catch (Exception e) {
logger.warn("transAllEarnestErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage());
logger.warn("{}, transfer fail", logTag, e);
String alarmMsg = "订单号:" + orderCode + ",操作类型(商家退出入驻退保证金),msg=" + e.getMessage();
if (jsonObject != null) {
alarmMsg += ",阿里返回DETAIL=" + jsonObject.toJSONString();
}
logger.info("transAllEarnestErr 转账失败 , alarmMsg is {}", alarmMsg);
alarm("转账失败", "ufo.order.transAllEarnest", alarmMsg);
transfer.setStatus(3);
if (e instanceof ServiceException) {
... ... @@ -663,17 +665,17 @@ public class PaymentServiceImpl implements IPaymentService {
}
} finally {
if (exceedMillionAndSuccess) {
logger.info("transferMon exceedMillion,转账结束,等待回调 orderCode is {}!", orderCode);
logger.info("{}, transfer exceed million waiting...", logTag);
return true;
}
logger.info("transAllEarnest最后更新状态 status= {}", transfer.getStatus());
logger.info("{}, transfer end update status to {}", logTag, transfer.getStatus());
transfer.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
// 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败
BillTradeStatus bts = transfer.getStatus() == 1 ? BillTradeStatus.SUCCESS : BillTradeStatus.TRANSFER_FAIL;
record.setTradeStatus(bts.getCode());
tradeBillsMapper.updateSelectiveByPrimaryKey(record);
logger.info("transAllEarnest最后更新状态完成,转账结束, orderCode is {}!", orderCode);
logger.info("{}, transfer end update status to {} ok", logTag, transfer.getStatus());
}
}
... ... @@ -1364,6 +1366,7 @@ public class PaymentServiceImpl implements IPaymentService {
TradeBills record = new TradeBills();
record.setUid(targetUid);
record.setOrderCode(buyerOrderCode);
record.setPaidOrderCode(0L);
record.setUserType(targetUserType.getCode());
record.setPayType(1);
// 如果[全部货款->卖家],否则[补偿款->卖家或买家] 2:货款;3:补偿款
... ...
... ... @@ -110,6 +110,7 @@ public class TradeBillsService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(2);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
... ... @@ -162,6 +163,7 @@ public class TradeBillsService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(1);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
... ... @@ -244,6 +246,7 @@ public class TradeBillsService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(1);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(2);//1:保证金;2:货款;3:补偿款
... ... @@ -283,6 +286,7 @@ public class TradeBillsService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(2);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
... ... @@ -309,6 +313,7 @@ public class TradeBillsService {
TradeBills record = new TradeBills();
record.setUid(uid);
record.setOrderCode(orderCode);
record.setPaidOrderCode(0L);
record.setUserType(2);// 1:买家uid; 2:卖家uid
record.setPayType(payType);// 1:支付宝; 2:微信
record.setTradeType(1);//1:保证金;2:货款;3:补偿款
... ...
... ... @@ -339,12 +339,13 @@ public class InBoxFacade extends BaseNoticeFacade{
* @param productCode
* @param wayBillCode
*/
public void sendInboxSmsWhenAppraiseFinished(int uid, String prdName, String productCode,String wayBillCode){
public void sendInboxSmsWhenAppraiseFinished(InboxBusinessTypeEnum inbox, InboxBusinessTypeEnum sms,
int uid, String prdName, String productCode,String wayBillCode){
try {
executorService.execute(() -> {
String params = buildParams(prdName, productCode);
InboxReqVO req = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.INBOX_DELIVERY_APPRAISE_FINISHED);
InboxReqVO req = buildInboxReqVO(uid, params, inbox);
InBoxResponse resp = inBoxSDK.addInbox(req);
log.info("record sendInboxSmsWhenAppraiseFinished inbox msg, uid {}, prdName {}, wayBillCode {}, resp {}", uid, prdName, wayBillCode, resp);
... ... @@ -356,7 +357,7 @@ public class InBoxFacade extends BaseNoticeFacade{
return;
}
List<String> mobileList = Arrays.asList(phone);
String content = getReplacedContent(InboxBusinessTypeEnum.SMS_DELIVERY_APPRAISE_FINISHED.getContent(), prdName ,productCode,wayBillCode);
String content = getReplacedContent(sms.getContent(), prdName ,productCode,wayBillCode);
sendSmsService.smsSendByMobile(content, mobileList);
log.info("sendInboxSmsWhenAppraiseFinished sms content {}, mobileList {}", content, mobileList);
});
... ...
... ... @@ -8,7 +8,7 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.ApiResponse;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.caller.UfoServiceCaller;
... ... @@ -822,14 +822,15 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
Map<String, Object> resultMap = new HashMap<>();
if (isServiceOrder(orderCode)) {
AppraiseOrder order = appraiseOrderMapper.selectByOrderCode(orderCode);
resultMap.put("status", order.getStatus());
AppraiseOrderGoods goods = appraiseOrderGoodsMapper.selectOneByOrderCode(orderCode);
AppraiseOrderStorage storage = appraiseOrderStorageMapper.selectByOrderCode(orderCode);
resultMap.put("image", goods == null ? "" : ImageUrlAssist.getAllProductPicUrl(goods.getImageUrl(), "goodsimg", "center", "d2hpdGU="));
resultMap.put("productId", goods == null ? "" : goods.getProductId());
resultMap.put("productName", goods == null ? "" : goods.getProductName());
resultMap.put("productCode", goods == null ? "" : goods.getProductCode());
resultMap.put("size", storage == null ? "" : storage.getSizeName());
resultMap.put("color", storage == null ? "" : storage.getColorName());
resultMap.put("size", storage == null ? "-" : storage.getSizeName());
resultMap.put("color", storage == null ? "-" : storage.getColorName());
resultMap.put("uid", order == null ? "" : order.getUid());
} else {
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
... ... @@ -860,7 +861,7 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
}
private boolean isServiceOrder(long orderCode) {
ApiResponse<Boolean> resp = ufoServiceCaller.call("ufo.order.isServiceOrder", ApiResponse.class, orderCode);
ApiResponse resp = ufoServiceCaller.call("ufo.order.isServiceOrder", ApiResponse.class, orderCode);
if (resp != null) {
return (Boolean) resp.getData();
}
... ...