用户消息

This commit is contained in:
devil_gong
2018-10-15 11:17:14 +08:00
parent c7b6916c3c
commit ddfb8066cc
14 changed files with 400 additions and 69 deletions

View File

@ -424,7 +424,7 @@ return array(
// 消息类型
'common_message_type_list' => array(
0 => array('id' => 0, 'name' => '普通通知', 'checked' => true),
0 => array('id' => 0, 'name' => '默认', 'checked' => true),
),
// 支付类型
@ -435,7 +435,8 @@ return array(
// 业务类型
'common_business_type_list' => array(
0 => array('id' => 0, 'name' => '订单', 'checked' => true),
0 => array('id' => 0, 'name' => '默认', 'checked' => true),
1 => array('id' => 1, 'name' => '订单'),
),
// 用户积分 - 操作类型

View File

@ -6,6 +6,7 @@ use Think\Controller;
use Service\GoodsService;
use Service\NavigationService;
use Service\BuyService;
use Service\MessageService;
/**
* 前台
@ -161,9 +162,14 @@ class CommonController extends Controller
$this->assign('goods_category_list', GoodsService::GoodsCategory());
// 购物车商品总数
$common_cart_total = BuyService::CartTotal(['user'=>$this->user]);
$common_cart_total = BuyService::UserCartTotal(['user'=>$this->user]);
$this->assign('common_cart_total', ($common_cart_total > 99) ? '99+' : $common_cart_total);
// 未读消息总数
$params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0];
$common_message_total = MessageService::UserMessageTotal($params);
$this->assign('common_message_total', ($common_message_total > 99) ? '99+' : $common_message_total);
// 当前控制器名称
$this->assign('controller_name', CONTROLLER_NAME);
}

View File

@ -0,0 +1,92 @@
<?php
namespace Home\Controller;
use Service\MessageService;
/**
* 消息管理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class MessageController extends CommonController
{
/**
* [_initialize 前置操作-继承公共前置方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-03T12:39:08+0800
*/
public function _initialize()
{
// 调用父类前置方法
parent::_initialize();
// 是否登录
$this->Is_Login();
}
/**
* 消息列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-28
* @desc description
*/
public function Index()
{
// 参数
$params = array_merge($_POST, $_GET);
$params['user'] = $this->user;
// 分页
$number = 10;
// 条件
$where = MessageService::UserMessgeListWhere($params);
// 获取总数
$total = MessageService::MessageTotal($where);
// 分页
$page_params = array(
'number' => $number,
'total' => $total,
'where' => $params,
'url' => U('Home/Message/Index'),
);
$page = new \Library\Page($page_params);
$this->assign('page_html', $page->GetPageHtml());
// 获取列表
$data_params = array(
'limit_start' => $page->GetPageStarNumber(),
'limit_number' => $number,
'where' => $where,
);
$data = MessageService::MessageList($data_params);
$this->assign('data_list', $data['data']);
// 消息更新未已读
MessageService::MessageRead($params);
// 业务类型
$this->assign('common_business_type_list', L('common_business_type_list'));
// 消息类型
$this->assign('common_message_type_list', L('common_message_type_list'));
// 是否已读
$this->assign('common_is_read_list', L('common_is_read_list'));
// 参数
$this->assign('params', $params);
$this->display('Index');
}
}
?>

View File

@ -48,7 +48,7 @@ class OrderController extends CommonController
$number = 10;
// 条件
$where = OrderService::HomeOrderListWhere($params);
$where = OrderService::UserOrderListWhere($params);
// 获取总数
$total = OrderService::OrderTotal($where);
@ -107,7 +107,7 @@ class OrderController extends CommonController
$params['user'] = $this->user;
// 条件
$where = OrderService::HomeOrderListWhere($params);
$where = OrderService::UserOrderListWhere($params);
// 获取列表
$data_params = array(
@ -144,7 +144,7 @@ class OrderController extends CommonController
$params['user'] = $this->user;
// 条件
$where = OrderService::HomeOrderListWhere($params);
$where = OrderService::UserOrderListWhere($params);
// 获取列表
$data_params = array(

View File

@ -0,0 +1,134 @@
<include file="Public/Header" />
<!-- header top nav -->
<include file="Public/HeaderTopNav" />
<!-- search -->
<include file="Public/NavSearch" />
<!-- header nav -->
<include file="Public/HeaderNav" />
<!-- goods category -->
<include file="Public/GoodsCategory" />
<!-- content -->
<div class="am-container user-main">
<!-- user menu start -->
<include file="Public/UserMenu" />
<!-- user menu end -->
<!-- content start -->
<div class="user-content">
<div class="user-content-body">
<form class="am-form form-validation" method="post" action="{{:U('Home/Message/Index')}}" request-type="form">
<div class="thin">
<div class="am-input-group am-input-group-sm am-fl so">
<input type="text" name="keywords" class="am-radius" placeholder="其实搜索很简单 ^_^" value="<notempty name="params.keywords">{{$params.keywords}}</notempty>" />
<span class="am-input-group-btn">
<button class="am-btn am-btn-default am-radius" type="submit" data-am-loading="{spinner:'circle-o-notch', loadingText:'搜索中...'}">搜索</button>
</span>
</div>
<label class="am-fl thin_sub more-submit">
更多筛选条件
<input type="checkbox" name="is_more" value="1" class="none am-field-valid" <if condition="isset($params['is_more'])">checked</if> />
<i class="am-icon-angle-up"></i>
</label>
</div>
<table class="so-list more-where <if condition="!isset($params['is_more'])">none</if>">
<tbody>
<tr>
<td>
<span>类型:</span>
<select name="type" class="chosen-select" data-placeholder="业务类型...">
<option value="-1">消息类型...</option>
<notempty name="common_message_type_list">
<foreach name="common_message_type_list" item="v">
<option value="{{$v.id}}" <if condition="isset($params['type']) and $params['type'] eq $v['id']">selected</if>>{{$v.name}}</option>
</foreach>
</notempty>
</select>
</td>
<td>
<span>业务:</span>
<select name="business_type" class="chosen-select" data-placeholder="业务类型...">
<option value="-1">业务类型...</option>
<notempty name="common_business_type_list">
<foreach name="common_business_type_list" item="v">
<option value="{{$v.id}}" <if condition="isset($params['business_type']) and $params['business_type'] eq $v['id']">selected</if>>{{$v.name}}</option>
</foreach>
</notempty>
</select>
</td>
</tr>
<tr>
<td>
<span>状态:</span>
<select name="is_read" class="chosen-select" data-placeholder="消息状态...">
<option value="-1">消息状态...</option>
<notempty name="common_is_read_list">
<foreach name="common_is_read_list" item="v">
<option value="{{$v.id}}" <if condition="isset($params['is_read']) and $params['is_read'] eq $v['id']">selected</if>>{{$v.name}}</option>
</foreach>
</notempty>
</select>
</td>
<td>
<button type="submit" class="am-btn am-btn-primary am-radius am-btn-xs btn-loading-example" data-am-loading="{spinner:'circle-o-notch', loadingText:'搜索中...'}">搜索</button>
<a href="{{:U('Home/Message/Index')}}" class="am-btn am-btn-warning am-radius am-btn-sm reset-submit">清除条件</a>
</td>
</tr>
</tbody>
</table>
</form>
<!-- 消息列表 -->
<div class="data-list">
<table class="am-table">
<thead>
<tr>
<th>标题</th>
<th class="am-hide-sm-only">类型</th>
<th class="am-hide-sm-only">业务</th>
<th>详情</th>
<th class="am-hide-sm-only">状态</th>
<th class="am-hide-sm-only">时间</th>
</tr>
</thead>
<tbody>
<notempty name="data_list">
<foreach name="data_list" item="v">
<tr>
<td>{{$v.title}}</td>
<td class="am-hide-sm-only">{{$v.type_name}}</td>
<td class="am-hide-sm-only">{{$v.business_type_name}}</td>
<td>{{$v.detail}}</td>
<td class="am-hide-sm-only">{{$v.is_read_name}}</td>
<td class="am-hide-sm-only">{{$v.add_time_time}}</td>
</tr>
</foreach>
</notempty>
<empty name="data_list">
<tr>
<td colspan="5">
<div class="table-no"><i class="am-icon-warning"></i> {{:L('common_not_data_tips')}}</div>
</td>
</tr>
</empty>
</tbody>
</table>
</div>
<!-- 分页 -->
<notempty name="data_list">
{{$page_html}}
</notempty>
</div>
</div>
<!-- content end -->
</div>
<!-- footer start -->
<include file="Public/Footer" />
<!-- footer end -->

View File

@ -30,13 +30,13 @@
<button class="am-btn am-btn-default am-radius" type="submit" data-am-loading="{spinner:'circle-o-notch', loadingText:'搜索中...'}">搜索</button>
</span>
</div>
<label class="am-fl thin_sub">
<label class="am-fl thin_sub more-submit">
更多筛选条件
<input type="checkbox" name="is_more" value="1" class="none am-field-valid" <if condition="isset($params['is_more'])">checked</if> />
<i class="am-icon-angle-up"></i>
</label>
</div>
<table class="so-list <if condition="!isset($params['is_more'])">none</if>">
<table class="so-list more-where <if condition="!isset($params['is_more'])">none</if>">
<tbody>
<tr>
<td class="time">

View File

@ -64,7 +64,7 @@
<div class="top-nav-items top-nav-mini-cart">
<div class="menu-hd <if condition="empty($user)">login-event</if>">
<a id="mc-menu-hd" href="<if condition="empty($user)">javascript:;<else />{{:U('Home/Cart/Index')}}</if>" target="_top">
<i class="am-icon-shopping-cart am-icon-fw"></i>
<i class="am-icon-shopping-cart am-icon-fw"></i>
<span>购物车</span>
<if condition="$common_cart_total gt 0">
<strong class="am-badge am-badge-danger am-round common-cart-total">{{$common_cart_total}}</strong>
@ -74,6 +74,17 @@
</a>
</div>
</div>
<div class="top-nav-items top-nav-mini-cart">
<div class="menu-hd <if condition="empty($user)">login-event</if>">
<a id="mc-menu-hd" href="<if condition="empty($user)">javascript:;<else />{{:U('Home/Message/Index')}}</if>" target="_top">
<i class="am-icon-bell am-icon-fw"></i>
<span>消息</span>
<if condition="$common_message_total gt 0">
<strong class="am-badge am-badge-danger am-round common-cart-total">{{$common_message_total}}</strong>
</if>
</a>
</div>
</div>
</ul>
</div>
</div>

View File

@ -40,7 +40,7 @@
</div>
</div>
<div class="user-base-right">
<a href="{{:U('Home/Message/Index')}}" class="am-icon-bell-o message"> 消息</a>
<a href="{{:U('Home/Message/Index')}}" class="am-icon-bell-o message"> 消息 <if condition="$common_message_total gt 0">{{$common_message_total}}</if></a>
</div>
<ul class="user-base-icon">
<li>

View File

@ -81,7 +81,7 @@ class BuyService
$data['add_time'] = time();
if($m->add($data) > 0)
{
return DataReturn(L('common_join_success'), 0, self::CartTotal($params));
return DataReturn(L('common_join_success'), 0, self::UserCartTotal($params));
}
} else {
$data['upd_time'] = time();
@ -92,7 +92,7 @@ class BuyService
}
if($m->where($where)->save($data))
{
return DataReturn(L('common_join_success'), 0, self::CartTotal($params));
return DataReturn(L('common_join_success'), 0, self::UserCartTotal($params));
}
}
@ -217,7 +217,7 @@ class BuyService
];
if(M('Cart')->where($where)->delete())
{
return DataReturn(L('common_operation_delete_success'), 0, self::CartTotal($params));
return DataReturn(L('common_operation_delete_success'), 0, self::UserCartTotal($params));
}
return DataReturn(L('common_operation_delete_error'), -100);
}
@ -685,6 +685,20 @@ class BuyService
* @param [array] $params [输入参数]
*/
public static function CartTotal($params = [])
{
return (int) M('Cart')->where($where)->count();
}
/**
* 用户购物车总数
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function UserCartTotal($params = [])
{
// 请求参数
$p = [
@ -699,7 +713,7 @@ class BuyService
{
return 0;
}
return (int) M('Cart')->where(['user_id'=>$params['user']['id']])->count();
return self::CartTotal(['user_id'=>$params['user']['id']]);
}
}
?>

View File

@ -35,6 +35,7 @@ class MessageService
'business_type' => intval($business_type),
'business_id' => intval($business_id),
'type' => intval($type),
'is_read' => 0,
'add_time' => time(),
);
return M('Message')->add($data) > 0;
@ -49,7 +50,7 @@ class MessageService
* @desc description
* @param [array] $params [输入参数]
*/
public static function HomeMessgeListWhere($params = [])
public static function UserMessgeListWhere($params = [])
{
$where = [
'is_delete_time' => 0,
@ -70,7 +71,7 @@ class MessageService
if(!empty($params['keywords']))
{
$like_keywords = array('like', '%'.I('keywords').'%');
$like_keywords = array('like', '%'.$params['keywords'].'%');
$where[] = [
'title' => $like_keywords,
'detail' => $like_keywords,
@ -79,30 +80,30 @@ class MessageService
}
// 是否更多条件
if(I('is_more', 0) == 1)
if(isset($params['is_more']) && $params['is_more'] == 1)
{
// 等值
if(I('business_type', -1) > -1)
if(isset($params['business_type']) && $params['business_type'] > -1)
{
$where['business_type'] = intval(I('business_type', 0));
$where['business_type'] = intval($params['business_type']);
}
if(I('type', -1) > -1)
if(isset($params['type']) && $params['type'] > -1)
{
$where['type'] = intval(I('type', 0));
$where['type'] = intval($params['type']);
}
if(I('is_read', -1) > -1)
if(isset($params['is_read']) && $params['is_read'] > -1)
{
$where['is_read'] = intval(I('is_read', 0));
$where['is_read'] = intval($params['is_read']);
}
// 时间
if(!empty($_REQUEST['time_start']))
if(!empty($params['time_start']))
{
$where['add_time'][] = array('gt', strtotime(I('time_start')));
$where['add_time'][] = array('gt', strtotime($params['time_start']));
}
if(!empty($_REQUEST['time_end']))
if(!empty($params['time_end']))
{
$where['add_time'][] = array('lt', strtotime(I('time_end')));
$where['add_time'][] = array('lt', strtotime($params['time_end']));
}
}
@ -123,6 +124,33 @@ class MessageService
return (int) M('Message')->where($where)->count();
}
/**
* 用户消息总数
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-29
* @desc description
* @param [array] $params [输入参数]
*/
public static function UserMessageTotal($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'user',
'error_msg' => '用户信息有误',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
{
return 0;
}
return self::MessageTotal(self::UserMessgeListWhere($params));
}
/**
* 订单列表
* @author Devil
@ -184,9 +212,44 @@ class MessageService
// 业务类型
$v['business_type_name'] = $common_business_type_list[$v['business_type']]['name'];
// 时间
$v['add_time_time'] = date('Y-m-d H:i:s', $v['add_time']);
$v['add_time_date'] = date('Y-m-d', $v['add_time']);
}
}
return DataReturn('处理成功', 0, $data);
}
/**
* 消息更新未已读
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-10-15
* @desc description
* @param [array] $params [输入参数]
*/
public static function MessageRead($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'user',
'error_msg' => '用户信息有误',
]
];
$ret = params_checked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 更新用户未读消息为已读
$where = ['user_id'=>$params['user']['id'], 'is_read'=>0];
$ret = M('Message')->where($where)->save(['is_read'=>1]);
return DataReturn('处理成功', 0, $ret);
}
}
?>

