新增在线发送短信功能,处理了短信发送逻辑

This commit is contained in:
wanggeng 2021-10-22 18:14:40 +08:00
parent ebdc524c48
commit d1bd705350
12 changed files with 421 additions and 116 deletions

View File

@ -3,9 +3,9 @@ package ink.wgink.module.sms.controller.api.sms;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.RemoveException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.ListPage;
@ -16,7 +16,6 @@ import ink.wgink.util.RegexUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.AbstractController;
import java.util.Arrays;
import java.util.List;
@ -40,6 +39,15 @@ public class SmsController extends DefaultBaseController {
@Autowired
private ISmsService smsService;
@ApiOperation(value = "发送短信", notes = "发送短信接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("send")
@CheckRequestBodyAnnotation
public SuccessResult send(@RequestBody SmsSendVO smsSendVO) throws Exception {
smsService.send(smsSendVO);
return new SuccessResult();
}
@ApiOperation(value = "新增短信", notes = "新增短信接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")

View File

@ -29,4 +29,11 @@ public class SmsRouteController {
return mv;
}
@GetMapping("send")
public ModelAndView send() {
ModelAndView mv = new ModelAndView();
mv.setViewName("sms/send");
return mv;
}
}

View File

@ -60,9 +60,9 @@ public class DefaultSmsSendImpl implements ISmsSend {
String result = restTemplate.getForObject(URL_SMS, String.class, paramArray);
JSONObject jsonObject = XML.toJSONObject(result);
if (StringUtils.equals("Success", jsonObject.getJSONObject("returnsms").getString("returnstatus"))) {
LOG.info("验证码发送成功");
LOG.info("短信发送成功");
} else {
LOG.error("验证码发送失败,原因:{}。", jsonObject);
LOG.error("短信发送失败,原因:{}。", jsonObject);
throw new SystemException(jsonObject.toString());
}
}

View File

@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: SmsDTO
* @Description: 短信
* @Author: WenG
@ -16,8 +15,12 @@ public class SmsDTO {
@ApiModelProperty(name = "smsId", value = "主键")
private String smsId;
@ApiModelProperty(name = "userId", value = "用户ID")
private String userId;
@ApiModelProperty(name = "phone", value = "电话")
private String phone;
@ApiModelProperty(name = "userName", value = "用户昵称")
private String userName;
@ApiModelProperty(name = "content", value = "发送内容")
private String content;
@ApiModelProperty(name = "sendStatus", value = "发送状态")
@ -34,6 +37,15 @@ public class SmsDTO {
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getUserId() {
return userId == null ? "" : userId.trim();
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPhone() {
return phone == null ? "" : phone;
}
@ -42,6 +54,14 @@ public class SmsDTO {
this.phone = phone;
}
public String getUserName() {
return userName == null ? "" : userName.trim();
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getContent() {
return content == null ? "" : content;
}
@ -74,22 +94,4 @@ public class SmsDTO {
this.gmtCreate = gmtCreate;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"smsId\":\"")
.append(smsId).append('\"');
sb.append(",\"phone\":\"")
.append(phone).append('\"');
sb.append(",\"content\":\"")
.append(content).append('\"');
sb.append(",\"sendStatus\":")
.append(sendStatus);
sb.append(",\"errorMessage\":\"")
.append(errorMessage).append('\"');
sb.append(",\"gmtCreate\":\"")
.append(gmtCreate).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -1,8 +1,5 @@
package ink.wgink.module.sms.pojo.pos.sms;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @ClassName: SmsDTO
@ -14,29 +11,48 @@ import io.swagger.annotations.ApiModelProperty;
public class SmsPO {
private String smsId;
private String userId;
private String phone;
private String userName;
private String content;
private Integer sendStatus;
private String errorMessage;
private String gmtCreate;
public String getSmsId() {
return smsId == null ? "" : smsId;
return smsId == null ? "" : smsId.trim();
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getUserId() {
return userId == null ? "" : userId.trim();
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPhone() {
return phone == null ? "" : phone;
return phone == null ? "" : phone.trim();
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getUserName() {
return userName == null ? "" : userName.trim();
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getContent() {
return content == null ? "" : content;
return content == null ? "" : content.trim();
}
public void setContent(String content) {
@ -52,7 +68,7 @@ public class SmsPO {
}
public String getErrorMessage() {
return errorMessage == null ? "" : errorMessage;
return errorMessage == null ? "" : errorMessage.trim();
}
public void setErrorMessage(String errorMessage) {
@ -60,29 +76,10 @@ public class SmsPO {
}
public String getGmtCreate() {
return gmtCreate == null ? "" : gmtCreate;
return gmtCreate == null ? "" : gmtCreate.trim();
}
public void setGmtCreate(String gmtCreate) {
this.gmtCreate = gmtCreate;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"smsId\":\"")
.append(smsId).append('\"');
sb.append(",\"phone\":\"")
.append(phone).append('\"');
sb.append(",\"content\":\"")
.append(content).append('\"');
sb.append(",\"sendStatus\":")
.append(sendStatus);
sb.append(",\"errorMessage\":\"")
.append(errorMessage).append('\"');
sb.append(",\"gmtCreate\":\"")
.append(gmtCreate).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,40 @@
package ink.wgink.module.sms.pojo.vos.sms;
import ink.wgink.annotation.CheckEmptyAnnotation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* @ClassName: SmsVO
* @Description: 短信
* @Author: WenG
* @Date: 2020-03-14 16:01
* @Version: 1.0
**/
@ApiModel
public class SmsSendVO {
@ApiModelProperty(name = "userIds", value = "用户ID列表")
@CheckEmptyAnnotation(name = "用户ID列表")
private String userIds;
@ApiModelProperty(name = "content", value = "发送内容")
@CheckEmptyAnnotation(name = "发送内容")
private String content;
public String getUserIds() {
return userIds == null ? "" : userIds.trim();
}
public void setUserIds(String userIds) {
this.userIds = userIds;
}
public String getContent() {
return content == null ? "" : content;
}
public void setContent(String content) {
this.content = content;
}
}

View File

@ -15,6 +15,12 @@ import io.swagger.annotations.ApiModelProperty;
@ApiModel
public class SmsVO {
@ApiModelProperty(name = "userId", value = "用户ID")
@CheckEmptyAnnotation(name = "用户ID")
private String userId;
@ApiModelProperty(name = "userName", value = "用户昵称")
@CheckEmptyAnnotation(name = "用户昵称")
private String userName;
@ApiModelProperty(name = "phone", value = "电话")
@CheckEmptyAnnotation(name = "电话", verifyType = "phone")
private String phone;
@ -26,6 +32,22 @@ public class SmsVO {
@ApiModelProperty(name = "errorMessage", value = "错误信息")
private String errorMessage;
public String getUserId() {
return userId == null ? "" : userId.trim();
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName == null ? "" : userName.trim();
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPhone() {
return phone == null ? "" : phone;
}
@ -58,18 +80,4 @@ public class SmsVO {
this.errorMessage = errorMessage;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"phone\":\"")
.append(phone).append('\"');
sb.append(",\"content\":\"")
.append(content).append('\"');
sb.append(",\"sendStatus\":")
.append(sendStatus);
sb.append(",\"errorMessage\":\"")
.append(errorMessage).append('\"');
sb.append('}');
return sb.toString();
}
}

View File

@ -2,6 +2,7 @@ package ink.wgink.module.sms.service.sms;
import ink.wgink.interfaces.sms.ISmsBaseService;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList;
@ -71,10 +72,12 @@ public interface ISmsService extends ISmsBaseService {
/**
* 发送短信
*
* @param phone
* @param content
* @param userId 用户ID
* @param phone 用户手机
* @param userName 用户昵称
* @param content 发送内容
*/
void sendContent(String phone, String content);
void sendContentByUserIdAndPhoneAndUserName(String userId, String phone, String userName, String content);
/**
* 发送验证码
@ -83,5 +86,10 @@ public interface ISmsService extends ISmsBaseService {
*/
void sendVerifyCode(String phone);
/**
* 发送短信
*
* @param smsSendVO
*/
void send(SmsSendVO smsSendVO);
}

View File

@ -5,22 +5,29 @@ import com.github.pagehelper.PageInfo;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.interfaces.user.IUserBaseService;
import ink.wgink.module.sms.dao.sms.ISmsDao;
import ink.wgink.module.sms.factory.sms.SmsSendFactory;
import ink.wgink.module.sms.manager.VerifyCodeManager;
import ink.wgink.module.sms.pojo.dtos.sms.SmsDTO;
import ink.wgink.module.sms.pojo.vos.sms.SmsSendVO;
import ink.wgink.module.sms.pojo.vos.sms.SmsVO;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.properties.sms.SmsProperties;
import ink.wgink.util.RegexUtil;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.map.HashMapUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* When you feel like quitting. Think about why you started
@ -39,6 +46,9 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
private SmsProperties smsProperties;
@Autowired
private ISmsDao smsDao;
@Autowired
private IUserBaseService userBaseService;
private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(2);
@Override
public void save(SmsVO smsVO) {
@ -82,8 +92,10 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
}
@Override
public void sendContent(String phone, String content) {
public void sendContentByUserIdAndPhoneAndUserName(String userId, String phone, String userName, String content) {
SmsVO smsVO = new SmsVO();
smsVO.setUserId(userId);
smsVO.setUserName(userName);
smsVO.setPhone(phone);
smsVO.setContent(content);
try {
@ -129,8 +141,52 @@ public class SmsServiceImpl extends DefaultBaseService implements ISmsService {
}
}
@Override
public void send(SmsSendVO smsSendVO) {
List<String> userIds = Arrays.asList(smsSendVO.getUserIds().split("\\_"));
List<UserDTO> userDTOs = userBaseService.listByUserIds(userIds);
for (UserDTO userDTO : userDTOs) {
if (!RegexUtil.isPhone(userDTO.getUserUsername())) {
throw new ParamsException(userDTO.getUserName() + " 的用户名不是手机号");
}
}
scheduledExecutorService.schedule(() -> {
for (UserDTO userDTO : userDTOs) {
sendContentByUserIdAndPhoneAndUserName(userDTO.getUserId(), userDTO.getUserUsername(), userDTO.getUserName(), smsSendVO.getContent());
}
}, 3, TimeUnit.SECONDS);
}
@Override
public String getVerifyCode(String phone) {
return VerifyCodeManager.getInstance().getVerifyCode(phone);
}
/**
* 设置用户
*
* @param smsDTOs
*/
private void setUser(List<SmsDTO> smsDTOs) {
if (smsDTOs.isEmpty()) {
return;
}
Set<String> usernameSet = new HashSet<>();
for (SmsDTO smsDTO : smsDTOs) {
usernameSet.add(smsDTO.getPhone());
}
List<UserDTO> userDTOs = userBaseService.listByUsernames(new ArrayList<>(usernameSet));
if (userDTOs.isEmpty()) {
return;
}
for (SmsDTO smsDTO : smsDTOs) {
for (UserDTO userDTO : userDTOs) {
if (StringUtils.equals(smsDTO.getPhone(), userDTO.getUserUsername())) {
smsDTO.setUserName(userDTO.getUserName());
break;
}
}
}
}
}

View File

@ -4,15 +4,20 @@
<resultMap id="smsDTO" type="ink.wgink.module.sms.pojo.dtos.sms.SmsDTO">
<id column="sms_id" property="smsId"/>
<result column="user_id" property="userId"/>
<result column="phone" property="phone"/>
<result column="user_name" property="userName"/>
<result column="content" property="content"/>
<result column="send_status" property="sendStatus"/>
<result column="error_message" property="errorMessage"/>
<result column="gmt_create" property="gmtCreate"/>
</resultMap>
<resultMap id="smsPO" type="ink.wgink.module.sms.pojo.pos.sms.SmsPO">
<id column="sms_id" property="smsId"/>
<result column="user_id" property="userId"/>
<result column="phone" property="phone"/>
<result column="user_name" property="userName"/>
<result column="content" property="content"/>
<result column="send_status" property="sendStatus"/>
<result column="error_message" property="errorMessage"/>
@ -24,7 +29,9 @@
CREATE TABLE IF NOT EXISTS `sms_sms` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`sms_id` char(36) NOT NULL COMMENT '主键',
`user_id` char(36) DEFAULT NULL COMMENT '用户ID',
`phone` varchar(255) DEFAULT NULL COMMENT '电话',
`user_name` varchar(255) DEFAULT NULL COMMENT '昵称',
`content` varchar(255) DEFAULT NULL COMMENT '发送内容',
`send_status` int(11) DEFAULT NULL COMMENT '发送状态',
`error_message` varchar(255) DEFAULT NULL COMMENT '错误信息',
@ -38,14 +45,16 @@
KEY `phone` (`phone`),
KEY `send_status` (`send_status`),
KEY `is_delete` (`is_delete`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
</update>
<!-- 新增短信 -->
<insert id="save" parameterType="map">
INSERT INTO sms_sms(
sms_id,
user_id,
phone,
user_name,
content,
send_status,
error_message,
@ -56,7 +65,9 @@
is_delete
) VALUES(
#{smsId},
#{userId},
#{phone},
#{userName},
#{content},
#{sendStatus},
#{errorMessage},
@ -109,7 +120,9 @@
<!-- 短信详情 -->
<select id="get" parameterType="map" resultMap="smsDTO">
SELECT
t1.user_id,
t1.phone,
t1.user_name,
t1.content,
t1.send_status,
t1.error_message,
@ -127,7 +140,9 @@
<!-- 短信详情 -->
<select id="getPO" parameterType="map" resultMap="smsPO">
SELECT
t1.user_id,
t1.phone,
t1.user_name,
t1.content,
t1.send_status,
t1.error_message,
@ -145,10 +160,13 @@
<!-- 短信列表 -->
<select id="list" parameterType="map" resultMap="smsDTO">
SELECT
t1.user_id,
t1.phone,
t1.user_name,
t1.content,
t1.send_status,
t1.error_message,
LEFT(t1.gmt_create, 19) gmt_create,
t1.sms_id
FROM
sms_sms t1
@ -156,6 +174,8 @@
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND (
t1.user_name LIKE CONCAT('%', #{keywords}, '%')
OR
t1.phone LIKE CONCAT('%', #{keywords}, '%')
OR
t1.content LIKE CONCAT('%', #{keywords}, '%')
@ -169,11 +189,18 @@
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="phones != null and phones.size > 0">
AND
t1.phone IN
<foreach collection="phones" index="index" open="(" separator="," close=")">
#{phones[${index}]}
</foreach>
</if>
<if test="smsIds != null and smsIds.size > 0">
AND
t1.sms_id IN
<foreach collection="smsIds" index="index" open="(" separator="," close=")">
#{smsIds[${index}]}
#{smsIds[${index}]}
</foreach>
</if>
</select>
@ -181,7 +208,9 @@
<!-- 短信列表 -->
<select id="listPO" parameterType="map" resultMap="smsPO">
SELECT
t1.user_id,
t1.phone,
t1.user_name,
t1.content,
t1.send_status,
t1.error_message,

View File

@ -18,13 +18,14 @@
<div class="layui-card-body">
<div class="test-table-reload-btn" style="margin-bottom: 10px;">
<div class="layui-inline">
<input type="text" id="keywords" class="layui-input search-item" placeholder="输入关键字">
<input type="text" id="keywords" class="layui-input search-item search-item-width-100" placeholder="输入关键字">
</div>
发送时间
<div class="layui-inline">
<input type="text" id="startTime" class="layui-input search-item search-item-width-100" placeholder="开始时间" readonly>
</div>
<div class="layui-inline">
<input type="text" id="startTime" class="layui-input search-item" placeholder="开始时间" readonly>
</div>
<div class="layui-inline">
<input type="text" id="endTime" class="layui-input search-item" placeholder="结束时间" readonly>
<input type="text" id="endTime" class="layui-input search-item search-item-width-100" placeholder="结束时间" readonly>
</div>
<button type="button" id="search" class="layui-btn layui-btn-sm">
<i class="fa fa-lg fa-search"></i> 搜索
@ -76,46 +77,72 @@
pageName: 'page',
limitName: 'rows'
},
cols: [[
{type:'checkbox', fixed: 'left'},
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
{field: 'phone', width: 200, title: '电话', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
cols: [
[
{type:'checkbox', fixed: 'left'},
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
{field: 'userName', width: 200, title: '用户昵称', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
return rowData;
}
},
{field: 'content', width: 300, title: '发送内容', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
},
{field: 'phone', width: 200, title: '电话', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
return rowData;
}
},
{field: 'sendStatus', width: 100, title: '发送状态', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
},
{field: 'content', width: 300, title: '发送内容', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
return rowData;
}
},
{field: 'errorMessage', width: 200, title: '错误信息', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
},
{field: 'sendStatus', width: 100, title: '发送状态', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null) {
return '-';
}
if(rowData == 0) {
return '<span class="layui-btn layui-btn-xs layui-btn-danger">发送失败</span>';
}
if(rowData == 1) {
return '<span class="layui-btn layui-btn-xs">发送成功</span>';
}
return rowData;
}
return rowData;
}
},
]],
},
{field: 'errorMessage', width: 200, title: '错误信息', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
},
{field: 'gmtCreate', width: 180, title: '发送时间', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
},
]
],
page: true,
parseData: function(data) {
return {
@ -130,7 +157,6 @@
// 重载表格
function reloadTable(currentPage) {
table.reload('dataTable', {
url: top.restAjax.path(tableUrl, []),
where: {
keywords: $('#keywords').val(),
startTime: $('#startTime').val(),
@ -139,7 +165,6 @@
page: {
curr: currentPage
},
height: $win.height() - 90,
});
}
// 初始化日期

View File

@ -0,0 +1,125 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<base th:href="${#request.getContextPath() + '/'}">
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
<div class="layui-card">
<blockquote class="layui-elem-quote layui-quote-nm">用户名必须是手机号时才能正常发送</blockquote>
<div class="layui-card-body" style="padding: 15px;">
<form class="layui-form layui-form-pane" lay-filter="dataForm">
<div class="layui-form-item">
<label class="layui-form-label">接收人</label>
<div class="layui-input-block">
<input type="hidden" id="userIds" name="userIds">
<input type="text" id="userNames" name="userNames" class="layui-input" value="" placeholder="请选择接收人" lay-verify="required" readonly style="cursor:pointer;">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">短信内容</label>
<div class="layui-input-block">
<textarea name="content" placeholder="请输入通知内容最多80字" class="layui-textarea" rows="10" lay-verify="required" maxlength="80"></textarea>
</div>
</div>
<button type="button" class="layui-btn" lay-submit lay-filter="submitForm">发送短信</button>
</form>
</div>
</div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
layui.config({
base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate', 'laytpl'], function(){
var $ = layui.$;
var form = layui.form;
var laytpl = layui.laytpl;
var laydate = layui.laydate;
function closeBox() {
parent.layer.close(parent.layer.getFrameIndex(window.name));
}
// 初始化内容
function initData() {
}
initData();
// 提交表单
form.on('submit(submitForm)', function(formData) {
top.dialog.confirm(top.dataMessage.commit, function(index) {
top.dialog.close(index);
var loadLayerIndex;
top.restAjax.post(top.restAjax.path('api/sms/send', []), formData.field, null, function(code, data) {
var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
time: 0,
btn: [top.dataMessage.button.yes],
shade: 0.3,
yes: function(index) {
top.dialog.close(index);
window.location.reload();
}
});
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
});
return false;
});
$('#userNames').on('click', function() {
top.dialog.dialogData.selectedUserIds = $('#userIds').val();
top.dialog.open({
url: top.restAjax.path('route/department/user/select-user', []),
title: '选择用户',
width: '500px',
height: '500px',
closeBtn: 0,
onClose: function() {
var selectedUsers = top.dialog.dialogData.selectedDepartmentUsers;
console.log(selectedUsers);
// 这里写处理逻辑
var userIds = '';
var userPhones = '';
var userNames = '';
if(selectedUsers && selectedUsers.length > 0) {
for(var i = 0, item; item = selectedUsers[i++]; ) {
if(userIds.length > 0) {
userIds += '_';
userNames += ',';
}
userIds += item.userId;
userNames += item.userName + '【' + item.username + '】';
}
}
$('#userIds').val(userIds);
$('#userNames').val(userNames);
}
})
})
$('.close').on('click', function() {
closeBox();
});
// 校验
form.verify({
});
});
</script>
</body>
</html>