|
|
@@ -39,7 +39,11 @@ import com.ruoyi.web.modules.merchant.dto.MerchantCreateDTO;
|
|
39
|
39
|
import com.ruoyi.web.modules.merchant.mapper.BizMerchantMapper;
|
|
40
|
40
|
import com.ruoyi.web.modules.merchant.service.IMerchantAccountBindService;
|
|
41
|
41
|
import com.ruoyi.web.modules.merchant.support.BizCompleteEvaluator;
|
|
|
42
|
+import com.ruoyi.web.modules.merchant.vo.MerchantShopBriefVO;
|
|
42
|
43
|
import com.ruoyi.web.modules.store.dto.ShopCreateDTO;
|
|
|
44
|
+import com.ruoyi.web.modules.store.domain.BizMerchantAccount;
|
|
|
45
|
+import com.ruoyi.web.modules.store.domain.BizShop;
|
|
|
46
|
+import com.ruoyi.web.modules.store.mapper.BizMerchantAccountMapper;
|
|
43
|
47
|
import com.ruoyi.web.modules.store.mapper.BizShopMapper;
|
|
44
|
48
|
import com.ruoyi.web.modules.store.service.IShopService;
|
|
45
|
49
|
|
|
|
@@ -57,6 +61,9 @@ public class MerchantEntryApplyServiceImpl implements IMerchantEntryApplyService
|
|
57
|
61
|
@Autowired
|
|
58
|
62
|
private BizShopMapper shopMapper;
|
|
59
|
63
|
|
|
|
64
|
+ @Autowired
|
|
|
65
|
+ private BizMerchantAccountMapper merchantAccountMapper;
|
|
|
66
|
+
|
|
60
|
67
|
@Autowired
|
|
61
|
68
|
private BizMemberMapper memberMapper;
|
|
62
|
69
|
|
|
|
@@ -255,7 +262,29 @@ public class MerchantEntryApplyServiceImpl implements IMerchantEntryApplyService
|
|
255
|
262
|
|
|
256
|
263
|
private Map<String, Object> finalizeEntry(BizMerchantEntryApply apply, String operator)
|
|
257
|
264
|
{
|
|
|
265
|
+ if (apply.getMerchantId() != null && apply.getShopId() != null)
|
|
|
266
|
+ {
|
|
|
267
|
+ return markApplyApproved(apply, apply.getMerchantId(), apply.getShopId(), operator, false);
|
|
|
268
|
+ }
|
|
|
269
|
+
|
|
258
|
270
|
EntryApplySubmitDTO submitDto = buildSubmitFromApply(apply);
|
|
|
271
|
+
|
|
|
272
|
+ BizMerchant memberAdminMerchant = findMerchantByMemberAdmin(apply.getMemberId());
|
|
|
273
|
+ if (memberAdminMerchant != null)
|
|
|
274
|
+ {
|
|
|
275
|
+ log.info("会员已是商户管理员,复用商户并按申请创建店铺完成入驻,applyId={},merchantId={}",
|
|
|
276
|
+ apply.getApplyId(), memberAdminMerchant.getMerchantId());
|
|
|
277
|
+ return reconcileWithExistingMerchant(apply, memberAdminMerchant, submitDto, operator, true);
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ BizMerchant existingMerchant = findExistingMerchant(submitDto, apply.getMerchantType());
|
|
|
281
|
+ if (existingMerchant != null && canReconcileExistingMerchant(existingMerchant, apply.getMemberId()))
|
|
|
282
|
+ {
|
|
|
283
|
+ log.info("入驻申请关联已有商户建档,applyId={},merchantId={}", apply.getApplyId(),
|
|
|
284
|
+ existingMerchant.getMerchantId());
|
|
|
285
|
+ return reconcileWithExistingMerchant(apply, existingMerchant, submitDto, operator, false);
|
|
|
286
|
+ }
|
|
|
287
|
+
|
|
259
|
288
|
assertUniqueOnSubmit(submitDto, apply.getMerchantType(), apply.getApplyId());
|
|
260
|
289
|
EntryApplyFormValidator.validateMobileSubmit(submitDto);
|
|
261
|
290
|
|
|
|
@@ -291,22 +320,142 @@ public class MerchantEntryApplyServiceImpl implements IMerchantEntryApplyService
|
|
291
|
320
|
shopFundService.seedContactBankAccountFromEntry(shopId, merchant.getContactName(),
|
|
292
|
321
|
merchant.getBankAccount(), operator);
|
|
293
|
322
|
|
|
|
323
|
+ return markApplyApproved(apply, merchant.getMerchantId(), shopId, operator, true);
|
|
|
324
|
+ }
|
|
|
325
|
+
|
|
|
326
|
+ private Map<String, Object> markApplyApproved(BizMerchantEntryApply apply, Long merchantId, Long shopId,
|
|
|
327
|
+ String operator, boolean notifyMember)
|
|
|
328
|
+ {
|
|
294
|
329
|
BizMerchantEntryApply update = new BizMerchantEntryApply();
|
|
295
|
330
|
update.setApplyId(apply.getApplyId());
|
|
296
|
331
|
update.setApplyStatus(MerchantEntryApplyConstants.STATUS_APPROVED);
|
|
297
|
|
- update.setMerchantId(merchant.getMerchantId());
|
|
|
332
|
+ update.setMerchantId(merchantId);
|
|
298
|
333
|
update.setShopId(shopId);
|
|
299
|
334
|
update.setUpdateBy(operator);
|
|
300
|
335
|
applyMapper.updateAuditResult(update);
|
|
301
|
336
|
|
|
302
|
|
- messageSupport.sendPass(apply.getMemberId(), apply.getApplyId(), apply.getApplyNo());
|
|
|
337
|
+ if (notifyMember)
|
|
|
338
|
+ {
|
|
|
339
|
+ messageSupport.sendPass(apply.getMemberId(), apply.getApplyId(), apply.getApplyNo());
|
|
|
340
|
+ }
|
|
303
|
341
|
|
|
304
|
342
|
Map<String, Object> data = new HashMap<>();
|
|
305
|
|
- data.put("merchantId", merchant.getMerchantId());
|
|
|
343
|
+ data.put("merchantId", merchantId);
|
|
306
|
344
|
data.put("shopId", shopId);
|
|
307
|
345
|
return data;
|
|
308
|
346
|
}
|
|
309
|
347
|
|
|
|
348
|
+ private Map<String, Object> reconcileWithExistingMerchant(BizMerchantEntryApply apply, BizMerchant merchant,
|
|
|
349
|
+ EntryApplySubmitDTO submitDto, String operator, boolean createShopFromApply)
|
|
|
350
|
+ {
|
|
|
351
|
+ requireMember(apply.getMemberId());
|
|
|
352
|
+ EntryApplyFormValidator.validateMobileSubmit(submitDto);
|
|
|
353
|
+
|
|
|
354
|
+ BizMerchantAccount account = merchantAccountMapper.selectByMerchantId(merchant.getMerchantId());
|
|
|
355
|
+ if (account == null)
|
|
|
356
|
+ {
|
|
|
357
|
+ MerchantCreateDTO bindDto = EntryApplyFormMapper.toMerchantCreateDTO(merchant, apply.getMemberId());
|
|
|
358
|
+ accountBindService.bindAccountOnMerchantCreate(merchant.getMerchantId(), bindDto, operator);
|
|
|
359
|
+ }
|
|
|
360
|
+
|
|
|
361
|
+ Long shopId = resolveShopForReconcile(apply, merchant, submitDto, operator, createShopFromApply);
|
|
|
362
|
+ shopFundService.seedContactBankAccountFromEntry(shopId, merchant.getContactName(),
|
|
|
363
|
+ merchant.getBankAccount(), operator);
|
|
|
364
|
+
|
|
|
365
|
+ return markApplyApproved(apply, merchant.getMerchantId(), shopId, operator, true);
|
|
|
366
|
+ }
|
|
|
367
|
+
|
|
|
368
|
+ private Long resolveShopForReconcile(BizMerchantEntryApply apply, BizMerchant merchant,
|
|
|
369
|
+ EntryApplySubmitDTO submitDto, String operator, boolean createShopFromApply)
|
|
|
370
|
+ {
|
|
|
371
|
+ if (apply.getShopId() != null)
|
|
|
372
|
+ {
|
|
|
373
|
+ return apply.getShopId();
|
|
|
374
|
+ }
|
|
|
375
|
+ String shopName = submitDto.getShop().getShopName();
|
|
|
376
|
+ if (createShopFromApply)
|
|
|
377
|
+ {
|
|
|
378
|
+ Long matchedShopId = findShopIdByNameUnderMerchant(merchant.getMerchantId(), shopName);
|
|
|
379
|
+ if (matchedShopId != null)
|
|
|
380
|
+ {
|
|
|
381
|
+ return matchedShopId;
|
|
|
382
|
+ }
|
|
|
383
|
+ if (shopMapper.countByShopName(shopName, null) > 0)
|
|
|
384
|
+ {
|
|
|
385
|
+ throw new ServiceException("店铺名称已存在");
|
|
|
386
|
+ }
|
|
|
387
|
+ ShopCreateDTO shopDto = EntryApplyFormMapper.toShopCreateDTO(apply.getFormJson(), merchant.getMerchantId());
|
|
|
388
|
+ return shopService.createShop(shopDto, operator);
|
|
|
389
|
+ }
|
|
|
390
|
+
|
|
|
391
|
+ BizShop earliest = shopMapper.selectEarliestByMerchantId(merchant.getMerchantId());
|
|
|
392
|
+ if (earliest != null)
|
|
|
393
|
+ {
|
|
|
394
|
+ return earliest.getShopId();
|
|
|
395
|
+ }
|
|
|
396
|
+ if (shopMapper.countByShopName(shopName, null) > 0)
|
|
|
397
|
+ {
|
|
|
398
|
+ throw new ServiceException("店铺名称已存在");
|
|
|
399
|
+ }
|
|
|
400
|
+ ShopCreateDTO shopDto = EntryApplyFormMapper.toShopCreateDTO(apply.getFormJson(), merchant.getMerchantId());
|
|
|
401
|
+ return shopService.createShop(shopDto, operator);
|
|
|
402
|
+ }
|
|
|
403
|
+
|
|
|
404
|
+ private Long findShopIdByNameUnderMerchant(Long merchantId, String shopName)
|
|
|
405
|
+ {
|
|
|
406
|
+ if (StringUtils.isEmpty(shopName))
|
|
|
407
|
+ {
|
|
|
408
|
+ return null;
|
|
|
409
|
+ }
|
|
|
410
|
+ for (MerchantShopBriefVO shop : shopMapper.selectBriefByMerchantId(merchantId))
|
|
|
411
|
+ {
|
|
|
412
|
+ if (shopName.equals(shop.getShopName()))
|
|
|
413
|
+ {
|
|
|
414
|
+ return shop.getShopId();
|
|
|
415
|
+ }
|
|
|
416
|
+ }
|
|
|
417
|
+ return null;
|
|
|
418
|
+ }
|
|
|
419
|
+
|
|
|
420
|
+ private BizMerchant findMerchantByMemberAdmin(Long memberId)
|
|
|
421
|
+ {
|
|
|
422
|
+ if (memberId == null)
|
|
|
423
|
+ {
|
|
|
424
|
+ return null;
|
|
|
425
|
+ }
|
|
|
426
|
+ BizMerchantAccount account = merchantAccountMapper.selectMerchantAdminByUserId(memberId);
|
|
|
427
|
+ if (account == null || account.getMerchantId() == null)
|
|
|
428
|
+ {
|
|
|
429
|
+ return null;
|
|
|
430
|
+ }
|
|
|
431
|
+ return merchantMapper.selectById(account.getMerchantId());
|
|
|
432
|
+ }
|
|
|
433
|
+
|
|
|
434
|
+ private BizMerchant findExistingMerchant(EntryApplySubmitDTO dto, String merchantType)
|
|
|
435
|
+ {
|
|
|
436
|
+ if (MerchantConstants.TYPE_PERSON.equals(merchantType) && dto.getSubject() != null
|
|
|
437
|
+ && StringUtils.isNotEmpty(dto.getSubject().getIdCardNo()))
|
|
|
438
|
+ {
|
|
|
439
|
+ return merchantMapper.selectByIdCardNo(dto.getSubject().getIdCardNo());
|
|
|
440
|
+ }
|
|
|
441
|
+ if (MerchantConstants.TYPE_ENTERPRISE.equals(merchantType) && dto.getSubject() != null
|
|
|
442
|
+ && StringUtils.isNotEmpty(dto.getSubject().getCreditCode()))
|
|
|
443
|
+ {
|
|
|
444
|
+ return merchantMapper.selectByCreditCode(dto.getSubject().getCreditCode());
|
|
|
445
|
+ }
|
|
|
446
|
+ return null;
|
|
|
447
|
+ }
|
|
|
448
|
+
|
|
|
449
|
+ private boolean canReconcileExistingMerchant(BizMerchant merchant, Long memberId)
|
|
|
450
|
+ {
|
|
|
451
|
+ BizMerchantAccount account = merchantAccountMapper.selectByMerchantId(merchant.getMerchantId());
|
|
|
452
|
+ if (account == null)
|
|
|
453
|
+ {
|
|
|
454
|
+ return true;
|
|
|
455
|
+ }
|
|
|
456
|
+ return memberId != null && memberId.equals(account.getAccountId());
|
|
|
457
|
+ }
|
|
|
458
|
+
|
|
310
|
459
|
@Override
|
|
311
|
460
|
@Transactional(rollbackFor = Exception.class)
|
|
312
|
461
|
public void reject(EntryApplyRejectDTO dto, String operator)
|