Authored by mali

Merge branch 'test6.8.2' of http://git.yoho.cn/ufo/yohoufo-fore into test6.8.2

Showing 30 changed files with 760 additions and 204 deletions
... ... @@ -6,6 +6,7 @@ import com.yoho.error.exception.ServiceException;
import com.yoho.error.exception.handler.ServiceGlobalExceptionHandler;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.SessionExpireException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.ServletUtils;
import org.apache.commons.httpclient.HttpStatus;
import org.slf4j.Logger;
... ... @@ -58,7 +59,8 @@ public class GlobalDefaultExceptionHandler {
}
//如果是业务异常,则返回http 200,并且构造json消息体中错误码&错误内容
if (e instanceof GatewayException || e instanceof ServiceException || e instanceof Exception) {
if (e instanceof GatewayException || e instanceof ServiceException
|| e instanceof UfoServiceException || e instanceof Exception) {
int code;
String desc;
if (e instanceof GatewayException) {
... ... @@ -72,7 +74,10 @@ public class GlobalDefaultExceptionHandler {
if (serviceException.getParams() != null) {
desc = MessageFormat.format(desc, serviceException.getParams());
}
}else {
}else if(e instanceof UfoServiceException){
code = ((UfoServiceException) e).getCode();
desc = ((UfoServiceException) e).getErrorMessage();
} else{
code = 500;
desc = "服务暂时异常,请稍等";
}
... ...
package com.yohoufo.common.exception;
/**
* Created by chao.chen on 2018/11/21.
*/
public class UfoServiceException extends RuntimeException {
private final int code;
private final String errorMessage;
public UfoServiceException(int code, String errorMessage){
this.code = code;
this.errorMessage = errorMessage;
}
public int getCode() {
return code;
}
public String getErrorMessage() {
return errorMessage;
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface BuyerOrderGoodsMapper {
... ... @@ -22,11 +23,7 @@ public interface BuyerOrderGoodsMapper {
int updateByPrimaryKey(BuyerOrderGoods record);
/**
* 这个是个错误的方法
* @param skup
* @return
*/
BuyerOrderGoods selectBySkup(Integer skup);
List<BuyerOrderGoods> selectBySkups(@Param("skups") Collection<Integer> skups);
}
\ No newline at end of file
... ...
... ... @@ -53,4 +53,7 @@ public interface BuyerOrderMapper {
int selectCntByUid(@Param("uid")int uid);
int selectCntBySellerUid(@Param("sellerUid")int sellerUid, @Param("statusList")Collection<Integer> statusList);
List<BuyerOrder> selectByOrderCodes(@Param("orderCodes") Collection<Long> orderCodes,
@Param("statusList")Collection<Integer> statusList);
}
\ No newline at end of file
... ...
... ... @@ -15,7 +15,7 @@ public interface SellerOrderGoodsMapper {
SellerOrderGoods selectByPrimaryKey(Integer id);
List<SellerOrderGoods> selectByBatchNo(SellerOrderGoods record);
List<SellerOrderGoods> selectByBatchNo(@Param("condition")SellerOrderGoods record, @Param("statusList") Collection<Integer> statusList);
List<SellerOrderGoods> selectBySkups(@Param("list") List<Integer> skup);
... ...
package com.yohoufo.dal.order;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.order.model.SellerWalletDetail;
public interface SellerWalletDetailMapper {
... ... @@ -14,4 +18,8 @@ public interface SellerWalletDetailMapper {
int updateByPrimaryKeySelective(SellerWalletDetail record);
int updateByPrimaryKey(SellerWalletDetail record);
int selectUserDetailCount(@Param("uid") Integer uid);
List<SellerWalletDetail> selectUserDetailCount(@Param("uid") Integer uid, @Param("start") Integer start, @Param("count") Integer count);
}
\ No newline at end of file
... ...
... ... @@ -37,6 +37,8 @@ public class SellerOrderGoods {
private Integer num;
private String skupList;
public String getImageUrl() {
return imageUrl;
}
... ... @@ -174,4 +176,12 @@ public class SellerOrderGoods {
public void setNum(Integer num) {
this.num = num;
}
public String getSkupList() {
return skupList;
}
public void setSkupList(String skupList) {
this.skupList = skupList;
}
}
\ No newline at end of file
... ...
... ... @@ -2,12 +2,20 @@ package com.yohoufo.dal.order.model;
import java.math.BigDecimal;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class SellerWallet {
private Integer id;
private Integer uid;
private BigDecimal amount;
private BigDecimal lockAmount;
private Integer status;
... ... @@ -17,66 +25,4 @@ public class SellerWallet {
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "SellerWallet [id=" + id + ", uid=" + uid + ", amount=" + amount + ", status=" + status + ", type="
+ type + ", createTime=" + createTime + ", updateTime=" + updateTime + "]";
}
}
\ No newline at end of file
... ...
... ... @@ -25,6 +25,55 @@ public class SellerWalletDetail {
private Integer updateTime;
private Integer isBatch;
private String attachValue;
private BigDecimal availAmount;
private BigDecimal lockAmount;
private Integer isSet;
public enum Type {
// 1:充值,11:发布上架,12:加价,13:减价,
// 21卖家下架,22系统下架,31卖家不卖,32卖家超时发货,33鉴定不通过,
// 41买家取消(无物流), 42买家取消(有物流),
// 51鉴定通过,
// 61退还保证金(退出商家)
RE_CHARGE("充值保证金", 1),
PUBLISH("卖家发布商品", 11),
ADD_PRICE("卖家调高商品价格", 11),
SUBTRACT_PRICE("卖家调低商品价格", 11),
SELLER_OFF("卖家下架商品", 11),
SYSTEM_OFF("系统下架商品", 11),
SELLER_CANCEL("卖家不卖了", 11),
SELLER_OVER_TIME("卖家发货超时", 11),
APPRAISE_FAIL("鉴定不通过", 11),
BUYER_CANCEL_NO_DELIVERY("买家取消(无物流)", 11),
BUYER_CANCEL_DELIVERY("买家取消(有物流)", 11),
APPRAISE_OK("鉴定通过", 11),
MERCHANT_EXIT("商家退出入驻", 11);
private String name;
private int value;
private Type(String name, int value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public int getValue() {
return value;
}
public static Type of(int value) {
for (Type t : values()) {
if (t.value == value) {
return t;
}
}
return null;
}
}
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product.model;
import java.math.BigDecimal;
public class Storage {
private Integer id;
... ... @@ -14,6 +16,10 @@ public class Storage {
private Integer updateTime;
private Integer createTime;
private BigDecimal suggestLowPrice;
private BigDecimal suggestHighPrice;
public Integer getId() {
return id;
... ... @@ -70,4 +76,21 @@ public class Storage {
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public BigDecimal getSuggestLowPrice() {
return suggestLowPrice;
}
public void setSuggestLowPrice(BigDecimal suggestLowPrice) {
this.suggestLowPrice = suggestLowPrice;
}
public BigDecimal getSuggestHighPrice() {
return suggestHighPrice;
}
public void setSuggestHighPrice(BigDecimal suggestHighPrice) {
this.suggestHighPrice = suggestHighPrice;
}
}
\ No newline at end of file
... ...
... ... @@ -22,11 +22,14 @@
</select>
<select id="selectBySkup" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<select id="selectBySkups" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from buyer_order_goods
where skup = #{skup,jdbcType=INTEGER}
where skup in
<foreach collection="skups" item="skup" separator="," open="(" close=")">
#{skup,jdbcType=INTEGER}
</foreach>
</select>
<select id="selectByOrderCodeList" resultMap="BaseResultMap">
... ...
... ... @@ -82,6 +82,24 @@
limit 1
</select>
<select id="selectByOrderCodes" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from buyer_order
where order_code IN
<foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
#{orderCode,jdbcType=BIGINT}
</foreach>
<if test="statusList != null">
and status in
<foreach item="status" collection="statusList" open="(" separator="," close=")">
#{status}
</foreach>
</if>
</select>
<select id="selectByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -18,6 +18,7 @@
<result column="is_del" jdbcType="TINYINT" property="isDel" />
<result column="batch_no" jdbcType="BIGINT" property="batchNo" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="skup_list" jdbcType="VARCHAR" property="skupList" />
</resultMap>
<sql id="Base_Column_List">
id, uid, product_id, product_name, storage_id, depot_no, size_id, size_name,
... ... @@ -44,11 +45,14 @@
</if>
</select>
<select id="selectByBatchNo" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" resultMap="BaseResultMap">
<select id="selectByBatchNo" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_order_goods
where batch_no = #{batchNo,jdbcType=BIGINT} and status = #{status,jdbcType=TINYINT}
where batch_no = #{condition.batchNo,jdbcType=BIGINT} and status in
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=TINYINT}
</foreach>
</select>
... ... @@ -294,7 +298,7 @@
</select>
<select id="selectByUidStatusGBBNList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />,count(*) num from seller_order_goods
select <include refid="Base_Column_List" />,count(*) num,GROUP_CONCAT(id) skup_list from seller_order_goods
where <include refid="sql_where_4_select_UidStatusGBBNList"/>
order by id desc
limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
... ...
... ... @@ -11,9 +11,13 @@
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="is_batch" property="isBatch" jdbcType="INTEGER" />
<result column="attach_value" property="attachValue" jdbcType="VARCHAR" />
<result column="avail_amount" property="availAmount" jdbcType="DECIMAL" />
<result column="lock_amount" property="lockAmount" jdbcType="DECIMAL" />
<result column="is_set" property="isSet" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, wallet_id, uid, order_code, amount, type, create_time, update_time,is_batch
id, wallet_id, uid, order_code, amount, type, create_time, update_time,is_batch,attach_value,avail_amount,lock_amount,is_set
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -28,10 +32,10 @@
<insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
insert into seller_wallet_detail (id, wallet_id, uid,
order_code, amount, type,
create_time, update_time,is_batch)
create_time, update_time,is_batch,attach_value,avail_amount,lock_amount,is_set)
values (#{id,jdbcType=INTEGER}, #{walletId,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{orderCode,jdbcType=BIGINT}, #{amount,jdbcType=DECIMAL}, #{type,jdbcType=TINYINT},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{isBatch,jdbcType=INTEGER})
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{isBatch,jdbcType=INTEGER}, #{attachValue,jdbcType=VARCHAR},#{availAmount,jdbcType=DECIMAL},#{lockAmount,jdbcType=DECIMAL},#{isSet,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
insert into seller_wallet_detail
... ... @@ -63,6 +67,18 @@
<if test="isBatch != null" >
is_batch,
</if>
<if test="attachValue != null" >
attach_value,
</if>
<if test="availAmount != null" >
avail_amount,
</if>
<if test="lockAmount != null" >
lock_amount,
</if>
<if test="isSet != null" >
is_set,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
... ... @@ -92,6 +108,18 @@
<if test="isBatch != null" >
#{isBatch,jdbcType=INTEGER},
</if>
<if test="attachValue != null" >
#{attachValue,jdbcType=VARCHAR},
</if>
<if test="availAmount != null" >
#{availAmount,jdbcType=DECIMAL},
</if>
<if test="lockAmount != null" >
#{lockAmount,jdbcType=DECIMAL},
</if>
<if test="isSet != null" >
#{isSet,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" >
... ... @@ -118,6 +146,21 @@
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
<if test="isBatch != null" >
is_batch = #{isBatch,jdbcType=INTEGER},
</if>
<if test="attachValue != null" >
attach_value = #{attachValue,jdbcType=VARCHAR},
</if>
<if test="availAmount != null" >
avail_amount = #{availAmount,jdbcType=DECIMAL},
</if>
<if test="lockAmount != null" >
lock_amount = #{lockAmount,jdbcType=DECIMAL},
</if>
<if test="isSet != null" >
is_set = #{isSet,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -129,7 +172,27 @@
amount = #{amount,jdbcType=DECIMAL},
type = #{type,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
update_time = #{updateTime,jdbcType=INTEGER},
is_batch = #{isBatch,jdbcType=INTEGER},
attach_value = #{attachValue,jdbcType=VARCHAR},
avail_amount = #{availAmount,jdbcType=DECIMAL},
lock_amount = #{lockAmount,jdbcType=DECIMAL},
is_set = #{isSet,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectUserDetailCount" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
count(*)
from seller_wallet_detail
where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61)
</select>
<select id="selectUserDetail" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from seller_wallet_detail
where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61) order by id desc limit #{start},#{count}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -5,13 +5,14 @@
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="lock_amount" property="lockAmount" jdbcType="DECIMAL" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, amount, status, type, create_time, update_time
id, uid, amount,lock_amount, status, type, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -32,10 +33,10 @@
</select>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
insert into seller_wallet (id, uid, amount,
insert into seller_wallet (id, uid, amount, lock_amount,
status, type, create_time,
update_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL},
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, #{lockAmount,jdbcType=DECIMAL},
#{status,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER})
</insert>
... ... @@ -51,6 +52,9 @@
<if test="amount != null" >
amount,
</if>
<if test="lockAmount != null" >
lock_amount,
</if>
<if test="status != null" >
status,
</if>
... ... @@ -74,6 +78,9 @@
<if test="amount != null" >
#{amount,jdbcType=DECIMAL},
</if>
<if test="lockAmount != null" >
#{lockAmount,jdbcType=DECIMAL},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
... ... @@ -97,6 +104,9 @@
<if test="amount != null" >
amount = #{amount,jdbcType=DECIMAL},
</if>
<if test="lockAmount != null" >
lock_amount = #{lockAmount,jdbcType=DECIMAL},
</if>
<if test="status != null" >
status = #{status,jdbcType=INTEGER},
</if>
... ... @@ -116,6 +126,7 @@
update seller_wallet
set uid = #{uid,jdbcType=INTEGER},
amount = #{amount,jdbcType=DECIMAL},
lock_amount = #{lockAmount,jdbcType=DECIMAL},
status = #{status,jdbcType=INTEGER},
type = #{type,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
... ... @@ -130,7 +141,22 @@
</select>
<update id="addMoney" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
update seller_wallet set amount = amount + #{amount,jdbcType=DECIMAL},update_time = #{updateTime,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} and amount + #{amount,jdbcType=DECIMAL} &gt;= 0 and status=1
update seller_wallet set
<if test="amount != null" >
amount = amount + #{amount,jdbcType=DECIMAL},
</if>
<if test="lockAmount != null" >
lock_amount = lock_amount + #{lockAmount,jdbcType=DECIMAL},
</if>
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
<if test="amount != null" >
and amount + #{amount,jdbcType=DECIMAL} &gt;= 0
</if>
<if test="lockAmount != null" >
lock_amount = lock_amount + #{lockAmount,jdbcType=DECIMAL} &gt;= 0
</if>
and status=1
</update>
<update id="returnMoney" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
... ...
... ... @@ -9,6 +9,8 @@
<result column="storage_num" jdbcType="INTEGER" property="storageNum" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="suggest_low_price" jdbcType="DECIMAL" property="suggestLowPrice" />
<result column="suggest_high_price" jdbcType="DECIMAL" property="suggestHighPrice" />
</resultMap>
... ... @@ -45,7 +47,7 @@
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price
from storage
where id = #{id,jdbcType=INTEGER}
</select>
... ...
package com.yohoufo.order.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.MerchantOrderPaymentService;
@RestController
public class MerchantController {
private final Logger LOG = LoggerFactory.getLogger(MerchantController.class);
@Autowired
MerchantOrderPaymentService service;
@RequestMapping(params = "method=ufo.merchant.account")
@ResponseBody
public ApiResponse getAccountInfo(@RequestParam("uid") int uid) {
LOG.info("getAccountInfo uid={}", uid);
return service.getMerchantWalletInfo(uid);
}
@RequestMapping(params = "method=ufo.merchant.accountDetail")
@ResponseBody
public ApiResponse getAccountDetailInfo(@RequestParam("uid") int uid,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
LOG.info("getAccountDetailInfo uid={}, page={}, limit={}", uid, page, limit);
return service.getMerchantWalletDetailInfo(uid, page, limit);
}
}
... ...
package com.yohoufo.order.model;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import lombok.Data;
import lombok.ToString;
... ... @@ -31,5 +33,5 @@ public class PayRefundBo {
private int uid;
private SellerWalletDetail.Type refundType;
}
... ...
package com.yohoufo.order.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
import java.math.BigDecimal;
import java.util.List;
/**
* Created by chao.chen on 2018/11/21.
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChangePricePrepareDTO {
BigDecimal salePrice;
List<Integer> skupList;
}
... ...
package com.yohoufo.order.service;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
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;
... ... @@ -9,26 +21,26 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.utils.TimeUtils;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
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.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 {
... ... @@ -102,6 +114,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
sw = new SellerWallet();
sw.setUid(orderInfo.getUid());
sw.setAmount(orderInfo.getAmount());
sw.setLockAmount(BigDecimal.ZERO);
sw.setStatus(1);
sw.setType(1);
sw.setCreateTime(TimeUtils.getTimeStampSecond());
... ... @@ -141,8 +154,12 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
swd.setWalletId(sw.getId());
swd.setAmount(orderInfo.getAmount());
swd.setIsBatch(0);
swd.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
swd.setCreateTime(TimeUtils.getTimeStampSecond());
swd.setUpdateTime(0);
JSONObject att = new JSONObject();
att.put("payment", orderInfo.getPayment());
swd.setAttachValue(att.toJSONString());
logger.info("充值后,处理增加钱包明细,bean={}", swd);
sellerWalletDetailMapper.insert(swd);
logger.info("充值后,处理增加钱包明细成功,orderCode={}", orderInfo.getOrderCode());
... ... @@ -293,25 +310,86 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
return buildOrderInfo(buyerOrder);
}
public com.yohoufo.common.ApiResponse getMerchantWalletInfo(Integer uid) {
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw == null) {
return new com.yohoufo.common.ApiResponse(400, "钱包不存在", null);
}
if (sw.getStatus() == null || sw.getStatus() == 0) {
return new com.yohoufo.common.ApiResponse(400, "钱包不可用", null);
}
JSONObject result = new JSONObject();
result.put("all", sw.getAmount().add(sw.getLockAmount()));
result.put("used", sw.getLockAmount());
result.put("avail", sw.getAmount());
return new com.yohoufo.common.ApiResponse(200, "查询成功", result);
}
public com.yohoufo.common.ApiResponse getMerchantWalletDetailInfo(Integer uid, int page, int limit) {
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw == null) {
return new com.yohoufo.common.ApiResponse(400, "钱包不存在", null);
}
if (sw.getStatus() == null || sw.getStatus() == 0) {
return new com.yohoufo.common.ApiResponse(400, "钱包不可用", null);
}
int count = sellerWalletDetailMapper.selectUserDetailCount(uid);
PageResp<JSONObject> pageResp = new PageResp<>();
pageResp.setPage(page);
pageResp.setPageSize(limit);
pageResp.setTotal(count);
pageResp.setPagetotal((int) Math.ceil(count * 1.0 / limit));
if (count == 0) {
pageResp.setData(new ArrayList<>());
return new com.yohoufo.common.ApiResponse(200, "查询成功", pageResp);
} else {
List<SellerWalletDetail> resultList = sellerWalletDetailMapper.selectUserDetailCount(uid,
(page - 1) * limit, count);
List<JSONObject> array = new ArrayList<>();
pageResp.setData(array);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
for (SellerWalletDetail detail : resultList) {
JSONObject result = new JSONObject();
result.put("amount", detail.getAmount());
result.put("type", sw.getType());
result.put("info", SellerWalletDetail.Type.of(sw.getType()).getName());
result.put("time", sdf.format(new Date(1000L * detail.getCreateTime())));
array.add(result);
}
return new com.yohoufo.common.ApiResponse(200, "查询成功", pageResp);
}
}
// 支付保证金:总账修改
public SellerWallet useEarnest(Integer uid, BigDecimal money) {
return changeEarnest(uid, money, "支付保证金", 2);
public SellerWallet useEarnest(Integer uid, BigDecimal money, String attach) {
return changeEarnest(uid, money, 0L, attach, SellerWalletDetail.Type.PUBLISH);
}
// 修改价格保证金差价:总账修改
public SellerWallet changePriceUseEarnest(Integer uid, BigDecimal money) {
return changeEarnest(uid, money, "支付保证金(修改价格)", 4);
public SellerWallet changePriceUseEarnest(Integer uid, BigDecimal money, String attach) {
if(money.compareTo(BigDecimal.ZERO) > 0) {
return changeEarnest(uid, money, 0L, attach, SellerWalletDetail.Type.ADD_PRICE);
} else {
return changeEarnest(uid, money, 0L, attach, SellerWalletDetail.Type.SUBTRACT_PRICE);
}
}
// 退还保证金:总账修改
public SellerWallet refundEarnest(Integer uid, BigDecimal money) {
return changeEarnest(uid, money, "退还保证金", 3);
// 卖家下架、系统下架、鉴定通过、买家取消
public SellerWallet refundEarnest(Integer uid, BigDecimal money, String attach, long orderCode, SellerWalletDetail.Type type) {
return changeEarnest(uid, money, orderCode, attach, type);
}
// 处罚保证金:总账修改
// 卖家取消、鉴定失败
public SellerWallet punishEarnest(Integer uid, BigDecimal money, String attach, SellerWalletDetail.Type type) {
return changeEarnest(uid, money, 0L, attach, type);
}
// 支付保证金:明细记录+orders_pay记录
public void useEarnestAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
for(OrderInfo oi : orderList) {
SellerWalletDetail swd = addUseEarnestDetail(sw, oi.getOrderCode(), oi.getAmount(), 1);
SellerWalletDetail swd = addWalletDetail(sw, oi.getOrderCode(), oi.getAmount(), 1, SellerWalletDetail.Type.PUBLISH);
addOrdersPay(swd);
}
}
... ... @@ -319,15 +397,21 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
// 修改价格:明细记录+orders_pay金额修改
public void changePriceAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
for(OrderInfo oi : orderList) {
SellerWalletDetail swd = addChangePriceWalletDetail(sw, oi.getOrderCode(), oi.getAmount(), 1);
SellerWalletDetail.Type t;
if (orderList.get(0).getAmount().compareTo(BigDecimal.ZERO) > 0) {
t = SellerWalletDetail.Type.ADD_PRICE;
} else {
t = SellerWalletDetail.Type.SUBTRACT_PRICE;
}
SellerWalletDetail swd = addWalletDetail(sw, oi.getOrderCode(), oi.getAmount(), 1, t);
changePriceUpdateOrdersPay(swd);
}
}
// 下架商品:明细记录+退款表记录
public void unshelveAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList) {
// 下架商品(卖家+系统):明细记录+退款表记录
public void unshelveAddWalletDetail(SellerWallet sw, List<OrderInfo> orderList, SellerWalletDetail.Type type) {
for(OrderInfo oi : orderList) {
SellerWalletDetail swd = refundEarnestDetail(sw, oi.getOrderCode(), oi.getAmount(), 1);
SellerWalletDetail swd = addWalletDetail(sw, oi.getOrderCode(), oi.getAmount(), 1, type);
addRefundRecord(swd, oi.getAmount());
}
}
... ... @@ -345,23 +429,6 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
return paymentService.transAllEarnest(orderCode, uid, money, alipayAccount);
}
// 退还保证金
public SellerWalletDetail refundEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount, Integer isBatch) {
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(orderCode);
swd.setType(3); // 单笔退还
swd.setUid(sw.getUid());
swd.setWalletId(sw.getId());
swd.setAmount(amount);
swd.setIsBatch(isBatch);
swd.setCreateTime(TimeUtils.getTimeStampSecond());
swd.setUpdateTime(0);
logger.info("退还保证金,钱包明细记录,bean={}", swd);
sellerWalletDetailMapper.insert(swd);
logger.info("退还保证金,钱包明细记录成功,bean={}", swd);
return swd;
}
// 退出入驻:归还所有保证金 总账+明细
private BigDecimal returnEarnest(Integer uid, long orderCode) {
logger.info("商家退出,退还保证金,钱包归零处理开始,uid={},orderCode={}", uid, orderCode);
... ... @@ -391,7 +458,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
// 增加充值记录
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(orderCode);
swd.setType(5);// 退还所有保证金
swd.setType(SellerWalletDetail.Type.MERCHANT_EXIT.getValue());// 退还所有保证金
swd.setUid(uid);
swd.setWalletId(sw.getId());
swd.setAmount(amount);
... ... @@ -404,47 +471,30 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
return amount;
}
// 支付保证金:明细
private SellerWalletDetail addUseEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount, Integer isBatch) {
Integer uid = sw.getUid();
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(orderCode);
swd.setType(2);
swd.setUid(uid);
swd.setWalletId(sw.getId());
swd.setAmount(amount);
swd.setIsBatch(isBatch);
swd.setCreateTime(TimeUtils.getTimeStampSecond());
swd.setUpdateTime(0);
logger.info("支付保证金,钱包明细记录,bean={}", swd);
sellerWalletDetailMapper.insert(swd);
logger.info("支付保证金,钱包明细记录成功,bean={}", swd);
return swd;
}
// 修改价格支付保证金:明细
private SellerWalletDetail addChangePriceWalletDetail(SellerWallet sw, long orderCode, BigDecimal amount, Integer isBatch) {
// 增加:明细
private SellerWalletDetail addWalletDetail(SellerWallet sw, long orderCode, BigDecimal amount, Integer isBatch, SellerWalletDetail.Type type) {
Integer uid = sw.getUid();
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(orderCode);
swd.setType(4);
swd.setType(type.getValue());
swd.setUid(uid);
swd.setWalletId(sw.getId());
swd.setAmount(amount);
swd.setIsBatch(isBatch);
swd.setCreateTime(TimeUtils.getTimeStampSecond());
swd.setUpdateTime(0);
logger.info("修改价格支付保证金,钱包明细记录,bean={}", swd);
logger.info("增加保证金明细({}),bean={}", type.getName(), swd);
sellerWalletDetailMapper.insert(swd);
logger.info("修改价格支付保证金,钱包明细记录成功,bean={}", swd);
logger.info("增加保证金明细({}),bean={}", type.getName(), swd);
return swd;
}
private SellerWallet changeEarnest(Integer uid, BigDecimal money, String message, int type) {
logger.info("{}修改钱包表入口,uid={},money={}", message, uid, money);
private SellerWallet changeEarnest(Integer uid, BigDecimal money, long orderCode, String attach, SellerWalletDetail.Type type) {
logger.info("{}修改钱包表入口,uid={},money={}", type.getName(), uid, money);
String message = type.getName();
// 使用钱包余额,支付保证金
SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
if (sw == null) {
logger.error(message + "失败,钱包不存在,uid={}", uid);
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不存在uid=" + uid+", 金额为:"+money);
... ... @@ -455,15 +505,34 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包不可用uid=" + uid+", 金额为:"+money);
return null;
}
if ((type == 2 || type == 4) && sw.getAmount().compareTo(money) < 0) {
if ((type == SellerWalletDetail.Type.PUBLISH || type == SellerWalletDetail.Type.ADD_PRICE) && sw.getAmount().compareTo(money) < 0) {
logger.error(message + "{}失败,钱包余额不足,uid={}", money, uid);
CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePrice", "钱包余额不足uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
return null;
}
if (type == 2 || type == 4) {
sw.setAmount(null);
sw.setLockAmount(null);
// 减去保证金
if (type == SellerWalletDetail.Type.PUBLISH
|| type == SellerWalletDetail.Type.ADD_PRICE
|| type == SellerWalletDetail.Type.SUBTRACT_PRICE) {
sw.setAmount(money.multiply(new BigDecimal("-1")));
} else {
sw.setLockAmount(money);
} else if (type == SellerWalletDetail.Type.SELLER_OFF
|| type == SellerWalletDetail.Type.SYSTEM_OFF
|| type == SellerWalletDetail.Type.APPRAISE_OK
|| type == SellerWalletDetail.Type.BUYER_CANCEL_DELIVERY
|| type == SellerWalletDetail.Type.BUYER_CANCEL_NO_DELIVERY) {
// 增加保证金
sw.setAmount(money);
sw.setLockAmount(money.multiply(new BigDecimal("-1")));
} else if (type == SellerWalletDetail.Type.SELLER_CANCEL
|| type == SellerWalletDetail.Type.SELLER_OVER_TIME
|| type == SellerWalletDetail.Type.APPRAISE_FAIL) {
// 处罚保证金
sw.setLockAmount(money.multiply(new BigDecimal("-1")));
}
sw.setUpdateTime(TimeUtils.getTimeStampSecond());
logger.info("{}修改钱包表余额,bean={}", sw);
... ... @@ -475,12 +544,13 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
logger.info("{}修改钱包表余额成功,bean={}", sw);
SellerWalletDetail swd = new SellerWalletDetail();
swd.setOrderCode(0L);
swd.setType(type);
swd.setOrderCode(orderCode);
swd.setType(type.getValue());
swd.setUid(uid);
swd.setWalletId(sw.getId());
swd.setAmount(money);
swd.setIsBatch(0);
swd.setAttachValue(attach);
swd.setCreateTime(TimeUtils.getTimeStampSecond());
swd.setUpdateTime(0);
logger.info("增加钱包明细汇总记录,bean={}", swd);
... ...
... ... @@ -389,7 +389,7 @@ public class PaymentServiceImpl implements IPaymentService {
PayRefundBo refundBo = payService.refundOpenApi(payRefundBo);
//退款申请成功的记录添加到orders_pay_refund表
if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) {
if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS && Payment.WALLET.getCode()!=orderInfo.getPayment()) {
recordPayRefund(refundBo);
}
... ... @@ -970,7 +970,7 @@ public class PaymentServiceImpl implements IPaymentService {
PayRefundBo refundBo = payService.refundOpenApi(payRefundBo);
//退款申请成功的记录添加到orders_pay_refund表
if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) {
if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS && Payment.WALLET.getCode()!=orderInfo.getPayment()) {
recordPayRefund(refundBo);
}
return refundBo;
... ...
... ... @@ -78,7 +78,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
SkupStatus.SELF_CANCEL_PAY, SkupStatus.TIMEOUT_CANCEL,
SkupStatus.SELLER_CANCEL_SELL, SkupStatus.YOHO_CANCEL_SELL);
private static final List<Long> SELLER_TYPES = Arrays.asList(OrderCodeType.SELLER_TYPE.getType(),
OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType());
@Override
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest) {
int uid;
... ... @@ -97,14 +98,15 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
OrderDetailInfo orderDetailInfo = orderCacheService.getOrderDetailInfo(uid, orderCode, TabType.SELL);
if (Objects.isNull(orderDetailInfo)){
if(OrderCodeType.SELLER_TYPE.getType() == codeMeta.getType()){
if( SELLER_TYPES.contains(codeMeta.getType())){
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
logger.warn("can not find seller order, req {}", orderRequest);
return null;
}
boolean isEntry = userProxyService.isEntryShop(uid);
boolean isEntry = userProxyService.isEntryShop(uid)
&& OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType() == sellerOrder.getPayment();
SellerType sellerType = isEntry ? SellerType.ENTRY : SellerType.COMMON;
Integer skup = sellerOrder.getSkup();
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
... ...
... ... @@ -3,10 +3,7 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SellerType;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
... ... @@ -24,6 +21,8 @@ import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -59,6 +58,9 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
@Autowired
private UserProxyService userProxyService;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Override
public PageResp<OrderListInfo> getOrderList(OrderListRequest request){
... ... @@ -138,11 +140,12 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
}
OrderListInfo buildOrderListInfo(SellerOrderGoods sellerOrderGoods,
SellerOrder sellerOrder, SellerType sellerType) {
SellerOrder sellerOrder, SellerType st) {
OrderListInfo orderListInfo = new OrderListInfo();
Long orderCode;
orderListInfo.setUid(sellerOrder.getUid());
orderListInfo.setOrderCode(sellerOrder.getOrderCode());
orderListInfo.setOrderCode(orderCode=sellerOrder.getOrderCode());
orderListInfo.setRealPrice(sellerOrderGoods.getGoodsPrice().toPlainString());
SellerOrderStatus sellerOrderStatus = SellerOrderStatus.getSellerOrderStatus(sellerOrder.getStatus());
SkupStatus skupStatus = sellerOrderStatus.getSkupStatus();
... ... @@ -154,9 +157,13 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
// 订单中状态显示
orderListInfo.setStatus(skupStatus.getCode());
orderListInfo.setStatuStr(skupStatus.getDesc());
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
//异常扯淡,兼容老数据,
final SellerType lst = (st == SellerType.ENTRY
&& OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType() == sellerOrder.getPayment()) ?
SellerType.ENTRY : SellerType.COMMON;
// 按钮显示
orderListInfo.setButtons(skupStatus.getListButtons(sellerType));
orderListInfo.setButtons(skupStatus.getListButtons(lst));
// 当订单状态是待付款, 显示leftTime
if (sellerOrderGoods.getStatus() == SkupStatus.CAN_NOT_SELL.getCode()){
... ... @@ -175,6 +182,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
goodsInfo.setStorageId(sellerOrderGoods.getStorageId());
goodsInfo.setBatchNo(sellerOrderGoods.getBatchNo());
goodsInfo.setStorageNum(sellerOrderGoods.getNum());
goodsInfo.setSkupList(sellerOrderGoods.getSkupList());
orderListInfo.setGoodsInfo(goodsInfo);
orderListInfo.setSecendLevelCreateTime(sellerOrder.getCreateTime());
orderListInfo.setCreateTime(DateUtil.formatDate(sellerOrder.getCreateTime(), DateUtil.yyyy_MM_dd_HH_mm_SS));
... ...
... ... @@ -31,6 +31,7 @@ import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
import com.yohoufo.order.event.EventHandlerContainer;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -45,6 +46,7 @@ import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.processor.ChangePricePrepareProcessor;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
... ... @@ -152,11 +154,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}
}*/
BigDecimal prdPrice = null;
try{
... ... @@ -169,6 +171,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
return buildSoldPrdComputeBo(uid, num, prdPrice);
}
private OrderSubmitResp publishSinglePrd(SellerOrderSubmitReq req, SellerOrderContext context) throws GatewayException {
int storageId = context.getStorageId();
int uid = context.getUid();
... ... @@ -242,7 +246,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
BigDecimal mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
SellerWallet sellerWallet = merchantOrderPaymentService.useEarnest(uid, mEarestMoney);
SellerWallet sellerWallet = merchantOrderPaymentService.useEarnest(uid, mEarestMoney, null);
// invoke pay by wallet
boolean paySuccess = Objects.nonNull(sellerWallet);
if (!paySuccess){
... ... @@ -283,11 +287,20 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
/**
* todo
* 总指导思想:先下架商品
* @param req
* @return
*/
public boolean batchCancel(SellerOrderBatchCancelReq req){
//TODO check
//TODO 1 商品下架
//1.1 商品下架成功后
//TODO 2 划账(退还下架成功的skup对应的保证金)
//2.1 划账成功
//TODO 3 修改 seller_order(状态)sell_order_goods(状态)
//TODO 4 划账记录
//1.2 商品下架失败后
return true;
... ... @@ -391,7 +404,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
/**
* 验证是否是入驻商家
*/
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult, num, prdPrice);
if(sellerOrderPrepareProcessor.checkIsEntry(uid)){
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice);
}
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
return computeBo;
}
... ... @@ -457,12 +473,28 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
.actor(orderRequest.getTabType()).build();
}
@Autowired
private ChangePricePrepareProcessor changePricePrepareProcessor;
/**
* todo
* @param req
* @return
*/
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req){
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req) throws GatewayException {
ChangePricePrepareDTO cppDto = changePricePrepareProcessor.checkAndAcquire(req);
//TODO 1 划账
//1.1 划账成功后
//TODO 2 商品变价(同步价格到商品)
//TODO 3 修改 seller_order(保证金)sell_order_goods(价格) order_meta 算费
//TODO 4 划账记录
//1.2 划账失败后
BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(1).failCnt(1)
.tips("变价成功1个,失败1个").build();
... ...
package com.yohoufo.order.service.impl.processor;
import com.google.common.base.Splitter;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.req.BatchChangePriceReq;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Created by chao.chen on 2018/11/21.
*/
@Service
public class ChangePricePrepareProcessor {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
@Autowired
private SellerOrderComputeHandler computeHandler;
public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException {
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[uid]错误");
}
if(!sellerOrderPrepareProcessor.checkIsEntry(uid)){
logger.warn("ChangePrice checkAndAcquire uid is not entry shop , req {}", req);
throw new UfoServiceException(400, "您不是入驻商家");
}
String skupList = req.getSkupList();
if (StringUtils.isBlank(skupList)){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[skupList]为空");
}
//todo 若考虑到并发,需要进行过滤,将不是出售中状态的skup排除掉;
//todo 不做过滤导致后面的数量 扣费检查都可能不对
List<String> skupStrList = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(skupList);
List<Integer> needChangePriceSkupList = skupStrList.parallelStream().map(Integer::valueOf).collect(Collectors.toList());
//check batch no
Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req);
BigDecimal salePrice;
try{
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
logger.warn("ChangePrice checkAndAcquire salePrice illegal , req {}", req);
throw new UfoServiceException(400, "售价格式错误");
}
int sampleSkup = needChangePriceSkupList.get(0);
SellerOrderGoods sampleSog = sellerOrderGoodsMapper.selectByPrimaryKey(sampleSkup);
if (Objects.isNull(sampleSog)){
logger.warn("ChangePrice checkAndAcquire skup not exist , {} req {}", sampleSkup, req);
throw new UfoServiceException(400, "部分商品不存在");
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup);
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
int storageId = sampleSog.getStorageId();
sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true);
// compute every fee from price
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
//todo 这个数量不是准确的
int num = needChangePriceSkupList.size();
//作为入驻商户 检查钱包
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, diffEarnestMoney, num, salePrice);
sellerOrderPrepareProcessor.checkIncome(storageId, computeResult.getIncome());
//检查是否有买家下单
checkExistWaitingBuyerPay(batchNo, req);
return ChangePricePrepareDTO.builder().salePrice(salePrice).skupList(needChangePriceSkupList).build();
}
private BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){
return targetEM.subtract(sourceEM);
}
private Long checkNAcquireBatchNo(String batchNoStr, BatchChangePriceReq req){
Long batchNo = null;
boolean isIllegalBatchNo;
try {
isIllegalBatchNo = (StringUtils.isBlank(batchNoStr) || (batchNo = Long.valueOf(batchNoStr)) <= 0L);
}catch (Exception ex){
isIllegalBatchNo = true;
logger.warn("ChangePrice checkAndAcquire batchNoStr illegal , req {}", req, ex);
}
if (isIllegalBatchNo){
throw new UfoServiceException(400, "参数[batchNoStr]非法");
}
return batchNo;
}
private void checkExistWaitingBuyerPay(long batchNo, BatchChangePriceReq req){
SellerOrderGoods condition = new SellerOrderGoods();
condition.setBatchNo(batchNo);
List<SellerOrderGoods> sellerOrderGoodList = sellerOrderGoodsMapper.selectByBatchNo(condition, Arrays.asList(SkupStatus.CAN_SELL.getCode(), SkupStatus.SELL_OUT.getCode()));
List<Integer> skups = sellerOrderGoodList.parallelStream().map(SellerOrderGoods::getId).collect(Collectors.toList());
logger.info("batch change price checkExistWaitingBuyerPay req {} skups {}", req, skups);
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectBySkups(skups);
List<BuyerOrder> buyerOrderList = null;
if (CollectionUtils.isNotEmpty(buyerOrderGoodsList)){
List<Long> orderCodeList = buyerOrderGoodsList.parallelStream()
.map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
buyerOrderList = buyerOrderMapper.selectByOrderCodes(orderCodeList, Arrays.asList(OrderStatus.WAITING_PAY.getCode()));
}
if (CollectionUtils.isNotEmpty(buyerOrderList)){
logger.warn("ChangePrice checkAndAcquire storageId illegal , req {}", req);
throw new UfoServiceException(400, "部分商品正在等待买家支付");
}
}
}
... ...
... ... @@ -18,7 +18,6 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.utils.AddressHelper;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.response.StorageDataResp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -93,11 +92,11 @@ public class SellerOrderPrepareProcessor {
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}
}*/
BigDecimal salePrice;
try{
... ... @@ -182,9 +181,10 @@ public class SellerOrderPrepareProcessor {
}
public void checkPrice(int storageId, BigDecimal prdPrice, boolean validateMaxPrice) throws GatewayException {
ProductInfo productInfo = productProxyService.getPrdPriceRange(storageId);
BigDecimal minPrice = productInfo.getMinPrice();
BigDecimal maxPrice = productInfo.getMaxPrice();
ProductProxyService.PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPrice, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
BigDecimal minPrice = prdPriceRange.getMinPrice();
BigDecimal maxPrice = prdPriceRange.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
throw new GatewayException(501, "您的出价过低");
... ... @@ -194,6 +194,11 @@ public class SellerOrderPrepareProcessor {
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
throw new GatewayException(501, "您的出价过高");
}
BigDecimal suggestMaxPrice = prdPriceRange.getSuggestMaxPrice();
if (Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0){
log.warn("in computePublishPrd,prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
throw new GatewayException(501, "您的出价已超出建议售价,此商品将不会给顾客展示!");
}
}
public void checkIncome(int storageId, BigDecimal income) throws GatewayException {
... ... @@ -203,22 +208,22 @@ public class SellerOrderPrepareProcessor {
}
}
public BigDecimal checkNGetMergeEarnestMoney(int uid, SellerOrderComputeResult computeResult, int num, BigDecimal prdPrice){
boolean isEntryShop = userProxyService.isEntryShop(uid);
BigDecimal mEarestMoney = null;
if(isEntryShop){
BigDecimal singleEarestMoney = computeResult.getEarnestMoney().getEarnestMoney();
mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
boolean isEnough = isEnough(uid, mEarestMoney);
if (!isEnough){
log.warn("in buildSoldPrdComputeBo,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
uid, num, prdPrice, singleEarestMoney);
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
public BigDecimal checkNGetMergeEarnestMoney(int uid, BigDecimal singleEarestMoney, int num, BigDecimal prdPrice){
BigDecimal mEarestMoney;
mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
boolean isEnough = isEnough(uid, mEarestMoney);
if (!isEnough){
log.warn("in checkNGetMergeEarnestMoney,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
uid, num, prdPrice, singleEarestMoney);
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
return mEarestMoney;
}
public boolean checkIsEntry(int uid){
return userProxyService.isEntryShop(uid);
}
/**
*
* @param uid
... ...
... ... @@ -15,6 +15,7 @@ import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.MerchantOrderPaymentService;
import com.yohoufo.order.service.impl.PaymentServiceImpl;
import com.yohoufo.order.service.pay.AbstractPayService;
import org.springframework.stereotype.Service;
... ... @@ -24,7 +25,7 @@ public class WalletPayService extends AbstractPayService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
IPaymentService paymentService;
PaymentServiceImpl paymentService;
@Autowired
MerchantOrderPaymentService merchantOrderPaymentService;
... ... @@ -45,16 +46,25 @@ public class WalletPayService extends AbstractPayService {
public PayRefundBo refundOpenApi(PayRefundBo refundBo) {
try {
refundBo.setSerialNo("");
paymentService.recordPayRefund(refundBo);
} catch (Exception e) {
logger.info("钱包退款失败msg=" + e.getMessage() + ",refundBo=" + refundBo, e);
refundBo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS);
refundBo.setRefundMsg("退款已完成");
return refundBo;
}
try {
BigDecimal amount = new BigDecimal(Double.toString(refundBo.getAmount()));
SellerWallet sw = merchantOrderPaymentService.refundEarnest(refundBo.getUid(), amount);
SellerWallet sw = merchantOrderPaymentService.refundEarnest(refundBo.getUid(), amount, "", refundBo.getPayOrderCode(), refundBo.getRefundType());
if (sw == null) {
refundBo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_REQERR);
refundBo.setRefundMsg("钱包退款请求失败");
return refundBo;
} else {
refundBo.setRefundStatus(RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS);
refundBo.setRefundMsg("退款成功");
}
SellerWalletDetail swd = merchantOrderPaymentService.refundEarnestDetail(sw, refundBo.getPayOrderCode(), amount, 0);
refundBo.setSerialNo(Integer.toString(swd.getId()));
refundBo.setRefundOrderCode(Integer.toString(sw.getId()));
return refundBo;
} catch (Exception e) {
logger.error("钱包退款失败msg=" + e.getMessage() + ",refundBo=" + refundBo, e);
... ...
... ... @@ -9,6 +9,7 @@ import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.StorageDataResp;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -61,8 +62,15 @@ public class ProductProxyService {
return (resp == null || resp.getData()==null) ? false : (boolean)resp.getData();
}
@Data
public static class PrdPrice{
private BigDecimal maxPrice;
private BigDecimal minPrice;
private BigDecimal suggestMaxPrice;
private BigDecimal suggestMinPrice;
}
public ProductInfo getPrdPriceRange(int storageId) throws GatewayException {
public PrdPrice getPrdPriceRange(int storageId) throws GatewayException {
StorageDataResp storage = getStorageData(storageId);
Integer productId=null;
if (Objects.isNull(storage) || Objects.isNull(productId=storage.getProductId()) || productId == 0){
... ... @@ -73,18 +81,23 @@ public class ProductProxyService {
ProductDetailResp resp = ufoServiceCaller.call("ufo.product.baseInfo", productId);
ProductInfo productInfo = null;
BigDecimal leastPrice;
BigDecimal leastPrice,maxPrice;
if (Objects.isNull(resp)
|| Objects.isNull(productInfo = resp.getProduct_info())
|| Objects.isNull(leastPrice = productInfo.getMinPrice())
|| Objects.isNull(productInfo.getMaxPrice())
|| Objects.isNull(maxPrice=productInfo.getMaxPrice())
|| leastPrice.doubleValue() < 0D
|| productInfo.getMaxPrice().doubleValue() == 0D){
logger.warn("in getPrdPriceRange wrong,storageId {}, productId {}, productInfo {}",
storageId, productId, productInfo);
throw new GatewayException(501, "无法比对商品价格限制");
}
return productInfo;
PrdPrice prdPrice = new PrdPrice();
prdPrice.minPrice = leastPrice;
prdPrice.maxPrice = maxPrice;
prdPrice.suggestMaxPrice = storage.getSuggestHighPrice();
prdPrice.suggestMinPrice = storage.getSuggestLowPrice();
return prdPrice;
}
... ...
package com.yohoufo.product.response;
import java.math.BigDecimal;
import com.alibaba.fastjson.annotation.JSONField;
import com.yohoufo.product.model.GoodsSize;
import lombok.Data;
... ... @@ -28,4 +31,10 @@ public class StorageDataResp {
@JSONField(name = "status")
private Integer status;
@JSONField(name = "suggest_low_price")
private BigDecimal suggestLowPrice;
@JSONField(name = "suggest_high_price")
private BigDecimal suggestHighPrice;
}
... ...
... ... @@ -162,6 +162,9 @@ public class ProductServiceImpl implements ProductService{
resp.setStatus(product.getShelveStatus());
}
}
resp.setSuggestLowPrice(storage.getSuggestLowPrice());
resp.setSuggestHighPrice(storage.getSuggestHighPrice());
return resp;
}
... ...