Authored by Lixiaodi

修改记账分总账分账

1 package com.yohoufo.dal.order; 1 package com.yohoufo.dal.order;
2 2
  3 +import java.util.List;
  4 +
  5 +import org.apache.ibatis.annotations.Param;
  6 +
3 import com.yohoufo.dal.order.model.SellerWalletDetail; 7 import com.yohoufo.dal.order.model.SellerWalletDetail;
4 8
5 public interface SellerWalletDetailMapper { 9 public interface SellerWalletDetailMapper {
@@ -14,4 +18,8 @@ public interface SellerWalletDetailMapper { @@ -14,4 +18,8 @@ public interface SellerWalletDetailMapper {
14 int updateByPrimaryKeySelective(SellerWalletDetail record); 18 int updateByPrimaryKeySelective(SellerWalletDetail record);
15 19
16 int updateByPrimaryKey(SellerWalletDetail record); 20 int updateByPrimaryKey(SellerWalletDetail record);
  21 +
  22 + int selectUserDetailCount(@Param("uid") Integer uid);
  23 +
  24 + List<SellerWalletDetail> selectUserDetailCount(@Param("uid") Integer uid, @Param("start") Integer start, @Param("count") Integer count);
17 } 25 }
@@ -65,6 +65,15 @@ public class SellerWalletDetail { @@ -65,6 +65,15 @@ public class SellerWalletDetail {
65 public int getValue() { 65 public int getValue() {
66 return value; 66 return value;
67 } 67 }
  68 +
  69 + public static Type of(int value) {
  70 + for (Type t : values()) {
  71 + if (t.value == value) {
  72 + return t;
  73 + }
  74 + }
  75 + return null;
  76 + }
68 } 77 }
69 78
70 } 79 }
@@ -180,4 +180,19 @@ @@ -180,4 +180,19 @@
180 is_set = #{isSet,jdbcType=INTEGER} 180 is_set = #{isSet,jdbcType=INTEGER}
181 where id = #{id,jdbcType=INTEGER} 181 where id = #{id,jdbcType=INTEGER}
182 </update> 182 </update>
  183 +
  184 + <select id="selectUserDetailCount" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  185 + select
  186 + count(*)
  187 + from seller_wallet_detail
  188 + where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61)
  189 + </select>
  190 + <select id="selectUserDetail" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  191 + select
  192 + <include refid="Base_Column_List" />
  193 + from seller_wallet_detail
  194 + where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61) order by id desc limit #{start},#{count}
  195 + </select>
  196 +
  197 +
183 </mapper> 198 </mapper>
  1 +package com.yohoufo.order.controller;
  2 +
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.RequestMapping;
  7 +import org.springframework.web.bind.annotation.RequestParam;
  8 +import org.springframework.web.bind.annotation.ResponseBody;
  9 +import org.springframework.web.bind.annotation.RestController;
  10 +
  11 +import com.yohoufo.common.ApiResponse;
  12 +import com.yohoufo.order.service.MerchantOrderPaymentService;
  13 +
  14 +@RestController
  15 +public class MerchantController {
  16 +
  17 + private final Logger LOG = LoggerFactory.getLogger(MerchantController.class);
  18 +
  19 + @Autowired
  20 + MerchantOrderPaymentService service;
  21 +
  22 + @RequestMapping(params = "method=ufo.merchant.account")
  23 + @ResponseBody
  24 + public ApiResponse getAccountInfo(@RequestParam("uid") int uid) {
  25 + LOG.info("getAccountInfo uid={}", uid);
  26 + return service.getMerchantWalletInfo(uid);
  27 + }
  28 +
  29 + @RequestMapping(params = "method=ufo.merchant.accountDetail")
  30 + @ResponseBody
  31 + public ApiResponse getAccountDetailInfo(@RequestParam("uid") int uid,
  32 + @RequestParam(value = "page", required = false, defaultValue = "1") int page,
  33 + @RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
  34 + LOG.info("getAccountDetailInfo uid={}, page={}, limit={}", uid, page, limit);
  35 + return service.getMerchantWalletDetailInfo(uid, page, limit);
  36 + }
  37 +
  38 +}
