2020-03-28 22:03:25 +08:00
|
|
|
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
use think\facade\Db;
|
|
|
|
use think\facade\Session;
|
|
|
|
use think\facade\Request;
|
|
|
|
use app\common\model\Message as MessageModel;
|
|
|
|
use app\common\model\MessageTo;
|
|
|
|
|
|
|
|
class Message
|
|
|
|
{
|
|
|
|
//send msg
|
|
|
|
public function sendMsg($sendId,$receveId,$data)
|
|
|
|
{
|
|
|
|
$msg = MessageModel::create($data);
|
|
|
|
$msgId = $msg->id;
|
|
|
|
$result = MessageTo::create(['send_id'=>$sendId,'receve_id'=>$receveId,'message_id'=>$msgId]);
|
|
|
|
if($result){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//receve msg
|
|
|
|
public function receveMsg($uid)
|
|
|
|
{
|
|
|
|
$msg = Db::name('message_to')
|
|
|
|
->alias('t')
|
|
|
|
->join('message m','t.message_id = m.id' )
|
|
|
|
->join('user u','t.send_id = u.id')
|
2020-03-29 19:57:18 +08:00
|
|
|
->field('t.id as id,name,title,link,receve_id,t.create_time as create_time,is_read')
|
2020-03-28 22:03:25 +08:00
|
|
|
->where('t.receve_id',$uid)
|
2020-03-29 20:23:52 +08:00
|
|
|
->where(['t.delete_time'=>0])
|
|
|
|
->order(['t.create_time'=>'desc'])
|
2020-03-28 22:03:25 +08:00
|
|
|
->select();
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|