View File

@ -329,7 +329,7 @@ class OrderService
'subject' => isset($params['pay']['subject']) ? $params['pay']['subject'] : '订单支付',
'payment' => $params['payment']['payment'],
'payment_name' => $params['payment']['name'],
'business_type' => 0,
'business_type' => 1,
'add_time' => time(),
];
M('PayLog')->add($pay_log_data);
@ -380,7 +380,7 @@ class OrderService
* @desc description
* @param [array] $params [输入参数]
*/
public static function HomeOrderListWhere($params = [])
public static function UserOrderListWhere($params = [])
{
$where = [
'is_delete_time' => 0,
@ -401,7 +401,7 @@ class OrderService
if(!empty($params['keywords']))
{
$like_keywords = array('like', '%'.I('keywords').'%');
$like_keywords = array('like', '%'.$params['keywords'].'%');
$where[] = [
'order_no' => $like_keywords,
'receive_name' => $like_keywords,
@ -411,46 +411,46 @@ class OrderService
}
// 是否更多条件
if(I('is_more', 0) == 1)
if(isset($params['is_more']) && $params['is_more'] == 1)
{
// 等值
if(I('payment_id', -1) > -1)
if(isset($pa['payment_id']) && $params['payment_id'] > -1)
{
$where['payment_id'] = intval(I('payment_id', 0));
$where['payment_id'] = intval($params['payment_id']);
}
if(I('pay_status', -1) > -1)
if(isset($pa['pay_status']) && $params['pay_status'] > -1)
{
$where['pay_status'] = intval(I('pay_status', 0));
$where['pay_status'] = intval($params['pay_status']);
}
if(I('status', -1) > -1)
if(isset($pa['status']) && $params['status'] > -1)
{
$where['status'] = intval(I('status', 0));
$where['status'] = intval($params['status']);
}
// 评价状态
if(I('is_comments', -1) > -1)
if(isset($pa['is_comments']) && $params['is_comments'] > -1)
{
$where['user_is_comments'] = (I('is_comments', 0) == 0) ? 0 : ['GT', 0];
}
// 时间
if(!empty($_REQUEST['time_start']))
if(!empty($params['time_start']))
{
$where['add_time'][] = array('gt', strtotime(I('time_start')));
$where['add_time'][] = array('gt', strtotime($params['time_start']));
}
if(!empty($_REQUEST['time_end']))
if(!empty($params['time_end']))
{
$where['add_time'][] = array('lt', strtotime(I('time_end')));
$where['add_time'][] = array('lt', strtotime($params['time_end']));
}
// 价格
if(!empty($_REQUEST['price_start']))
if(!empty($params['price_start']))
{
$where['price'][] = array('gt', floatval(I('price_start')));
$where['price'][] = array('gt', floatval($params['price_start']));
}
if(!empty($_REQUEST['price_end']))
if(!empty($params['price_end']))
{
$where['price'][] = array('lt', floatval(I('price_end')));
$where['price'][] = array('lt', floatval($params['price_end']));
}
}

View File

@ -0,0 +1,32 @@
/* 筛选 */
.thin, .pay-list { overflow:hidden; }
.thin .so { width:66%; }
.thin_sub { font-weight:100; margin:10px 0px 0px 10px; cursor: pointer; }
.so-list { width:100%; margin-top: 20px; }
.so-list * { font-size:1.2rem !important; }
.so-list input { height:28px; display:inline !important; }
.time input, .so-list .chosen-container { background:#FFF !important; }
.time input { width:100px !important; }
.time i { position:absolute; margin:4px 0px 0px -15px; }
.price input { width:101px !important; }
.time, .time { width:50%; }
.so-list tr+tr>td:first-child { padding-top:10px; }
.so-list .chosen-container { border-radius:2px; }
.text-grey { color: #999; }
.chosen-container-single .chosen-single, .so-list select { height: 28px; line-height: 28px; width: 100%; }
.reset-submit { margin-left: 20px; }
.so-list select { padding: 0 0 0 8px; }
@media only screen and (min-width: 641px){
.so-list .chosen-container, .so-list select { width:217px !important; display: -webkit-inline-box; }
.thin_sub:hover { color:#F60; }
}
@media only screen and (max-width: 641px){
.so-list input { width:40% !important; }
.so-list td { width:100%; display:block; }
.so-list tr td:last-child { margin-top:10px; }
.so-list .chosen-container { width:85%; }
.so-list .chosen-container { width:100%; }
.so-list tr td:last-child { padding-top:0px !important; }
.chosen-container-single .chosen-search input[type="text"] { width: 100% !important; }
.so-list select { width: calc(100% - 44px); display: -webkit-inline-box; }
}

View File

@ -28,7 +28,7 @@
.so-list .chosen-container { width:100%; }
.so-list tr td:last-child { padding-top:0px !important; }
.chosen-container-single .chosen-search input[type="text"] { width: 100% !important; }
.so-list select { width: calc(100% - 40px); display: -webkit-inline-box; }
.so-list select { width: calc(100% - 44px); display: -webkit-inline-box; }
}
/**

View File

@ -1,27 +1,5 @@
$(function()
{
/* 搜索切换 */
var $so_list = $('.so-list');
$thin_sub = $('.thin_sub');
$thin_sub.find('input[name="is_more"]').change(function()
{
if($thin_sub.find('i').hasClass('am-icon-angle-down'))
{
$thin_sub.find('i').removeClass('am-icon-angle-down');
$thin_sub.find('i').addClass('am-icon-angle-up');
} else {
$thin_sub.find('i').addClass('am-icon-angle-down');
$thin_sub.find('i').removeClass('am-icon-angle-up');
}
if($thin_sub.find('input[name="is_more"]:checked').val() == undefined)
{
$so_list.addClass('none');
} else {
$so_list.removeClass('none');
}
});
// 支付操作
$('.submit-pay').on('click', function()
{