Showing
1 changed file
with
103 additions
and
114 deletions
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 | -import java.util.Map; | ||
10 | -import java.util.Objects; | ||
11 | - | ||
12 | -import com.yohoufo.common.alarm.EventBusPublisher; | ||
13 | -import com.yohoufo.order.common.EnterQuitEnum; | ||
14 | -import com.yohoufo.order.event.InviteRecordEvent; | ||
15 | -import com.yohoufo.order.service.impl.TradeBillsService; | ||
16 | -import org.apache.commons.lang3.StringUtils; | ||
17 | -import org.slf4j.Logger; | ||
18 | -import org.slf4j.LoggerFactory; | ||
19 | -import org.springframework.beans.factory.annotation.Autowired; | ||
20 | -import org.springframework.stereotype.Service; | ||
21 | - | ||
22 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
23 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
24 | import com.yoho.core.common.utils.DateUtil; | 5 | import com.yoho.core.common.utils.DateUtil; |
@@ -31,31 +12,33 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo; | @@ -31,31 +12,33 @@ import com.yohobuy.ufo.model.order.bo.OrderInfo; | ||
31 | import com.yohobuy.ufo.model.order.common.EntrySellerType; | 12 | import com.yohobuy.ufo.model.order.common.EntrySellerType; |
32 | import com.yohobuy.ufo.model.order.common.OrderCodeType; | 13 | import com.yohobuy.ufo.model.order.common.OrderCodeType; |
33 | import com.yohobuy.ufo.model.order.common.OrderStatus; | 14 | import com.yohobuy.ufo.model.order.common.OrderStatus; |
15 | +import com.yohobuy.ufo.model.order.common.Payment; | ||
34 | import com.yohobuy.ufo.model.order.resp.EntryThreshold; | 16 | import com.yohobuy.ufo.model.order.resp.EntryThreshold; |
35 | import com.yohobuy.ufo.model.order.resp.PageResp; | 17 | import com.yohobuy.ufo.model.order.resp.PageResp; |
36 | import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; | 18 | import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; |
37 | import com.yohoufo.common.alarm.CommonAlarmEventPublisher; | 19 | import com.yohoufo.common.alarm.CommonAlarmEventPublisher; |
20 | +import com.yohoufo.common.alarm.EventBusPublisher; | ||
38 | import com.yohoufo.common.caller.UfoServiceCaller; | 21 | import com.yohoufo.common.caller.UfoServiceCaller; |
39 | import com.yohoufo.common.utils.TimeUtils; | 22 | import com.yohoufo.common.utils.TimeUtils; |
40 | -import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper; | ||
41 | -import com.yohoufo.dal.order.OrdersPayMapper; | ||
42 | -import com.yohoufo.dal.order.OrdersPayRefundMapper; | ||
43 | -import com.yohoufo.dal.order.SellerJoinHistoryMapper; | ||
44 | -import com.yohoufo.dal.order.SellerWalletDetailMapper; | ||
45 | -import com.yohoufo.dal.order.SellerWalletMapper; | ||
46 | -import com.yohoufo.dal.order.model.EntrySellerRechargeOrder; | ||
47 | -import com.yohoufo.dal.order.model.OrdersPay; | ||
48 | -import com.yohoufo.dal.order.model.OrdersPayRefund; | ||
49 | -import com.yohoufo.dal.order.model.SellerJoinHistory; | ||
50 | -import com.yohoufo.dal.order.model.SellerWallet; | ||
51 | -import com.yohoufo.dal.order.model.SellerWalletDetail; | ||
52 | -import com.yohoufo.dal.order.model.StoredSeller; | 23 | +import com.yohoufo.dal.order.*; |
24 | +import com.yohoufo.dal.order.model.*; | ||
53 | import com.yohoufo.dal.user.model.ZhiMaCert; | 25 | import com.yohoufo.dal.user.model.ZhiMaCert; |
54 | -import com.yohobuy.ufo.model.order.common.Payment; | 26 | +import com.yohoufo.order.common.EnterQuitEnum; |
27 | +import com.yohoufo.order.event.InviteRecordEvent; | ||
55 | import com.yohoufo.order.model.request.PaymentRequest; | 28 | import com.yohoufo.order.model.request.PaymentRequest; |
56 | import com.yohoufo.order.model.response.PrepayResponse; | 29 | import com.yohoufo.order.model.response.PrepayResponse; |
57 | import com.yohoufo.order.service.impl.PaymentServiceImpl; | 30 | import com.yohoufo.order.service.impl.PaymentServiceImpl; |
58 | import com.yohoufo.order.service.impl.SellerService; | 31 | import com.yohoufo.order.service.impl.SellerService; |
32 | +import com.yohoufo.order.service.impl.TradeBillsService; | ||
33 | +import org.apache.commons.lang3.StringUtils; | ||
34 | +import org.slf4j.Logger; | ||
35 | +import org.slf4j.LoggerFactory; | ||
36 | +import org.springframework.beans.factory.annotation.Autowired; | ||
37 | +import org.springframework.stereotype.Service; | ||
38 | + | ||
39 | +import java.math.BigDecimal; | ||
40 | +import java.text.SimpleDateFormat; | ||
41 | +import java.util.*; | ||
59 | 42 | ||
60 | @Service | 43 | @Service |
61 | public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | 44 | public class MerchantOrderPaymentService extends AbstractOrderPaymentService { |
@@ -139,6 +122,84 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | @@ -139,6 +122,84 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | ||
139 | return result; | 122 | return result; |
140 | } | 123 | } |
141 | 124 | ||
125 | + private void processFirstTimeCharge(SellerWallet sw, OrderInfo orderInfo){ | ||
126 | + Long orderCode = orderInfo.getOrderCode(); | ||
127 | + BigDecimal amount = orderInfo.getAmount(); | ||
128 | + Integer uid = orderInfo.getUid(); | ||
129 | + | ||
130 | + ZhiMaCert cert = null; | ||
131 | + try { | ||
132 | + ApiResponse<?> resp = ufoServiceCaller.call("ufo.user.zhiMaCertInfo", ApiResponse.class, uid); | ||
133 | + cert = (ZhiMaCert) resp.getData(); | ||
134 | + } catch (Exception e) { | ||
135 | + CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "没有芝麻认证信息:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
136 | + logger.error("重新入驻首次充值保证金={},没有芝麻认证信息,uid={}", amount, uid); | ||
137 | + return; | ||
138 | + } | ||
139 | + if(cert == null || StringUtils.isBlank(cert.getCertNo())) { | ||
140 | + CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "芝麻认证信息有误:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
141 | + logger.error("重新入驻首次充值保证金={},没有芝麻认证信息有误,uid={}", amount, uid); | ||
142 | + return; | ||
143 | + } | ||
144 | + String certNo = cert.getCertNo(); | ||
145 | + | ||
146 | + if (sw != null) { | ||
147 | + logger.info("重新入驻首次充值保证金={},已入驻次数为,uid={}", amount, uid, sw.getJoinTimes()); | ||
148 | + if (sw.getStatus() == null || sw.getStatus() != 0) { | ||
149 | + CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "入驻状态异常:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount); | ||
150 | + logger.error("重新入驻首次充值保证金={},发现入驻状态异常,uid={},times={}", amount, uid, sw.getJoinTimes()); | ||
151 | + return; | ||
152 | + } | ||
153 | + if (!canRejoin(uid, sw, cert)) { | ||
154 | + CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "超过入最大驻次数:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
155 | + logger.error("重新入驻首次充值保证金={},发现已超过最大入驻次数,uid={},times={}", amount, uid, sw.getJoinTimes()); | ||
156 | + return; | ||
157 | + } | ||
158 | + // 更新钱包 | ||
159 | + logger.info("重新入驻首次充值保证金={},更新钱包信息,uid={}", amount, uid); | ||
160 | + int exe = sellerWalletMapper.rejoin(uid, amount, null, TimeUtils.getTimeStampSecond(), sw.getJoinTimes() + 1); | ||
161 | + if (exe == 0) { | ||
162 | + CommonAlarmEventPublisher.publish("重新入驻修改钱包失败", "ufo.order.recharge", "更新钱包不成功:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount+ ",钱包信息为:"+sw); | ||
163 | + logger.info("重新入驻失败,首次充值保证金={},更新钱包信息失败,uid={}, 钱包信息={}", amount, uid, sw); | ||
164 | + return; | ||
165 | + } | ||
166 | + // 数据清理 | ||
167 | + // 钱包明细 | ||
168 | + logger.info("重新入驻orderCode={},清理历史钱包明细数据,uid={}", orderCode, uid); | ||
169 | + int clearCount = sellerWalletDetailMapper.clearUserHistoryData(uid); | ||
170 | + logger.info("重新入驻orderCode={},清理历史钱包明细数据={},uid={}", orderCode, clearCount, uid); | ||
171 | + // 充值信息 | ||
172 | + logger.info("重新入驻orderCode={},清理充值表数据,uid={}", orderCode, uid); | ||
173 | + clearCount = entrySellerRechargeOrderMapper.clearUserHistoryData(uid, orderCode); | ||
174 | + logger.info("重新入驻orderCode={},清理充值表数据={},uid={}", orderCode, clearCount, uid); | ||
175 | + // 入驻信息 | ||
176 | + logger.info("重新入驻orderCode={},清理历史入驻表数据,uid={}", orderCode, uid); | ||
177 | + clearCount = storedSellerService.removeStoredSeller(uid); | ||
178 | + logger.info("重新入驻orderCode={},清理历史入驻表数据={},uid={}", orderCode, clearCount, uid); | ||
179 | + | ||
180 | + } else { | ||
181 | + // 首次充值,创建钱包信息 | ||
182 | + sw = new SellerWallet(); | ||
183 | + sw.setUid(uid); | ||
184 | + sw.setAmount(amount); | ||
185 | + sw.setLockAmount(BigDecimal.ZERO); | ||
186 | + sw.setStatus(1); | ||
187 | + sw.setType(1); | ||
188 | + sw.setCreateTime(TimeUtils.getTimeStampSecond()); | ||
189 | + sw.setUpdateTime(0); | ||
190 | + sw.setJoinTimes(0); | ||
191 | + logger.info("首次充值后回调,处理总账表新增账号,bean={}", sw); | ||
192 | + sellerWalletMapper.insert(sw); | ||
193 | + logger.info("首次充值后回调,处理总账表新增账号成功,bean={}", sw); | ||
194 | + | ||
195 | + // 首次入驻 | ||
196 | + InviteRecordEvent inviteRecordEvent = InviteRecordEvent.builder().uid(uid).orderCode(orderCode).eventType(EnterQuitEnum.ENTER).build(); | ||
197 | + EventBusPublisher.publishEvent(inviteRecordEvent); | ||
198 | + } | ||
199 | + addJoinHistory(uid, certNo); | ||
200 | + | ||
201 | + } | ||
202 | + | ||
142 | @Override | 203 | @Override |
143 | public void processAfterPay(OrderInfo orderInfo) { | 204 | public void processAfterPay(OrderInfo orderInfo) { |
144 | logger.info("充值后回调,处理processAfterPay,orderInfo={}", orderInfo); | 205 | logger.info("充值后回调,处理processAfterPay,orderInfo={}", orderInfo); |
@@ -147,92 +208,20 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | @@ -147,92 +208,20 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | ||
147 | Integer payment = orderInfo.getPayment(); | 208 | Integer payment = orderInfo.getPayment(); |
148 | tradeBillsService.addPayRechargeEnsureRecord(orderInfo.getUid(), orderInfo.getSkup(), orderCode, payment, | 209 | tradeBillsService.addPayRechargeEnsureRecord(orderInfo.getUid(), orderInfo.getSkup(), orderCode, payment, |
149 | orderInfo.getAmount()); | 210 | orderInfo.getAmount()); |
150 | - | ||
151 | - BigDecimal beforeAmount = BigDecimal.ZERO; | ||
152 | - BigDecimal beforeLockAmount = BigDecimal.ZERO; | ||
153 | - | ||
154 | - BigDecimal afterAmount = BigDecimal.ZERO; | ||
155 | - BigDecimal afterLockAmount = BigDecimal.ZERO; | ||
156 | - | ||
157 | - Integer uid = orderInfo.getUid(); | ||
158 | 211 | ||
212 | + BigDecimal beforeAmount = BigDecimal.ZERO; | ||
213 | + BigDecimal beforeLockAmount = BigDecimal.ZERO; | ||
159 | 214 | ||
215 | + BigDecimal afterAmount = BigDecimal.ZERO; | ||
216 | + BigDecimal afterLockAmount = BigDecimal.ZERO; | ||
160 | 217 | ||
218 | + Integer uid = orderInfo.getUid(); | ||
219 | + | ||
161 | SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1); | 220 | SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1); |
162 | logger.info("充值后回调,处理总账表,orderCode={}", orderCode); | 221 | logger.info("充值后回调,处理总账表,orderCode={}", orderCode); |
163 | if (orderInfo.getType() == TYPE_FIRST_RECHARGE) { | 222 | if (orderInfo.getType() == TYPE_FIRST_RECHARGE) { |
164 | - ZhiMaCert cert = null; | ||
165 | - try { | ||
166 | - ApiResponse<?> resp = ufoServiceCaller.call("ufo.user.zhiMaCertInfo", ApiResponse.class, uid); | ||
167 | - cert = (ZhiMaCert) resp.getData(); | ||
168 | - } catch (Exception e) { | ||
169 | - CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "没有芝麻认证信息:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
170 | - logger.error("重新入驻首次充值保证金={},没有芝麻认证信息,uid={}", amount, uid); | ||
171 | - return; | ||
172 | - } | ||
173 | - if(cert == null || StringUtils.isBlank(cert.getCertNo())) { | ||
174 | - CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "芝麻认证信息有误:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
175 | - logger.error("重新入驻首次充值保证金={},没有芝麻认证信息有误,uid={}", amount, uid); | ||
176 | - return; | ||
177 | - } | ||
178 | - String certNo = cert.getCertNo(); | ||
179 | - | ||
180 | - if (sw != null) { | ||
181 | - logger.info("重新入驻首次充值保证金={},已入驻次数为,uid={}", amount, uid, sw.getJoinTimes()); | ||
182 | - if (sw.getStatus() == null || sw.getStatus() != 0) { | ||
183 | - CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "入驻状态异常:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount); | ||
184 | - logger.error("重新入驻首次充值保证金={},发现入驻状态异常,uid={},times={}", amount, uid, sw.getJoinTimes()); | ||
185 | - return; | ||
186 | - } | ||
187 | - if (!canRejoin(uid, sw, cert)) { | ||
188 | - CommonAlarmEventPublisher.publish("重新入驻首次充值保证金失败", "ufo.order.recharge", "超过入最大驻次数:uid=" + uid + ",充值订单号为:" + orderCode+", 充值金额为:"+amount); | ||
189 | - logger.error("重新入驻首次充值保证金={},发现已超过最大入驻次数,uid={},times={}", amount, uid, sw.getJoinTimes()); | ||
190 | - return; | ||
191 | - } | ||
192 | - // 更新钱包 | ||
193 | - logger.info("重新入驻首次充值保证金={},更新钱包信息,uid={}", amount, uid); | ||
194 | - int exe = sellerWalletMapper.rejoin(uid, amount, null, TimeUtils.getTimeStampSecond(), sw.getJoinTimes() + 1); | ||
195 | - if (exe == 0) { | ||
196 | - CommonAlarmEventPublisher.publish("重新入驻修改钱包失败", "ufo.order.recharge", "更新钱包不成功:uid=" + uid + ",充值订单号为:" + orderCode + ", 充值金额为:" + amount+ ",钱包信息为:"+sw); | ||
197 | - logger.info("重新入驻失败,首次充值保证金={},更新钱包信息失败,uid={}, 钱包信息={}", amount, uid, sw); | ||
198 | - return; | ||
199 | - } | ||
200 | - // 数据清理 | ||
201 | - // 钱包明细 | ||
202 | - logger.info("重新入驻orderCode={},清理历史钱包明细数据,uid={}", orderCode, uid); | ||
203 | - int clearCount = sellerWalletDetailMapper.clearUserHistoryData(uid); | ||
204 | - logger.info("重新入驻orderCode={},清理历史钱包明细数据={},uid={}", orderCode, clearCount, uid); | ||
205 | - // 充值信息 | ||
206 | - logger.info("重新入驻orderCode={},清理充值表数据,uid={}", orderCode, uid); | ||
207 | - clearCount = entrySellerRechargeOrderMapper.clearUserHistoryData(uid, orderCode); | ||
208 | - logger.info("重新入驻orderCode={},清理充值表数据={},uid={}", orderCode, clearCount, uid); | ||
209 | - // 入驻信息 | ||
210 | - logger.info("重新入驻orderCode={},清理历史入驻表数据,uid={}", orderCode, uid); | ||
211 | - clearCount = storedSellerService.removeStoredSeller(uid); | ||
212 | - logger.info("重新入驻orderCode={},清理历史入驻表数据={},uid={}", orderCode, clearCount, uid); | ||
213 | - | ||
214 | - } else { | ||
215 | - // 首次充值,创建钱包信息 | ||
216 | - sw = new SellerWallet(); | ||
217 | - sw.setUid(uid); | ||
218 | - sw.setAmount(amount); | ||
219 | - sw.setLockAmount(BigDecimal.ZERO); | ||
220 | - sw.setStatus(1); | ||
221 | - sw.setType(1); | ||
222 | - sw.setCreateTime(TimeUtils.getTimeStampSecond()); | ||
223 | - sw.setUpdateTime(0); | ||
224 | - sw.setJoinTimes(0); | ||
225 | - logger.info("首次充值后回调,处理总账表新增账号,bean={}", sw); | ||
226 | - sellerWalletMapper.insert(sw); | ||
227 | - logger.info("首次充值后回调,处理总账表新增账号成功,bean={}", sw); | ||
228 | - | ||
229 | - // 首次入驻 | ||
230 | - InviteRecordEvent inviteRecordEvent = InviteRecordEvent.builder().uid(uid).orderCode(orderCode).eventType(EnterQuitEnum.ENTER).build(); | ||
231 | - EventBusPublisher.publishEvent(inviteRecordEvent); | ||
232 | - } | ||
233 | - addJoinHistory(uid, certNo); | ||
234 | - afterAmount = amount; | ||
235 | - | 223 | + processFirstTimeCharge(sw, orderInfo); |
224 | + afterAmount = amount; | ||
236 | } else { | 225 | } else { |
237 | // 修改钱包余额 | 226 | // 修改钱包余额 |
238 | if (sw == null) { | 227 | if (sw == null) { |
@@ -1040,7 +1029,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | @@ -1040,7 +1029,7 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { | ||
1040 | newRecord.setStatus((byte) 0); | 1029 | newRecord.setStatus((byte) 0); |
1041 | newRecord.setSerialNo(Integer.toString(swd.getId())); | 1030 | newRecord.setSerialNo(Integer.toString(swd.getId())); |
1042 | newRecord.setOrderType(0); | 1031 | newRecord.setOrderType(0); |
1043 | - int timeStamp = (int) (new Date().getTime() / 1000); | 1032 | + int timeStamp = DateUtil.currentTimeSeconds(); |
1044 | newRecord.setCreateTime(timeStamp); | 1033 | newRecord.setCreateTime(timeStamp); |
1045 | newRecord.setUpdateTime(timeStamp); | 1034 | newRecord.setUpdateTime(timeStamp); |
1046 | logger.info("商品下架,添加退款记录,bean={}", newRecord); | 1035 | logger.info("商品下架,添加退款记录,bean={}", newRecord); |
-
Please register or login to post a comment