添加:消息插件
This commit is contained in:
parent
212fe1afb4
commit
f57cba1784
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace addon\message\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class Message extends BaseModel{
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = 'a.*', $alias = 'a', $join = []){
|
||||
$list = model('message_center')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
/**
|
||||
* Common: 添加消息
|
||||
* Author: wu-hui
|
||||
* Time: 2023/03/04 14:09
|
||||
* @param int $siteId
|
||||
* @param string $content
|
||||
* @param int $type
|
||||
* @param string|int $member_id
|
||||
* @param int $orderId
|
||||
* @return array
|
||||
*/
|
||||
public function addMessage(int $siteId,string $content,int $type,$member_id = 'all',int $orderId = 0){
|
||||
if(!$content) return $this->error('','消息不能为空!');
|
||||
// 记录消息信息
|
||||
try{
|
||||
$messageId = Db::name('message_center')
|
||||
->insertGetId([
|
||||
'site_id' => $siteId,
|
||||
'type' => $type,
|
||||
'message_content' => $content,
|
||||
'created_time' => time()
|
||||
]);
|
||||
// 关联用户信息
|
||||
if($member_id == 'all'){
|
||||
// 发送给全部用户的消息
|
||||
$time = time();
|
||||
$insertData = Db::name('member')
|
||||
->field("site_id,member_id,{$messageId} as message_center_id,{$time} as created_time")
|
||||
->where('site_id',$siteId)
|
||||
->select();
|
||||
if($insertData){
|
||||
$insertData = $insertData->toArray();
|
||||
Db::name('message_center_read')->insertAll($insertData);
|
||||
}
|
||||
}
|
||||
else{
|
||||
// 发送给某个用户
|
||||
Db::name('message_center_read')
|
||||
->insert([
|
||||
'site_id' => $siteId,
|
||||
'member_id' => $member_id,
|
||||
'created_time' => time(),
|
||||
'order_id' => $orderId,
|
||||
'message_center_id' => $messageId,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}catch(Exception $e){
|
||||
return $this->error('',$e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -11,12 +11,50 @@
|
|||
* ==========================================================
|
||||
*/
|
||||
namespace addon\message\shop\controller;
|
||||
|
||||
use app\shop\controller\BaseShop;
|
||||
use addon\futures\model\Futures as futuresModel;
|
||||
use addon\message\model\Message as messageModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Message extends BaseShop{
|
||||
// 进入消息中心
|
||||
public function index(){
|
||||
if(request()->isAjax()){
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
debug(table('message_center_read'));
|
||||
// 参数获取
|
||||
$page = input('page',1);
|
||||
$pageSize = input('page_size',PAGE_LIST_ROWS);
|
||||
// 获取内容
|
||||
$field = [
|
||||
'a.id',
|
||||
'a.type',
|
||||
'a.created_time',
|
||||
'count(a.id) as total',
|
||||
'(select count(id) from )',
|
||||
|
||||
];
|
||||
// 表关联
|
||||
$join = [
|
||||
['message_center_read mcr', 'mcr.message_center_id = a.id', 'left'],
|
||||
];
|
||||
// 条件生成
|
||||
$condition = [
|
||||
['a.site_id','=',$this->site_id]
|
||||
];
|
||||
$res = (new messageModel())->getPageList($condition, $page, $pageSize, 'a.created_time desc,a.id desc', $field, 'a', $join);
|
||||
|
||||
debug($res);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -24,10 +62,22 @@ class Message extends BaseShop{
|
|||
$this->forthMenu();
|
||||
return $this->fetch('message/index');
|
||||
}
|
||||
/**
|
||||
* Common: 消息发布
|
||||
* Author: wu-hui
|
||||
* Time: 2023/03/04 14:10
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function sendMessage(){
|
||||
if(request()->isAjax()){
|
||||
// 参数获取
|
||||
$type = input('type',2);
|
||||
$content = input('message_content','');
|
||||
|
||||
return (new messageModel())->addMessage($this->site_id,$content,$type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->fetch('message/send_message');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +1,11 @@
|
|||
{extend name="app/shop/view/base.html"/}
|
||||
{block name="resources"}
|
||||
<style>
|
||||
.prompt-block .prompt {
|
||||
display: inline-block;
|
||||
}
|
||||
.prompt-block .prompt {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
position: relative;
|
||||
}
|
||||
.user-head-img{
|
||||
width:40px;
|
||||
height:40px;
|
||||
margin-right:20px;
|
||||
}
|
||||
.time_p{
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.publish-btn{
|
||||
background-color: #009688;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
{/block}
|
||||
|
||||
|
|
@ -76,6 +62,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<button class="layui-btn publish-btn" lay-submit lay-filter="publish">发布</button>
|
||||
<button class="layui-btn" lay-submit lay-filter="search">筛选</button>
|
||||
<button type="reset" lay-submit lay-filter="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
|
|
@ -181,6 +168,19 @@
|
|||
{title: '操作', toolbar: '#operation', unresize: 'false', align: 'right'}
|
||||
]],
|
||||
});
|
||||
// 点击发布
|
||||
form.on('submit(publish)', function(data) {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '消息发布',
|
||||
skin: 'layer-tips-class',
|
||||
area: ['80%','90%'],
|
||||
content: ns.url("message://shop/message/sendMessage"),
|
||||
end: function(){
|
||||
table.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
// 点击搜索
|
||||
form.on('submit(search)', function(data) {
|
||||
table.reload({
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
{extend name="app/shop/view/base.html"/}
|
||||
{block name="resources"}
|
||||
<style>
|
||||
.tips{
|
||||
font-size: 13px;
|
||||
color: #cccccc;
|
||||
}
|
||||
.hide{
|
||||
display: none;
|
||||
}
|
||||
.goods-list{
|
||||
width: calc(100% - 230px);
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
margin-left: 200px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.goods-list .goods-item{
|
||||
position: relative;
|
||||
margin-top: 10px;
|
||||
margin-right: 10px;
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 1px solid #cccccc;
|
||||
padding: 10px;
|
||||
}
|
||||
.goods-list .goods-item .image{
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.goods-list .goods-item .image .image-img{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.goods-list .goods-item .info{
|
||||
width: 150px;
|
||||
}
|
||||
.goods-list .goods-item .info .name{
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical; /*设置对齐模式*/
|
||||
-webkit-line-clamp: 2; /*设置多行的行数*/
|
||||
}
|
||||
.goods-list .goods-item .del-button{
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
font-size: 25px;
|
||||
color: #e30000;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
{/block}
|
||||
|
||||
{block name="body"}
|
||||
<div class="layui-form form-wrap" lay-filter="formInfo">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label img-upload-lable short-label">消息类型:</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="type">
|
||||
<option value="2">系统消息</option>
|
||||
<option value="3">通知消息</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label img-upload-lable short-label"><span class="required">*</span>消息内容:</label>
|
||||
<div class="layui-input-inline">
|
||||
<textarea name="message_content" class="layui-textarea len-long" rows="15"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<!--提交按钮-->
|
||||
<div class="form-row">
|
||||
<button class="layui-btn" lay-submit lay-filter="save">提交</button>
|
||||
<button class="layui-btn layui-btn-primary" onclick="closeIframe()">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="script"}
|
||||
<script>
|
||||
var _thisIndex,form,repeat_flag = false,goods_info = {};
|
||||
$(function () {
|
||||
// 基本参数
|
||||
_thisIndex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
|
||||
// 表单内容
|
||||
layui.use(['form'], function() {
|
||||
form = layui.form;
|
||||
form.render();
|
||||
// 表单提交
|
||||
form.on('submit(save)', function(data){
|
||||
var field = data.field;
|
||||
// 判断信息是否完整
|
||||
if(!field['message_content']){
|
||||
layer.msg('请输入消息内容!');
|
||||
return false;
|
||||
}
|
||||
// 数据提交
|
||||
layer.confirm('确认发布当前消息给所有用户?', {icon: 3, title:'提示'}, function(index){
|
||||
layer.close(index);
|
||||
if(repeat_flag) return;
|
||||
repeat_flag = true;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
url: ns.url("message://shop/message/sendMessage"),
|
||||
data: field,
|
||||
async: false,
|
||||
success: function(res){
|
||||
repeat_flag = false;
|
||||
if (res.code == 0) {
|
||||
layer.alert('发布成功', function(index){
|
||||
parent.layer.close(_thisIndex);
|
||||
});
|
||||
}else{
|
||||
layer.msg(res.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// 点击关闭弹框
|
||||
function closeIframe() {
|
||||
parent.layer.close(_thisIndex); //再执行关闭
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
Loading…
Reference in New Issue