|
@@ -2,36 +2,64 @@
|
|
|
namespace app\newhome\controller;
|
|
|
|
|
|
use think\Controller;
|
|
|
-use app\user\model\User;
|
|
|
use app\user\model\Mail;
|
|
|
-use app\user\model\Notice;
|
|
|
+use app\user\model\ReadMail;
|
|
|
|
|
|
class Message extends Controller {
|
|
|
|
|
|
- private $userModel, $noticeModel, $mailModel;
|
|
|
+ private $readModel, $mailModel;
|
|
|
|
|
|
public function _initialize(){
|
|
|
parent::_initialize();
|
|
|
|
|
|
- $this->userModel = new User();
|
|
|
+ $this->readModel = new ReadMail();
|
|
|
$this->mailModel = new Mail();
|
|
|
- $this->noticeModel = new Notice();
|
|
|
}
|
|
|
|
|
|
- public function notice()
|
|
|
+ public function read()
|
|
|
{
|
|
|
+ $uid = $this->request->post('u', '1907239071686061468');
|
|
|
+ $mid = $this->request->post('i', 5);
|
|
|
|
|
|
+ $res = $this->readModel->where(['uid'=>$uid, 'mid'=>$mid])->find();
|
|
|
+ if (empty($res)) {
|
|
|
+ $this->readModel->save(['uid'=>$uid, 'mid'=>$mid]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return json(['error'=>0]);
|
|
|
}
|
|
|
|
|
|
public function mail(){
|
|
|
- $uid = $this->request->post('i', '1907239071686061468');
|
|
|
+ $uid = $this->request->post('u', '1907239071686061468');
|
|
|
+
|
|
|
+ // 找到用户的所有邮件
|
|
|
$res = $this->mailModel
|
|
|
- ->where(['is_del'=>0])
|
|
|
- ->where(['users'=>['like', "%{$uid}%"]])
|
|
|
- ->whereOr(['users'=>''])
|
|
|
- ->select();
|
|
|
- echo '<pre>';
|
|
|
- print_r(collection($res)->toArray());
|
|
|
+ ->where(['is_del'=>0])
|
|
|
+ ->where(function ($query) {
|
|
|
+ $uid = $this->request->post('u', '1907239071686061468');
|
|
|
+ $query->where(['users'=>['like', "%{$uid}%"]])->whereOr(['users'=>'']);
|
|
|
+ })
|
|
|
+ ->where(function ($query) {
|
|
|
+ $time = getCurrentTime();
|
|
|
+ $query->where(['begin'=>['<', $time]])->whereOr('begin', null);
|
|
|
+ })
|
|
|
+ ->where(function ($query) {
|
|
|
+ $time = getCurrentTime();
|
|
|
+ $query->where(['end'=>['>', $time]])->whereOr('end', null);
|
|
|
+ })
|
|
|
+ ->order('create_time', 'desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $read = $this->readModel->where(['uid'=>$uid])->column('mid');
|
|
|
+
|
|
|
+ foreach ($res as $key=>$val) {
|
|
|
+ if(in_array($val['id'], $read)) unset($res[$key]);
|
|
|
+
|
|
|
+ unset($val['users']);
|
|
|
+ unset($val['is_del']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return json(array_values($res));
|
|
|
}
|
|
|
|
|
|
|