|
|
@@ -1,19 +1,18 @@
|
|
|
package com.fs.app.controller;
|
|
|
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.FsBindCompanyUserParam;
|
|
|
import com.fs.app.param.HelpPatientAndAddressParam;
|
|
|
import com.fs.common.annotation.Log;
|
|
|
-import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.constant.HttpStatus;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.enums.BusinessType;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
@@ -25,17 +24,21 @@ import com.fs.company.param.companyUserAddPrintParam;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.service.ICompanyUserUserService;
|
|
|
import com.fs.config.ai.AiHostProper;
|
|
|
+import com.fs.course.mapper.FsUserCompanyUserMapper;
|
|
|
import com.fs.fastGpt.domain.FastgptChatVoiceHomo;
|
|
|
import com.fs.fastGpt.mapper.FastgptChatVoiceHomoMapper;
|
|
|
import com.fs.fastgptApi.util.AudioUtils;
|
|
|
import com.fs.fastgptApi.vo.AudioVO;
|
|
|
+import com.fs.his.domain.FsCoupon;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.domain.FsUserCoupon;
|
|
|
+import com.fs.his.mapper.FsCouponMapper;
|
|
|
+import com.fs.his.mapper.FsUserCouponMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.*;
|
|
|
import com.fs.his.service.IFsPrescribeService;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.vo.FsPrescribeListDVO;
|
|
|
-import com.fs.his.vo.FsUserVO;
|
|
|
import com.fs.his.vo.MyMemberVO;
|
|
|
import com.fs.sop.domain.QwSopTempVoice;
|
|
|
import com.fs.sop.service.IQwSopTempVoiceService;
|
|
|
@@ -62,6 +65,8 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.*;
|
|
|
import java.util.Base64;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -98,6 +103,15 @@ public class CompanyUserController extends AppBaseController {
|
|
|
@Autowired
|
|
|
private FsUserMapper fsUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsCouponMapper fsCouponMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCouponMapper fsUserCouponMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCompanyUserMapper fsUserCompanyUserMapper;
|
|
|
+
|
|
|
|
|
|
public static final String SOP_TEMP_VOICE_KEY = "sop:tempVoice";
|
|
|
|
|
|
@@ -200,6 +214,119 @@ public class CompanyUserController extends AppBaseController {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ @Login
|
|
|
+ @ApiOperation("绑定销售并发放新人券")
|
|
|
+ @PostMapping("/bindCompanyUserAndCoupon")
|
|
|
+ @Transactional
|
|
|
+ public R bindCompanyUserAndCoupon(@Validated @RequestBody FsBindCompanyUserParam param, HttpServletRequest request) {
|
|
|
+ Long currentUserId = Long.parseLong(getUserId());
|
|
|
+ FsUser user = fsUserService.selectFsUserByUserId(currentUserId);
|
|
|
+ if (user == null) {
|
|
|
+ return R.error(HttpStatus.UNAUTHORIZED, "用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FsUser> usersByPhone = findUsersByPhone(param.getPhone());
|
|
|
+
|
|
|
+ if (usersByPhone != null && usersByPhone.size() > 1) {
|
|
|
+ return R.error("手机号已注册,请联系您的专属客服");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (usersByPhone != null && usersByPhone.size() == 1) {
|
|
|
+ FsUser userByPhone = usersByPhone.get(0);
|
|
|
+ if (!user.getUserId().equals(userByPhone.getUserId())) {
|
|
|
+ if (StringUtils.isBlank(userByPhone.getUnionId())) {
|
|
|
+ mergeUserFields(user, userByPhone);
|
|
|
+ } else if (!user.getUnionId().equals(userByPhone.getUnionId())) {
|
|
|
+ return R.error("手机号已注册,请联系您的专属客服");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setPhone(encryptPhone(param.getPhone()));
|
|
|
+ fsUserMapper.updateFsUser(user);
|
|
|
+
|
|
|
+ CompanyUserUser map = new CompanyUserUser();
|
|
|
+ map.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ map.setUserId(currentUserId);
|
|
|
+ List<CompanyUserUser> list = companyUserUserService.selectCompanyUserUserList(map);
|
|
|
+ boolean isNewUser = fsUserCompanyUserMapper.countByUserId(currentUserId) == 0;
|
|
|
+
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser != null && companyUser.getStatus().equals("0")) {
|
|
|
+ map.setCompanyId(companyUser.getCompanyId());
|
|
|
+ map.setIsSend(0);
|
|
|
+ companyUserUserService.insertCompanyUserUser(map);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CompanyUserUser companyUserUser = list.get(0);
|
|
|
+ companyUserUser.setIsSend(0);
|
|
|
+ companyUserUserService.updateCompanyUserUser(companyUserUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isNewUser) {
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser != null && companyUser.getStatus().equals("0")) {
|
|
|
+ issueNewUserCoupon(currentUserId, companyUser);
|
|
|
+ return R.ok().put("msg", "绑定成功,已领取门店核销券");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok().put("msg", "绑定成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void issueNewUserCoupon(Long userId, CompanyUser companyUser) {
|
|
|
+ FsCoupon query = new FsCoupon();
|
|
|
+ query.setCouponType(8);
|
|
|
+ query.setStatus(1);
|
|
|
+ List<FsCoupon> coupons = fsCouponMapper.selectFsCouponList(query);
|
|
|
+ if (coupons == null || coupons.isEmpty()) {
|
|
|
+ throw new CustomException("无可用门店核销券");
|
|
|
+ }
|
|
|
+ FsCoupon coupon = coupons.get(0);
|
|
|
+
|
|
|
+ if (coupon.getRemainNumber() == null || coupon.getRemainNumber() <= 0) {
|
|
|
+ throw new CustomException("门店核销券已领完");
|
|
|
+ }
|
|
|
+ if (coupon.getLimitTime() != null && coupon.getLimitTime().before(new Date())) {
|
|
|
+ throw new CustomException("门店核销券已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ int alreadyReceived = fsUserCouponMapper.selectFsUserCouponByUserIdCount(userId, 8);
|
|
|
+ if (alreadyReceived > 0) {
|
|
|
+ throw new CustomException("用户已领取过门店核销券");
|
|
|
+ }
|
|
|
+
|
|
|
+ String verifyCode = generateUniqueVerifyCode();
|
|
|
+
|
|
|
+ FsUserCoupon userCoupon = new FsUserCoupon();
|
|
|
+ userCoupon.setCouponId(coupon.getCouponId());
|
|
|
+ userCoupon.setCouponCode("C"+System.currentTimeMillis());
|
|
|
+ userCoupon.setUserId(userId);
|
|
|
+ userCoupon.setVerifyCode(verifyCode);
|
|
|
+ userCoupon.setStatus(0);
|
|
|
+ userCoupon.setCompanyId(companyUser.getCompanyId());
|
|
|
+ userCoupon.setCompanyUserId(companyUser.getUserId());
|
|
|
+ userCoupon.setCreateTime(new Date());
|
|
|
+ if (coupon.getLimitDay() != null && coupon.getLimitDay() > 0) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, coupon.getLimitDay());
|
|
|
+ userCoupon.setLimitTime(cal.getTime());
|
|
|
+ }
|
|
|
+ fsUserCouponMapper.insertFsUserCoupon(userCoupon);
|
|
|
+ fsCouponMapper.updateRemainCount(coupon.getCouponId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private String generateUniqueVerifyCode() {
|
|
|
+ java.security.SecureRandom random = new java.security.SecureRandom();
|
|
|
+ String code;
|
|
|
+ int maxRetries = 100;
|
|
|
+ do {
|
|
|
+ code = String.format("%06d", random.nextInt(1000000));
|
|
|
+ maxRetries--;
|
|
|
+ } while (maxRetries > 0 && fsUserCouponMapper.countByVerifyCode(code) > 0);
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
private List<FsUser> findUsersByPhone(String phone) {
|
|
|
// 先根据加密手机号查询用户
|
|
|
String jiami = (encryptPhone(phone));
|