三七 1 deň pred
rodič
commit
026a5ae572

+ 4 - 0
fs-service/src/main/java/com/fs/his/mapper/FsUserMapper.java

@@ -470,6 +470,10 @@ public interface FsUserMapper
 
     List<FsUser> selectFsUserListByPhone(String phone);
 
+
+    @Select("select * from fs_user where apple_key = #{appleKey}")
+    FsUser findUserByAppleKey(String appleKey);
+
     void updatePasswordByPhone(@Param("password")String password, @Param("encryptPhone")String encryptPhone);
 
     /**

+ 8 - 0
fs-service/src/main/java/com/fs/his/service/IFsUserCouponService.java

@@ -1,6 +1,8 @@
 package com.fs.his.service;
 
 import java.util.List;
+
+import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserCoupon;
 import com.fs.his.param.FsUserCouponParam;
 import com.fs.his.param.FsUserCouponSendParam;
@@ -74,4 +76,10 @@ public interface IFsUserCouponService
     List<FsUserCouponListUVO> getMyEnableCouponList(FsUserCouponUParam param);
 
     FsUserCouponCountUVO selectFsUserCouponCountUVO(FsUserCouponUParam param);
+
+    /**
+     * 发送注册优惠券
+     * @param user
+     */
+    void sendRegisterCoupon(FsUser user);
 }

+ 44 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsUserCouponServiceImpl.java

@@ -1,12 +1,18 @@
 package com.fs.his.service.impl;
 
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
 import java.util.List;
 
+import cn.hutool.json.JSONUtil;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.StringUtils;
+import com.fs.his.config.CouponConfig;
 import com.fs.his.domain.FsCoupon;
+import com.fs.his.domain.FsUser;
 import com.fs.his.mapper.FsCouponMapper;
 import com.fs.his.param.FsUserCouponParam;
 import com.fs.his.param.FsUserCouponSendParam;
@@ -15,6 +21,7 @@ import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsUserCouponCountUVO;
 import com.fs.his.vo.FsUserCouponListUVO;
 import com.fs.his.vo.FsUserCouponListVO;
+import com.fs.system.service.ISysConfigService;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -37,6 +44,10 @@ public class FsUserCouponServiceImpl implements IFsUserCouponService
 
     @Autowired
     private FsCouponMapper fsCouponMapper;
+
+    @Autowired
+    private ISysConfigService configService;
+
     /**
      * 查询会员优惠券
      *
@@ -192,4 +203,37 @@ public class FsUserCouponServiceImpl implements IFsUserCouponService
         }
         return countUVO;
     }
+
+    @Override
+    public void sendRegisterCoupon(FsUser user) {
+        Date createTime = user.getCreateTime();
+        if (!isCreateTimeMoreThanOneDay(createTime)) {
+            Long userId = user.getUserId();
+            String json = configService.selectConfigByKey("his.coupon");
+            CouponConfig config = JSONUtil.toBean(json, CouponConfig.class);
+            Long[] registerCoupons = config.getRegisterCoupon();
+            if (registerCoupons != null){
+                for (Long registerCoupon : registerCoupons) {
+                    FsUserCouponSendParam param = new FsUserCouponSendParam();
+                    param.setCouponId(registerCoupon);
+                    param.setUserId(userId);
+                    sendFsUserCoupon(param);
+                }
+            }
+
+        }
+    }
+
+    /**
+     * 判断是否超过一天
+     * @param createTime
+     * @return
+     */
+    public static boolean isCreateTimeMoreThanOneDay(Date createTime) {
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime createTimeLocal = createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+
+        // 判断是否超过一天
+        return createTimeLocal.isBefore(now.minusDays(1));
+    }
 }

+ 50 - 0
fs-user-app/src/main/java/com/fs/app/controller/AppLoginController.java

@@ -18,6 +18,7 @@ import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserNewTask;
 import com.fs.his.mapper.FsUserMapper;
+import com.fs.his.service.IFsUserCouponService;
 import com.fs.his.service.IFsUserNewTaskService;
 import com.fs.his.service.IFsUserService;
 import com.fs.his.utils.ConfigUtil;
@@ -63,6 +64,9 @@ public class AppLoginController extends AppBaseController{
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private IFsUserCouponService fsUserCouponService;
+
     @Autowired
     private ISmsService smsService;
     @ApiOperation("注册app用户")
@@ -301,6 +305,52 @@ public class AppLoginController extends AppBaseController{
 
     }
 
+
+    @ApiOperation("苹果登录")
+    @PostMapping("/loginByApple")
+    @Transactional
+    public R loginByApple(@Validated @RequestBody FsUserLoginByAppleParam param) {
+        try {
+            if (StringUtils.isEmpty(param.getAppleKey())) {
+                return R.error("获取苹果key失败");
+            }
+            // 根据苹果key查询用户
+            FsUser user = userMapper.findUserByAppleKey(param.getAppleKey());
+            Map<String, Object> map = new HashMap<>();
+            if (user == null) {
+                map.put("isNew", true);
+                return R.ok(map);
+            } else {
+                if (StringUtils.isNotEmpty(param.getJpushId())) {
+                    updateExistingUserJpushId(user, param.getJpushId());
+                    try {
+                        //发送注册优惠券
+                        fsUserCouponService.sendRegisterCoupon(user);
+                    } catch (Exception e) {
+                        logger.error("发送注册优惠券失败:{}",e.getMessage());
+                    }
+                }
+                if (StringUtils.isEmpty(user.getPhone())) {
+                    map.put("isNew", true);
+                    return R.ok(map);
+                }
+            }
+            /*if (user.getStatus()==0){
+                return R.error("登录失败,账户被禁用");
+            }*/
+            int isFirstLogin = userNewTaskService.performTaskOne(user.getUserId());
+            String token = jwtUtils.generateToken(user.getUserId());
+            redisCache.setCacheObject("userToken:" + user.getUserId(), token, 604800, TimeUnit.SECONDS);
+            map.put("token", token);
+            map.put("user", user);
+            map.put("isFirst",isFirstLogin);
+            return R.ok(map);
+        }catch (Exception e){
+            logger.error("zyp 苹果登录失败:{}", e.getMessage());
+            return R.error("登录失败");
+        }
+    }
+
     @PostMapping("/loginByPhone")
     public R loginByPhone(@RequestBody Map<String,String> map){
         String phone = map.get("phone");

+ 17 - 0
fs-user-app/src/main/java/com/fs/app/param/FsUserLoginByAppleParam.java

@@ -0,0 +1,17 @@
+package com.fs.app.param;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class FsUserLoginByAppleParam implements Serializable {
+    private String jpushId;
+
+    private String loginDevice;//当前登陆设备
+
+    private String source; //app来源
+
+    private String appleKey;
+
+}