From 9a12466b7a4bb0ad16e1fb4374b769be71dd2bcb Mon Sep 17 00:00:00 2001
From: puhanshu <a9236326>
Date: 星期四, 06 一月 2022 18:23:56 +0800
Subject: [PATCH] 商业街H5登录

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
index 5b5bbca..318e000 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
@@ -9,8 +9,13 @@
 import java.util.List;
 
 import javax.annotation.Resource;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Pattern;
 
+import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO;
 import org.springframework.beans.BeanUtils;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -54,6 +59,8 @@
     private McsConfigDAO mcsConfigDAO;
     @Resource
     private McsGameDAO mcsGameDAO;
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
 
     /**
      * 新增数字商业街商家
@@ -81,8 +88,8 @@
             //添加user
             R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO);
             if (R.isOk(addUserResult)) {
-                Long merchantUserId = ((Integer) addUserResult.getData()).longValue();
-                mcsMerchant.setUserId(merchantUserId);
+                LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), LoginUserInfoVO.class);
+                mcsMerchant.setUserId(loginUserInfoVO.getUserId());
                 this.baseMapper.updateById(mcsMerchant);
             } else {
                 throw new ServiceException("406", addUserResult.getMsg());
@@ -278,6 +285,47 @@
         }
     }
 
+    /**
+     * 验证码登录
+     * @param loginDTO
+     * @return
+     */
+    @Override
+    public R loginWithPhone(LoginWithPhoneDTO loginDTO) {
+        String phone = loginDTO.getPhone();
+        String redisKey = String.join("::", phone, loginDTO.getCode());
+        Boolean hasKey = stringRedisTemplate.hasKey(redisKey);
+        if (hasKey) {
+            //通过验证
+            R r = userService.getSysUserByPhone(phone, 11);
+            if (R.isOk(r)) {
+                if (nonNull(r.getData())) {
+                    //已有用户
+                    LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginUserInfoVO.class);
+                    stringRedisTemplate.delete(redisKey);
+                    return R.ok(loginUserInfoVO);
+                } else {
+                    //自动创建用户
+                    McsMerchantDTO mcsMerchantDTO = new McsMerchantDTO();
+                    mcsMerchantDTO.setAccount(phone);
+                    mcsMerchantDTO.setPassword("88888888");
+                    mcsMerchantDTO.setAccountStatus(1);
+                    mcsMerchantDTO.setPhone(phone);
+                    R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO);
+                    if (R.isOk(addUserResult)) {
+                        LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), LoginUserInfoVO.class);
+                        stringRedisTemplate.delete(redisKey);
+                        return R.ok(loginUserInfoVO);
+                    }
+                    return addUserResult;
+                }
+            }
+            return r;
+        } else {
+            return R.fail("验证码错误");
+        }
+    }
+
     private void retrieveMerchantSurplusLitDays(McsMerchantVO merchantVO) {
         Integer publishLimit = merchantVO.getPublishLimit();
         Integer publishCount = mcsGameDAO.selectPublishCount(merchantVO.getId());

--
Gitblit v1.7.1