1 package com.yohoufo.order.service; 1 package com.yohoufo.order.service;
2 2
  3 +import java.math.BigDecimal;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.ArrayList;
  6 +import java.util.Arrays;
  7 +import java.util.Date;
  8 +import java.util.List;
  9 +
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Service;
  14 +
3 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.core.common.utils.DateUtil; 16 import com.yoho.core.common.utils.DateUtil;
5 import com.yoho.error.ServiceError; 17 import com.yoho.error.ServiceError;
@@ -9,26 +21,26 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo; @@ -9,26 +21,26 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo;
9 import com.yohobuy.ufo.model.order.common.OrderCodeType; 21 import com.yohobuy.ufo.model.order.common.OrderCodeType;
10 import com.yohobuy.ufo.model.order.common.OrderStatus; 22 import com.yohobuy.ufo.model.order.common.OrderStatus;
11 import com.yohobuy.ufo.model.order.common.TabType; 23 import com.yohobuy.ufo.model.order.common.TabType;
  24 +import com.yohobuy.ufo.model.order.resp.PageResp;
12 import com.yohoufo.common.alarm.CommonAlarmEventPublisher; 25 import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
13 import com.yohoufo.common.caller.UfoServiceCaller; 26 import com.yohoufo.common.caller.UfoServiceCaller;
14 import com.yohoufo.common.utils.TimeUtils; 27 import com.yohoufo.common.utils.TimeUtils;
15 -import com.yohoufo.dal.order.*;  
16 -import com.yohoufo.dal.order.model.*; 28 +import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
  29 +import com.yohoufo.dal.order.OrdersPayMapper;
  30 +import com.yohoufo.dal.order.OrdersPayRefundMapper;
  31 +import com.yohoufo.dal.order.SellerWalletDetailMapper;
  32 +import com.yohoufo.dal.order.SellerWalletMapper;
  33 +import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
  34 +import com.yohoufo.dal.order.model.OrdersPay;
  35 +import com.yohoufo.dal.order.model.OrdersPayRefund;
  36 +import com.yohoufo.dal.order.model.SellerWallet;
  37 +import com.yohoufo.dal.order.model.SellerWalletDetail;
