user = $user->data(); } /** * 获取我的消息 * * @return mixed */ public function read($uid, $type = false, $update = false, $status = false, $project = 1) { if (!$uid) { Dever::alert('错误的用户信息'); } $prefix = defined('DEVER_PROJECT') && DEVER_PROJECT != 'default' ? DEVER_PROJECT . '_' : ''; $outbox = $prefix . 'message_outbox'; $inbox = $prefix . 'message_inbox'; $where = ' and a.state = 1 and a.project_id = ' . $project; # 去掉a.type判断 $where .= ' and a.scope = 2'; # 这个是兼容历史版本 //$where .= ' (and a.type <= 10 || a.scope = 2)'; # 读取outbox里的数据 $sql = 'select a.name,a.content,a.id,a.type,a.uid,a.project_id,a.scope from '.$outbox.' as a where not exists(select oid from '.$inbox.' where a.id = oid and uid = '.$uid.')' . $where . ' '; $state = Dever::db('message/inbox')->query($sql); $outbox = $state->fetchAll(); if ($outbox) { foreach ($outbox as $k => $v) { $insert['add_uid'] = $uid; $insert['add_oid'] = $v['id']; $insert['add_status'] = 1; $insert['add_project_id'] = $v['project_id']; $insert['add_type'] = $v['type']; //$insert['add_site'] = $v['site']; $insert['add_from_uid'] = $v['uid']; $insert['add_name'] = $v['name']; $insert['add_scope'] = $v['scope']; $insert['add_content'] = $v['content']; Dever::load('message/inbox-insert', $insert); } } if ($project) { $param['option_project_id'] = $project; } if ($type) { $param['option_type'] = $type; } $param['option_uid'] = $uid; if ($status > 0) { $param['option_status'] = $status; return Dever::load('message/inbox-total', $param); } $data = Dever::load('message/inbox-getAll', $param); if ($update) { foreach ($data as $k => $v) { Dever::load('message/inbox-update', array('where_id' => $v['id'], 'set_status' => 2)); } } return $data; } /** * 查看我的新消息 * * @return mixed */ public function num($uid, $project = 1) { return $this->read($uid, false, false, 1, $project); } /** * 查看我的消息 * * @return mixed */ public function view($uid, $id) { if ($id > 0) { $info = Dever::load('message/inbox-one', array('option_uid' => $uid, 'option_id' => $id)); if ($info) { Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2)); $data = Dever::load('message/inbox-one', $id); return $data; } } Dever::alert('错误的消息信息'); } public function test_api() { $type = Dever::input('type', 1); $id = Dever::input('id', 1); $push = array('type' => $type, 'id' => $id); $push = json_encode($push); $uid = -1; $to_uid = Dever::input('uid', 7); $name = Dever::input('name', 'test'); $content = Dever::input('content', 'test'); $result = $this->push($uid, $to_uid, $name, $content, 11, 1, 1, $push); return 'ok'; } /** * 推送消息 * * @return mixed */ public function push($uid, $to_uid, $name, $content, $type = 11, $project = 1, $scope = false, $push = false, $id = -1) { if (!is_numeric($type)) { Dever::alert('错误的消息类型'); } $config = Dever::load('message/type-one', $type); if (!$config) { Dever::alert('错误的消息类型'); } if (!$content) { Dever::alert('错误的消息内容'); } if (!$scope) { $scope = $config['scope']; } if ($scope == 1 && !$uid) { Dever::alert('错误的发件人id'); } if ($scope == 1 && !$to_uid) { Dever::alert('错误的收件人id'); } if ($scope == 2) { $uid = -1; } if (is_numeric($uid)) { if ($id <= 0) { $data['add_uid'] = $uid; $data['add_name'] = $name; $data['add_content'] = $content; $data['add_type'] = $type; $data['add_scope'] = $scope; $data['add_project_id'] = $project; $id = Dever::load('message/outbox-insert', $data); } if ($id > 0) { if ($to_uid) { if (strstr($to_uid, ',')) { $to_uid = explode(',', $to_uid); } else { $to_uid = explode("\n", $to_uid); } foreach ($to_uid as $k => $v) { $insert['add_uid'] = $v; $insert['add_oid'] = $id; $insert['add_status'] = 1; $insert['add_type'] = $type; $insert['add_scope'] = $scope; $insert['add_project_id'] = $project; $insert['add_from_uid'] = $uid; $insert['add_name'] = $name; $insert['add_content'] = $content; //$insert['add_origin'] = $origin; Dever::load('message/inbox-insert', $insert); } } //这里可以设置发送push if (isset($config['push']) && $config['push'] > 0) { if ($scope == 2) { # 发送全部 $to_uid = array(); } Dever::load('message/lib/push')->send($config['push'], $to_uid, $name, $content, $push); //Dever::daemon('lib/push.send?', 'message'); } } } } }