Authored by mali

Merge branch 'master' of http://git.yoho.cn/ufo/yohoufo-fore

Conflicts:
	common/yohoufo-fore-common.iml
	order/yohoufo-fore-order.iml
	payment/yohoufo-fore-payment.iml
package com.yohoufo.common.utils;
import com.netflix.config.DynamicPropertyFactory;
import com.yoho.core.common.utils.AES;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AddressUtil {
private final static Logger logger = LoggerFactory.getLogger(AddressUtil.class);
/**
* 解密地址
* @param str
* @return
*/
public static String getDecryptStr(String str){
String decryptStr = str;
try{
str = str.replace(' ','+');
decryptStr = AES.decrypt(DynamicPropertyFactory.getInstance().getStringProperty("password.aes.key", "yoho9646yoho9646").get(), str);
}catch (Exception e){
logger.error("getDecryptStr failed. str is {}, e is {}", str, e);
}
logger.info("getDecryptStr, str is {}, decryptStr is {}", str, decryptStr);
return decryptStr;
}
}
... ...
... ... @@ -27,6 +27,18 @@ public class SellerOrderGoods {
private Byte status;
private String imageUrl;
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public Integer getId() {
return id;
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.order.SellerOrderGoodsMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.SellerOrderGoods">
<mapper namespace="com.yohoufo.order.dal.SellerOrderGoodsMapper">
<resultMap id="BaseResultMap" type="om.yohoufo.order.dal.model.SellerOrderGoods">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="product_name" jdbcType="VARCHAR" property="productName" />
... ... @@ -14,10 +14,11 @@
<result column="color_name" jdbcType="VARCHAR" property="colorName" />
<result column="goods_price" jdbcType="DECIMAL" property="goodsPrice" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="image_url" jdbcType="VARCHAR" property="imageUrl" />
</resultMap>
<sql id="Base_Column_List">
id, product_id, product_name, storage_id, depot_no, size_id, size_name, goods_id,
color_id, color_name, goods_price, status
color_id, color_name, goods_price, status, image_url
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
... ... @@ -25,12 +26,17 @@
from seller_order_goods
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from seller_order_goods
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" useGeneratedKeys="true">
insert into seller_order_goods (product_id, product_name, storage_id,
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="om.yohoufo.order.dal.model.SellerOrderGoods" useGeneratedKeys="true">
insert into seller_order_goods (product_id, product_name, storage_id,
depot_no, size_id, size_name,
goods_id, color_id, color_name,
goods_price, status)
... ... @@ -112,7 +118,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods">
<update id="updateByPrimaryKeySelective" parameterType="om.yohoufo.order.dal.model.SellerOrderGoods">
update seller_order_goods
<set>
<if test="productId != null">
... ...
... ... @@ -25,6 +25,16 @@
from seller_order
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectBySkup" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_order
where skup = #{skup,jdbcType=INTEGER}
limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from seller_order
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -38,5 +38,9 @@
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rest-client-simple</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-dal</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.yohoufo.order.common;
public enum SellerOrderStatus {
WAITING_PAY(0, "待付保证金"),
SELLER_CANCEL_PAY(1, "上架关闭(卖家取消支付)"),
SELLER_CANCEL_TIMEOUT(2, "上架关闭(卖家支付超时)"),
HAS_PAYED(3, "已支付"),
SELLER_CANCEL_SELL(4, "上架关闭(卖家取消出售)"),
BACKGROUNP_CANCEL_SELL(5, "上架关闭(平台取消出售)"),
HAS_SELLED(6, "已售出");
SellerOrderStatus(int code, String desc) {
this.code = code;
this.desc = desc;
}
int code;
String desc;
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
... ...
package com.yohoufo.order.common;
public enum SkupStatus {
CAN_SELL(1),
CAN_NOT_SELL(0);
SkupStatus(int code) {
this.code = code;
}
int code;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
... ...
package com.yohoufo.order.constants;
public interface OrderConstant {
// 在线支付
int PAYMENT_ONLINE = 1;
String PAYMENT_ONLINE_NAME = "在线支付";
// 顺丰快递
int DELIVERY_WAY_SF = 2;
String DELIVERY_WAY_SF_NAME = "顺丰速运";
int DELIVERY_WAY_SF_COST = 15;
String GOODS_PRICE = "商品金额";
String DELIVERY_DESC = "运费";
String GOODS_REAL_PRICE = "实付金额";
String MONEY_SIGN = "¥";
String PLUS_SIGN = "+";
String DAMAGES_DESC = "如卖家原因导致交易失败,您将获得赔偿金";
String MONEY_UNIT = "元";
}
... ...
... ... @@ -19,10 +19,20 @@ public class ShoppingController {
IShoppingService shoppingService;
/**
* 结算
* @param shoppingRequest
* @return
*/
@RequestMapping("/payment")
@ResponseBody
public ShoppingPaymentResponse payment(@RequestBody ShoppingRequest shoppingRequest){
return null;
return shoppingService.payment(shoppingRequest);
}
}
... ...
... ... @@ -5,7 +5,20 @@ import lombok.Data;
@Data
public class ShoppingRequest {
private String skup;
private int skup;
private int uid;
/**
* 加密过的地址Id
*/
private String addressId;
/**
* 客户端类型
*/
private String clientType;
private String uid;
}
... ...
package com.yohoufo.order.response;
import lombok.Data;
import lombok.ToString;
import java.math.BigDecimal;
import java.util.List;
@Data
@ToString
public class ShoppingPaymentResponse {
/**
* 支付方式:在线支付
*/
PaymentWay paymentWay;
/**
* 快递方式
*/
DeliveryWay deliveryWay;
/**
* 商品情报
*/
List<Goods> goodsList;
/**
* 费用列表
*/
List<PromotionFormula> promotionFormulaList;
/**
* 赔偿金文案
*/
String damagesDesc;
@Data
@ToString
public static class PaymentWay{
private int paymentType;
private String paymentTypeName;
}
@Data
@ToString
public static class DeliveryWay{
/**
* 快递方式
*/
private int deliveryWayId;
private String deliveryWayName;
private int deliveryWayCost;
}
@Data
@ToString
public static class Goods{
// 封面图
private String goodsImg;
private String productName;
private int colorId;
private String color;
private int sizeId;
private String sizeName;
private int buyNumber;
private BigDecimal salePrice;
}
@Data
@ToString
public static class PromotionFormula{
private String promotion;
private String promotionAmount;
}
}
... ...
package com.yohoufo.order.service;
import com.yohoufo.order.request.ShoppingRequest;
import com.yohoufo.order.response.ShoppingPaymentResponse;
public interface IShoppingService {
/**
* 结算页数据
* @param shoppingRequest
* @return
*/
public ShoppingPaymentResponse payment(ShoppingRequest shoppingRequest);
}
... ...
package com.yohoufo.order.service.impl;
import com.yoho.core.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.SellerOrderStatus;
import com.yohoufo.order.common.SkupStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class OrdeCreationServiceImpl {
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
SellerOrderMapper sellerOrderMapper;
@Autowired
BuyerOrderMapper buyerOrderMapper;
@Autowired
BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
BuyerOrderMetaMapper buyerOrderMetaMapper;
/**
* 创建订单
*/
@Transactional
public void create(int skup, int productId, long orderCode, int uid, String clientType){
try{
// 扣减库存,入口参数:skup, product_id TODO
// 1.skup不可售
// 2.卖家订单,skup已经售出
SellerOrderGoods sellerOrderGoods = new SellerOrderGoods();
sellerOrderGoods.setId(skup);
sellerOrderGoods.setStatus((byte)SkupStatus.CAN_NOT_SELL.getCode());
sellerOrderGoodsMapper.updateByPrimaryKeySelective(sellerOrderGoods);
// 根据skup 查询卖家订单 ==> 卖家uid
// SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
// sellerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond());
// sellerOrder.setStatus((byte) SellerOrderStatus.HAS_SELLED.getCode());
// sellerOrderMapper.updateByPrimaryKeySelective(sellerOrder);
// 订单入口
BuyerOrder buyerOrder = new BuyerOrder();
buyerOrder.setUid(uid);
buyerOrder.setOrderCode(orderCode);
// buyerOrder.setSellerUid(sellerOrder.getUid());
// buyerOrder.setPaymentType();
buyerOrderMapper.insert(buyerOrder);
}catch (Exception e){
throw e;
}
}
}
... ...
... ... @@ -2,12 +2,22 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.consts.Constant;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.SkupStatus;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.request.ShoppingRequest;
import com.yohoufo.order.response.ShoppingPaymentResponse;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.support.ShoppingSupport;
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;
import java.math.BigDecimal;
import java.util.Arrays;
import org.springframework.stereotype.Service;
@Service
... ... @@ -15,20 +25,100 @@ public class ShoppingServiceImpl implements IShoppingService{
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
ShoppingSupport shoppingSupport;
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
OrderCodeGenerator orderCodeGenerator;
/**
* 结算页数据
* @param shoppingRequest
* @return
*/
public ShoppingPaymentResponse payment(ShoppingRequest shoppingRequest){
// 入口参数检查
if (StringUtils.isEmpty(shoppingRequest.getUid())
|| StringUtils.isEmpty(shoppingRequest.getSkup())){
if (shoppingRequest.getUid()<0
|| shoppingRequest.getSkup()<0){
logger.warn("payment uid or skup is null");
// TODO
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
// skup是否是可售状态
SellerOrderGoods skup = sellerOrderGoodsMapper.selectByPrimaryKey(shoppingRequest.getSkup());
if (skup == null){
logger.warn("payment skup not exist, skup is {}", shoppingRequest.getSkup());
// TODO
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
// 不可售
if (skup.getStatus()!=null
&& skup.getStatus().intValue() != SkupStatus.CAN_SELL.getCode()){
logger.warn("payment skup status, skup is {}", shoppingRequest.getSkup());
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
ShoppingPaymentResponse response = new ShoppingPaymentResponse();
response.setPaymentWay(shoppingSupport.getPaymentWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay());
response.setGoodsList(Arrays.asList(shoppingSupport.getGoodsInfo(skup)));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(skup));
// TODO 赔偿金计算
response.setDamagesDesc(shoppingSupport.getDamagesDesc(null));
return response;
}
public void submit(ShoppingRequest shoppingRequest){
// 入口参数检查
if (shoppingRequest.getSkup() < 0
|| shoppingRequest.getUid() < 0
|| StringUtils.isEmpty(shoppingRequest.getAddressId())){
logger.warn("submit param is null");
// TODO
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
// 创建订单
// 校验 skup是否是可售
SellerOrderGoods skup = sellerOrderGoodsMapper.selectByPrimaryKey(shoppingRequest.getSkup());
if (skup == null){
logger.warn("payment skup not exist, skup is {}", shoppingRequest.getSkup());
// TODO
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
// 不可售
if (skup.getStatus()!=null
&& skup.getStatus().intValue() != SkupStatus.CAN_SELL.getCode()){
logger.warn("payment skup status, skup is {}", shoppingRequest.getSkup());
throw new ServiceException(ServiceError.ORDER_REQUEST_ERROR);
}
// 生成订单号 TODO
long orderCode = orderCodeGenerator.generate();
// 减库存,skup更新成不可售,入库
// 返回结果
return null;
}
}
... ...
package com.yohoufo.order.service.support;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.response.ShoppingPaymentResponse;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
@Service
public class ShoppingSupport {
/**
* 支付方式
* @return
*/
public ShoppingPaymentResponse.PaymentWay getPaymentWay() {
// 支付方式: 在线支付
ShoppingPaymentResponse.PaymentWay paymentWay = new ShoppingPaymentResponse.PaymentWay();
paymentWay.setPaymentType(OrderConstant.PAYMENT_ONLINE);
paymentWay.setPaymentTypeName(OrderConstant.PAYMENT_ONLINE_NAME);
return paymentWay;
}
/**
* 配送方式
* @return
*/
public ShoppingPaymentResponse.DeliveryWay getDeliverWay() {
// 快递方式
ShoppingPaymentResponse.DeliveryWay deliveryWay = new ShoppingPaymentResponse.DeliveryWay();
deliveryWay.setDeliveryWayId(OrderConstant.DELIVERY_WAY_SF);
deliveryWay.setDeliveryWayCost(OrderConstant.DELIVERY_WAY_SF_COST);
deliveryWay.setDeliveryWayName(OrderConstant.DELIVERY_WAY_SF_NAME);
return deliveryWay;
}
/**
* 商品情报
* @param skup
* @return
*/
public ShoppingPaymentResponse.Goods getGoodsInfo(SellerOrderGoods skup) {
ShoppingPaymentResponse.Goods goods = new ShoppingPaymentResponse.Goods();
goods.setProductName(skup.getProductName());
goods.setColorId(skup.getColorId() == null ? 0 : skup.getColorId());
goods.setColor(skup.getColorName());
goods.setSizeId(skup.getSizeId() == null ? 0:skup.getSizeId());
goods.setSizeName(skup.getSizeName());
goods.setSalePrice(skup.getGoodsPrice());
goods.setGoodsImg(skup.getImageUrl());
return goods;
}
/**
* 付款信息
* @param skup
* @return
*/
public List<ShoppingPaymentResponse.PromotionFormula> getPromotionFormula(SellerOrderGoods skup) {
ShoppingPaymentResponse.PromotionFormula formula1 = new ShoppingPaymentResponse.PromotionFormula();
formula1.setPromotion(OrderConstant.GOODS_PRICE);
formula1.setPromotionAmount(OrderConstant.MONEY_SIGN + skup.getGoodsPrice());
ShoppingPaymentResponse.PromotionFormula formula2 = new ShoppingPaymentResponse.PromotionFormula();
formula2.setPromotion(OrderConstant.DELIVERY_DESC);
formula2.setPromotionAmount(OrderConstant.PLUS_SIGN + OrderConstant.MONEY_SIGN + OrderConstant.DELIVERY_WAY_SF_COST);
ShoppingPaymentResponse.PromotionFormula formula3 = new ShoppingPaymentResponse.PromotionFormula();
formula3.setPromotion(OrderConstant.GOODS_REAL_PRICE);
formula3.setPromotionAmount(OrderConstant.MONEY_SIGN + skup.getGoodsPrice().add(new BigDecimal(OrderConstant.DELIVERY_WAY_SF_COST)));
return Arrays.asList(formula1, formula2, formula3);
}
/**
* 赔偿金文案
* @param damagedPrice
* @return
*/
public String getDamagesDesc(BigDecimal damagedPrice){
StringBuilder damagesDesc = new StringBuilder();
damagesDesc.append(OrderConstant.DAMAGES_DESC);
damagesDesc.append(OrderConstant.MONEY_SIGN);
damagesDesc.append(damagedPrice);
damagesDesc.append(OrderConstant.MONEY_UNIT);
return damagesDesc.toString();
}
}
... ...
package com.yohoufo.order.service.support.codegenerator;
public interface OrderCodeGenerator {
/**
* 根据产生订单号
* @return
*/
long generate();
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.core.common.utils.MD5;
import org.junit.Test;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
... ... @@ -31,11 +32,14 @@ public class PayTest {
data.put("msgType", "trade.precreate"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
// 支付宝- 31945075157
data.put("merOrderId", "31945075157");
data.put("merOrderId", "31942222222222");
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
data.put("tid","00000001"); //终端号
data.put("instMid", "APPDEFAULT"); // 机构商户号
data.put("totalAmount", 1);
// 回调接口 http://api-test3.dev.yohocorp.com/payment/weixin_notify
data.put("notifyUrl", "http://testapi.yohops.com/payment/weixin_notify");
data.put("sign", getSign(data));
... ... @@ -126,19 +130,25 @@ public class PayTest {
* 订单查询接口
*/
@Test
public void testQuary(){
public void testQuary() throws Exception{
JSONObject data = new JSONObject();
data.put("msgSrc","WWW.TEST.COM");
// 支付宝
data.put("msgType", "query"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
data.put("merOrderId", "24455075157");
data.put("merOrderId", "319450751581111111");
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
data.put("tid","00000001"); //终端号
data.put("instMid", "APPDEFAULT"); // 机构商户号
data.put("sign", getSign(data));
HttpClient httpClient = new HttpClient();
httpClient.init();
String result = httpClient.post(url, JSON.toJSONString(data));
System.out.println(result);
}
... ... @@ -146,20 +156,25 @@ public class PayTest {
* 订单退款
*/
@Test
public void testRefund(){
public void testRefund()throws Exception{
JSONObject data = new JSONObject();
data.put("msgSrc","WWW.TEST.COM");
// 支付宝
data.put("msgType", "refund"); // 微信:wx.unifiedOrder, 支付宝:trade.precreate, 全民付:qmf.order, 银联云闪付:uac.appOrder
data.put("requestTimestamp", DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss"));
data.put("merOrderId", "24455075157");
data.put("merOrderId", "319450751589999");
data.put("mid", "898310148160568"); //商户号 仅用于支付宝和云闪付
data.put("tid","00000001"); //终端号
data.put("instMid", "APPDEFAULT"); // 机构商户号
data.put("refundAmount",1);
data.put("sign", getSign(data));
HttpClient httpClient = new HttpClient();
httpClient.init();
String result = httpClient.post(url, JSON.toJSONString(data));
System.out.println(result);
}
/**
... ... @@ -184,4 +199,13 @@ public class PayTest {
// 回调接口
@Test
public void tes(){
BigDecimal bigDecimal = new BigDecimal("22.88");
System.out.println(bigDecimal);
}
}
... ...