17 import com.yohoufo.order.common.Payment; 38 import com.yohoufo.order.common.Payment;
18 import com.yohoufo.order.model.request.PaymentRequest; 39 import com.yohoufo.order.model.request.PaymentRequest;
19 import com.yohoufo.order.model.response.PrepayResponse; 40 import com.yohoufo.order.model.response.PrepayResponse;
20 import com.yohoufo.order.service.cache.CacheCleaner; 41 import com.yohoufo.order.service.cache.CacheCleaner;
21 import com.yohoufo.order.service.cache.CacheKeyBuilder; 42 import com.yohoufo.order.service.cache.CacheKeyBuilder;
22 import com.yohoufo.order.service.impl.PaymentServiceImpl; 43 import com.yohoufo.order.service.impl.PaymentServiceImpl;
23 -import org.slf4j.Logger;  
24 -import org.slf4j.LoggerFactory;  
25 -import org.springframework.beans.factory.annotation.Autowired;  
26 -import org.springframework.stereotype.Service;  
27 -  
28 -import java.math.BigDecimal;  
29 -import java.util.Arrays;  
30 -import java.util.Date;  
31 -import java.util.List;  
32 44
33 @Service 45 @Service
34 public class MerchantOrderPaymentService extends AbstractOrderPaymentService { 46 public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
@@ -145,6 +157,9 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { @@ -145,6 +157,9 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
145 swd.setType(SellerWalletDetail.Type.RE_CHARGE.getValue()); 157 swd.setType(SellerWalletDetail.Type.RE_CHARGE.getValue());
146 swd.setCreateTime(TimeUtils.getTimeStampSecond()); 158 swd.setCreateTime(TimeUtils.getTimeStampSecond());
147 swd.setUpdateTime(0); 159 swd.setUpdateTime(0);
  160 + JSONObject att = new JSONObject();
  161 + att.put("payment", orderInfo.getPayment());
  162 + swd.setAttachValue(att.toJSONString());
148 logger.info("充值后,处理增加钱包明细,bean={}", swd); 163 logger.info("充值后,处理增加钱包明细,bean={}", swd);
149 sellerWalletDetailMapper.insert(swd); 164 sellerWalletDetailMapper.insert(swd);
150 logger.info("充值后,处理增加钱包明细成功,orderCode={}", orderInfo.getOrderCode()); 165 logger.info("充值后,处理增加钱包明细成功,orderCode={}", orderInfo.getOrderCode());
@@ -295,6 +310,56 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { @@ -295,6 +310,56 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
295 return buildOrderInfo(buyerOrder); 310 return buildOrderInfo(buyerOrder);
296 } 311 }
297 312
  313 + public com.yohoufo.common.ApiResponse getMerchantWalletInfo(Integer uid) {
  314 + SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
  315 + if (sw == null) {
  316 + return new com.yohoufo.common.ApiResponse(400, "钱包不存在", null);
  317 + }
  318 + if (sw.getStatus() == null || sw.getStatus() == 0) {
  319 + return new com.yohoufo.common.ApiResponse(400, "钱包不可用", null);
  320 + }
  321 + JSONObject result = new JSONObject();
  322 + result.put("all", sw.getAmount().add(sw.getLockAmount()));
  323 + result.put("used", sw.getLockAmount());
  324 + result.put("avail", sw.getAmount());
  325 + return new com.yohoufo.common.ApiResponse(200, "查询成功", result);
  326 + }
  327 +
  328 + public com.yohoufo.common.ApiResponse getMerchantWalletDetailInfo(Integer uid, int page, int limit) {
  329 + SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
  330 + if (sw == null) {
  331 + return new com.yohoufo.common.ApiResponse(400, "钱包不存在", null);
  332 + }
  333 + if (sw.getStatus() == null || sw.getStatus() == 0) {
  334 + return new com.yohoufo.common.ApiResponse(400, "钱包不可用", null);
  335 + }
  336 + int count = sellerWalletDetailMapper.selectUserDetailCount(uid);
  337 + PageResp<JSONObject> pageResp = new PageResp<>();
  338 + pageResp.setPage(page);
  339 + pageResp.setPageSize(limit);
  340 + pageResp.setTotal(count);
  341 + pageResp.setPagetotal((int) Math.ceil(count * 1.0 / limit));
  342 + if (count == 0) {
  343 + pageResp.setData(new ArrayList<>());
  344 + return new com.yohoufo.common.ApiResponse(200, "查询成功", pageResp);
  345 + } else {
  346 + List<SellerWalletDetail> resultList = sellerWalletDetailMapper.selectUserDetailCount(uid,
  347 + (page - 1) * limit, count);
  348 + List<JSONObject> array = new ArrayList<>();
  349 + pageResp.setData(array);
  350 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
  351 + for (SellerWalletDetail detail : resultList) {
  352 + JSONObject result = new JSONObject();
  353 + result.put("amount", detail.getAmount());
  354 + result.put("type", sw.getType());
  355 + result.put("info", SellerWalletDetail.Type.of(sw.getType()).getName());
  356 + result.put("time", sdf.format(new Date(1000L * detail.getCreateTime())));
  357 + array.add(result);
  358 + }
  359 + return new com.yohoufo.common.ApiResponse(200, "查询成功", pageResp);
  360 + }
  361 + }
  362 +
298 // 支付保证金:总账修改 363 // 支付保证金:总账修改
299 public SellerWallet useEarnest(Integer uid, BigDecimal money, String attach) { 364 public SellerWallet useEarnest(Integer uid, BigDecimal money, String attach) {
300 return changeEarnest(uid, money, 0L, attach, SellerWalletDetail.Type.PUBLISH); 365 return changeEarnest(uid, money, 0L, attach, SellerWalletDetail.Type.PUBLISH);