作者 郭宇鹏
1 个管道 的构建 通过 耗费 0 秒

'12-29'

... ... @@ -76,7 +76,7 @@ class Article extends BaseApi
//6.查询数据
$article = model('article')->where('id',$article['id'])->find();
//7.获取关注自己的的用户id 并推送消息
$user_ids = model('user_attention')->where('in_user_id',$this->auth->id)->column('id');
$user_ids = model('user_attention')->where('in_user_id',$this->auth->id)->column('user_id');
if ($user_ids){
foreach ($user_ids as $val){
//增加消息
... ...
... ... @@ -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
... ...
... ... @@ -813,20 +813,20 @@ class Production extends BaseApi
$order->save();
//查询用户和动态
$user = model('user')->where('id',$order['user_id'])->find();
$article = model('production')->where('id',$order['production_id'])->find();
$production = model('production')->where('id',$order['production_id'])->find();
//给礼物用户一个通知
if ($user){
$str = empty($order['gift_id'])?'自定义礼物':$order['gift_name'];
$message = [
'user_id'=>$order['article_user_id'],
'user_id'=>$order['production_user_id'],
'in_user_id'=>$user['id'],
'avatar'=>$user['avatar'],
'nickname'=>$user['nickname'],
'title'=>$article['content'],
'brief'=>'用户:'.$this->auth->nickname.' 送给您的动态一个:'.$str,
'title'=>$production['title'],
'brief'=>'用户:'.$this->auth->nickname.' 送给您的作品一个:'.$str,
'status'=>3,
'is_stu'=>2,
'key_id'=>$article['id'],
'key_id'=>$production['id'],
];
model('message')->create($message);
}
... ...
此 diff 太大无法显示。