123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\newhome\controller;
- use think\Controller;
- use app\user\model\Mail;
- use app\user\model\ReadMail;
- class Message extends Controller {
-
- private $readModel, $mailModel;
-
- public function _initialize(){
- parent::_initialize();
-
- $this->readModel = new ReadMail();
- $this->mailModel = new Mail();
- }
-
- 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('u', '1907239071686061468');
-
- // 找到用户的所有邮件
- $res = $this->mailModel
- ->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));
- }
-
-
- }
|