...
|
...
|
@@ -3,12 +3,100 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
|
|
|
/**
|
|
|
* 消息相关
|
|
|
* @package app\api\controller
|
|
|
*/
|
|
|
class Message extends BaseApi
|
|
|
{
|
|
|
|
|
|
protected $noNeedLogin = '';
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
/**
|
|
|
* 获取用户总的未读消息
|
|
|
* @ApiTitle (获取用户总的未读消息)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/message/getIsReadNum)
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "请求数量成功",
|
|
|
"time": "1609323269",
|
|
|
"data": "获取用户总的未读消息"
|
|
|
})
|
|
|
*/
|
|
|
public function getIsReadNum(){
|
|
|
$count = model('message')->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
$this->success('请求数量成功',$count);
|
|
|
}
|
|
|
/**
|
|
|
* 分类获取用户的未读消息
|
|
|
* @ApiTitle (分类获取用户的未读消息)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/message/getTypeIsReadNum)
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "请求数量成功",
|
|
|
"time": "1609323546",
|
|
|
"data": {
|
|
|
"one": "收藏消息",
|
|
|
"two": "动态消息",
|
|
|
"three": "礼物消息",
|
|
|
"four": "通知消息"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function getTypeIsReadNum(){
|
|
|
$data = [];
|
|
|
$data['one'] = model('message')->where('status',1)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
$data['two'] = model('message')->where('status',2)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
$data['three'] = model('message')->where('status',3)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
$data['four'] = model('message')->where('status',4)->where('user_id',$this->auth->id)->where('is_read',0)->count();
|
|
|
$this->success('请求数量成功',$data);
|
|
|
}
|
|
|
/**
|
|
|
* 获取列表消息
|
|
|
* @ApiTitle (获取列表消息)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/message/getMessageList)
|
|
|
* @ApiParams (name="status", type="string", required=true, description="1=收藏2=动态3=礼物4=通知")
|
|
|
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
|
|
|
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ()
|
|
|
*/
|
|
|
public function getMessageList(){
|
|
|
//1.获取状态
|
|
|
$data = $this->get_data_array([
|
|
|
['status','状态不能为空'],
|
|
|
['page','分页次数不能为空'],
|
|
|
['num','分页数量不能为空'],
|
|
|
]);
|
|
|
//2.查询数据
|
|
|
$res = model('message')
|
|
|
->where('status',$data['status'])
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('is_read',0)
|
|
|
->order('createtime','desc')
|
|
|
->page($data['page'],$data['num'])
|
|
|
->select();
|
|
|
//3.将数据变为已读
|
|
|
model('message')
|
|
|
->where('status',$data['status'])
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('is_read',0)
|
|
|
->update(['is_read'=>1]);
|
|
|
$this->success('请求数据成功',$res);
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|