From 7a0b33a5f2e0ba589bf35a1b8d896700a21f94a4 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 30 四月 2026 16:00:55 +0800
Subject: [PATCH] 支付宝支付dddadd
---
server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java | 180 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 147 insertions(+), 33 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
index 9f7a9b3..87cd2c6 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/ShopInfoServiceImpl.java
@@ -26,7 +26,14 @@
import com.doumee.dao.business.model.Orders;
import com.doumee.dao.business.model.PricingRule;
import com.doumee.dao.business.model.ShopInfo;
+import com.doumee.config.xyy.XyyConfig;
+import com.doumee.config.xyy.dto.AddPrinterRequest;
+import com.doumee.config.xyy.dto.AddPrinterRequestItem;
+import com.doumee.config.xyy.dto.DelPrinterRequest;
+import com.doumee.config.xyy.vo.ObjectRestResponse;
+import com.doumee.config.xyy.vo.PrinterResult;
import com.doumee.dao.dto.*;
+import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.vo.ShopDetailVO;
@@ -92,6 +99,12 @@
@Autowired
private SmsrecordMapper smsrecordMapper;
+
+ @Autowired
+ private PrintService printService;
+
+ @Autowired
+ private XyyConfig xyyConfig;
@Override
public Integer create(ShopInfo shopInfo) {
shopInfoMapper.insert(shopInfo);
@@ -228,13 +241,7 @@
if (pageWrap.getModel().getOpenid() != null) {
queryWrapper.lambda().like(ShopInfo::getOpenid, pageWrap.getModel().getOpenid());
}
- for (PageWrap.SortData sortData : pageWrap.getSorts()) {
- if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
- queryWrapper.orderByDesc(sortData.getProperty());
- } else {
- queryWrapper.orderByAsc(sortData.getProperty());
- }
- }
+ queryWrapper.lambda().orderByDesc(ShopInfo::getId);
return PageData.from(shopInfoMapper.selectPage(page, queryWrapper));
}
@@ -293,8 +300,7 @@
Integer shopId;
if (existing != null) {
// 鏍¢獙鐘舵�侊細鍙湁寰呭鎵�(0)鍜岃椹冲洖(2)鍙慨鏀�
- if (!Constants.equalsInteger(existing.getAuditStatus(), Constants.ZERO)
- && !Constants.equalsInteger(existing.getAuditStatus(), Constants.TWO)) {
+ if (!Constants.equalsInteger(existing.getAuditStatus(), Constants.TWO)) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠闂ㄥ簵鐘舵�佷笉鍏佽淇敼");
}
// 鏍¢獙openid鍖归厤锛氬綋鍓嶇櫥褰曚細鍛樼殑openid蹇呴』涓庨棬搴楃殑openid涓�鑷�
@@ -360,6 +366,7 @@
shopInfo.setSalt(salt);
shopInfo.setAliAccount(request.getAliAccount());
shopInfo.setAliName(request.getAliName());
+ shopInfo.setAuditStatus(Constants.ZERO);
shopInfo.setStatus(Constants.ZERO);
shopInfo.setDeleted(Constants.ZERO);
shopInfo.setCreateTime(now);
@@ -367,6 +374,8 @@
shopInfo.setRegionMemberId(member.getId());
// 璇诲彇鎶奸噾閲戦
setDepositAmountFromPricingRule(shopInfo);
+ // 璁剧疆榛樿閰嶉�佽寖鍥�
+ setDefaultDeliveryRange(shopInfo);
shopInfoMapper.insert(shopInfo);
shopId = shopInfo.getId();
}
@@ -469,7 +478,8 @@
if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) {
// 瀹℃牳閫氳繃 鈫� 閫氱煡缂寸撼鎶奸噾
String depositMoney = shopInfo.getDepositAmount() != null
- ? String.valueOf(shopInfo.getDepositAmount() / 100.0) : "0";
+ ? new java.math.BigDecimal(shopInfo.getDepositAmount())
+ .divide(new java.math.BigDecimal(100), 2, java.math.RoundingMode.HALF_UP).toPlainString() : "0";
sendSmsNotify(shopInfo.getTelephone(),
Constants.SmsNotify.SHOP_AUTH_APPROVED_DEPOSIT,
"storeName", shopInfo.getName(),
@@ -757,6 +767,13 @@
}
}
+ // 闂ㄥ簵澶村儚锛氫紭鍏堜娇鐢� coverImg锛屼负绌哄垯鍙栭棬澶寸収绗竴寮�
+ if (StringUtils.isNotBlank(shopInfo.getCoverImg())) {
+ vo.setShopAvatar(imgPrefix + shopInfo.getCoverImg());
+ } else if (!CollectionUtils.isEmpty(vo.getStoreFrontImgUrls())) {
+ vo.setShopAvatar(vo.getStoreFrontImgUrls().get(0));
+ }
+
return vo;
}
@@ -787,7 +804,8 @@
// 闂ㄥ簵鍚嶇О妯$硦鏌ヨ
if (StringUtils.isNotBlank(dto.getName())) {
- qw.lambda().like(ShopInfo::getName, dto.getName());
+ qw.lambda().and(q -> q.like(ShopInfo::getName, dto.getName()).or()
+ .like(ShopInfo::getAddress, dto.getName()));
}
// 鍩庡競绛涢�夛紙areaId鏄尯鍘匡紝闇�鍖归厤鍏秔arentId绛変簬鍩庡競ID锛�
@@ -864,6 +882,7 @@
vo.setFeeStandard(shop.getFeeStandard());
vo.setLatitude(shop.getLatitude());
vo.setLongitude(shop.getLongitude());
+ vo.setLinkPhone(shop.getLinkPhone());
// 闂ㄥご鐓� + 鍐呴儴鐓� 鍏ㄨ矾寰勯泦鍚�
String imgPrefix = getShopPrefix();
@@ -906,8 +925,8 @@
}
@Override
- public ShopInfoMaintainDTO getShopMaintainInfo(Integer memberId) {
- ShopInfo shop = shopInfoMapper.selectById(memberId);
+ public ShopInfoMaintainDTO getShopMaintainInfo(Integer shopId) {
+ ShopInfo shop = shopInfoMapper.selectById(shopId);
if (Objects.isNull(shop) || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
return null;
}
@@ -919,6 +938,10 @@
dto.setDeliveryArea(shop.getDeliveryArea());
dto.setShopHours(shop.getShopHours());
dto.setBusinessType(shop.getBusinessType());
+ // 澶村儚鍏ㄨ矾寰�
+ if (StringUtils.isNotBlank(shop.getCoverImg())) {
+ dto.setCoverImgUrl(getShopPrefix() + shop.getCoverImg());
+ }
return dto;
}
@@ -1072,12 +1095,15 @@
// 瀛樹欢闂ㄥ簵
List<Orders> depositSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
.eq(Orders::getDeleted, Constants.ZERO)
+ .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
.ge(Orders::getCreateTime, startTime)
.lt(Orders::getCreateTime, endTime)
.eq(Orders::getDepositShopId, shopId));
// 鍙栦欢闂ㄥ簵
List<Orders> takeSalesOrders = ordersMapper.selectList(new QueryWrapper<Orders>().lambda()
.eq(Orders::getDeleted, Constants.ZERO)
+ .eq(Orders::getType,Constants.ONE)
+ .notIn(Orders::getStatus,Constants.OrderStatus.cancelled.getStatus(),Constants.OrderStatus.waitPay.getStatus())
.ge(Orders::getCreateTime, startTime)
.lt(Orders::getCreateTime, endTime)
.eq(Orders::getTakeShopId, shopId));
@@ -1108,19 +1134,27 @@
vo.setSettlementProfit(depositFee + takeFee);
// 3. 鍦ㄥ簱璁㈠崟鏁�
- // 3.1 瀛樹欢闂ㄥ簵=鏈棬搴楋紝status in (2宸插瘎瀛�, 5寰呭彇浠�)
- Long depositStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+ // 3.1 灏卞湴璁㈠崟锛氬瓨浠堕棬搴�=鏈棬搴楋紝type=0锛宻tatus in (2宸插瘎瀛�, 5寰呭彇浠�)
+ Long localStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
.eq(Orders::getDeleted, Constants.ZERO)
.eq(Orders::getDepositShopId, shopId)
+ .eq(Orders::getType, Constants.ZERO)
.in(Orders::getStatus,
Constants.OrderStatus.deposited.getStatus(),
Constants.OrderStatus.arrived.getStatus()));
- // 3.2 鍙栦欢闂ㄥ簵=鏈棬搴楋紝status = 5寰呭彇浠�
+ // 3.2 寮傚湴璁㈠崟锛氬瓨浠堕棬搴�=鏈棬搴楋紝type=1锛宻tatus=2宸插瘎瀛�
+ Long remoteStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
+ .eq(Orders::getDeleted, Constants.ZERO)
+ .eq(Orders::getDepositShopId, shopId)
+ .eq(Orders::getType, Constants.ONE)
+ .eq(Orders::getStatus, Constants.OrderStatus.deposited.getStatus()));
+ // 3.3 鍙栦欢闂ㄥ簵=鏈棬搴楋紝寮傚湴璁㈠崟锛宻tatus = 5寰呭彇浠�
Long takeStorageCount = ordersMapper.selectCount(new QueryWrapper<Orders>().lambda()
.eq(Orders::getDeleted, Constants.ZERO)
+ .eq(Orders::getType,Constants.ONE)
.eq(Orders::getTakeShopId, shopId)
.eq(Orders::getStatus, Constants.OrderStatus.arrived.getStatus()));
- vo.setStorageCount(depositStorageCount.intValue() + takeStorageCount.intValue());
+ vo.setStorageCount(localStorageCount.intValue() + remoteStorageCount.intValue() + takeStorageCount.intValue());
return vo;
}
@@ -1134,7 +1168,6 @@
public ShopLoginVO shopPasswordLogin(ShopLoginDTO dto){
if(StringUtils.isBlank(dto.getTelephone())
|| StringUtils.isBlank(dto.getPassword())
- || StringUtils.isBlank(dto.getOpenid())
){
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛鍚嶆垨瀵嗙爜涓嶈兘涓虹┖");
}
@@ -1143,7 +1176,16 @@
.last("limit 1")
);
if(shop==null){
- throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇锋牳瀵圭櫥褰曟墜鏈哄彿鏄惁姝g‘");
+ }
+ if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵宸茬鐢紝璇疯仈绯荤鐞嗗憳");
+ }
+ if(!Constants.equalsInteger(shop.getAuditStatus(),Constants.THREE)){
+ if(Constants.equalsInteger(shop.getAuditStatus(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璇峰畬鎴愬鎵规祦绋� - 鏀粯鎶奸噾");
+ }
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵瀹℃壒娴佺▼鏈畬鎴愶紝璇峰畬鎴愬鎵规祦绋�");
}
//鍔犲瘑瀵嗙爜
String pwd = Utils.Secure.encryptPassword( dto.getPassword(), shop.getSalt());
@@ -1168,7 +1210,6 @@
// 鍒涘缓token锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
-
// 鏋勫缓鍝嶅簲
ShopLoginVO vo = new ShopLoginVO();
vo.setToken(token);
@@ -1196,6 +1237,9 @@
.last("limit 1"));
if (shop == null) {
return null;
+ }
+ if(Constants.equalsInteger(shop.getStatus(),Constants.ONE)){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闂ㄥ簵宸茬鐢紝璇疯仈绯荤鐞嗗憳");
}
// 鍒涘缓token锛坓enerateTokenForRedis 宸茶嚜鍔ㄦ竻闄よ鐢ㄦ埛鏃oken锛屼繚璇佸敮涓�鏈夋晥锛�
String token = JwtTokenUtil.generateTokenForRedis(shop.getId(), Constants.TWO, JSONObject.toJSONString(shop), redisTemplate);
@@ -1307,13 +1351,25 @@
if (shopInfo.getCompanyType() == null) {
return;
}
+ Areas areas = areasService.findById(shopInfo.getAreaId());
PricingRule pricingRule = pricingRuleMapper.selectOne(new QueryWrapper<PricingRule>().lambda()
.eq(PricingRule::getDeleted, Constants.ZERO)
.eq(PricingRule::getType, Constants.THREE)
- .eq(PricingRule::getFieldA, String.valueOf(shopInfo.getCompanyType()))
+ .eq(PricingRule::getFieldA, String.valueOf(Constants.equalsInteger(shopInfo.getCompanyType(),Constants.ZERO)?Constants.ONE:Constants.ZERO))
+ .eq(PricingRule::getCityId, areas.getParentId())
.last("limit 1"));
if (pricingRule != null && StringUtils.isNotBlank(pricingRule.getFieldB())) {
shopInfo.setDepositAmount(Long.parseLong(pricingRule.getFieldB()));
+ }
+ }
+
+ /**
+ * 浠庤繍钀ラ厤缃鍙栭粯璁ら厤閫佽寖鍥村苟璧嬪�煎埌闂ㄥ簵璁板綍
+ */
+ private void setDefaultDeliveryRange(ShopInfo shopInfo) {
+ SystemDictData data = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, Constants.OP_DEFAULT_DELIVERY_RANGE);
+ if (data != null && StringUtils.isNotBlank(data.getCode())) {
+ shopInfo.setDeliveryArea(new java.math.BigDecimal(data.getCode()));
}
}
@@ -1330,19 +1386,16 @@
for (int i = 0; i < paramPairs.length - 1; i += 2) {
templateParam.put(paramPairs[i], paramPairs[i + 1]);
}
- boolean result = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(),
+ String error = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(),
templateParam.toJSONString());
- if (result) {
- log.info("鐭俊鍙戦�佹垚鍔�: phone={}, template={}", phone, smsNotify.name());
- } else {
- log.warn("鐭俊鍙戦�佸け璐�: phone={}, template={}", phone, smsNotify.name());
- }
- // 瀛樺偍鐭俊璁板綍
Smsrecord smsRecord = new Smsrecord();
smsRecord.setPhone(phone);
smsRecord.setContent(content);
smsRecord.setType(Constants.ONE);
- smsRecord.setStatus(result ? Constants.ONE : Constants.ZERO);
+ smsRecord.setStatus(error == null ? Constants.ONE : Constants.ZERO);
+ if (error != null) {
+ smsRecord.setRemark(error);
+ }
smsRecord.setCreateTime(new Date());
smsRecord.setDeleted(Constants.ZERO);
smsrecordMapper.insert(smsRecord);
@@ -1352,11 +1405,14 @@
}
@Override
- public void changePassword(Integer shopId, String newPassword, String token) {
- if (StringUtils.isBlank(newPassword)) {
- throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵嗙爜涓嶈兘涓虹┖");
+ public void changePassword(Integer shopId, String oldPassword, String newPassword, String token) {
+ if (StringUtils.isBlank(oldPassword)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃у瘑鐮佷笉鑳戒负绌�");
}
- // 鏍¢獙瀵嗙爜蹇呴』鍚屾椂鍖呭惈瀛楁瘝鍜屾暟瀛�
+ if (StringUtils.isBlank(newPassword)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏂板瘑鐮佷笉鑳戒负绌�");
+ }
+ // 鏍¢獙鏂板瘑鐮佸繀椤诲悓鏃跺寘鍚瓧姣嶅拰鏁板瓧
boolean hasLetter = newPassword.chars().anyMatch(Character::isLetter);
boolean hasDigit = newPassword.chars().anyMatch(Character::isDigit);
if (!hasLetter || !hasDigit) {
@@ -1367,6 +1423,11 @@
if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) {
throw new BusinessException(ResponseStatus.DATA_EMPTY);
}
+ // 鏍¢獙鏃у瘑鐮�
+ String oldEncryptPwd = Utils.Secure.encryptPassword(oldPassword, shopInfo.getSalt());
+ if (!oldEncryptPwd.equals(shopInfo.getPassword())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃у瘑鐮侀敊璇�");
+ }
// 閲嶆柊鐢熸垚salt锛屽姞瀵嗘柊瀵嗙爜骞舵洿鏂�
String salt = RandomStringUtils.randomAlphabetic(6);
shopInfo.setPassword(Utils.Secure.encryptPassword(newPassword, salt));
@@ -1378,4 +1439,57 @@
}
}
+ @Override
+ public void maintainPrinterSn(ShopPrinterDTO dto) {
+ ShopInfo shop = shopInfoMapper.selectById(dto.getId());
+ if (shop == null || Constants.equalsInteger(shop.getDeleted(), Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ String oldSn = shop.getPrinterSn();
+ String newSn = dto.getPrinterSn();
+ boolean hasNewSn = StringUtils.isNotBlank(newSn);
+ boolean hasOldSn = StringUtils.isNotBlank(oldSn);
+
+ if (!hasNewSn) {
+ // 鏈紶鎵撳嵃鏈篠N 鈫� 鍒犻櫎閫昏緫
+ if (hasOldSn) {
+ delPrinterFromXyy(oldSn);
+ shop.setPrinterSn(null);
+ shopInfoMapper.updateById(shop);
+ }
+ return;
+ }
+
+ // 浼犱簡鎵撳嵃鏈篠N 鈫� 濡傛灉鏃х粦瀹氬瓨鍦紝鍏堝垹闄�
+ if (hasOldSn) {
+ delPrinterFromXyy(oldSn);
+ }
+
+ // 缁戝畾鏂版墦鍗版満
+ AddPrinterRequest addReq = new AddPrinterRequest();
+ xyyConfig.createRequestHeader(addReq);
+ addReq.setItems(new AddPrinterRequestItem[]{new AddPrinterRequestItem() {{
+ setSn(newSn);
+ setName(shop.getName());
+ }}});
+ ObjectRestResponse<PrinterResult> addResp = printService.addPrinters(addReq);
+ if (addResp.getCode() != 0) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "缁戝畾鎵撳嵃鏈哄け璐ワ細" + addResp.getMsg());
+ }
+ log.info("缁戝畾鎴愬姛锛歿}", newSn);
+ shop.setPrinterSn(newSn);
+ shopInfoMapper.updateById(shop);
+ }
+
+ private void delPrinterFromXyy(String sn) {
+ DelPrinterRequest delReq = new DelPrinterRequest();
+ xyyConfig.createRequestHeader(delReq);
+ delReq.setSnlist(new String[]{sn});
+ ObjectRestResponse<PrinterResult> delResp = printService.delPrinters(delReq);
+ if (delResp.getCode() != 0) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瑙g粦鎵撳嵃鏈哄け璐ワ細" + delResp.getMsg());
+ }
+ log.info("瑙g粦鎴愬姛锛歿}", sn);
+ }
+
}
--
Gitblit v1.9.3