150 lines
5.9 KiB
PHP
150 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
use think\Db;
|
|
|
|
class UserMessage extends Model
|
|
{
|
|
|
|
//发送消息
|
|
public function send_message($uid, $type, $id, $title, $content)
|
|
{
|
|
$UserMessage = model('admin/UserMessage')->TypeLable();
|
|
if (empty($UserMessage[$type])) {
|
|
return ['code' => 201, 'msg' => '非法消息类型', 'data' => null];
|
|
}
|
|
$data = [];
|
|
$data['uid'] = $uid;
|
|
$data['type'] = $type;
|
|
$data['id'] = $id;
|
|
$data['title'] = $title;
|
|
$data['content'] = $content;
|
|
$data['is_read'] = 1;
|
|
$data['read_time'] = 0;
|
|
$data['add_time'] = time();
|
|
$data['update_time'] = time();
|
|
$reslut = Db::name('user_message')->insert($data);
|
|
if ($reslut) {
|
|
return ['code' => 200, 'msg' => '发送成功', 'data' => null];
|
|
} else {
|
|
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
|
}
|
|
}
|
|
//系统封面消息接口
|
|
public function get_user_message_cover_info($uid)
|
|
{
|
|
//获取系统消息
|
|
$map = [];
|
|
$map[] = ['uid', '=', $uid];
|
|
$map[] = ['is_read', '=', 1];
|
|
$map[] = ['type', '=', 1];
|
|
$system_no_read_count = db::name('user_message')->where($map)->count();
|
|
//获取最后一条未读系统消息
|
|
$system_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
|
|
|
//获取订单消息
|
|
$map = [];
|
|
$map[] = ['uid', '=', $uid];
|
|
$map[] = ['is_read', '=', 1];
|
|
$map[] = ['type', '=', 2];
|
|
$order_no_read_count = db::name('user_message')->where($map)->count();
|
|
//获取最后一条未读系统消息
|
|
$order_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
|
//获取互动消息未处理数量
|
|
|
|
$map = [];
|
|
$map[] = ['uid', '=', $uid];
|
|
$map[] = ['is_read', '=', 1];
|
|
$map[] = ['type', '=', 3];
|
|
$relation_no_read_count = db::name('user_message')->where($map)->count();
|
|
//获取最后一条未读系统消息
|
|
$relation_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
|
|
|
$map = [];
|
|
$map[] = ['uid', '=', $uid];
|
|
$map[] = ['is_read', '=', 1];
|
|
$map[] = ['type', '=',4];
|
|
$zone_no_read_count = db::name('user_message')->where($map)->count();
|
|
//获取最后一条未读系统消息
|
|
$zone_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
|
|
|
$data = [];
|
|
$data['system_no_read_count'] = $system_no_read_count;
|
|
$data['system_last_message'] = $system_last_message;
|
|
$data['order_no_read_count'] = $order_no_read_count;
|
|
$data['order_last_message'] = $order_last_message;
|
|
$data['relation_no_read_count'] = $relation_no_read_count;
|
|
$data['relation_last_message'] = $relation_last_message;
|
|
$data['zone_no_read_count'] = $zone_no_read_count;
|
|
$data['zone_last_message'] = $zone_last_message;
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
|
}
|
|
//消息列表接口
|
|
public function get_user_message_list($uid, $type, $page, $page_limit)
|
|
{
|
|
if (!in_array($type, [1, 2, 3])) {
|
|
return ['code' => 201, 'msg' => 'type非法参数', 'data' => null];
|
|
}
|
|
$page = intval($page);
|
|
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
|
|
|
$map = [];
|
|
$map[] = ['uid', '=', $uid];
|
|
$map[] = ['type', '=', $type];
|
|
$map[] = ['is_show', '=', 1];
|
|
|
|
//设置消息已读
|
|
$data = [];
|
|
$data['is_read'] = 2;
|
|
$data['read_time'] = time();
|
|
$data['update_time'] = time();
|
|
db::name('user_message')->where($map)->update($data);
|
|
|
|
//获取最后一条未读系统消息
|
|
$list = db::name('user_message')->field('mid,title,type,content,id,is_read,add_time')->where($map)->order('mid desc')->page($page, $page_limit)->select();
|
|
foreach ($list as $k => &$v) {
|
|
|
|
|
|
switch ($v['type']) {
|
|
case '2':
|
|
$map = [];
|
|
$map[] = ['oid', '=', $v['id']];
|
|
$play_order_info = db::name('user_player_order')->field('oid,order_sn,uid,player_uid,status,add_time,receive_time,complete_time,is_over,over_close_time')->where($map)->find();
|
|
if (!empty($play_order_info)) {
|
|
$play_order_info['is_player']=1;//非陪玩
|
|
if($uid==$play_order_info['player_uid']){
|
|
$play_order_info['is_player']=2;//陪玩
|
|
}
|
|
$v['data'] = $play_order_info;
|
|
}
|
|
break;
|
|
|
|
case '3':
|
|
$map = [];
|
|
$map[] = ['aid', '=', $v['id']];
|
|
$user_relation_apply_info = db::name('user_relation_apply')->field('aid,type,uid,recived_uid,status,deal_time')->where($map)->find();
|
|
if (!empty($user_relation_apply_info)) {
|
|
$v['data'] = $user_relation_apply_info;
|
|
}
|
|
break;
|
|
case '4':
|
|
$map = [];
|
|
$map[] = ['cid', '=', $v['id']];
|
|
$user_zone_comment_info = db::name('user_zone_comment')->field('cid,uid,recived_uid,content,add_time')->where($map)->find();
|
|
if (!empty($user_zone_comment_info)) {
|
|
$v['data'] = $user_zone_comment_info;
|
|
}
|
|
break;
|
|
default:
|
|
$v['data'] = [];
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
|
}
|
|
}
|