|
@@ -5,15 +5,21 @@ import com.caimei365.user.mapper.OperationMapper;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
import com.caimei365.user.model.dto.OperationDto;
|
|
|
import com.caimei365.user.model.po.OperationPo;
|
|
|
+import com.caimei365.user.model.vo.OperationVo;
|
|
|
+import com.caimei365.user.model.vo.PaginationVo;
|
|
|
import com.caimei365.user.service.OperationService;
|
|
|
import com.caimei365.user.utils.AliyunSmsUtil;
|
|
|
import com.caimei365.user.utils.CodeUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
+import java.util.GregorianCalendar;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -37,58 +43,168 @@ public class OperationServiceImpl implements OperationService {
|
|
|
* linkName 姓名
|
|
|
* userId 用户Id(userID)
|
|
|
* clubId 机构Id
|
|
|
+ * shopId 供应商Id
|
|
|
* configFlag 确认标志
|
|
|
* }
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson addOperation(OperationDto operationDto) {
|
|
|
// 查询使用该手机号的运营人员或用户
|
|
|
-// String checkRust = commonService.operationBindCheck(operationDto.getMobile(), null);
|
|
|
-// if (checkRust != null) {
|
|
|
-// return ResponseJson.error(checkRust, null);
|
|
|
-// }
|
|
|
-// OperationPo operation = new OperationPo();
|
|
|
-// Date date = new Date();
|
|
|
-// // 保存生成邀请码
|
|
|
-// if (operationDto.getConfigFlag() == 2) {
|
|
|
-// //生成随机码6位
|
|
|
-// String invitationCode = generateInvitationCode();
|
|
|
-// operation.setInvitationCode(invitationCode);
|
|
|
-// operation.setInvitationCodeTime(date);
|
|
|
-// operation.setStatus(1);
|
|
|
-// //发送短信
|
|
|
-// String name = null;
|
|
|
-// if (operationDto.getClubId() != null) {
|
|
|
-// name = operationMapper.findClubNameById(operationDto.getClubId());
|
|
|
-// } else {
|
|
|
-// name = operationMapper.findShopNameById(operationDto.getShopId());
|
|
|
-// }
|
|
|
-// String mobile = operationDto.getMobile();
|
|
|
-// boolean sendFlag = false;
|
|
|
-// if (StringUtils.isNotEmpty(mobile)) {
|
|
|
-// sendFlag = AliyunSmsUtil.sendSms(mobile, 11, "{name:"+ name +",code:" + invitationCode + "}");
|
|
|
-// log.info("欢迎成为"+ name +"的运营人员,您的邀请码为:" + invitationCode);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (operationDto.getShopId() == null) {
|
|
|
-// operation.setUserType(1);
|
|
|
-// } else {
|
|
|
-// operation.setUserType(2);
|
|
|
-// }
|
|
|
-// operation.setAddTime(date);
|
|
|
-// operation.setUpdateTime(date);
|
|
|
-// operation.setDelFlag(0);
|
|
|
-// operation.setOrganizeId(0);
|
|
|
-// int flag = 0;
|
|
|
-// if (operation.getId() == null) {
|
|
|
-// operation.setAccount(operationDto.getMobile() + CodeUtil.generateAccount(2));
|
|
|
-// operation.setStatus(1);
|
|
|
-// flag = operationMapper.insertOperation(operation);
|
|
|
-// } else {
|
|
|
-// flag = operationMapper.updateOperation(operation);
|
|
|
-// }
|
|
|
-// return flag > 0 ? ResponseJson.success() : ResponseJson.error();
|
|
|
- return null;
|
|
|
+ String checkRust = commonService.operationBindCheck(operationDto.getMobile(), null);
|
|
|
+ if (checkRust != null) {
|
|
|
+ return ResponseJson.error(checkRust, null);
|
|
|
+ }
|
|
|
+ OperationPo operation = new OperationPo();
|
|
|
+ operation.setId(operationDto.getId());
|
|
|
+ operation.setMobile(operationDto.getMobile());
|
|
|
+ operation.setLinkName(operationDto.getLinkName());
|
|
|
+ operation.setUserId(operationDto.getUserId());
|
|
|
+ operation.setClubId(operationDto.getClubId());
|
|
|
+ operation.setShopId(operationDto.getShopId());
|
|
|
+ Date date = new Date();
|
|
|
+ // 保存生成邀请码
|
|
|
+ if (operationDto.getConfigFlag() == 2) {
|
|
|
+ //生成随机码6位
|
|
|
+ String invitationCode = generateInvitationCode();
|
|
|
+ operation.setInvitationCode(invitationCode);
|
|
|
+ operation.setInvitationCodeTime(date);
|
|
|
+ operation.setStatus(1);
|
|
|
+ //发送短信
|
|
|
+ String name = null;
|
|
|
+ if (operationDto.getClubId() != null) {
|
|
|
+ name = operationMapper.findClubNameById(operationDto.getClubId());
|
|
|
+ } else {
|
|
|
+ name = operationMapper.findShopNameById(operationDto.getShopId());
|
|
|
+ }
|
|
|
+ String mobile = operationDto.getMobile();
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
+ AliyunSmsUtil.sendSms(mobile, 11, "{name:"+ name +",code:" + invitationCode + "}");
|
|
|
+ log.info("欢迎成为"+ name +"的运营人员,您的邀请码为:" + invitationCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (operationDto.getShopId() == null) {
|
|
|
+ operation.setUserType(1);
|
|
|
+ } else {
|
|
|
+ operation.setUserType(2);
|
|
|
+ }
|
|
|
+ operation.setAddTime(date);
|
|
|
+ operation.setUpdateTime(date);
|
|
|
+ operation.setDelFlag(0);
|
|
|
+ operation.setOrganizeId(0);
|
|
|
+ int flag = 0;
|
|
|
+ if (operation.getId() == null) {
|
|
|
+ operation.setAccount(operationDto.getMobile() + CodeUtil.generateAccount(2));
|
|
|
+ operation.setStatus(1);
|
|
|
+ flag = operationMapper.insertOperation(operation);
|
|
|
+ } else {
|
|
|
+ flag = operationMapper.updateOperation(operation);
|
|
|
+ }
|
|
|
+ return flag > 0 ? ResponseJson.success() : ResponseJson.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新邀请码
|
|
|
+ *
|
|
|
+ * @param operationDto {
|
|
|
+ * id 运营人员Id
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateInvitationCode(OperationDto operationDto) {
|
|
|
+ OperationPo operation = operationMapper.getOperationCodeInfoById(operationDto.getId());
|
|
|
+ int flag = 0;
|
|
|
+ if (operation.getStatus() == 2) {
|
|
|
+ return ResponseJson.error("该邀请码已绑定");
|
|
|
+ } else {
|
|
|
+ //生成随机码6位
|
|
|
+ String invitationCode = generateInvitationCode();
|
|
|
+ operation.setInvitationCode(invitationCode);
|
|
|
+ operation.setInvitationCodeTime(new Date());
|
|
|
+ operation.setStatus(1);
|
|
|
+ //发送短信
|
|
|
+ String name = null;
|
|
|
+ if (operation.getClubId() != null) {
|
|
|
+ name = operationMapper.findClubNameById(operation.getClubId());
|
|
|
+ } else {
|
|
|
+ name = operationMapper.findShopNameById(operation.getShopId());
|
|
|
+ }
|
|
|
+ String mobile = operation.getMobile();
|
|
|
+ if (StringUtils.isNotEmpty(mobile)) {
|
|
|
+ AliyunSmsUtil.sendSms(mobile, 11, "{name:"+ name +",code:" + invitationCode + "}");
|
|
|
+ log.info("欢迎成为"+ name +"的运营人员,您的邀请码为:" + invitationCode);
|
|
|
+ }
|
|
|
+ flag = operationMapper.updateOperation(operation);
|
|
|
+ }
|
|
|
+ return flag > 0 ? ResponseJson.success() : ResponseJson.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除运营人员(解绑)
|
|
|
+ *
|
|
|
+ * @param operationDto {
|
|
|
+ * id 运营人员Id
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson unbindOperation(OperationDto operationDto) {
|
|
|
+ int flag = commonService.unbindOperation(operationDto.getId());
|
|
|
+ return flag > 0 ? ResponseJson.success() : ResponseJson.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取运营人员列表
|
|
|
+ *
|
|
|
+ * @param operationDto {
|
|
|
+ * mobile 手机号
|
|
|
+ * linkName 姓名
|
|
|
+ * userId 用户Id(userID)
|
|
|
+ * }
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PaginationVo<OperationVo>> getOperationList(OperationDto operationDto, int pageNum, int pageSize) {
|
|
|
+ Integer userId = operationDto.getUserId();
|
|
|
+ String mobile = operationDto.getMobile();
|
|
|
+ String linkName = operationDto.getLinkName();
|
|
|
+ if (userId == null) {
|
|
|
+ return ResponseJson.error("参数错误:userId不能为空!", null);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<OperationVo> operationList = operationMapper.getOperationListByUserId(userId, mobile, linkName);
|
|
|
+ if (null != operationList) {
|
|
|
+ // 判断邀请码是否有效
|
|
|
+ for (OperationVo operation : operationList) {
|
|
|
+ // 1未绑定,2已绑定
|
|
|
+ if (operation.getStatus() == 2) {
|
|
|
+ // 邀请码是否有效 1有效,2已使用,3已失效
|
|
|
+ operation.setEffectiveFlag(2);
|
|
|
+ } else {
|
|
|
+ Date invitationCodeTime = operation.getInvitationCodeTime();
|
|
|
+ if (null != invitationCodeTime) {
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
+ calendar.setTime(invitationCodeTime);
|
|
|
+ // num为增加的天数,可以改变的
|
|
|
+ calendar.add(Calendar.DATE, 7);
|
|
|
+ invitationCodeTime = calendar.getTime();
|
|
|
+ boolean before = invitationCodeTime.before(new Date());
|
|
|
+ if (before) {
|
|
|
+ //如果验证码时间加上168小时小于当前时间则已过期
|
|
|
+ operation.setEffectiveFlag(3);
|
|
|
+ } else {
|
|
|
+ operation.setEffectiveFlag(1);
|
|
|
+ long time = operation.getInvitationCodeTime().getTime();
|
|
|
+ long now = (new Date()).getTime();
|
|
|
+ int days = (int) ((now - time) / (1000 * 60 * 60 * 24));
|
|
|
+ int effectiveDays = 7 - days;
|
|
|
+ operation.setEffectiveDays(effectiveDays);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PaginationVo<OperationVo> pageData = new PaginationVo<>(operationList);
|
|
|
+ return ResponseJson.success(pageData);
|
|
|
}
|
|
|
|
|
|
|